[email protected] | f3d3b38 | 2014-03-14 21:19:28 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | f3d3b38 | 2014-03-14 21:19:28 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_ |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 7 | |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 8 | #include <list> |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 9 | #include <string> |
| 10 | |
[email protected] | f3d3b38 | 2014-03-14 21:19:28 | [diff] [blame] | 11 | #include "chrome/browser/extensions/pending_extension_info.h" |
[email protected] | d42c1115 | 2013-08-22 19:36:32 | [diff] [blame] | 12 | #include "extensions/common/manifest.h" |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 13 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 14 | class GURL; |
[email protected] | 1f04ef4 | 2013-04-22 07:35:50 | [diff] [blame] | 15 | |
| 16 | namespace base { |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 17 | class Version; |
[email protected] | 1f04ef4 | 2013-04-22 07:35:50 | [diff] [blame] | 18 | } |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 19 | |
[email protected] | 46f3e10 | 2014-03-25 01:22:45 | [diff] [blame] | 20 | namespace content { |
| 21 | class BrowserContext; |
| 22 | } |
| 23 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 24 | FORWARD_DECLARE_TEST(ExtensionServiceTest, |
| 25 | UpdatePendingExtensionAlreadyInstalled); |
| 26 | |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 27 | namespace extensions { |
[email protected] | b52f8ca | 2013-11-28 08:25:22 | [diff] [blame] | 28 | class Extension; |
| 29 | class PendingExtensionManager; |
| 30 | |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 31 | class ExtensionUpdaterTest; |
| 32 | void SetupPendingExtensionManagerForTest( |
| 33 | int count, const GURL& update_url, |
| 34 | PendingExtensionManager* pending_extension_manager); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 35 | |
| 36 | // Class PendingExtensionManager manages the set of extensions which are |
[email protected] | 7576451 | 2011-12-19 19:54:28 | [diff] [blame] | 37 | // being installed or updated. In general, installation and updates take |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 38 | // time, because they involve downloading, unpacking, and installing. |
| 39 | // This class allows us to avoid race cases where multiple sources install |
| 40 | // the same extension. |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 41 | // The ExtensionService creates an instance of this class, and manages its |
| 42 | // lifetime. This class should only be used from the UI thread. |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 43 | class PendingExtensionManager { |
| 44 | public: |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 45 | explicit PendingExtensionManager(content::BrowserContext* context); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 46 | ~PendingExtensionManager(); |
| 47 | |
| 48 | // TODO(skerner): Many of these methods can be private once code in |
| 49 | // ExtensionService is moved into methods of this class. |
| 50 | |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 51 | // Remove extension with id |id| from the set of pending extensions. Returns |
| 52 | // true if such an extension was found and removed, false otherwise. |
| 53 | bool Remove(const std::string& id); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 54 | |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 55 | // Get the information for a pending extension. Returns a pointer to the |
| 56 | // pending extension with id |id|, or NULL if there is no such extension. |
| 57 | const PendingExtensionInfo* GetById(const std::string& id) const; |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 58 | |
| 59 | // Is |id| in the set of pending extensions? |
| 60 | bool IsIdPending(const std::string& id) const; |
| 61 | |
[email protected] | 9bd9a686 | 2012-11-29 09:24:22 | [diff] [blame] | 62 | // Returns true if there are any extensions pending. |
| 63 | bool HasPendingExtensions() const; |
| 64 | |
[email protected] | d31e19e | 2012-08-22 00:19:04 | [diff] [blame] | 65 | // Whether there is pending extension install from sync. |
| 66 | bool HasPendingExtensionFromSync() const; |
| 67 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 68 | // Adds an extension in a pending state; the extension with the |
| 69 | // given info will be installed on the next auto-update cycle. |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 70 | // Return true if the extension was added. Will return false |
| 71 | // if the extension is pending from another source which overrides |
| 72 | // sync installs (such as a policy extension) or if the extension |
| 73 | // is already installed. |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 74 | // |
| 75 | // TODO(akalin): Replace |install_silently| with a list of |
| 76 | // pre-enabled permissions. |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 77 | bool AddFromSync( |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 78 | const std::string& id, |
| 79 | const GURL& update_url, |
| 80 | PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 81 | bool install_silently, |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame^] | 82 | bool remote_install, |
| 83 | bool installed_by_custodian); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 84 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 85 | // Adds an extension that was depended on by another extension. |
| 86 | bool AddFromExtensionImport( |
| 87 | const std::string& id, |
| 88 | const GURL& update_url, |
| 89 | PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install); |
| 90 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 91 | // Given an extension id and an update URL, schedule the extension |
| 92 | // to be fetched, installed, and activated. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 93 | bool AddFromExternalUpdateUrl(const std::string& id, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 94 | const std::string& install_parameter, |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 95 | const GURL& update_url, |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 96 | Manifest::Location location, |
| 97 | int creation_flags, |
| 98 | bool mark_acknowledged); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 99 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 100 | // Add a pending extension record for an external CRX file. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 101 | // Return true if the CRX should be installed, false if an existing |
| 102 | // pending record overrides it. |
| 103 | bool AddFromExternalFile( |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 104 | const std::string& id, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 105 | Manifest::Location location, |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 106 | const base::Version& version, |
| 107 | int creation_flags, |
| 108 | bool mark_acknowledged); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 109 | |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 110 | // Get the list of pending IDs that should be installed from an update URL. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 111 | // Pending extensions that will be installed from local files will not be |
| 112 | // included in the set. |
| 113 | void GetPendingIdsForUpdateCheck( |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 114 | std::list<std::string>* out_ids_for_update_check) const; |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 115 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 116 | private: |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 117 | typedef std::list<PendingExtensionInfo> PendingExtensionList; |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 118 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 119 | // Assumes an extension with id |id| is not already installed. |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 120 | // Return true if the extension was added. |
| 121 | bool AddExtensionImpl( |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 122 | const std::string& id, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 123 | const std::string& install_parameter, |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 124 | const GURL& update_url, |
[email protected] | 1f04ef4 | 2013-04-22 07:35:50 | [diff] [blame] | 125 | const base::Version& version, |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 126 | PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, |
| 127 | bool is_from_sync, |
| 128 | bool install_silently, |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 129 | Manifest::Location install_source, |
| 130 | int creation_flags, |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 131 | bool mark_acknowledged, |
| 132 | bool remote_install); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 133 | |
| 134 | // Add a pending extension record directly. Used for unit tests that need |
| 135 | // to set an inital state. Use friendship to allow the tests to call this |
| 136 | // method. |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 137 | void AddForTesting(const PendingExtensionInfo& pending_extension_info); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 138 | |
[email protected] | 46f3e10 | 2014-03-25 01:22:45 | [diff] [blame] | 139 | // The BrowserContext with which the manager is associated. |
| 140 | content::BrowserContext* context_; |
| 141 | |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 142 | PendingExtensionList pending_extension_list_; |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 143 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 144 | FRIEND_TEST_ALL_PREFIXES(::ExtensionServiceTest, |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 145 | UpdatePendingExtensionAlreadyInstalled); |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 146 | friend class ExtensionUpdaterTest; |
| 147 | friend void SetupPendingExtensionManagerForTest( |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 148 | int count, const GURL& update_url, |
| 149 | PendingExtensionManager* pending_extension_manager); |
| 150 | |
| 151 | DISALLOW_COPY_AND_ASSIGN(PendingExtensionManager); |
| 152 | }; |
| 153 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 154 | } // namespace extensions |
| 155 | |
[email protected] | f3d3b38 | 2014-03-14 21:19:28 | [diff] [blame] | 156 | #endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_ |