[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 | #ifndef CHROME_BROWSER_EXTENSIONS_INSTALL_TRACKER_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_INSTALL_TRACKER_H_ |
| 7 | |
[email protected] | 773272b | 2014-07-18 05:48:35 | [diff] [blame] | 8 | #include <map> |
| 9 | |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 10 | #include "base/macros.h" |
[email protected] | ef9d274 | 2013-02-26 12:48:35 | [diff] [blame] | 11 | #include "base/observer_list.h" |
[email protected] | 773272b | 2014-07-18 05:48:35 | [diff] [blame] | 12 | #include "base/scoped_observer.h" |
| 13 | #include "chrome/browser/extensions/active_install_data.h" |
[email protected] | ef9d274 | 2013-02-26 12:48:35 | [diff] [blame] | 14 | #include "chrome/browser/extensions/install_observer.h" |
[email protected] | b33f0b11 | 2014-03-13 17:05:30 | [diff] [blame] | 15 | #include "components/keyed_service/core/keyed_service.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 16 | #include "components/prefs/pref_change_registrar.h" |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 17 | #include "content/public/browser/notification_observer.h" |
| 18 | #include "content/public/browser/notification_registrar.h" |
Evan Stade | 75872a6 | 2019-09-06 21:17:38 | [diff] [blame] | 19 | #include "extensions/browser/extension_registry.h" |
[email protected] | 773272b | 2014-07-18 05:48:35 | [diff] [blame] | 20 | #include "extensions/browser/extension_registry_observer.h" |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 21 | |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 22 | namespace content { |
| 23 | class BrowserContext; |
| 24 | } |
| 25 | |
[email protected] | ef9d274 | 2013-02-26 12:48:35 | [diff] [blame] | 26 | namespace extensions { |
| 27 | |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 28 | class ExtensionPrefs; |
| 29 | |
[email protected] | b33f0b11 | 2014-03-13 17:05:30 | [diff] [blame] | 30 | class InstallTracker : public KeyedService, |
[email protected] | 773272b | 2014-07-18 05:48:35 | [diff] [blame] | 31 | public content::NotificationObserver, |
| 32 | public ExtensionRegistryObserver { |
[email protected] | ef9d274 | 2013-02-26 12:48:35 | [diff] [blame] | 33 | public: |
[email protected] | 6d6579a | 2014-07-30 14:24:13 | [diff] [blame] | 34 | InstallTracker(content::BrowserContext* browser_context, |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 35 | extensions::ExtensionPrefs* prefs); |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 36 | ~InstallTracker() override; |
[email protected] | ef9d274 | 2013-02-26 12:48:35 | [diff] [blame] | 37 | |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 38 | static InstallTracker* Get(content::BrowserContext* context); |
| 39 | |
[email protected] | ef9d274 | 2013-02-26 12:48:35 | [diff] [blame] | 40 | void AddObserver(InstallObserver* observer); |
| 41 | void RemoveObserver(InstallObserver* observer); |
| 42 | |
[email protected] | 773272b | 2014-07-18 05:48:35 | [diff] [blame] | 43 | // If an install is currently in progress for |extension_id|, returns details |
| 44 | // of the installation. This instance retains ownership of the returned |
| 45 | // pointer. Returns NULL if the extension is not currently being installed. |
| 46 | const ActiveInstallData* GetActiveInstall( |
| 47 | const std::string& extension_id) const; |
| 48 | |
| 49 | // Registers an install initiated by the user to allow checking of duplicate |
| 50 | // installs. Download of the extension has not necessarily started. |
| 51 | // RemoveActiveInstall() must be called when install is complete regardless of |
| 52 | // success or failure. Consider using ScopedActiveInstall rather than calling |
| 53 | // this directly. |
| 54 | void AddActiveInstall(const ActiveInstallData& install_data); |
| 55 | |
| 56 | // Deregisters an active install. |
| 57 | void RemoveActiveInstall(const std::string& extension_id); |
| 58 | |
[email protected] | ef9d274 | 2013-02-26 12:48:35 | [diff] [blame] | 59 | void OnBeginExtensionInstall( |
[email protected] | fa517d0 | 2013-11-18 09:33:09 | [diff] [blame] | 60 | const InstallObserver::ExtensionInstallParams& params); |
[email protected] | c80fe5f | 2014-03-26 04:36:30 | [diff] [blame] | 61 | void OnBeginExtensionDownload(const std::string& extension_id); |
[email protected] | ef9d274 | 2013-02-26 12:48:35 | [diff] [blame] | 62 | void OnDownloadProgress(const std::string& extension_id, |
| 63 | int percent_downloaded); |
[email protected] | c80fe5f | 2014-03-26 04:36:30 | [diff] [blame] | 64 | void OnBeginCrxInstall(const std::string& extension_id); |
[email protected] | 73cd487c | 2014-04-16 05:22:50 | [diff] [blame] | 65 | void OnFinishCrxInstall(const std::string& extension_id, bool success); |
[email protected] | ef9d274 | 2013-02-26 12:48:35 | [diff] [blame] | 66 | void OnInstallFailure(const std::string& extension_id); |
| 67 | |
[email protected] | b8e45df | 2014-06-11 19:32:36 | [diff] [blame] | 68 | // NOTE(limasdf): For extension [un]load and [un]installed, use |
| 69 | // ExtensionRegistryObserver. |
| 70 | |
[email protected] | 96ac596 | 2014-04-22 19:49:58 | [diff] [blame] | 71 | // Overriddes for KeyedService. |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 72 | void Shutdown() override; |
[email protected] | 523352c92 | 2013-02-28 01:38:52 | [diff] [blame] | 73 | |
[email protected] | ef9d274 | 2013-02-26 12:48:35 | [diff] [blame] | 74 | private: |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 75 | void OnAppsReordered(); |
| 76 | |
[email protected] | 17f0782 | 2014-05-22 08:45:15 | [diff] [blame] | 77 | // content::NotificationObserver implementation. |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 78 | void Observe(int type, |
| 79 | const content::NotificationSource& source, |
| 80 | const content::NotificationDetails& details) override; |
[email protected] | 96ac596 | 2014-04-22 19:49:58 | [diff] [blame] | 81 | |
[email protected] | 773272b | 2014-07-18 05:48:35 | [diff] [blame] | 82 | // ExtensionRegistryObserver implementation. |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 83 | void OnExtensionInstalled(content::BrowserContext* browser_context, |
| 84 | const Extension* extension, |
| 85 | bool is_update) override; |
[email protected] | 773272b | 2014-07-18 05:48:35 | [diff] [blame] | 86 | |
| 87 | // Maps extension id to the details of an active install. |
| 88 | typedef std::map<std::string, ActiveInstallData> ActiveInstallsMap; |
| 89 | ActiveInstallsMap active_installs_; |
| 90 | |
Trent Apted | a250ec3ab | 2018-08-19 08:52:19 | [diff] [blame] | 91 | base::ObserverList<InstallObserver>::Unchecked observers_; |
[email protected] | 67e0a26 | 2013-03-15 13:14:49 | [diff] [blame] | 92 | content::NotificationRegistrar registrar_; |
| 93 | PrefChangeRegistrar pref_change_registrar_; |
[email protected] | 773272b | 2014-07-18 05:48:35 | [diff] [blame] | 94 | ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
Evan Stade | 75872a6 | 2019-09-06 21:17:38 | [diff] [blame] | 95 | extension_registry_observer_{this}; |
[email protected] | ef9d274 | 2013-02-26 12:48:35 | [diff] [blame] | 96 | |
[email protected] | ef9d274 | 2013-02-26 12:48:35 | [diff] [blame] | 97 | DISALLOW_COPY_AND_ASSIGN(InstallTracker); |
| 98 | }; |
| 99 | |
| 100 | } // namespace extensions |
| 101 | |
| 102 | #endif // CHROME_BROWSER_EXTENSIONS_INSTALL_TRACKER_H_ |