diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-31 18:03:50 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-31 18:03:50 +0000 |
commit | 814e87b6e5236aaa38d97a9e2b2e9e6a4bae2c59 (patch) | |
tree | 9f22b67ac44e86bec6ab4df7334dbff0c55f719a /chrome/browser/download | |
parent | f35b200b5ac84762a2bb1c266ab6c960ea16f20e (diff) | |
download | chromium_src-814e87b6e5236aaa38d97a9e2b2e9e6a4bae2c59.zip chromium_src-814e87b6e5236aaa38d97a9e2b2e9e6a4bae2c59.tar.gz chromium_src-814e87b6e5236aaa38d97a9e2b2e9e6a4bae2c59.tar.bz2 |
Revert 87302 - Show that CRX unpacking is happening in the download shelf
BUG=80010
TEST=manual for now
Review URL: http://codereview.chromium.org/7047017
TBR=skerner@chromium.org
Review URL: http://codereview.chromium.org/7053045
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87326 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download')
-rw-r--r-- | chrome/browser/download/download_item.cc | 73 | ||||
-rw-r--r-- | chrome/browser/download/download_item.h | 24 | ||||
-rw-r--r-- | chrome/browser/download/download_item_model.cc | 9 | ||||
-rw-r--r-- | chrome/browser/download/download_util.cc | 28 | ||||
-rw-r--r-- | chrome/browser/download/download_util.h | 14 |
5 files changed, 25 insertions, 123 deletions
diff --git a/chrome/browser/download/download_item.cc b/chrome/browser/download/download_item.cc index 31fa520..f2cc384 100644 --- a/chrome/browser/download/download_item.cc +++ b/chrome/browser/download/download_item.cc @@ -22,7 +22,6 @@ #include "chrome/browser/download/download_prefs.h" #include "chrome/browser/download/download_state_info.h" #include "chrome/browser/download/download_util.h" -#include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/history/download_history_info.h" #include "chrome/browser/platform_util.h" #include "chrome/browser/prefs/pref_service.h" @@ -30,7 +29,6 @@ #include "chrome/common/extensions/extension.h" #include "chrome/common/pref_names.h" #include "content/browser/browser_thread.h" -#include "content/common/notification_source.h" #include "ui/base/l10n/l10n_util.h" // A DownloadItem normally goes through the following states: @@ -363,8 +361,12 @@ void DownloadItem::Completed() { UpdateObservers(); download_manager_->DownloadCompleted(id()); download_util::RecordDownloadCount(download_util::COMPLETED_COUNT); + + // Handle chrome extensions explicitly and skip the shell execute. if (is_extension_install()) { - // Extensions should already have been unpacked and opened. + download_util::OpenChromeExtension(download_manager_->profile(), + download_manager_, + *this); auto_opened_ = true; } else if (open_when_complete() || download_manager_->ShouldOpenFileBasedOnExtension( @@ -381,57 +383,6 @@ void DownloadItem::Completed() { } } -void DownloadItem::StartCrxInstall() { - DCHECK(is_extension_install()); - DCHECK(all_data_saved_); - - // We keep a scoped_refptr to the installer. This ensures that - // the installer continues to exist as long as we need to reference - // it. Our reference will be removed when installation completes, - // and NotificationType::CRX_INSTALLER_DONE fires. - scoped_refptr<CrxInstaller> crx_installer = - download_util::OpenChromeExtension( - download_manager_->profile(), - download_manager_, - *this); - - // We are only listening for events from the installer we started. - registrar_.Add(this, - NotificationType::CRX_INSTALLER_DONE, - Source<CrxInstaller>(crx_installer.get())); - - // The status text and percent complete indicator will change now - // that we are installing a CRX. Update observers so that they pick - // up the change. - UpdateObservers(); - - // At this point, we hold a reference to the installer and are - // listening for CRX_INSTALLER_DONE from that installer. - // If we are around when CRX_INSTALLER_DONE fires, Observe() will - // unreference |crx_installer_| and remove the listener from - // |registrar_|. If this download item is destroyed (user cancels, - // browser quits, etc) then |crx_installer_| goes out of scope, - // removing our reference. |registrar_|'s destructor will remove - // the listener for CRX_INSTALLER_DONE. -} - -// NotificationObserver implementation. -void DownloadItem::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - DCHECK(type == NotificationType::CRX_INSTALLER_DONE); - - // No need to listen for CRX_INSTALLER_DONE anymore. - registrar_.Remove(this, - NotificationType::CRX_INSTALLER_DONE, - source); - - auto_opened_ = true; - DCHECK(all_data_saved_); - - Completed(); -} - void DownloadItem::Interrupted(int64 size, int os_error) { if (!IsInProgress()) return; @@ -491,13 +442,6 @@ int64 DownloadItem::CurrentSpeed() const { } int DownloadItem::PercentComplete() const { - // We don't have an accurate way to estimate the time to unpack a CRX. - // The slowest part is re-encoding images, and time to do this depends on - // the contents of the image. If a CRX is being unpacked, indicate that - // we do not know how close to completion we are. - if (IsCrxInstallRuning()) - return -1; - return (total_bytes_ > 0) ? static_cast<int>(received_bytes_ * 100.0 / total_bytes_) : @@ -534,7 +478,6 @@ void DownloadItem::OnDownloadCompleting(DownloadFileManager* file_manager) { return; } - DCHECK(!is_extension_install()); Completed(); BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, @@ -551,12 +494,6 @@ void DownloadItem::OnDownloadRenamedToFinalName(const FilePath& full_path) { Rename(full_path); - if (is_extension_install()) { - StartCrxInstall(); - // Completed() will be called when the installer finishes. - return; - } - Completed(); } diff --git a/chrome/browser/download/download_item.h b/chrome/browser/download/download_item.h index 0178d3b..93acbf3 100644 --- a/chrome/browser/download/download_item.h +++ b/chrome/browser/download/download_item.h @@ -27,11 +27,8 @@ #include "base/timer.h" #include "chrome/browser/download/download_process_handle.h" #include "chrome/browser/download/download_state_info.h" -#include "content/common/notification_observer.h" -#include "content/common/notification_registrar.h" #include "googleurl/src/gurl.h" -class CrxInstaller; class DownloadFileManager; class DownloadManager; struct DownloadCreateInfo; @@ -42,7 +39,7 @@ struct DownloadHistoryInfo; // Destination tab's download view, may refer to a given DownloadItem. // // This is intended to be used only on the UI thread. -class DownloadItem : public NotificationObserver { +class DownloadItem { public: enum DownloadState { // Download is actively progressing. @@ -130,11 +127,6 @@ class DownloadItem : public NotificationObserver { // Notifies our observers periodically. void UpdateObservers(); - // NotificationObserver implementation. - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - // Returns true if it is OK to open this download. bool CanOpenDownload(); @@ -323,13 +315,6 @@ class DownloadItem : public NotificationObserver { return state_info_.target_name != full_path_.BaseName(); } - // Is a CRX installer running on this download? - bool IsCrxInstallRuning() const { - return (is_extension_install() && - all_data_saved() && - state_ == IN_PROGRESS); - } - std::string DebugString(bool verbose) const; #ifdef UNIT_TEST @@ -351,10 +336,6 @@ class DownloadItem : public NotificationObserver { void StartProgressTimer(); void StopProgressTimer(); - // Call to install this item as a CRX. Should only be called on - // items which are CRXes. Use is_extension_install() to check. - void StartCrxInstall(); - // State information used by the download manager. DownloadStateInfo state_info_; @@ -458,9 +439,6 @@ class DownloadItem : public NotificationObserver { // only. bool open_enabled_; - // DownloadItem observes CRX installs it initiates. - NotificationRegistrar registrar_; - DISALLOW_COPY_AND_ASSIGN(DownloadItem); }; diff --git a/chrome/browser/download/download_item_model.cc b/chrome/browser/download/download_item_model.cc index bbac94b..760d136 100644 --- a/chrome/browser/download/download_item_model.cc +++ b/chrome/browser/download/download_item_model.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -55,12 +55,7 @@ string16 DownloadItemModel::GetStatusText() { string16 status_text; switch (download_->state()) { case DownloadItem::IN_PROGRESS: - if (download_->IsCrxInstallRuning()) { - // The download is a CRX (app, extension, theme, ...) and it is - // being unpacked and validated. - status_text = l10n_util::GetStringUTF16( - IDS_DOWNLOAD_STATUS_CRX_INSTALL_RUNNING); - } else if (download_->open_when_complete()) { + if (download_->open_when_complete()) { if (simple_time.empty()) { status_text = l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE); diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc index 70616ba..ee2fe3a 100644 --- a/chrome/browser/download/download_util.cc +++ b/chrome/browser/download/download_util.cc @@ -333,10 +333,9 @@ void GenerateSafeFileName(const std::string& mime_type, FilePath* file_name) { #endif } -scoped_refptr<CrxInstaller> OpenChromeExtension( - Profile* profile, - DownloadManager* download_manager, - const DownloadItem& download_item) { +void OpenChromeExtension(Profile* profile, + DownloadManager* download_manager, + const DownloadItem& download_item) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(download_item.is_extension_install()); @@ -356,19 +355,18 @@ scoped_refptr<CrxInstaller> OpenChromeExtension( download_item.mime_type())) { installer->InstallUserScript(download_item.full_path(), download_item.GetURL()); - } else { - bool is_gallery_download = service->IsDownloadFromGallery( - download_item.GetURL(), download_item.referrer_url()); - installer->set_original_mime_type(download_item.original_mime_type()); - installer->set_apps_require_extension_mime_type(true); - installer->set_original_url(download_item.GetURL()); - installer->set_is_gallery_install(is_gallery_download); - installer->set_allow_silent_install(is_gallery_download); - installer->set_install_cause(extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); - installer->InstallCrx(download_item.full_path()); + return; } - return installer; + bool is_gallery_download = service->IsDownloadFromGallery( + download_item.GetURL(), download_item.referrer_url()); + installer->set_original_mime_type(download_item.original_mime_type()); + installer->set_apps_require_extension_mime_type(true); + installer->set_original_url(download_item.GetURL()); + installer->set_is_gallery_install(is_gallery_download); + installer->set_allow_silent_install(is_gallery_download); + installer->set_install_cause(extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); + installer->InstallCrx(download_item.full_path()); } void RecordDownloadCount(DownloadCountTypes type) { diff --git a/chrome/browser/download/download_util.h b/chrome/browser/download/download_util.h index e89572e..3fedb5a 100644 --- a/chrome/browser/download/download_util.h +++ b/chrome/browser/download/download_util.h @@ -12,7 +12,6 @@ #include "base/basictypes.h" #include "base/file_path.h" -#include "base/memory/ref_counted.h" #include "base/string16.h" #include "chrome/browser/download/download_process_handle.h" #include "ui/gfx/native_widget_types.h" @@ -22,7 +21,6 @@ #endif class BaseDownloadItemModel; -class CrxInstaller; class DictionaryValue; class DownloadItem; class DownloadManager; @@ -85,14 +83,10 @@ void GenerateFileName(const GURL& url, // full path to a file. void GenerateSafeFileName(const std::string& mime_type, FilePath* file_name); -// Start installing a downloaded item item as a CRX (extension, theme, app, -// ...). The installer does work on the file thread, so the installation -// is not complete when this function returns. Returns the object managing -// the installation. -scoped_refptr<CrxInstaller> OpenChromeExtension( - Profile* profile, - DownloadManager* download_manager, - const DownloadItem& download_item); +// Opens downloaded Chrome extension file (*.crx). +void OpenChromeExtension(Profile* profile, + DownloadManager* download_manager, + const DownloadItem& download_item); // Download progress animations ------------------------------------------------ |