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

Side by Side 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: Address xiyuan@'s comment. Rebase 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/ash/launcher/launcher_extension_app_updater.h" 5 #include "chrome/browser/ui/ash/launcher/launcher_extension_app_updater.h"
6 6
7 #include "chrome/browser/chromeos/profiles/profile_helper.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/common/extensions/extension_constants.h"
7 #include "extensions/browser/extension_registry.h" 10 #include "extensions/browser/extension_registry.h"
8 11
9 LauncherExtensionAppUpdater::LauncherExtensionAppUpdater( 12 LauncherExtensionAppUpdater::LauncherExtensionAppUpdater(
10 Delegate* delegate, 13 Delegate* delegate,
11 content::BrowserContext* browser_context) 14 content::BrowserContext* browser_context)
12 : LauncherAppUpdater(delegate, browser_context) { 15 : LauncherAppUpdater(delegate, browser_context) {
13 extensions::ExtensionRegistry::Get(browser_context)->AddObserver(this); 16 StartObservingExtensionRegistry();
17
18 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
19 // ArcAuthService may not be available for some unit tests.
20 if (arc_auth_service)
21 arc_auth_service->AddObserver(this);
14 } 22 }
15 23
16 LauncherExtensionAppUpdater::~LauncherExtensionAppUpdater() { 24 LauncherExtensionAppUpdater::~LauncherExtensionAppUpdater() {
17 extensions::ExtensionRegistry::Get(browser_context())->RemoveObserver(this); 25 StopObservingExtensionRegistry();
26
27 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get();
28 if (arc_auth_service)
29 arc_auth_service->RemoveObserver(this);
18 } 30 }
19 31
20 void LauncherExtensionAppUpdater::OnExtensionLoaded( 32 void LauncherExtensionAppUpdater::OnExtensionLoaded(
21 content::BrowserContext* browser_context, 33 content::BrowserContext* browser_context,
22 const extensions::Extension* extension) { 34 const extensions::Extension* extension) {
23 delegate()->OnAppInstalled(browser_context, extension->id()); 35 delegate()->OnAppInstalled(browser_context, extension->id());
24 } 36 }
25 37
26 void LauncherExtensionAppUpdater::OnExtensionUnloaded( 38 void LauncherExtensionAppUpdater::OnExtensionUnloaded(
27 content::BrowserContext* browser_context, 39 content::BrowserContext* browser_context,
28 const extensions::Extension* extension, 40 const extensions::Extension* extension,
29 extensions::UnloadedExtensionInfo::Reason reason) { 41 extensions::UnloadedExtensionInfo::Reason reason) {
30 if (reason == extensions::UnloadedExtensionInfo::REASON_UNINSTALL) 42 if (reason == extensions::UnloadedExtensionInfo::REASON_UNINSTALL)
31 delegate()->OnAppUninstalled(browser_context, extension->id()); 43 delegate()->OnAppUninstalledPrepared(browser_context, extension->id());
32 else 44 else
33 delegate()->OnAppUpdated(browser_context, extension->id()); 45 delegate()->OnAppUpdated(browser_context, extension->id());
34 } 46 }
47
48 void LauncherExtensionAppUpdater::OnExtensionUninstalled(
49 content::BrowserContext* browser_context,
50 const extensions::Extension* extension,
51 extensions::UninstallReason reason) {
52 delegate()->OnAppUninstalled(browser_context, extension->id());
53 }
54
55 void LauncherExtensionAppUpdater::OnShutdown(
56 extensions::ExtensionRegistry* registry) {
57 DCHECK_EQ(extension_registry_, registry);
58 StopObservingExtensionRegistry();
59 }
60
61 void LauncherExtensionAppUpdater::OnOptInChanged(
62 arc::ArcAuthService::State state) {
63 if (!chromeos::ProfileHelper::IsPrimaryProfile(
64 Profile::FromBrowserContext(browser_context()))) {
65 return;
66 }
67 UpdateHostedApps();
68 }
69
70 void LauncherExtensionAppUpdater::StartObservingExtensionRegistry() {
71 DCHECK(!extension_registry_);
72 extension_registry_ = extensions::ExtensionRegistry::Get(browser_context());
73 extension_registry_->AddObserver(this);
74 }
75
76 void LauncherExtensionAppUpdater::StopObservingExtensionRegistry() {
77 if (!extension_registry_)
78 return;
79 extension_registry_->RemoveObserver(this);
80 extension_registry_ = nullptr;
81 }
82
83 void LauncherExtensionAppUpdater::UpdateHostedApps() {
84 if (!extension_registry_)
85 return;
86
87 UpdateHostedApps(extension_registry_->enabled_extensions());
88 UpdateHostedApps(extension_registry_->disabled_extensions());
89 UpdateHostedApps(extension_registry_->terminated_extensions());
90 UpdateHostedApp(extension_misc::kChromeAppId);
91 }
92
93 void LauncherExtensionAppUpdater::UpdateHostedApps(
94 const extensions::ExtensionSet& extensions) {
95 content::BrowserContext* context = browser_context();
96 extensions::ExtensionSet::const_iterator it;
97 for (it = extensions.begin(); it != extensions.end(); ++it) {
98 if ((*it)->is_hosted_app())
99 delegate()->OnAppUpdated(context, (*it)->id());
100 }
101 }
102
103 void LauncherExtensionAppUpdater::UpdateHostedApp(const std::string& app_id) {
104 delegate()->OnAppUpdated(browser_context(), app_id);
105 }
OLDNEW
« 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