[email protected] | ef9d274 | 2013-02-26 12:48:35 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "chrome/browser/extensions/install_tracker.h" |
| 6 | |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | 49a01e64 | 2013-07-12 00:29:45 | [diff] [blame] | 8 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 9 | #include "chrome/common/pref_names.h" |
| 10 | #include "content/public/browser/notification_service.h" |
[email protected] | 489db084 | 2014-01-22 18:20:03 | [diff] [blame] | 11 | #include "extensions/browser/extension_prefs.h" |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 12 | #include "extensions/browser/pref_names.h" |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 13 | |
[email protected] | ef9d274 | 2013-02-26 12:48:35 | [diff] [blame] | 14 | namespace extensions { |
| 15 | |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 16 | InstallTracker::InstallTracker(Profile* profile, |
| 17 | extensions::ExtensionPrefs* prefs) { |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 18 | AppSorting* sorting = prefs->app_sorting(); |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 19 | |
[email protected] | b9b9b5d | 2013-07-12 05:11:39 | [diff] [blame] | 20 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, |
| 21 | content::Source<Profile>(profile)); |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 22 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 23 | content::Source<Profile>(profile)); |
[email protected] | ec87053 | 2014-03-19 20:24:05 | [diff] [blame] | 24 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 25 | content::Source<Profile>(profile)); |
[email protected] | 8ed2d35 | 2013-07-03 22:26:46 | [diff] [blame] | 26 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
| 27 | content::Source<Profile>(profile)); |
[email protected] | 8c17903 | 2014-03-20 22:49:10 | [diff] [blame^] | 28 | registrar_.Add(this, |
| 29 | chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
| 30 | content::Source<Profile>(profile)); |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 31 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 32 | content::Source<AppSorting>(sorting)); |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 33 | registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST, |
| 34 | content::Source<Profile>(profile)); |
| 35 | |
| 36 | pref_change_registrar_.Init(prefs->pref_service()); |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 37 | pref_change_registrar_.Add(pref_names::kExtensions, |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 38 | base::Bind(&InstallTracker::OnAppsReordered, |
| 39 | base::Unretained(this))); |
[email protected] | ef9d274 | 2013-02-26 12:48:35 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | InstallTracker::~InstallTracker() { |
| 43 | } |
| 44 | |
| 45 | void InstallTracker::AddObserver(InstallObserver* observer) { |
| 46 | observers_.AddObserver(observer); |
| 47 | } |
| 48 | |
| 49 | void InstallTracker::RemoveObserver(InstallObserver* observer) { |
| 50 | observers_.RemoveObserver(observer); |
| 51 | } |
| 52 | |
| 53 | void InstallTracker::OnBeginExtensionInstall( |
[email protected] | fa517d0 | 2013-11-18 09:33:09 | [diff] [blame] | 54 | const InstallObserver::ExtensionInstallParams& params) { |
[email protected] | ef9d274 | 2013-02-26 12:48:35 | [diff] [blame] | 55 | FOR_EACH_OBSERVER(InstallObserver, observers_, |
[email protected] | fa517d0 | 2013-11-18 09:33:09 | [diff] [blame] | 56 | OnBeginExtensionInstall(params)); |
[email protected] | ef9d274 | 2013-02-26 12:48:35 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | void InstallTracker::OnDownloadProgress(const std::string& extension_id, |
| 60 | int percent_downloaded) { |
| 61 | FOR_EACH_OBSERVER(InstallObserver, observers_, |
| 62 | OnDownloadProgress(extension_id, percent_downloaded)); |
| 63 | } |
| 64 | |
| 65 | void InstallTracker::OnInstallFailure( |
| 66 | const std::string& extension_id) { |
| 67 | FOR_EACH_OBSERVER(InstallObserver, observers_, |
| 68 | OnInstallFailure(extension_id)); |
| 69 | } |
| 70 | |
[email protected] | 523352c92 | 2013-02-28 01:38:52 | [diff] [blame] | 71 | void InstallTracker::Shutdown() { |
| 72 | FOR_EACH_OBSERVER(InstallObserver, observers_, OnShutdown()); |
| 73 | } |
| 74 | |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 75 | void InstallTracker::Observe(int type, |
| 76 | const content::NotificationSource& source, |
| 77 | const content::NotificationDetails& details) { |
| 78 | switch (type) { |
[email protected] | b9b9b5d | 2013-07-12 05:11:39 | [diff] [blame] | 79 | case chrome::NOTIFICATION_EXTENSION_INSTALLED: { |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 80 | const Extension* extension = |
[email protected] | 914358df | 2013-07-17 17:22:00 | [diff] [blame] | 81 | content::Details<const InstalledExtensionInfo>(details).ptr()-> |
| 82 | extension; |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 83 | FOR_EACH_OBSERVER(InstallObserver, observers_, |
| 84 | OnExtensionInstalled(extension)); |
| 85 | break; |
| 86 | } |
[email protected] | b9b9b5d | 2013-07-12 05:11:39 | [diff] [blame] | 87 | case chrome::NOTIFICATION_EXTENSION_LOADED: { |
| 88 | const Extension* extension = |
| 89 | content::Details<const Extension>(details).ptr(); |
| 90 | FOR_EACH_OBSERVER(InstallObserver, observers_, |
| 91 | OnExtensionLoaded(extension)); |
| 92 | break; |
| 93 | } |
[email protected] | ec87053 | 2014-03-19 20:24:05 | [diff] [blame] | 94 | case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 95 | const content::Details<extensions::UnloadedExtensionInfo>& unload_info( |
| 96 | details); |
| 97 | const Extension* extension = unload_info->extension; |
[email protected] | b9b9b5d | 2013-07-12 05:11:39 | [diff] [blame] | 98 | FOR_EACH_OBSERVER(InstallObserver, observers_, |
| 99 | OnExtensionUnloaded(extension)); |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 100 | break; |
| 101 | } |
[email protected] | 8ed2d35 | 2013-07-03 22:26:46 | [diff] [blame] | 102 | case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { |
| 103 | const Extension* extension = |
| 104 | content::Details<const Extension>(details).ptr(); |
| 105 | |
| 106 | FOR_EACH_OBSERVER(InstallObserver, observers_, |
| 107 | OnExtensionUninstalled(extension)); |
| 108 | break; |
| 109 | } |
[email protected] | 8c17903 | 2014-03-20 22:49:10 | [diff] [blame^] | 110 | case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: { |
| 111 | const Extension* extension = |
| 112 | content::Details<const Extension>(details).ptr(); |
| 113 | FOR_EACH_OBSERVER( |
| 114 | InstallObserver, observers_, OnDisabledExtensionUpdated(extension)); |
| 115 | break; |
| 116 | } |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 117 | case chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED: { |
| 118 | FOR_EACH_OBSERVER(InstallObserver, observers_, OnAppsReordered()); |
| 119 | break; |
| 120 | } |
| 121 | case chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST: { |
| 122 | const std::string& extension_id( |
| 123 | *content::Details<const std::string>(details).ptr()); |
| 124 | FOR_EACH_OBSERVER(InstallObserver, observers_, |
| 125 | OnAppInstalledToAppList(extension_id)); |
| 126 | break; |
| 127 | } |
| 128 | default: |
| 129 | NOTREACHED(); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | void InstallTracker::OnAppsReordered() { |
| 134 | FOR_EACH_OBSERVER(InstallObserver, observers_, OnAppsReordered()); |
| 135 | } |
| 136 | |
[email protected] | ef9d274 | 2013-02-26 12:48:35 | [diff] [blame] | 137 | } // namespace extensions |