blob: cbadf7dc2298f391f7253211f147e9b619e07e0c [file] [log] [blame]
[email protected]f3d3b382014-03-14 21:19:281// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]b2907fd2011-03-25 16:43:372// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]f3d3b382014-03-14 21:19:285#ifndef CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_
6#define CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_
[email protected]b2907fd2011-03-25 16:43:377
[email protected]51a3bf8b2012-06-08 22:53:068#include <list>
asargent56282ab72016-09-09 16:58:039#include <map>
[email protected]b2907fd2011-03-25 16:43:3710#include <string>
11
thestiga0e18cd2015-09-25 04:58:3612#include "base/gtest_prod_util.h"
avia2f4804a2015-12-24 23:11:1313#include "base/macros.h"
asargent56282ab72016-09-09 16:58:0314#include "base/time/time.h"
[email protected]f3d3b382014-03-14 21:19:2815#include "chrome/browser/extensions/pending_extension_info.h"
asargent56282ab72016-09-09 16:58:0316#include "extensions/common/extension_id.h"
[email protected]d42c11152013-08-22 19:36:3217#include "extensions/common/manifest.h"
[email protected]b2907fd2011-03-25 16:43:3718
[email protected]b2907fd2011-03-25 16:43:3719class GURL;
[email protected]1f04ef42013-04-22 07:35:5020
21namespace base {
[email protected]e3987852012-05-04 10:06:3022class Version;
[email protected]1f04ef42013-04-22 07:35:5023}
[email protected]42a08162012-03-16 18:09:1124
[email protected]46f3e102014-03-25 01:22:4525namespace content {
26class BrowserContext;
27}
28
Devlin Cronineea1b7a2018-05-26 02:46:2129namespace extensions {
[email protected]3f213ad2012-07-26 23:39:4130FORWARD_DECLARE_TEST(ExtensionServiceTest,
31 UpdatePendingExtensionAlreadyInstalled);
32
[email protected]b52f8ca2013-11-28 08:25:2233class PendingExtensionManager;
34
[email protected]42a08162012-03-16 18:09:1135class ExtensionUpdaterTest;
36void SetupPendingExtensionManagerForTest(
37 int count, const GURL& update_url,
38 PendingExtensionManager* pending_extension_manager);
[email protected]b2907fd2011-03-25 16:43:3739
40// Class PendingExtensionManager manages the set of extensions which are
[email protected]75764512011-12-19 19:54:2841// being installed or updated. In general, installation and updates take
[email protected]b2907fd2011-03-25 16:43:3742// time, because they involve downloading, unpacking, and installing.
43// This class allows us to avoid race cases where multiple sources install
44// the same extension.
[email protected]6c9bedf2014-05-21 03:55:5145// The ExtensionService creates an instance of this class, and manages its
46// lifetime. This class should only be used from the UI thread.
[email protected]b2907fd2011-03-25 16:43:3747class PendingExtensionManager {
48 public:
[email protected]6c9bedf2014-05-21 03:55:5149 explicit PendingExtensionManager(content::BrowserContext* context);
[email protected]b2907fd2011-03-25 16:43:3750 ~PendingExtensionManager();
51
52 // TODO(skerner): Many of these methods can be private once code in
53 // ExtensionService is moved into methods of this class.
54
[email protected]51a3bf8b2012-06-08 22:53:0655 // Remove extension with id |id| from the set of pending extensions. Returns
56 // true if such an extension was found and removed, false otherwise.
57 bool Remove(const std::string& id);
[email protected]b2907fd2011-03-25 16:43:3758
[email protected]51a3bf8b2012-06-08 22:53:0659 // Get the information for a pending extension. Returns a pointer to the
60 // pending extension with id |id|, or NULL if there is no such extension.
61 const PendingExtensionInfo* GetById(const std::string& id) const;
[email protected]b2907fd2011-03-25 16:43:3762
63 // Is |id| in the set of pending extensions?
64 bool IsIdPending(const std::string& id) const;
65
[email protected]9bd9a6862012-11-29 09:24:2266 // Returns true if there are any extensions pending.
67 bool HasPendingExtensions() const;
68
[email protected]d31e19e2012-08-22 00:19:0469 // Whether there is pending extension install from sync.
70 bool HasPendingExtensionFromSync() const;
71
Oleg Davydov6541a64f2019-04-17 13:17:3372 // Whether there is pending extension install from policy.
73 bool HasPendingExtensionFromPolicy() const;
74
asargent56282ab72016-09-09 16:58:0375 // Notifies the manager that we are reinstalling the policy force-installed
76 // extension with |id| because we detected corruption in the current copy.
77 void ExpectPolicyReinstallForCorruption(const ExtensionId& id);
78
79 // Are we expecting a reinstall of the extension with |id| due to corruption?
80 bool IsPolicyReinstallForCorruptionExpected(const ExtensionId& id) const;
81
lazyboy77214d3c2017-04-04 16:46:1282 // Whether or not there are any corrupted policy extensions.
83 bool HasAnyPolicyReinstallForCorruption() const;
84
[email protected]b2907fd2011-03-25 16:43:3785 // Adds an extension in a pending state; the extension with the
86 // given info will be installed on the next auto-update cycle.
[email protected]145a317b2011-04-12 16:03:4687 // Return true if the extension was added. Will return false
88 // if the extension is pending from another source which overrides
89 // sync installs (such as a policy extension) or if the extension
90 // is already installed.
treibe960e282015-09-11 10:38:0891 // After installation, the extension will be granted permissions iff
92 // |version| is valid and matches the actual installed version.
[email protected]145a317b2011-04-12 16:03:4693 bool AddFromSync(
[email protected]b2907fd2011-03-25 16:43:3794 const std::string& id,
95 const GURL& update_url,
treibe960e282015-09-11 10:38:0896 const base::Version& version,
[email protected]b2907fd2011-03-25 16:43:3797 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install,
mamir192d7882016-06-22 17:10:1698 bool remote_install);
[email protected]b2907fd2011-03-25 16:43:3799
[email protected]9f4e4f082013-06-21 07:11:19100 // Adds an extension that was depended on by another extension.
101 bool AddFromExtensionImport(
102 const std::string& id,
103 const GURL& update_url,
104 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install);
105
[email protected]b2907fd2011-03-25 16:43:37106 // Given an extension id and an update URL, schedule the extension
107 // to be fetched, installed, and activated.
[email protected]9060d8b02012-01-13 02:14:30108 bool AddFromExternalUpdateUrl(const std::string& id,
[email protected]d8fd0fd2014-03-24 13:16:06109 const std::string& install_parameter,
[email protected]b2907fd2011-03-25 16:43:37110 const GURL& update_url,
[email protected]464213a2013-10-15 01:06:48111 Manifest::Location location,
112 int creation_flags,
113 bool mark_acknowledged);
[email protected]b2907fd2011-03-25 16:43:37114
[email protected]b2907fd2011-03-25 16:43:37115 // Add a pending extension record for an external CRX file.
[email protected]9060d8b02012-01-13 02:14:30116 // Return true if the CRX should be installed, false if an existing
117 // pending record overrides it.
118 bool AddFromExternalFile(
[email protected]b2907fd2011-03-25 16:43:37119 const std::string& id,
[email protected]1d5e58b2013-01-31 08:41:40120 Manifest::Location location,
[email protected]464213a2013-10-15 01:06:48121 const base::Version& version,
122 int creation_flags,
123 bool mark_acknowledged);
[email protected]b2907fd2011-03-25 16:43:37124
[email protected]51a3bf8b2012-06-08 22:53:06125 // Get the list of pending IDs that should be installed from an update URL.
[email protected]9060d8b02012-01-13 02:14:30126 // Pending extensions that will be installed from local files will not be
127 // included in the set.
128 void GetPendingIdsForUpdateCheck(
[email protected]51a3bf8b2012-06-08 22:53:06129 std::list<std::string>* out_ids_for_update_check) const;
[email protected]9060d8b02012-01-13 02:14:30130
[email protected]b2907fd2011-03-25 16:43:37131 private:
[email protected]51a3bf8b2012-06-08 22:53:06132 typedef std::list<PendingExtensionInfo> PendingExtensionList;
[email protected]9060d8b02012-01-13 02:14:30133
[email protected]b2907fd2011-03-25 16:43:37134 // Assumes an extension with id |id| is not already installed.
[email protected]145a317b2011-04-12 16:03:46135 // Return true if the extension was added.
136 bool AddExtensionImpl(
[email protected]b2907fd2011-03-25 16:43:37137 const std::string& id,
[email protected]d8fd0fd2014-03-24 13:16:06138 const std::string& install_parameter,
[email protected]b2907fd2011-03-25 16:43:37139 const GURL& update_url,
[email protected]1f04ef42013-04-22 07:35:50140 const base::Version& version,
[email protected]b2907fd2011-03-25 16:43:37141 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install,
142 bool is_from_sync,
[email protected]464213a2013-10-15 01:06:48143 Manifest::Location install_source,
mamir0128d5a2016-07-15 20:55:48144 int creation_flags,
[email protected]21db9ef2014-05-16 02:06:27145 bool mark_acknowledged,
146 bool remote_install);
[email protected]b2907fd2011-03-25 16:43:37147
148 // Add a pending extension record directly. Used for unit tests that need
149 // to set an inital state. Use friendship to allow the tests to call this
150 // method.
[email protected]51a3bf8b2012-06-08 22:53:06151 void AddForTesting(const PendingExtensionInfo& pending_extension_info);
[email protected]b2907fd2011-03-25 16:43:37152
[email protected]46f3e102014-03-25 01:22:45153 // The BrowserContext with which the manager is associated.
154 content::BrowserContext* context_;
155
[email protected]51a3bf8b2012-06-08 22:53:06156 PendingExtensionList pending_extension_list_;
[email protected]b2907fd2011-03-25 16:43:37157
asargent56282ab72016-09-09 16:58:03158 // A set of policy force-installed extension ids that are being reinstalled
159 // due to corruption, mapped to the time we detected the corruption.
160 std::map<ExtensionId, base::TimeTicks> expected_policy_reinstalls_;
161
Devlin Cronineea1b7a2018-05-26 02:46:21162 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
[email protected]b2907fd2011-03-25 16:43:37163 UpdatePendingExtensionAlreadyInstalled);
[email protected]3f213ad2012-07-26 23:39:41164 friend class ExtensionUpdaterTest;
165 friend void SetupPendingExtensionManagerForTest(
[email protected]b2907fd2011-03-25 16:43:37166 int count, const GURL& update_url,
167 PendingExtensionManager* pending_extension_manager);
168
169 DISALLOW_COPY_AND_ASSIGN(PendingExtensionManager);
170};
171
[email protected]3f213ad2012-07-26 23:39:41172} // namespace extensions
173
[email protected]f3d3b382014-03-14 21:19:28174#endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_