blob: 51938891ee232a6a710abd8f1b62a9b15dc9d0a6 [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>
[email protected]b2907fd2011-03-25 16:43:379#include <string>
10
thestiga0e18cd2015-09-25 04:58:3611#include "base/gtest_prod_util.h"
[email protected]f3d3b382014-03-14 21:19:2812#include "chrome/browser/extensions/pending_extension_info.h"
[email protected]d42c11152013-08-22 19:36:3213#include "extensions/common/manifest.h"
[email protected]b2907fd2011-03-25 16:43:3714
[email protected]b2907fd2011-03-25 16:43:3715class GURL;
[email protected]1f04ef42013-04-22 07:35:5016
17namespace base {
[email protected]e3987852012-05-04 10:06:3018class Version;
[email protected]1f04ef42013-04-22 07:35:5019}
[email protected]42a08162012-03-16 18:09:1120
[email protected]46f3e102014-03-25 01:22:4521namespace content {
22class BrowserContext;
23}
24
[email protected]3f213ad2012-07-26 23:39:4125FORWARD_DECLARE_TEST(ExtensionServiceTest,
26 UpdatePendingExtensionAlreadyInstalled);
27
[email protected]42a08162012-03-16 18:09:1128namespace extensions {
[email protected]b52f8ca2013-11-28 08:25:2229class Extension;
30class PendingExtensionManager;
31
[email protected]42a08162012-03-16 18:09:1132class ExtensionUpdaterTest;
33void SetupPendingExtensionManagerForTest(
34 int count, const GURL& update_url,
35 PendingExtensionManager* pending_extension_manager);
[email protected]b2907fd2011-03-25 16:43:3736
37// Class PendingExtensionManager manages the set of extensions which are
[email protected]75764512011-12-19 19:54:2838// being installed or updated. In general, installation and updates take
[email protected]b2907fd2011-03-25 16:43:3739// time, because they involve downloading, unpacking, and installing.
40// This class allows us to avoid race cases where multiple sources install
41// the same extension.
[email protected]6c9bedf2014-05-21 03:55:5142// The ExtensionService creates an instance of this class, and manages its
43// lifetime. This class should only be used from the UI thread.
[email protected]b2907fd2011-03-25 16:43:3744class PendingExtensionManager {
45 public:
[email protected]6c9bedf2014-05-21 03:55:5146 explicit PendingExtensionManager(content::BrowserContext* context);
[email protected]b2907fd2011-03-25 16:43:3747 ~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]51a3bf8b2012-06-08 22:53:0652 // 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]b2907fd2011-03-25 16:43:3755
[email protected]51a3bf8b2012-06-08 22:53:0656 // 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]b2907fd2011-03-25 16:43:3759
60 // Is |id| in the set of pending extensions?
61 bool IsIdPending(const std::string& id) const;
62
[email protected]9bd9a6862012-11-29 09:24:2263 // Returns true if there are any extensions pending.
64 bool HasPendingExtensions() const;
65
[email protected]d31e19e2012-08-22 00:19:0466 // Whether there is pending extension install from sync.
67 bool HasPendingExtensionFromSync() const;
68
[email protected]b2907fd2011-03-25 16:43:3769 // 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]145a317b2011-04-12 16:03:4671 // 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.
treibe960e282015-09-11 10:38:0875 // After installation, the extension will be granted permissions iff
76 // |version| is valid and matches the actual installed version.
[email protected]145a317b2011-04-12 16:03:4677 bool AddFromSync(
[email protected]b2907fd2011-03-25 16:43:3778 const std::string& id,
79 const GURL& update_url,
treibe960e282015-09-11 10:38:0880 const base::Version& version,
[email protected]b2907fd2011-03-25 16:43:3781 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install,
[email protected]6338fa32014-07-16 21:41:5982 bool remote_install,
83 bool installed_by_custodian);
[email protected]b2907fd2011-03-25 16:43:3784
[email protected]9f4e4f082013-06-21 07:11:1985 // 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]b2907fd2011-03-25 16:43:3791 // Given an extension id and an update URL, schedule the extension
92 // to be fetched, installed, and activated.
[email protected]9060d8b02012-01-13 02:14:3093 bool AddFromExternalUpdateUrl(const std::string& id,
[email protected]d8fd0fd2014-03-24 13:16:0694 const std::string& install_parameter,
[email protected]b2907fd2011-03-25 16:43:3795 const GURL& update_url,
[email protected]464213a2013-10-15 01:06:4896 Manifest::Location location,
97 int creation_flags,
98 bool mark_acknowledged);
[email protected]b2907fd2011-03-25 16:43:3799
[email protected]b2907fd2011-03-25 16:43:37100 // Add a pending extension record for an external CRX file.
[email protected]9060d8b02012-01-13 02:14:30101 // Return true if the CRX should be installed, false if an existing
102 // pending record overrides it.
103 bool AddFromExternalFile(
[email protected]b2907fd2011-03-25 16:43:37104 const std::string& id,
[email protected]1d5e58b2013-01-31 08:41:40105 Manifest::Location location,
[email protected]464213a2013-10-15 01:06:48106 const base::Version& version,
107 int creation_flags,
108 bool mark_acknowledged);
[email protected]b2907fd2011-03-25 16:43:37109
[email protected]51a3bf8b2012-06-08 22:53:06110 // Get the list of pending IDs that should be installed from an update URL.
[email protected]9060d8b02012-01-13 02:14:30111 // Pending extensions that will be installed from local files will not be
112 // included in the set.
113 void GetPendingIdsForUpdateCheck(
[email protected]51a3bf8b2012-06-08 22:53:06114 std::list<std::string>* out_ids_for_update_check) const;
[email protected]9060d8b02012-01-13 02:14:30115
[email protected]b2907fd2011-03-25 16:43:37116 private:
[email protected]51a3bf8b2012-06-08 22:53:06117 typedef std::list<PendingExtensionInfo> PendingExtensionList;
[email protected]9060d8b02012-01-13 02:14:30118
[email protected]b2907fd2011-03-25 16:43:37119 // Assumes an extension with id |id| is not already installed.
[email protected]145a317b2011-04-12 16:03:46120 // Return true if the extension was added.
121 bool AddExtensionImpl(
[email protected]b2907fd2011-03-25 16:43:37122 const std::string& id,
[email protected]d8fd0fd2014-03-24 13:16:06123 const std::string& install_parameter,
[email protected]b2907fd2011-03-25 16:43:37124 const GURL& update_url,
[email protected]1f04ef42013-04-22 07:35:50125 const base::Version& version,
[email protected]b2907fd2011-03-25 16:43:37126 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install,
127 bool is_from_sync,
[email protected]464213a2013-10-15 01:06:48128 Manifest::Location install_source,
129 int creation_flags,
[email protected]21db9ef2014-05-16 02:06:27130 bool mark_acknowledged,
131 bool remote_install);
[email protected]b2907fd2011-03-25 16:43:37132
133 // Add a pending extension record directly. Used for unit tests that need
134 // to set an inital state. Use friendship to allow the tests to call this
135 // method.
[email protected]51a3bf8b2012-06-08 22:53:06136 void AddForTesting(const PendingExtensionInfo& pending_extension_info);
[email protected]b2907fd2011-03-25 16:43:37137
[email protected]46f3e102014-03-25 01:22:45138 // The BrowserContext with which the manager is associated.
139 content::BrowserContext* context_;
140
[email protected]51a3bf8b2012-06-08 22:53:06141 PendingExtensionList pending_extension_list_;
[email protected]b2907fd2011-03-25 16:43:37142
[email protected]3f213ad2012-07-26 23:39:41143 FRIEND_TEST_ALL_PREFIXES(::ExtensionServiceTest,
[email protected]b2907fd2011-03-25 16:43:37144 UpdatePendingExtensionAlreadyInstalled);
[email protected]3f213ad2012-07-26 23:39:41145 friend class ExtensionUpdaterTest;
146 friend void SetupPendingExtensionManagerForTest(
[email protected]b2907fd2011-03-25 16:43:37147 int count, const GURL& update_url,
148 PendingExtensionManager* pending_extension_manager);
149
150 DISALLOW_COPY_AND_ASSIGN(PendingExtensionManager);
151};
152
[email protected]3f213ad2012-07-26 23:39:41153} // namespace extensions
154
[email protected]f3d3b382014-03-14 21:19:28155#endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_