Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / extensions / install_tracker.cc
blob81e72feded968487972f0656a1e7e2fb1951d03d
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
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/install_tracker.h"
7 #include "base/bind.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/extensions/install_tracker_factory.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/pref_names.h"
12 #include "content/public/browser/notification_service.h"
13 #include "extensions/browser/extension_prefs.h"
14 #include "extensions/browser/extension_registry.h"
15 #include "extensions/browser/pref_names.h"
17 namespace extensions {
19 InstallTracker::InstallTracker(Profile* profile,
20 extensions::ExtensionPrefs* prefs)
21 : extension_registry_observer_(this) {
22 extension_registry_observer_.Add(ExtensionRegistry::Get(profile));
24 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
25 content::Source<Profile>(profile));
26 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
27 content::Source<Profile>(profile));
28 registrar_.Add(this,
29 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
30 content::Source<Profile>(profile));
31 AppSorting* sorting = prefs->app_sorting();
32 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED,
33 content::Source<AppSorting>(sorting));
34 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST,
35 content::Source<Profile>(profile));
37 pref_change_registrar_.Init(prefs->pref_service());
38 pref_change_registrar_.Add(pref_names::kExtensions,
39 base::Bind(&InstallTracker::OnAppsReordered,
40 base::Unretained(this)));
43 InstallTracker::~InstallTracker() {
46 // static
47 InstallTracker* InstallTracker::Get(content::BrowserContext* context) {
48 return InstallTrackerFactory::GetForProfile(
49 Profile::FromBrowserContext(context));
52 void InstallTracker::AddObserver(InstallObserver* observer) {
53 observers_.AddObserver(observer);
56 void InstallTracker::RemoveObserver(InstallObserver* observer) {
57 observers_.RemoveObserver(observer);
60 void InstallTracker::OnBeginExtensionInstall(
61 const InstallObserver::ExtensionInstallParams& params) {
62 FOR_EACH_OBSERVER(InstallObserver, observers_,
63 OnBeginExtensionInstall(params));
66 void InstallTracker::OnBeginExtensionDownload(const std::string& extension_id) {
67 FOR_EACH_OBSERVER(
68 InstallObserver, observers_, OnBeginExtensionDownload(extension_id));
71 void InstallTracker::OnDownloadProgress(const std::string& extension_id,
72 int percent_downloaded) {
73 FOR_EACH_OBSERVER(InstallObserver, observers_,
74 OnDownloadProgress(extension_id, percent_downloaded));
77 void InstallTracker::OnBeginCrxInstall(const std::string& extension_id) {
78 FOR_EACH_OBSERVER(
79 InstallObserver, observers_, OnBeginCrxInstall(extension_id));
82 void InstallTracker::OnFinishCrxInstall(const std::string& extension_id,
83 bool success) {
84 FOR_EACH_OBSERVER(
85 InstallObserver, observers_, OnFinishCrxInstall(extension_id, success));
88 void InstallTracker::OnInstallFailure(
89 const std::string& extension_id) {
90 FOR_EACH_OBSERVER(InstallObserver, observers_,
91 OnInstallFailure(extension_id));
94 void InstallTracker::Shutdown() {
95 FOR_EACH_OBSERVER(InstallObserver, observers_, OnShutdown());
98 void InstallTracker::OnExtensionLoaded(content::BrowserContext* browser_context,
99 const Extension* extension) {
100 FOR_EACH_OBSERVER(InstallObserver, observers_, OnExtensionLoaded(extension));
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));
111 void InstallTracker::Observe(int type,
112 const content::NotificationSource& source,
113 const content::NotificationDetails& details) {
114 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;
123 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
124 const Extension* extension =
125 content::Details<const Extension>(details).ptr();
127 FOR_EACH_OBSERVER(InstallObserver, observers_,
128 OnExtensionUninstalled(extension));
129 break;
131 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: {
132 const Extension* extension =
133 content::Details<const Extension>(details).ptr();
134 FOR_EACH_OBSERVER(
135 InstallObserver, observers_, OnDisabledExtensionUpdated(extension));
136 break;
138 case chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED: {
139 FOR_EACH_OBSERVER(InstallObserver, observers_, OnAppsReordered());
140 break;
142 case chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST: {
143 const std::string& extension_id(
144 *content::Details<const std::string>(details).ptr());
145 FOR_EACH_OBSERVER(InstallObserver, observers_,
146 OnAppInstalledToAppList(extension_id));
147 break;
149 default:
150 NOTREACHED();
154 void InstallTracker::OnAppsReordered() {
155 FOR_EACH_OBSERVER(InstallObserver, observers_, OnAppsReordered());
158 } // namespace extensions