| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <list> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> |
| 11 | 12 |
| 12 #include "chrome/browser/extensions/pending_extension_info.h" | 13 #include "chrome/browser/extensions/pending_extension_info.h" |
| 13 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 14 | 15 |
| 15 class ExtensionServiceInterface; | 16 class ExtensionServiceInterface; |
| 16 class GURL; | 17 class GURL; |
| 17 class PendingExtensionManager; | 18 class PendingExtensionManager; |
| 18 class Version; | 19 class Version; |
| 19 | 20 |
| 20 namespace extensions { | 21 namespace extensions { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 36 // |service| is a reference to the ExtensionService whose pending | 37 // |service| is a reference to the ExtensionService whose pending |
| 37 // extensions we are managing. The service creates an instance of | 38 // extensions we are managing. The service creates an instance of |
| 38 // this class on construction, and destroys it on destruction. | 39 // this class on construction, and destroys it on destruction. |
| 39 // The service remains valid over the entire lifetime of this class. | 40 // The service remains valid over the entire lifetime of this class. |
| 40 explicit PendingExtensionManager(const ExtensionServiceInterface& service); | 41 explicit PendingExtensionManager(const ExtensionServiceInterface& service); |
| 41 ~PendingExtensionManager(); | 42 ~PendingExtensionManager(); |
| 42 | 43 |
| 43 // TODO(skerner): Many of these methods can be private once code in | 44 // TODO(skerner): Many of these methods can be private once code in |
| 44 // ExtensionService is moved into methods of this class. | 45 // ExtensionService is moved into methods of this class. |
| 45 | 46 |
| 46 // Remove |id| from the set of pending extensions. | 47 // Remove extension with id |id| from the set of pending extensions. Returns |
| 47 void Remove(const std::string& id); | 48 // true if such an extension was found and removed, false otherwise. |
| 49 bool Remove(const std::string& id); |
| 48 | 50 |
| 49 // Get the information for a pending extension. Returns true and sets | 51 // Get the information for a pending extension. Returns a pointer to the |
| 50 // |out_pending_extension_info| if there is a pending extension with id | 52 // pending extension with id |id|, or NULL if there is no such extension. |
| 51 // |id|. Returns false otherwise. | 53 const PendingExtensionInfo* GetById(const std::string& id) const; |
| 52 bool GetById(const std::string& id, | |
| 53 PendingExtensionInfo* out_pending_extension_info) const; | |
| 54 | 54 |
| 55 // Is |id| in the set of pending extensions? | 55 // Is |id| in the set of pending extensions? |
| 56 bool IsIdPending(const std::string& id) const; | 56 bool IsIdPending(const std::string& id) const; |
| 57 | 57 |
| 58 // Adds an extension in a pending state; the extension with the | 58 // Adds an extension in a pending state; the extension with the |
| 59 // given info will be installed on the next auto-update cycle. | 59 // given info will be installed on the next auto-update cycle. |
| 60 // Return true if the extension was added. Will return false | 60 // Return true if the extension was added. Will return false |
| 61 // if the extension is pending from another source which overrides | 61 // if the extension is pending from another source which overrides |
| 62 // sync installs (such as a policy extension) or if the extension | 62 // sync installs (such as a policy extension) or if the extension |
| 63 // is already installed. | 63 // is already installed. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 77 extensions::Extension::Location location); | 77 extensions::Extension::Location location); |
| 78 | 78 |
| 79 // Add a pending extension record for an external CRX file. | 79 // Add a pending extension record for an external CRX file. |
| 80 // Return true if the CRX should be installed, false if an existing | 80 // Return true if the CRX should be installed, false if an existing |
| 81 // pending record overrides it. | 81 // pending record overrides it. |
| 82 bool AddFromExternalFile( | 82 bool AddFromExternalFile( |
| 83 const std::string& id, | 83 const std::string& id, |
| 84 extensions::Extension::Location location, | 84 extensions::Extension::Location location, |
| 85 const Version& version); | 85 const Version& version); |
| 86 | 86 |
| 87 // Get the set of pending IDs that should be installed from an update URL. | 87 // Get the list of pending IDs that should be installed from an update URL. |
| 88 // Pending extensions that will be installed from local files will not be | 88 // Pending extensions that will be installed from local files will not be |
| 89 // included in the set. | 89 // included in the set. |
| 90 void GetPendingIdsForUpdateCheck( | 90 void GetPendingIdsForUpdateCheck( |
| 91 std::set<std::string>* out_ids_for_update_check) const; | 91 std::list<std::string>* out_ids_for_update_check) const; |
| 92 | 92 |
| 93 private: | 93 private: |
| 94 typedef std::map<std::string, PendingExtensionInfo> PendingExtensionMap; | 94 typedef std::list<PendingExtensionInfo> PendingExtensionList; |
| 95 | 95 |
| 96 // Assumes an extension with id |id| is not already installed. | 96 // Assumes an extension with id |id| is not already installed. |
| 97 // Return true if the extension was added. | 97 // Return true if the extension was added. |
| 98 bool AddExtensionImpl( | 98 bool AddExtensionImpl( |
| 99 const std::string& id, | 99 const std::string& id, |
| 100 const GURL& update_url, | 100 const GURL& update_url, |
| 101 const Version& version, | 101 const Version& version, |
| 102 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, | 102 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, |
| 103 bool is_from_sync, | 103 bool is_from_sync, |
| 104 bool install_silently, | 104 bool install_silently, |
| 105 extensions::Extension::Location install_source); | 105 extensions::Extension::Location install_source); |
| 106 | 106 |
| 107 // Add a pending extension record directly. Used for unit tests that need | 107 // Add a pending extension record directly. Used for unit tests that need |
| 108 // to set an inital state. Use friendship to allow the tests to call this | 108 // to set an inital state. Use friendship to allow the tests to call this |
| 109 // method. | 109 // method. |
| 110 void AddForTesting(const std::string& id, | 110 void AddForTesting(const PendingExtensionInfo& pending_extension_info); |
| 111 const PendingExtensionInfo& pending_etension_info); | |
| 112 | 111 |
| 113 // Reference to the extension service whose pending extensions this class is | 112 // Reference to the extension service whose pending extensions this class is |
| 114 // managing. Because this class is a member of |service_|, it is created | 113 // managing. Because this class is a member of |service_|, it is created |
| 115 // and destroyed with |service_|. We only use methods from the interface | 114 // and destroyed with |service_|. We only use methods from the interface |
| 116 // ExtensionServiceInterface. | 115 // ExtensionServiceInterface. |
| 117 const ExtensionServiceInterface& service_; | 116 const ExtensionServiceInterface& service_; |
| 118 | 117 |
| 119 // A map from extension id to the pending extension info for that extension. | 118 PendingExtensionList pending_extension_list_; |
| 120 PendingExtensionMap pending_extension_map_; | |
| 121 | 119 |
| 122 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 120 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 123 UpdatePendingExtensionAlreadyInstalled); | 121 UpdatePendingExtensionAlreadyInstalled); |
| 124 friend class extensions::ExtensionUpdaterTest; | 122 friend class extensions::ExtensionUpdaterTest; |
| 125 friend void extensions::SetupPendingExtensionManagerForTest( | 123 friend void extensions::SetupPendingExtensionManagerForTest( |
| 126 int count, const GURL& update_url, | 124 int count, const GURL& update_url, |
| 127 PendingExtensionManager* pending_extension_manager); | 125 PendingExtensionManager* pending_extension_manager); |
| 128 | 126 |
| 129 DISALLOW_COPY_AND_ASSIGN(PendingExtensionManager); | 127 DISALLOW_COPY_AND_ASSIGN(PendingExtensionManager); |
| 130 }; | 128 }; |
| 131 | 129 |
| 132 #endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_ | 130 #endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_ |
| OLD | NEW |