OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_PENDING_EXTENSION_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "chrome/browser/extensions/pending_extension_info.h" | 11 #include "chrome/browser/extensions/pending_extension_info.h" |
12 #include "extensions/common/manifest.h" | 12 #include "extensions/common/manifest.h" |
13 | 13 |
14 class ExtensionServiceInterface; | |
15 class GURL; | 14 class GURL; |
16 | 15 |
17 namespace base { | 16 namespace base { |
18 class Version; | 17 class Version; |
19 } | 18 } |
20 | 19 |
21 namespace content { | 20 namespace content { |
22 class BrowserContext; | 21 class BrowserContext; |
23 } | 22 } |
24 | 23 |
25 FORWARD_DECLARE_TEST(ExtensionServiceTest, | 24 FORWARD_DECLARE_TEST(ExtensionServiceTest, |
26 UpdatePendingExtensionAlreadyInstalled); | 25 UpdatePendingExtensionAlreadyInstalled); |
27 | 26 |
28 namespace extensions { | 27 namespace extensions { |
29 class Extension; | 28 class Extension; |
30 class PendingExtensionManager; | 29 class PendingExtensionManager; |
31 | 30 |
32 class ExtensionUpdaterTest; | 31 class ExtensionUpdaterTest; |
33 void SetupPendingExtensionManagerForTest( | 32 void SetupPendingExtensionManagerForTest( |
34 int count, const GURL& update_url, | 33 int count, const GURL& update_url, |
35 PendingExtensionManager* pending_extension_manager); | 34 PendingExtensionManager* pending_extension_manager); |
36 | 35 |
37 // Class PendingExtensionManager manages the set of extensions which are | 36 // Class PendingExtensionManager manages the set of extensions which are |
38 // being installed or updated. In general, installation and updates take | 37 // being installed or updated. In general, installation and updates take |
39 // time, because they involve downloading, unpacking, and installing. | 38 // time, because they involve downloading, unpacking, and installing. |
40 // This class allows us to avoid race cases where multiple sources install | 39 // This class allows us to avoid race cases where multiple sources install |
41 // the same extension. | 40 // the same extension. |
42 // The extensions service creates an instance of this class, and manages | 41 // The ExtensionService creates an instance of this class, and manages its |
43 // its lifetime. This class should only be used from the UI thread. | 42 // lifetime. This class should only be used from the UI thread. |
44 class PendingExtensionManager { | 43 class PendingExtensionManager { |
45 public: | 44 public: |
46 // |service| is a reference to the ExtensionService whose pending | 45 explicit PendingExtensionManager(content::BrowserContext* context); |
47 // extensions we are managing. The service creates an instance of | |
48 // this class on construction, and destroys it on destruction. | |
49 // The service remains valid over the entire lifetime of this class. | |
50 explicit PendingExtensionManager(const ExtensionServiceInterface& service, | |
51 content::BrowserContext* context); | |
52 ~PendingExtensionManager(); | 46 ~PendingExtensionManager(); |
53 | 47 |
54 // TODO(skerner): Many of these methods can be private once code in | 48 // TODO(skerner): Many of these methods can be private once code in |
55 // ExtensionService is moved into methods of this class. | 49 // ExtensionService is moved into methods of this class. |
56 | 50 |
57 // Remove extension with id |id| from the set of pending extensions. Returns | 51 // Remove extension with id |id| from the set of pending extensions. Returns |
58 // true if such an extension was found and removed, false otherwise. | 52 // true if such an extension was found and removed, false otherwise. |
59 bool Remove(const std::string& id); | 53 bool Remove(const std::string& id); |
60 | 54 |
61 // Get the information for a pending extension. Returns a pointer to the | 55 // Get the information for a pending extension. Returns a pointer to the |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 Manifest::Location install_source, | 128 Manifest::Location install_source, |
135 int creation_flags, | 129 int creation_flags, |
136 bool mark_acknowledged, | 130 bool mark_acknowledged, |
137 bool remote_install); | 131 bool remote_install); |
138 | 132 |
139 // Add a pending extension record directly. Used for unit tests that need | 133 // Add a pending extension record directly. Used for unit tests that need |
140 // to set an inital state. Use friendship to allow the tests to call this | 134 // to set an inital state. Use friendship to allow the tests to call this |
141 // method. | 135 // method. |
142 void AddForTesting(const PendingExtensionInfo& pending_extension_info); | 136 void AddForTesting(const PendingExtensionInfo& pending_extension_info); |
143 | 137 |
144 // Reference to the extension service whose pending extensions this class is | |
145 // managing. Because this class is a member of |service_|, it is created | |
146 // and destroyed with |service_|. We only use methods from the interface | |
147 // ExtensionServiceInterface. | |
148 const ExtensionServiceInterface& service_; | |
149 | |
150 // The BrowserContext with which the manager is associated. | 138 // The BrowserContext with which the manager is associated. |
151 content::BrowserContext* context_; | 139 content::BrowserContext* context_; |
152 | 140 |
153 PendingExtensionList pending_extension_list_; | 141 PendingExtensionList pending_extension_list_; |
154 | 142 |
155 FRIEND_TEST_ALL_PREFIXES(::ExtensionServiceTest, | 143 FRIEND_TEST_ALL_PREFIXES(::ExtensionServiceTest, |
156 UpdatePendingExtensionAlreadyInstalled); | 144 UpdatePendingExtensionAlreadyInstalled); |
157 friend class ExtensionUpdaterTest; | 145 friend class ExtensionUpdaterTest; |
158 friend void SetupPendingExtensionManagerForTest( | 146 friend void SetupPendingExtensionManagerForTest( |
159 int count, const GURL& update_url, | 147 int count, const GURL& update_url, |
160 PendingExtensionManager* pending_extension_manager); | 148 PendingExtensionManager* pending_extension_manager); |
161 | 149 |
162 DISALLOW_COPY_AND_ASSIGN(PendingExtensionManager); | 150 DISALLOW_COPY_AND_ASSIGN(PendingExtensionManager); |
163 }; | 151 }; |
164 | 152 |
165 } // namespace extensions | 153 } // namespace extensions |
166 | 154 |
167 #endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_ | 155 #endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_ |
OLD | NEW |