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