Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / extensions / install_tracker.cc
bloba0dcd4ef2b0dc9652f212fe373dd2ae87406531c
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/extension_prefs.h"
10 #include "chrome/common/pref_names.h"
11 #include "content/public/browser/notification_service.h"
12 #include "extensions/browser/pref_names.h"
14 namespace extensions {
16 InstallTracker::InstallTracker(Profile* profile,
17 extensions::ExtensionPrefs* prefs) {
18 AppSorting* sorting = prefs->app_sorting();
20 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
21 content::Source<Profile>(profile));
22 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
23 content::Source<Profile>(profile));
24 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
25 content::Source<Profile>(profile));
26 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
27 content::Source<Profile>(profile));
28 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED,
29 content::Source<AppSorting>(sorting));
30 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST,
31 content::Source<Profile>(profile));
33 pref_change_registrar_.Init(prefs->pref_service());
34 pref_change_registrar_.Add(pref_names::kExtensions,
35 base::Bind(&InstallTracker::OnAppsReordered,
36 base::Unretained(this)));
39 InstallTracker::~InstallTracker() {
42 void InstallTracker::AddObserver(InstallObserver* observer) {
43 observers_.AddObserver(observer);
46 void InstallTracker::RemoveObserver(InstallObserver* observer) {
47 observers_.RemoveObserver(observer);
50 void InstallTracker::OnBeginExtensionInstall(
51 const InstallObserver::ExtensionInstallParams& params) {
52 FOR_EACH_OBSERVER(InstallObserver, observers_,
53 OnBeginExtensionInstall(params));
56 void InstallTracker::OnDownloadProgress(const std::string& extension_id,
57 int percent_downloaded) {
58 FOR_EACH_OBSERVER(InstallObserver, observers_,
59 OnDownloadProgress(extension_id, percent_downloaded));
62 void InstallTracker::OnInstallFailure(
63 const std::string& extension_id) {
64 FOR_EACH_OBSERVER(InstallObserver, observers_,
65 OnInstallFailure(extension_id));
68 void InstallTracker::Shutdown() {
69 FOR_EACH_OBSERVER(InstallObserver, observers_, OnShutdown());
72 void InstallTracker::Observe(int type,
73 const content::NotificationSource& source,
74 const content::NotificationDetails& details) {
75 switch (type) {
76 case chrome::NOTIFICATION_EXTENSION_INSTALLED: {
77 const Extension* extension =
78 content::Details<const InstalledExtensionInfo>(details).ptr()->
79 extension;
80 FOR_EACH_OBSERVER(InstallObserver, observers_,
81 OnExtensionInstalled(extension));
82 break;
84 case chrome::NOTIFICATION_EXTENSION_LOADED: {
85 const Extension* extension =
86 content::Details<const Extension>(details).ptr();
87 FOR_EACH_OBSERVER(InstallObserver, observers_,
88 OnExtensionLoaded(extension));
89 break;
91 case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
92 const content::Details<extensions::UnloadedExtensionInfo>& unload_info(
93 details);
94 const Extension* extension = unload_info->extension;
95 FOR_EACH_OBSERVER(InstallObserver, observers_,
96 OnExtensionUnloaded(extension));
97 break;
99 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
100 const Extension* extension =
101 content::Details<const Extension>(details).ptr();
103 FOR_EACH_OBSERVER(InstallObserver, observers_,
104 OnExtensionUninstalled(extension));
105 break;
107 case chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED: {
108 FOR_EACH_OBSERVER(InstallObserver, observers_, OnAppsReordered());
109 break;
111 case chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST: {
112 const std::string& extension_id(
113 *content::Details<const std::string>(details).ptr());
114 FOR_EACH_OBSERVER(InstallObserver, observers_,
115 OnAppInstalledToAppList(extension_id));
116 break;
118 default:
119 NOTREACHED();
123 void InstallTracker::OnAppsReordered() {
124 FOR_EACH_OBSERVER(InstallObserver, observers_, OnAppsReordered());
127 } // namespace extensions