OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "chrome/browser/extensions/pending_extension_info.h" | 12 #include "chrome/browser/extensions/pending_extension_info.h" |
13 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
14 | 14 |
15 class ExtensionServiceInterface; | 15 class ExtensionServiceInterface; |
16 class GURL; | 16 class GURL; |
17 class PendingExtensionManager; | 17 class PendingExtensionManager; |
18 class Version; | 18 class Version; |
19 | 19 |
| 20 FORWARD_DECLARE_TEST(ExtensionServiceTest, |
| 21 UpdatePendingExtensionAlreadyInstalled); |
| 22 |
20 namespace extensions { | 23 namespace extensions { |
21 class ExtensionUpdaterTest; | 24 class ExtensionUpdaterTest; |
22 void SetupPendingExtensionManagerForTest( | 25 void SetupPendingExtensionManagerForTest( |
23 int count, const GURL& update_url, | 26 int count, const GURL& update_url, |
24 PendingExtensionManager* pending_extension_manager); | 27 PendingExtensionManager* pending_extension_manager); |
25 } | |
26 | 28 |
27 // Class PendingExtensionManager manages the set of extensions which are | 29 // Class PendingExtensionManager manages the set of extensions which are |
28 // being installed or updated. In general, installation and updates take | 30 // being installed or updated. In general, installation and updates take |
29 // time, because they involve downloading, unpacking, and installing. | 31 // time, because they involve downloading, unpacking, and installing. |
30 // This class allows us to avoid race cases where multiple sources install | 32 // This class allows us to avoid race cases where multiple sources install |
31 // the same extension. | 33 // the same extension. |
32 // The extensions service creates an instance of this class, and manages | 34 // The extensions service creates an instance of this class, and manages |
33 // its lifetime. This class should only be used from the UI thread. | 35 // its lifetime. This class should only be used from the UI thread. |
34 class PendingExtensionManager { | 36 class PendingExtensionManager { |
35 public: | 37 public: |
(...skipping 30 matching lines...) Expand all Loading... |
66 bool AddFromSync( | 68 bool AddFromSync( |
67 const std::string& id, | 69 const std::string& id, |
68 const GURL& update_url, | 70 const GURL& update_url, |
69 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, | 71 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, |
70 bool install_silently); | 72 bool install_silently); |
71 | 73 |
72 // Given an extension id and an update URL, schedule the extension | 74 // Given an extension id and an update URL, schedule the extension |
73 // to be fetched, installed, and activated. | 75 // to be fetched, installed, and activated. |
74 bool AddFromExternalUpdateUrl(const std::string& id, | 76 bool AddFromExternalUpdateUrl(const std::string& id, |
75 const GURL& update_url, | 77 const GURL& update_url, |
76 extensions::Extension::Location location); | 78 Extension::Location location); |
77 | 79 |
78 // Add a pending extension record for an external CRX file. | 80 // Add a pending extension record for an external CRX file. |
79 // Return true if the CRX should be installed, false if an existing | 81 // Return true if the CRX should be installed, false if an existing |
80 // pending record overrides it. | 82 // pending record overrides it. |
81 bool AddFromExternalFile( | 83 bool AddFromExternalFile( |
82 const std::string& id, | 84 const std::string& id, |
83 extensions::Extension::Location location, | 85 Extension::Location location, |
84 const Version& version); | 86 const Version& version); |
85 | 87 |
86 // Get the list of pending IDs that should be installed from an update URL. | 88 // Get the list of pending IDs that should be installed from an update URL. |
87 // Pending extensions that will be installed from local files will not be | 89 // Pending extensions that will be installed from local files will not be |
88 // included in the set. | 90 // included in the set. |
89 void GetPendingIdsForUpdateCheck( | 91 void GetPendingIdsForUpdateCheck( |
90 std::list<std::string>* out_ids_for_update_check) const; | 92 std::list<std::string>* out_ids_for_update_check) const; |
91 | 93 |
92 private: | 94 private: |
93 typedef std::list<PendingExtensionInfo> PendingExtensionList; | 95 typedef std::list<PendingExtensionInfo> PendingExtensionList; |
94 | 96 |
95 // Assumes an extension with id |id| is not already installed. | 97 // Assumes an extension with id |id| is not already installed. |
96 // Return true if the extension was added. | 98 // Return true if the extension was added. |
97 bool AddExtensionImpl( | 99 bool AddExtensionImpl( |
98 const std::string& id, | 100 const std::string& id, |
99 const GURL& update_url, | 101 const GURL& update_url, |
100 const Version& version, | 102 const Version& version, |
101 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, | 103 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, |
102 bool is_from_sync, | 104 bool is_from_sync, |
103 bool install_silently, | 105 bool install_silently, |
104 extensions::Extension::Location install_source); | 106 Extension::Location install_source); |
105 | 107 |
106 // Add a pending extension record directly. Used for unit tests that need | 108 // Add a pending extension record directly. Used for unit tests that need |
107 // to set an inital state. Use friendship to allow the tests to call this | 109 // to set an inital state. Use friendship to allow the tests to call this |
108 // method. | 110 // method. |
109 void AddForTesting(const PendingExtensionInfo& pending_extension_info); | 111 void AddForTesting(const PendingExtensionInfo& pending_extension_info); |
110 | 112 |
111 // Reference to the extension service whose pending extensions this class is | 113 // Reference to the extension service whose pending extensions this class is |
112 // managing. Because this class is a member of |service_|, it is created | 114 // managing. Because this class is a member of |service_|, it is created |
113 // and destroyed with |service_|. We only use methods from the interface | 115 // and destroyed with |service_|. We only use methods from the interface |
114 // ExtensionServiceInterface. | 116 // ExtensionServiceInterface. |
115 const ExtensionServiceInterface& service_; | 117 const ExtensionServiceInterface& service_; |
116 | 118 |
117 PendingExtensionList pending_extension_list_; | 119 PendingExtensionList pending_extension_list_; |
118 | 120 |
119 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 121 FRIEND_TEST_ALL_PREFIXES(::ExtensionServiceTest, |
120 UpdatePendingExtensionAlreadyInstalled); | 122 UpdatePendingExtensionAlreadyInstalled); |
121 friend class extensions::ExtensionUpdaterTest; | 123 friend class ExtensionUpdaterTest; |
122 friend void extensions::SetupPendingExtensionManagerForTest( | 124 friend void SetupPendingExtensionManagerForTest( |
123 int count, const GURL& update_url, | 125 int count, const GURL& update_url, |
124 PendingExtensionManager* pending_extension_manager); | 126 PendingExtensionManager* pending_extension_manager); |
125 | 127 |
126 DISALLOW_COPY_AND_ASSIGN(PendingExtensionManager); | 128 DISALLOW_COPY_AND_ASSIGN(PendingExtensionManager); |
127 }; | 129 }; |
128 | 130 |
| 131 } // namespace extensions |
| 132 |
129 #endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_ | 133 #endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_ |
OLD | NEW |