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