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