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