diff options
author | achuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-27 00:36:27 +0000 |
---|---|---|
committer | achuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-27 00:36:27 +0000 |
commit | 6a3daaa75ac807f9af7dd75cbb7e5e26b7e5bf95 (patch) | |
tree | 9110adc92b7762e4069fb4eaed9e8861602c2e58 /chrome/browser | |
parent | 8f10d9b3bef691ee7daa0c9f876382b25e3a8746 (diff) | |
download | chromium_src-6a3daaa75ac807f9af7dd75cbb7e5e26b7e5bf95.zip chromium_src-6a3daaa75ac807f9af7dd75cbb7e5e26b7e5bf95.tar.gz chromium_src-6a3daaa75ac807f9af7dd75cbb7e5e26b7e5bf95.tar.bz2 |
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
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/chromeos/cros/mount_library.cc | 5 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros/mount_library.h | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/dom_ui/imageburner_ui.cc | 259 | ||||
-rw-r--r-- | chrome/browser/chromeos/dom_ui/imageburner_ui.h | 49 |
4 files changed, 155 insertions, 160 deletions
diff --git a/chrome/browser/chromeos/cros/mount_library.cc b/chrome/browser/chromeos/cros/mount_library.cc index 68bc53c..552ceaa 100644 --- a/chrome/browser/chromeos/cros/mount_library.cc +++ b/chrome/browser/chromeos/cros/mount_library.cc @@ -39,6 +39,10 @@ class MountLibraryImpl : public MountLibrary { return MountDevicePath(device_path); } + bool IsBootPath(const char* device_path) { + return IsBootDevicePath(device_path); + } + const DiskVector& disks() const { return disks_; } private: @@ -124,6 +128,7 @@ class MountLibraryStubImpl : public MountLibrary { virtual void RemoveObserver(Observer* observer) {} virtual const DiskVector& disks() const { return disks_; } virtual bool MountPath(const char* device_path) { return false; } + virtual bool IsBootPath(const char* device_path) { return true; } private: // The list of disks found. diff --git a/chrome/browser/chromeos/cros/mount_library.h b/chrome/browser/chromeos/cros/mount_library.h index 21b1dac..2b0fefe 100644 --- a/chrome/browser/chromeos/cros/mount_library.h +++ b/chrome/browser/chromeos/cros/mount_library.h @@ -49,6 +49,7 @@ class MountLibrary { class Observer { public: + virtual ~Observer() {} virtual void MountChanged(MountLibrary* obj, MountEventType evt, const std::string& path) = 0; @@ -59,6 +60,7 @@ class MountLibrary { virtual void RemoveObserver(Observer* observer) = 0; virtual const DiskVector& disks() const = 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. // For normal usage, access the singleton via CrosLibrary::Get(). diff --git a/chrome/browser/chromeos/dom_ui/imageburner_ui.cc b/chrome/browser/chromeos/dom_ui/imageburner_ui.cc index fefee0a..e5b9e4f 100644 --- a/chrome/browser/chromeos/dom_ui/imageburner_ui.cc +++ b/chrome/browser/chromeos/dom_ui/imageburner_ui.cc @@ -28,65 +28,142 @@ #include "ui/base/l10n/l10n_util.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() - : DataSource(chrome::kChromeUIImageBurnerHost, MessageLoop::current()) { -} - -void ImageBurnUIHTMLSource::StartDataRequest(const std::string& path, - bool is_off_the_record, - int request_id) { - DictionaryValue localized_strings; - localized_strings.SetString("burnConfirmText1", - l10n_util::GetStringUTF16(IDS_IMAGEBURN_CONFIM_BURN1)); - localized_strings.SetString("burnConfirmText2", - l10n_util::GetStringUTF16(IDS_IMAGEBURN_CONFIM_BURN2)); - localized_strings.SetString("burnUnsuccessfulMessage", - l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_UNSUCCESSFUL)); - localized_strings.SetString("burnSuccessfulMessage", - l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_SUCCESSFUL)); - localized_strings.SetString("downloadAbortedMessage", - l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_UNSUCCESSFUL)); - localized_strings.SetString("title", - l10n_util::GetStringUTF16(IDS_IMAGEBURN_TITLE)); - localized_strings.SetString("listTitle", - l10n_util::GetStringUTF16(IDS_IMAGEBURN_ROOT_LIST_TITLE)); - localized_strings.SetString("downloadStatusStart", - l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_STARTING_STATUS)); - localized_strings.SetString("downloadStatusInProgress", - l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_IN_PROGRESS_STATUS)); - localized_strings.SetString("downloadStatusComplete", - l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_COMPLETE_STATUS)); - localized_strings.SetString("downloadStatusCanceled", - l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_CANCELED_STATUS)); - localized_strings.SetString("burnStatusStart", - l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_STARTING_STATUS)); - localized_strings.SetString("burnStatusInProgress", - l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_IN_PROGRESS_STATUS)); - localized_strings.SetString("burnStatusComplete", - l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_COMPLETE_STATUS)); - localized_strings.SetString("burnStatusCanceled", - l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_CANCELED_STATUS)); - - SetFontAndTextDirection(&localized_strings); - - static const base::StringPiece imageburn_html( - ResourceBundle::GetSharedInstance().GetRawDataResource( - IDR_IMAGEBURNER_HTML)); - const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( - imageburn_html, &localized_strings); - - 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); -} +class ImageBurnUIHTMLSource : public ChromeURLDataManager::DataSource { + public: + ImageBurnUIHTMLSource() + : DataSource(chrome::kChromeUIImageBurnerHost, MessageLoop::current()) { + } + + // 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) { + DictionaryValue localized_strings; + localized_strings.SetString("burnConfirmText1", + l10n_util::GetStringUTF16(IDS_IMAGEBURN_CONFIM_BURN1)); + localized_strings.SetString("burnConfirmText2", + l10n_util::GetStringUTF16(IDS_IMAGEBURN_CONFIM_BURN2)); + localized_strings.SetString("burnUnsuccessfulMessage", + l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_UNSUCCESSFUL)); + localized_strings.SetString("burnSuccessfulMessage", + l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_SUCCESSFUL)); + localized_strings.SetString("downloadAbortedMessage", + l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_UNSUCCESSFUL)); + localized_strings.SetString("title", + l10n_util::GetStringUTF16(IDS_IMAGEBURN_TITLE)); + localized_strings.SetString("listTitle", + l10n_util::GetStringUTF16(IDS_IMAGEBURN_ROOT_LIST_TITLE)); + localized_strings.SetString("downloadStatusStart", + l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_STARTING_STATUS)); + localized_strings.SetString("downloadStatusInProgress", + l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_IN_PROGRESS_STATUS)); + localized_strings.SetString("downloadStatusComplete", + l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_COMPLETE_STATUS)); + localized_strings.SetString("downloadStatusCanceled", + l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_CANCELED_STATUS)); + localized_strings.SetString("burnStatusStart", + l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_STARTING_STATUS)); + localized_strings.SetString("burnStatusInProgress", + l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_IN_PROGRESS_STATUS)); + localized_strings.SetString("burnStatusComplete", + l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_COMPLETE_STATUS)); + localized_strings.SetString("burnStatusCanceled", + l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_CANCELED_STATUS)); + + SetFontAndTextDirection(&localized_strings); + + static const base::StringPiece imageburn_html( + ResourceBundle::GetSharedInstance().GetRawDataResource( + IDR_IMAGEBURNER_HTML)); + const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( + imageburn_html, &localized_strings); + + 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) { } void ImageBurnHandler::ModelChanged() { + // Find our item and observe it. std::vector<DownloadItem*> downloads; download_manager_->GetTemporaryDownloads( burn_resource_manager_->GetLocalImageDirPath(), &downloads); - if (download_item_observer_added_) + if (download_item_observer_added_) // Already added. return; std::vector<DownloadItem*>::const_iterator it = downloads.begin(); 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; (*it)->AddObserver(this); active_download_item_ = *it; @@ -213,18 +292,20 @@ void ImageBurnHandler::HandleGetRoots(const ListValue* args) { if (!burn_resource_manager_->CheckBurnInProgress()) { for (size_t i = 0; i < disks.size(); ++i) { if (!disks[i].mount_path.empty()) { - DictionaryValue* page_value = new DictionaryValue(); FilePath disk_path = FilePath(disks[i].system_path).DirName(); std::string title = "/dev/" + disk_path.BaseName().value(); - page_value->SetString(kPropertyTitle, title); - page_value->SetString(kPropertyPath, title); - page_value->SetBoolean(kPropertyDirectory, true); - results_value.Append(page_value); + if (!mount_lib->IsBootPath(title.c_str())) { + DictionaryValue* page_value = new DictionaryValue(); + page_value->SetString(std::string(kPropertyTitle), title); + 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(kPropertyPath, ""); + info_value.SetString(std::string(kPropertyPath), ""); dom_ui_->CallJavascriptFunction(L"browseFileResult", info_value, results_value); } @@ -282,10 +363,8 @@ void ImageBurnHandler::BurnImage() { void ImageBurnHandler::FinalizeBurn(bool successful) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (successful) - dom_ui_->CallJavascriptFunction(L"burnSuccessful"); - else - dom_ui_->CallJavascriptFunction(L"burnUnsuccessful"); + dom_ui_->CallJavascriptFunction(successful ? + L"burnSuccessful" : L"burnUnsuccessful"); } void ImageBurnHandler::UpdateBurnProgress(int64 total_burnt, @@ -392,48 +471,6 @@ void ImageBurnHandler::CreateLocalImagePath() { //////////////////////////////////////////////////////////////////////////////// // -// 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 // //////////////////////////////////////////////////////////////////////////////// @@ -445,10 +482,10 @@ ImageBurnResourceManager::ImageBurnResourceManager() download_manager_(NULL), download_item_observer_added_(false), active_download_item_(NULL), - image_url_(NULL), - image_fetcher_url_(kImageBaseURL + kImageFetcherName), + image_url_(new GURL(kImageDownloadURL)), + image_fetcher_url_(std::string(kImageBaseURL) + kImageFetcherName), image_url_fetching_requested_(false), - image_url_fetched_(false) { + image_url_fetched_(true) { local_image_dir_file_path_.clear(); image_fecher_local_path_ = GetLocalImageDirPath().Append(kImageFetcherName); } @@ -480,7 +517,7 @@ void ImageBurnResourceManager::OnDownloadFileCompleted(DownloadItem* download) { DCHECK(download->state() == DownloadItem::COMPLETE); std::string 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); } else { image_url_.reset(); diff --git a/chrome/browser/chromeos/dom_ui/imageburner_ui.h b/chrome/browser/chromeos/dom_ui/imageburner_ui.h index c3d6d47..b4d9130 100644 --- a/chrome/browser/chromeos/dom_ui/imageburner_ui.h +++ b/chrome/browser/chromeos/dom_ui/imageburner_ui.h @@ -28,37 +28,9 @@ 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 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, public chromeos::MountLibrary::Observer, public chromeos::BurnLibrary::Observer, @@ -137,27 +109,6 @@ class ImageBurnHandler : public DOMMessageHandler, 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, public DownloadItem::Observer { public: |