| Index: chrome/browser/extensions/install_tracker.cc
|
| diff --git a/chrome/browser/extensions/install_tracker.cc b/chrome/browser/extensions/install_tracker.cc
|
| index 52d9115775010c339bf9f50c580724ac6457d5d7..b701dfa536ee900eaf36499dcbe439c1614a12f3 100644
|
| --- a/chrome/browser/extensions/install_tracker.cc
|
| +++ b/chrome/browser/extensions/install_tracker.cc
|
| @@ -11,25 +11,40 @@
|
| #include "chrome/common/pref_names.h"
|
| #include "content/public/browser/notification_service.h"
|
| #include "extensions/browser/extension_prefs.h"
|
| +#include "extensions/browser/extension_registry.h"
|
| #include "extensions/browser/pref_names.h"
|
|
|
| namespace extensions {
|
|
|
| +InstallTracker::InstallProgressData::InstallProgressData()
|
| + : percent_downloaded(0), is_ephemeral(false) {
|
| +}
|
| +
|
| +InstallTracker::InstallProgressData::InstallProgressData(
|
| + const std::string& extension_id)
|
| + : extension_id(extension_id), percent_downloaded(0), is_ephemeral(false) {
|
| +}
|
| +
|
| InstallTracker::InstallTracker(Profile* profile,
|
| - extensions::ExtensionPrefs* prefs) {
|
| + extensions::ExtensionPrefs* prefs)
|
| + : extension_registry_observer_(this) {
|
| registrar_.Add(this,
|
| chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
|
| content::Source<Profile>(profile));
|
| - AppSorting* sorting = prefs->app_sorting();
|
| - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED,
|
| - content::Source<AppSorting>(sorting));
|
| registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST,
|
| content::Source<Profile>(profile));
|
| -
|
| - pref_change_registrar_.Init(prefs->pref_service());
|
| - pref_change_registrar_.Add(pref_names::kExtensions,
|
| - base::Bind(&InstallTracker::OnAppsReordered,
|
| - base::Unretained(this)));
|
| + extension_registry_observer_.Add(ExtensionRegistry::Get(profile));
|
| +
|
| + // Prefs may be null in tests.
|
| + if (prefs) {
|
| + AppSorting* sorting = prefs->app_sorting();
|
| + registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED,
|
| + content::Source<AppSorting>(sorting));
|
| + pref_change_registrar_.Init(prefs->pref_service());
|
| + pref_change_registrar_.Add(pref_names::kExtensions,
|
| + base::Bind(&InstallTracker::OnAppsReordered,
|
| + base::Unretained(this)));
|
| + }
|
| }
|
|
|
| InstallTracker::~InstallTracker() {
|
| @@ -49,8 +64,38 @@ void InstallTracker::RemoveObserver(InstallObserver* observer) {
|
| observers_.RemoveObserver(observer);
|
| }
|
|
|
| +const InstallTracker::InstallProgressData* InstallTracker::GetActiveInstall(
|
| + const std::string& extension_id) const {
|
| + ActiveInstallsMap::const_iterator install_data =
|
| + active_installs_.find(extension_id);
|
| + if (install_data == active_installs_.end())
|
| + return NULL;
|
| + else
|
| + return &(install_data->second);
|
| +}
|
| +
|
| +void InstallTracker::AddActiveInstall(const InstallProgressData& install_data) {
|
| + DCHECK(!install_data.extension_id.empty());
|
| + DCHECK(active_installs_.find(install_data.extension_id) ==
|
| + active_installs_.end());
|
| + active_installs_.insert(
|
| + std::make_pair(install_data.extension_id, install_data));
|
| +}
|
| +
|
| +void InstallTracker::RemoveActiveInstall(const std::string& extension_id) {
|
| + active_installs_.erase(extension_id);
|
| +}
|
| +
|
| void InstallTracker::OnBeginExtensionInstall(
|
| const InstallObserver::ExtensionInstallParams& params) {
|
| + ActiveInstallsMap::iterator install_data =
|
| + active_installs_.find(params.extension_id);
|
| + if (install_data == active_installs_.end()) {
|
| + InstallProgressData install_data(params.extension_id);
|
| + install_data.is_ephemeral = params.is_ephemeral;
|
| + active_installs_.insert(std::make_pair(params.extension_id, install_data));
|
| + }
|
| +
|
| FOR_EACH_OBSERVER(InstallObserver, observers_,
|
| OnBeginExtensionInstall(params));
|
| }
|
| @@ -62,6 +107,14 @@ void InstallTracker::OnBeginExtensionDownload(const std::string& extension_id) {
|
|
|
| void InstallTracker::OnDownloadProgress(const std::string& extension_id,
|
| int percent_downloaded) {
|
| + ActiveInstallsMap::iterator install_data =
|
| + active_installs_.find(extension_id);
|
| + if (install_data != active_installs_.end()) {
|
| + install_data->second.percent_downloaded = percent_downloaded;
|
| + } else {
|
| + NOTREACHED();
|
| + }
|
| +
|
| FOR_EACH_OBSERVER(InstallObserver, observers_,
|
| OnDownloadProgress(extension_id, percent_downloaded));
|
| }
|
| @@ -79,6 +132,7 @@ void InstallTracker::OnFinishCrxInstall(const std::string& extension_id,
|
|
|
| void InstallTracker::OnInstallFailure(
|
| const std::string& extension_id) {
|
| + RemoveActiveInstall(extension_id);
|
| FOR_EACH_OBSERVER(InstallObserver, observers_,
|
| OnInstallFailure(extension_id));
|
| }
|
| @@ -114,6 +168,12 @@ void InstallTracker::Observe(int type,
|
| }
|
| }
|
|
|
| +void InstallTracker::OnExtensionInstalled(
|
| + content::BrowserContext* browser_context,
|
| + const Extension* extension) {
|
| + RemoveActiveInstall(extension->id());
|
| +}
|
| +
|
| void InstallTracker::OnAppsReordered() {
|
| FOR_EACH_OBSERVER(InstallObserver, observers_, OnAppsReordered());
|
| }
|
|
|