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