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

Side by Side Diff: chrome/browser/extensions/install_tracker.cc

Issue 279073003: Add a function triggering extension installed to ExtensionRegistryObserver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/extensions/install_tracker.h" 5 #include "chrome/browser/extensions/install_tracker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/extensions/install_tracker_factory.h" 9 #include "chrome/browser/extensions/install_tracker_factory.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
12 #include "content/public/browser/notification_service.h" 12 #include "content/public/browser/notification_service.h"
13 #include "extensions/browser/extension_prefs.h" 13 #include "extensions/browser/extension_prefs.h"
14 #include "extensions/browser/extension_registry.h" 14 #include "extensions/browser/extension_registry.h"
15 #include "extensions/browser/pref_names.h" 15 #include "extensions/browser/pref_names.h"
16 16
17 namespace extensions { 17 namespace extensions {
18 18
19 InstallTracker::InstallTracker(Profile* profile, 19 InstallTracker::InstallTracker(Profile* profile,
20 extensions::ExtensionPrefs* prefs) 20 extensions::ExtensionPrefs* prefs)
21 : extension_registry_observer_(this) { 21 : extension_registry_observer_(this) {
22 extension_registry_observer_.Add(ExtensionRegistry::Get(profile)); 22 extension_registry_observer_.Add(ExtensionRegistry::Get(profile));
23 23
24 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
25 content::Source<Profile>(profile));
26 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, 24 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
27 content::Source<Profile>(profile)); 25 content::Source<Profile>(profile));
28 registrar_.Add(this, 26 registrar_.Add(this,
29 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, 27 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
30 content::Source<Profile>(profile)); 28 content::Source<Profile>(profile));
31 AppSorting* sorting = prefs->app_sorting(); 29 AppSorting* sorting = prefs->app_sorting();
32 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, 30 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED,
33 content::Source<AppSorting>(sorting)); 31 content::Source<AppSorting>(sorting));
34 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST, 32 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST,
35 content::Source<Profile>(profile)); 33 content::Source<Profile>(profile));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 void InstallTracker::OnInstallFailure( 86 void InstallTracker::OnInstallFailure(
89 const std::string& extension_id) { 87 const std::string& extension_id) {
90 FOR_EACH_OBSERVER(InstallObserver, observers_, 88 FOR_EACH_OBSERVER(InstallObserver, observers_,
91 OnInstallFailure(extension_id)); 89 OnInstallFailure(extension_id));
92 } 90 }
93 91
94 void InstallTracker::Shutdown() { 92 void InstallTracker::Shutdown() {
95 FOR_EACH_OBSERVER(InstallObserver, observers_, OnShutdown()); 93 FOR_EACH_OBSERVER(InstallObserver, observers_, OnShutdown());
96 } 94 }
97 95
98 void InstallTracker::OnExtensionLoaded(content::BrowserContext* browser_context,
99 const Extension* extension) {
100 FOR_EACH_OBSERVER(InstallObserver, observers_, OnExtensionLoaded(extension));
101 }
102
103 void InstallTracker::OnExtensionUnloaded(
104 content::BrowserContext* browser_context,
105 const Extension* extension,
106 UnloadedExtensionInfo::Reason reason) {
107 FOR_EACH_OBSERVER(
108 InstallObserver, observers_, OnExtensionUnloaded(extension));
109 }
110
111 void InstallTracker::Observe(int type, 96 void InstallTracker::Observe(int type,
112 const content::NotificationSource& source, 97 const content::NotificationSource& source,
113 const content::NotificationDetails& details) { 98 const content::NotificationDetails& details) {
114 switch (type) { 99 switch (type) {
115 case chrome::NOTIFICATION_EXTENSION_INSTALLED: {
116 const Extension* extension =
117 content::Details<const InstalledExtensionInfo>(details).ptr()->
118 extension;
119 FOR_EACH_OBSERVER(InstallObserver, observers_,
120 OnExtensionInstalled(extension));
121 break;
122 }
123 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { 100 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
124 const Extension* extension = 101 const Extension* extension =
125 content::Details<const Extension>(details).ptr(); 102 content::Details<const Extension>(details).ptr();
126 103
127 FOR_EACH_OBSERVER(InstallObserver, observers_, 104 FOR_EACH_OBSERVER(InstallObserver, observers_,
128 OnExtensionUninstalled(extension)); 105 OnExtensionUninstalled(extension));
129 break; 106 break;
130 } 107 }
131 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: { 108 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: {
132 const Extension* extension = 109 const Extension* extension =
(...skipping 11 matching lines...) Expand all
144 *content::Details<const std::string>(details).ptr()); 121 *content::Details<const std::string>(details).ptr());
145 FOR_EACH_OBSERVER(InstallObserver, observers_, 122 FOR_EACH_OBSERVER(InstallObserver, observers_,
146 OnAppInstalledToAppList(extension_id)); 123 OnAppInstalledToAppList(extension_id));
147 break; 124 break;
148 } 125 }
149 default: 126 default:
150 NOTREACHED(); 127 NOTREACHED();
151 } 128 }
152 } 129 }
153 130
131 void InstallTracker::OnExtensionLoaded(content::BrowserContext* browser_context,
132 const Extension* extension) {
133 FOR_EACH_OBSERVER(InstallObserver, observers_, OnExtensionLoaded(extension));
134 }
135
136 void InstallTracker::OnExtensionUnloaded(
137 content::BrowserContext* browser_context,
138 const Extension* extension,
139 UnloadedExtensionInfo::Reason reason) {
140 FOR_EACH_OBSERVER(
141 InstallObserver, observers_, OnExtensionUnloaded(extension));
142 }
143
144 void InstallTracker::OnExtensionInstalled(
145 content::BrowserContext* browser_context,
146 const Extension* extension,
147 InstalledExtensionInfo info) {
148 FOR_EACH_OBSERVER(
149 InstallObserver, observers_, OnExtensionInstalled(extension));
150 }
151
154 void InstallTracker::OnAppsReordered() { 152 void InstallTracker::OnAppsReordered() {
155 FOR_EACH_OBSERVER(InstallObserver, observers_, OnAppsReordered()); 153 FOR_EACH_OBSERVER(InstallObserver, observers_, OnAppsReordered());
156 } 154 }
157 155
158 } // namespace extensions 156 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698