Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7760)

Unified Diff: chrome/browser/ui/ash/launcher/launcher_extension_app_updater.cc

Issue 2067943004: ARC: Add badge for Chrome hosted Apps if Arc++ is enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix the failed unittest. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
+}
« no previous file with comments | « chrome/browser/ui/ash/launcher/launcher_extension_app_updater.h ('k') | chrome/chrome_browser_chromeos.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698