blob: 39d49324afa04fca8557beda1f45395b86c1ed1f [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
[email protected]f3d3b382014-03-14 21:19:2811#include "chrome/browser/extensions/pending_extension_info.h"
[email protected]d42c11152013-08-22 19:36:3212#include "extensions/common/manifest.h"
[email protected]b2907fd2011-03-25 16:43:3713
[email protected]b2907fd2011-03-25 16:43:3714class GURL;
[email protected]1f04ef42013-04-22 07:35:5015
16namespace base {
[email protected]e3987852012-05-04 10:06:3017class Version;
[email protected]1f04ef42013-04-22 07:35:5018}
[email protected]42a08162012-03-16 18:09:1119
[email protected]46f3e102014-03-25 01:22:4520namespace content {
21class BrowserContext;
22}
23
[email protected]3f213ad2012-07-26 23:39:4124FORWARD_DECLARE_TEST(ExtensionServiceTest,
25 UpdatePendingExtensionAlreadyInstalled);
26
[email protected]42a08162012-03-16 18:09:1127namespace extensions {
[email protected]b52f8ca2013-11-28 08:25:2228class Extension;
29class PendingExtensionManager;
30
[email protected]42a08162012-03-16 18:09:1131class ExtensionUpdaterTest;
32void SetupPendingExtensionManagerForTest(
33 int count, const GURL& update_url,
34 PendingExtensionManager* pending_extension_manager);
[email protected]b2907fd2011-03-25 16:43:3735
36// Class PendingExtensionManager manages the set of extensions which are
[email protected]75764512011-12-19 19:54:2837// being installed or updated. In general, installation and updates take
[email protected]b2907fd2011-03-25 16:43:3738// 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]6c9bedf2014-05-21 03:55:5141// 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]b2907fd2011-03-25 16:43:3743class PendingExtensionManager {
44 public:
[email protected]6c9bedf2014-05-21 03:55:5145 explicit PendingExtensionManager(content::BrowserContext* context);
[email protected]b2907fd2011-03-25 16:43:3746 ~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]51a3bf8b2012-06-08 22:53:0651 // 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]b2907fd2011-03-25 16:43:3754
[email protected]51a3bf8b2012-06-08 22:53:0655 // 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]b2907fd2011-03-25 16:43:3758
59 // Is |id| in the set of pending extensions?
60 bool IsIdPending(const std::string& id) const;
61
[email protected]9bd9a6862012-11-29 09:24:2262 // Returns true if there are any extensions pending.
63 bool HasPendingExtensions() const;
64
[email protected]d31e19e2012-08-22 00:19:0465 // Whether there is pending extension install from sync.
66 bool HasPendingExtensionFromSync() const;
67
[email protected]b2907fd2011-03-25 16:43:3768 // 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]145a317b2011-04-12 16:03:4670 // 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]b2907fd2011-03-25 16:43:3774 //
75 // TODO(akalin): Replace |install_silently| with a list of
76 // pre-enabled permissions.
[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,
80 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install,
[email protected]21db9ef2014-05-16 02:06:2781 bool install_silently,
[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,
128 bool install_silently,
[email protected]464213a2013-10-15 01:06:48129 Manifest::Location install_source,
130 int creation_flags,
[email protected]21db9ef2014-05-16 02:06:27131 bool mark_acknowledged,
132 bool remote_install);
[email protected]b2907fd2011-03-25 16:43:37133
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]51a3bf8b2012-06-08 22:53:06137 void AddForTesting(const PendingExtensionInfo& pending_extension_info);
[email protected]b2907fd2011-03-25 16:43:37138
[email protected]46f3e102014-03-25 01:22:45139 // The BrowserContext with which the manager is associated.
140 content::BrowserContext* context_;
141
[email protected]51a3bf8b2012-06-08 22:53:06142 PendingExtensionList pending_extension_list_;
[email protected]b2907fd2011-03-25 16:43:37143
[email protected]3f213ad2012-07-26 23:39:41144 FRIEND_TEST_ALL_PREFIXES(::ExtensionServiceTest,
[email protected]b2907fd2011-03-25 16:43:37145 UpdatePendingExtensionAlreadyInstalled);
[email protected]3f213ad2012-07-26 23:39:41146 friend class ExtensionUpdaterTest;
147 friend void SetupPendingExtensionManagerForTest(
[email protected]b2907fd2011-03-25 16:43:37148 int count, const GURL& update_url,
149 PendingExtensionManager* pending_extension_manager);
150
151 DISALLOW_COPY_AND_ASSIGN(PendingExtensionManager);
152};
153
[email protected]3f213ad2012-07-26 23:39:41154} // namespace extensions
155
[email protected]f3d3b382014-03-14 21:19:28156#endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_