Commit 6a3daaa7 authored by achuith@chromium.org's avatar achuith@chromium.org

Add IsBootPath to MountLibrary. Additional boot path check in imageburner so...

Add IsBootPath to MountLibrary. Additional boot path check in imageburner so boot drive is not presented as a target.
BUG=chromium-os:6788
TEST=chrome://imageburner should not display /dev/sda

Review URL: http://codereview.chromium.org/6348006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72733 0039d316-1c4b-4281-b951-d872f2087c98
parent 8f10d9b3
...@@ -39,6 +39,10 @@ class MountLibraryImpl : public MountLibrary { ...@@ -39,6 +39,10 @@ class MountLibraryImpl : public MountLibrary {
return MountDevicePath(device_path); return MountDevicePath(device_path);
} }
bool IsBootPath(const char* device_path) {
return IsBootDevicePath(device_path);
}
const DiskVector& disks() const { return disks_; } const DiskVector& disks() const { return disks_; }
private: private:
...@@ -124,6 +128,7 @@ class MountLibraryStubImpl : public MountLibrary { ...@@ -124,6 +128,7 @@ class MountLibraryStubImpl : public MountLibrary {
virtual void RemoveObserver(Observer* observer) {} virtual void RemoveObserver(Observer* observer) {}
virtual const DiskVector& disks() const { return disks_; } virtual const DiskVector& disks() const { return disks_; }
virtual bool MountPath(const char* device_path) { return false; } virtual bool MountPath(const char* device_path) { return false; }
virtual bool IsBootPath(const char* device_path) { return true; }
private: private:
// The list of disks found. // The list of disks found.
......
...@@ -49,6 +49,7 @@ class MountLibrary { ...@@ -49,6 +49,7 @@ class MountLibrary {
class Observer { class Observer {
public: public:
virtual ~Observer() {}
virtual void MountChanged(MountLibrary* obj, virtual void MountChanged(MountLibrary* obj,
MountEventType evt, MountEventType evt,
const std::string& path) = 0; const std::string& path) = 0;
...@@ -59,6 +60,7 @@ class MountLibrary { ...@@ -59,6 +60,7 @@ class MountLibrary {
virtual void RemoveObserver(Observer* observer) = 0; virtual void RemoveObserver(Observer* observer) = 0;
virtual const DiskVector& disks() const = 0; virtual const DiskVector& disks() const = 0;
virtual bool MountPath(const char* device_path) = 0; virtual bool MountPath(const char* device_path) = 0;
virtual bool IsBootPath(const char* device_path) = 0;
// Factory function, creates a new instance and returns ownership. // Factory function, creates a new instance and returns ownership.
// For normal usage, access the singleton via CrosLibrary::Get(). // For normal usage, access the singleton via CrosLibrary::Get().
......
...@@ -28,65 +28,142 @@ ...@@ -28,65 +28,142 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
static const char kPropertyPath[] = "path";
static const char kPropertyTitle[] = "title";
static const char kPropertyDirectory[] = "isDirectory";
static const char kImageBaseURL[] =
"http://chrome-master.mtv.corp.google.com/chromeos/dev-channel/";
static const char kImageFetcherName[] = "LATEST-x86-generic";
static const char kImageDownloadURL[] =
"https://dl.google.com/dl/chromeos/recovery/latest_mario_beta_channel";
static const char kImageFileName[] = "chromeos_image.bin.zip";
static const char kTempImageFolderName[] = "chromeos_image";
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
// ImageBurnUIHTMLSource // ImageBurnUIHTMLSource
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ImageBurnUIHTMLSource::ImageBurnUIHTMLSource() class ImageBurnUIHTMLSource : public ChromeURLDataManager::DataSource {
: DataSource(chrome::kChromeUIImageBurnerHost, MessageLoop::current()) { public:
} ImageBurnUIHTMLSource()
: DataSource(chrome::kChromeUIImageBurnerHost, MessageLoop::current()) {
void ImageBurnUIHTMLSource::StartDataRequest(const std::string& path, }
bool is_off_the_record,
int request_id) { // Called when the network layer has requested a resource underneath
DictionaryValue localized_strings; // the path we registered.
localized_strings.SetString("burnConfirmText1", virtual void StartDataRequest(const std::string& path,
l10n_util::GetStringUTF16(IDS_IMAGEBURN_CONFIM_BURN1)); bool is_off_the_record,
localized_strings.SetString("burnConfirmText2", int request_id) {
l10n_util::GetStringUTF16(IDS_IMAGEBURN_CONFIM_BURN2)); DictionaryValue localized_strings;
localized_strings.SetString("burnUnsuccessfulMessage", localized_strings.SetString("burnConfirmText1",
l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_UNSUCCESSFUL)); l10n_util::GetStringUTF16(IDS_IMAGEBURN_CONFIM_BURN1));
localized_strings.SetString("burnSuccessfulMessage", localized_strings.SetString("burnConfirmText2",
l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_SUCCESSFUL)); l10n_util::GetStringUTF16(IDS_IMAGEBURN_CONFIM_BURN2));
localized_strings.SetString("downloadAbortedMessage", localized_strings.SetString("burnUnsuccessfulMessage",
l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_UNSUCCESSFUL)); l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_UNSUCCESSFUL));
localized_strings.SetString("title", localized_strings.SetString("burnSuccessfulMessage",
l10n_util::GetStringUTF16(IDS_IMAGEBURN_TITLE)); l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_SUCCESSFUL));
localized_strings.SetString("listTitle", localized_strings.SetString("downloadAbortedMessage",
l10n_util::GetStringUTF16(IDS_IMAGEBURN_ROOT_LIST_TITLE)); l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_UNSUCCESSFUL));
localized_strings.SetString("downloadStatusStart", localized_strings.SetString("title",
l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_STARTING_STATUS)); l10n_util::GetStringUTF16(IDS_IMAGEBURN_TITLE));
localized_strings.SetString("downloadStatusInProgress", localized_strings.SetString("listTitle",
l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_IN_PROGRESS_STATUS)); l10n_util::GetStringUTF16(IDS_IMAGEBURN_ROOT_LIST_TITLE));
localized_strings.SetString("downloadStatusComplete", localized_strings.SetString("downloadStatusStart",
l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_COMPLETE_STATUS)); l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_STARTING_STATUS));
localized_strings.SetString("downloadStatusCanceled", localized_strings.SetString("downloadStatusInProgress",
l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_CANCELED_STATUS)); l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_IN_PROGRESS_STATUS));
localized_strings.SetString("burnStatusStart", localized_strings.SetString("downloadStatusComplete",
l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_STARTING_STATUS)); l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_COMPLETE_STATUS));
localized_strings.SetString("burnStatusInProgress", localized_strings.SetString("downloadStatusCanceled",
l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_IN_PROGRESS_STATUS)); l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_CANCELED_STATUS));
localized_strings.SetString("burnStatusComplete", localized_strings.SetString("burnStatusStart",
l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_COMPLETE_STATUS)); l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_STARTING_STATUS));
localized_strings.SetString("burnStatusCanceled", localized_strings.SetString("burnStatusInProgress",
l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_CANCELED_STATUS)); l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_IN_PROGRESS_STATUS));
localized_strings.SetString("burnStatusComplete",
SetFontAndTextDirection(&localized_strings); l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_COMPLETE_STATUS));
localized_strings.SetString("burnStatusCanceled",
static const base::StringPiece imageburn_html( l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_CANCELED_STATUS));
ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_IMAGEBURNER_HTML)); SetFontAndTextDirection(&localized_strings);
const std::string full_html = jstemplate_builder::GetI18nTemplateHtml(
imageburn_html, &localized_strings); static const base::StringPiece imageburn_html(
ResourceBundle::GetSharedInstance().GetRawDataResource(
scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); IDR_IMAGEBURNER_HTML));
html_bytes->data.resize(full_html.size()); const std::string full_html = jstemplate_builder::GetI18nTemplateHtml(
std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); imageburn_html, &localized_strings);
SendResponse(request_id, html_bytes); scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
} html_bytes->data.resize(full_html.size());
std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
SendResponse(request_id, html_bytes);
}
virtual std::string GetMimeType(const std::string&) const {
return "text/html";
}
private:
virtual ~ImageBurnUIHTMLSource() {}
DISALLOW_COPY_AND_ASSIGN(ImageBurnUIHTMLSource);
};
////////////////////////////////////////////////////////////////////////////////
//
// ImageBurnTaskProxy
//
////////////////////////////////////////////////////////////////////////////////
class ImageBurnTaskProxy
: public base::RefCountedThreadSafe<ImageBurnTaskProxy> {
public:
explicit ImageBurnTaskProxy(const base::WeakPtr<ImageBurnHandler>& handler)
: handler_(handler) {
resource_manager_ = ImageBurnResourceManager::GetInstance();
}
bool ReportDownloadInitialized() {
bool initialized = resource_manager_-> CheckImageDownloadStarted();
if (!initialized)
resource_manager_-> ReportImageDownloadStarted();
return initialized;
}
bool CheckDownloadFinished() {
return resource_manager_->CheckDownloadFinished();
}
void BurnImage() {
if (!resource_manager_->CheckBurnInProgress() && handler_) {
resource_manager_->SetBurnInProgress(true);
handler_->BurnImage();
}
}
void FinalizeBurn(bool success) {
if (handler_) {
handler_->FinalizeBurn(success);
resource_manager_->SetBurnInProgress(false);
}
}
void CreateImageUrl(TabContents* tab_contents, ImageBurnHandler* downloader) {
resource_manager_->CreateImageUrl(tab_contents, downloader);
}
private:
base::WeakPtr<ImageBurnHandler> handler_;
ImageBurnResourceManager* resource_manager_;
friend class base::RefCountedThreadSafe<ImageBurnTaskProxy>;
DISALLOW_COPY_AND_ASSIGN(ImageBurnTaskProxy);
};
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
...@@ -188,14 +265,16 @@ void ImageBurnHandler::OnDownloadOpened(DownloadItem* download) { ...@@ -188,14 +265,16 @@ void ImageBurnHandler::OnDownloadOpened(DownloadItem* download) {
} }
void ImageBurnHandler::ModelChanged() { void ImageBurnHandler::ModelChanged() {
// Find our item and observe it.
std::vector<DownloadItem*> downloads; std::vector<DownloadItem*> downloads;
download_manager_->GetTemporaryDownloads( download_manager_->GetTemporaryDownloads(
burn_resource_manager_->GetLocalImageDirPath(), &downloads); burn_resource_manager_->GetLocalImageDirPath(), &downloads);
if (download_item_observer_added_) if (download_item_observer_added_) // Already added.
return; return;
std::vector<DownloadItem*>::const_iterator it = downloads.begin(); std::vector<DownloadItem*>::const_iterator it = downloads.begin();
for (; it != downloads.end(); ++it) { for (; it != downloads.end(); ++it) {
if ((*it)->url() == *image_download_url_) { if ((*it)->original_url() == *image_download_url_) {
// Found it.
download_item_observer_added_ = true; download_item_observer_added_ = true;
(*it)->AddObserver(this); (*it)->AddObserver(this);
active_download_item_ = *it; active_download_item_ = *it;
...@@ -213,18 +292,20 @@ void ImageBurnHandler::HandleGetRoots(const ListValue* args) { ...@@ -213,18 +292,20 @@ void ImageBurnHandler::HandleGetRoots(const ListValue* args) {
if (!burn_resource_manager_->CheckBurnInProgress()) { if (!burn_resource_manager_->CheckBurnInProgress()) {
for (size_t i = 0; i < disks.size(); ++i) { for (size_t i = 0; i < disks.size(); ++i) {
if (!disks[i].mount_path.empty()) { if (!disks[i].mount_path.empty()) {
DictionaryValue* page_value = new DictionaryValue();
FilePath disk_path = FilePath(disks[i].system_path).DirName(); FilePath disk_path = FilePath(disks[i].system_path).DirName();
std::string title = "/dev/" + disk_path.BaseName().value(); std::string title = "/dev/" + disk_path.BaseName().value();
page_value->SetString(kPropertyTitle, title); if (!mount_lib->IsBootPath(title.c_str())) {
page_value->SetString(kPropertyPath, title); DictionaryValue* page_value = new DictionaryValue();
page_value->SetBoolean(kPropertyDirectory, true); page_value->SetString(std::string(kPropertyTitle), title);
results_value.Append(page_value); page_value->SetString(std::string(kPropertyPath), title);
page_value->SetBoolean(std::string(kPropertyDirectory), true);
results_value.Append(page_value);
}
} }
} }
} }
info_value.SetString("functionCall", "getRoots"); info_value.SetString("functionCall", "getRoots");
info_value.SetString(kPropertyPath, ""); info_value.SetString(std::string(kPropertyPath), "");
dom_ui_->CallJavascriptFunction(L"browseFileResult", dom_ui_->CallJavascriptFunction(L"browseFileResult",
info_value, results_value); info_value, results_value);
} }
...@@ -282,10 +363,8 @@ void ImageBurnHandler::BurnImage() { ...@@ -282,10 +363,8 @@ void ImageBurnHandler::BurnImage() {
void ImageBurnHandler::FinalizeBurn(bool successful) { void ImageBurnHandler::FinalizeBurn(bool successful) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (successful) dom_ui_->CallJavascriptFunction(successful ?
dom_ui_->CallJavascriptFunction(L"burnSuccessful"); L"burnSuccessful" : L"burnUnsuccessful");
else
dom_ui_->CallJavascriptFunction(L"burnUnsuccessful");
} }
void ImageBurnHandler::UpdateBurnProgress(int64 total_burnt, void ImageBurnHandler::UpdateBurnProgress(int64 total_burnt,
...@@ -390,48 +469,6 @@ void ImageBurnHandler::CreateLocalImagePath() { ...@@ -390,48 +469,6 @@ void ImageBurnHandler::CreateLocalImagePath() {
burn_resource_manager_->GetLocalImageDirPath().Append(kImageFileName); burn_resource_manager_->GetLocalImageDirPath().Append(kImageFileName);
} }
////////////////////////////////////////////////////////////////////////////////
//
// ImageBurnTaskProxy
//
////////////////////////////////////////////////////////////////////////////////
ImageBurnTaskProxy::ImageBurnTaskProxy(
const base::WeakPtr<ImageBurnHandler>& handler)
: handler_(handler) {
resource_manager_ = ImageBurnResourceManager::GetInstance();
}
bool ImageBurnTaskProxy::ReportDownloadInitialized() {
bool initialized = resource_manager_-> CheckImageDownloadStarted();
if (!initialized)
resource_manager_-> ReportImageDownloadStarted();
return initialized;
}
bool ImageBurnTaskProxy::CheckDownloadFinished() {
return resource_manager_->CheckDownloadFinished();
}
void ImageBurnTaskProxy:: BurnImage() {
if (!resource_manager_->CheckBurnInProgress() && handler_) {
resource_manager_->SetBurnInProgress(true);
handler_->BurnImage();
}
}
void ImageBurnTaskProxy::FinalizeBurn(bool success) {
if (handler_) {
handler_->FinalizeBurn(success);
resource_manager_->SetBurnInProgress(false);
}
}
void ImageBurnTaskProxy::CreateImageUrl(TabContents* tab_contents,
ImageBurnHandler* downloader) {
resource_manager_->CreateImageUrl(tab_contents, downloader);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
// ImageBurnResourceManager // ImageBurnResourceManager
...@@ -445,10 +482,10 @@ ImageBurnResourceManager::ImageBurnResourceManager() ...@@ -445,10 +482,10 @@ ImageBurnResourceManager::ImageBurnResourceManager()
download_manager_(NULL), download_manager_(NULL),
download_item_observer_added_(false), download_item_observer_added_(false),
active_download_item_(NULL), active_download_item_(NULL),
image_url_(NULL), image_url_(new GURL(kImageDownloadURL)),
image_fetcher_url_(kImageBaseURL + kImageFetcherName), image_fetcher_url_(std::string(kImageBaseURL) + kImageFetcherName),
image_url_fetching_requested_(false), image_url_fetching_requested_(false),
image_url_fetched_(false) { image_url_fetched_(true) {
local_image_dir_file_path_.clear(); local_image_dir_file_path_.clear();
image_fecher_local_path_ = GetLocalImageDirPath().Append(kImageFetcherName); image_fecher_local_path_ = GetLocalImageDirPath().Append(kImageFetcherName);
} }
...@@ -480,7 +517,7 @@ void ImageBurnResourceManager::OnDownloadFileCompleted(DownloadItem* download) { ...@@ -480,7 +517,7 @@ void ImageBurnResourceManager::OnDownloadFileCompleted(DownloadItem* download) {
DCHECK(download->state() == DownloadItem::COMPLETE); DCHECK(download->state() == DownloadItem::COMPLETE);
std::string image_url; std::string image_url;
if (file_util::ReadFileToString(image_fecher_local_path_, &image_url)) { if (file_util::ReadFileToString(image_fecher_local_path_, &image_url)) {
image_url_.reset(new GURL(kImageBaseURL + image_url)); image_url_.reset(new GURL(std::string(kImageBaseURL) + image_url));
ImageUrlFetched(true); ImageUrlFetched(true);
} else { } else {
image_url_.reset(); image_url_.reset();
......
...@@ -28,37 +28,9 @@ ...@@ -28,37 +28,9 @@
template <typename T> struct DefaultSingletonTraits; template <typename T> struct DefaultSingletonTraits;
static const std::string kPropertyPath = "path";
static const std::string kPropertyTitle = "title";
static const std::string kPropertyDirectory = "isDirectory";
static const std::string kImageBaseURL =
"http://chrome-master.mtv.corp.google.com/chromeos/dev-channel/";
static const std::string kImageFetcherName = "LATEST-x86-generic";
static const std::string kImageFileName = "chromeos_image.bin.gz";
static const std::string kTempImageFolderName = "chromeos_image";
class ImageBurnResourceManager; class ImageBurnResourceManager;
class TabContents; class TabContents;
class ImageBurnUIHTMLSource : public ChromeURLDataManager::DataSource {
public:
ImageBurnUIHTMLSource();
// Called when the network layer has requested a resource underneath
// the path we registered.
virtual void StartDataRequest(const std::string& path,
bool is_off_the_record,
int request_id);
virtual std::string GetMimeType(const std::string&) const {
return "text/html";
}
private:
~ImageBurnUIHTMLSource() {}
DISALLOW_COPY_AND_ASSIGN(ImageBurnUIHTMLSource);
};
class ImageBurnHandler : public DOMMessageHandler, class ImageBurnHandler : public DOMMessageHandler,
public chromeos::MountLibrary::Observer, public chromeos::MountLibrary::Observer,
public chromeos::BurnLibrary::Observer, public chromeos::BurnLibrary::Observer,
...@@ -137,27 +109,6 @@ class ImageBurnHandler : public DOMMessageHandler, ...@@ -137,27 +109,6 @@ class ImageBurnHandler : public DOMMessageHandler,
DISALLOW_COPY_AND_ASSIGN(ImageBurnHandler); DISALLOW_COPY_AND_ASSIGN(ImageBurnHandler);
}; };
class ImageBurnTaskProxy
: public base::RefCountedThreadSafe<ImageBurnTaskProxy> {
public:
explicit ImageBurnTaskProxy(const base::WeakPtr<ImageBurnHandler>& handler);
bool ReportDownloadInitialized();
bool CheckDownloadFinished();
void BurnImage();
void FinalizeBurn(bool success);
void CreateImageUrl(TabContents* tab_contents, ImageBurnHandler* downloader);
private:
base::WeakPtr<ImageBurnHandler> handler_;
ImageBurnResourceManager* resource_manager_;
friend class base::RefCountedThreadSafe<ImageBurnTaskProxy>;
DISALLOW_COPY_AND_ASSIGN(ImageBurnTaskProxy);
};
class ImageBurnResourceManager : public DownloadManager::Observer, class ImageBurnResourceManager : public DownloadManager::Observer,
public DownloadItem::Observer { public DownloadItem::Observer {
public: public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment