Index: chrome/browser/ui/ash/launcher/launcher_extension_app_updater.cc |
diff --git a/chrome/browser/ui/ash/launcher/launcher_extension_app_updater.cc b/chrome/browser/ui/ash/launcher/launcher_extension_app_updater.cc |
index adf3b07e89c9be7515092099dda5eb640d5e3542..4137de1246520e8dc493f81fbe0e8a83bd0014e9 100644 |
--- a/chrome/browser/ui/ash/launcher/launcher_extension_app_updater.cc |
+++ b/chrome/browser/ui/ash/launcher/launcher_extension_app_updater.cc |
@@ -4,17 +4,29 @@ |
#include "chrome/browser/ui/ash/launcher/launcher_extension_app_updater.h" |
+#include "chrome/browser/chromeos/profiles/profile_helper.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/common/extensions/extension_constants.h" |
#include "extensions/browser/extension_registry.h" |
LauncherExtensionAppUpdater::LauncherExtensionAppUpdater( |
Delegate* delegate, |
content::BrowserContext* browser_context) |
: LauncherAppUpdater(delegate, browser_context) { |
- extensions::ExtensionRegistry::Get(browser_context)->AddObserver(this); |
+ StartObservingExtensionRegistry(); |
+ |
+ arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); |
+ // ArcAuthService may not be available for some unit tests. |
+ if (arc_auth_service) |
+ arc_auth_service->AddObserver(this); |
} |
LauncherExtensionAppUpdater::~LauncherExtensionAppUpdater() { |
- extensions::ExtensionRegistry::Get(browser_context())->RemoveObserver(this); |
+ StopObservingExtensionRegistry(); |
+ |
+ arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); |
+ if (arc_auth_service) |
+ arc_auth_service->RemoveObserver(this); |
} |
void LauncherExtensionAppUpdater::OnExtensionLoaded( |
@@ -28,7 +40,66 @@ void LauncherExtensionAppUpdater::OnExtensionUnloaded( |
const extensions::Extension* extension, |
extensions::UnloadedExtensionInfo::Reason reason) { |
if (reason == extensions::UnloadedExtensionInfo::REASON_UNINSTALL) |
- delegate()->OnAppUninstalled(browser_context, extension->id()); |
+ delegate()->OnAppUninstalledPrepared(browser_context, extension->id()); |
else |
delegate()->OnAppUpdated(browser_context, extension->id()); |
} |
+ |
+void LauncherExtensionAppUpdater::OnExtensionUninstalled( |
+ content::BrowserContext* browser_context, |
+ const extensions::Extension* extension, |
+ extensions::UninstallReason reason) { |
+ delegate()->OnAppUninstalled(browser_context, extension->id()); |
+} |
+ |
+void LauncherExtensionAppUpdater::OnShutdown( |
+ extensions::ExtensionRegistry* registry) { |
+ DCHECK_EQ(extension_registry_, registry); |
+ StopObservingExtensionRegistry(); |
+} |
+ |
+void LauncherExtensionAppUpdater::OnOptInChanged( |
+ arc::ArcAuthService::State state) { |
+ if (!chromeos::ProfileHelper::IsPrimaryProfile( |
+ Profile::FromBrowserContext(browser_context()))) { |
+ return; |
+ } |
+ UpdateHostedApps(); |
+} |
+ |
+void LauncherExtensionAppUpdater::StartObservingExtensionRegistry() { |
+ DCHECK(!extension_registry_); |
+ extension_registry_ = extensions::ExtensionRegistry::Get(browser_context()); |
+ extension_registry_->AddObserver(this); |
+} |
+ |
+void LauncherExtensionAppUpdater::StopObservingExtensionRegistry() { |
+ if (!extension_registry_) |
+ return; |
+ extension_registry_->RemoveObserver(this); |
+ extension_registry_ = nullptr; |
+} |
+ |
+void LauncherExtensionAppUpdater::UpdateHostedApps() { |
+ if (!extension_registry_) |
+ return; |
+ |
+ UpdateHostedApps(extension_registry_->enabled_extensions()); |
+ UpdateHostedApps(extension_registry_->disabled_extensions()); |
+ UpdateHostedApps(extension_registry_->terminated_extensions()); |
+ UpdateHostedApp(extension_misc::kChromeAppId); |
+} |
+ |
+void LauncherExtensionAppUpdater::UpdateHostedApps( |
+ const extensions::ExtensionSet& extensions) { |
+ content::BrowserContext* context = browser_context(); |
+ extensions::ExtensionSet::const_iterator it; |
+ for (it = extensions.begin(); it != extensions.end(); ++it) { |
+ if ((*it)->is_hosted_app()) |
+ delegate()->OnAppUpdated(context, (*it)->id()); |
+ } |
+} |
+ |
+void LauncherExtensionAppUpdater::UpdateHostedApp(const std::string& app_id) { |
+ delegate()->OnAppUpdated(browser_context(), app_id); |
+} |