Chromium Code Reviews| 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..e0d3d35d68e86f280c9a151a2cede4d54bd0d8e4 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( |
| @@ -32,3 +44,62 @@ void LauncherExtensionAppUpdater::OnExtensionUnloaded( |
| else |
| delegate()->OnAppUpdated(browser_context, extension->id()); |
| } |
| + |
| +void LauncherExtensionAppUpdater::OnExtensionUninstalled( |
| + content::BrowserContext* browser_context, |
| + const extensions::Extension* extension, |
| + extensions::UninstallReason reason) { |
| + if (reason == extensions::UNINSTALL_REASON_FOR_TESTING) |
| + 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; |
| + } |
| + UpdateHostApps(); |
| +} |
| + |
| +void LauncherExtensionAppUpdater::StartObservingExtensionRegistry() { |
| + DCHECK(!extension_registry_); |
| + extension_registry_ = extensions::ExtensionRegistry::Get(browser_context()); |
| + extension_registry_->AddObserver(this); |
| +} |
| + |
| +void LauncherExtensionAppUpdater::StopObservingExtensionRegistry() { |
| + if (extension_registry_) |
| + extension_registry_->RemoveObserver(this); |
|
Mr4D (OOO till 08-26)
2016/06/15 23:03:23
you might do if (!extension_registry_) return; ..
|
| + extension_registry_ = nullptr; |
| +} |
| + |
| +void LauncherExtensionAppUpdater::UpdateHostApps() { |
| + if (!extension_registry_) |
| + return; |
| + |
| + UpdateHostApps(extension_registry_->enabled_extensions()); |
| + UpdateHostApps(extension_registry_->disabled_extensions()); |
| + UpdateHostApps(extension_registry_->terminated_extensions()); |
| + UpdateHostApp(extension_misc::kChromeAppId); |
| +} |
| + |
| +void LauncherExtensionAppUpdater::UpdateHostApps( |
| + 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::UpdateHostApp(const std::string& app_id) { |
| + delegate()->OnAppUpdated(browser_context(), app_id); |
| +} |