1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_
6 #define CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_
11 #include "chrome/browser/extensions/pending_extension_info.h"
12 #include "extensions/common/manifest.h"
24 FORWARD_DECLARE_TEST(ExtensionServiceTest,
25 UpdatePendingExtensionAlreadyInstalled);
27 namespace extensions {
29 class PendingExtensionManager;
31 class ExtensionUpdaterTest;
32 void SetupPendingExtensionManagerForTest(
33 int count, const GURL& update_url,
34 PendingExtensionManager* pending_extension_manager);
36 // Class PendingExtensionManager manages the set of extensions which are
37 // being installed or updated. In general, installation and updates take
38 // 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.
41 // The ExtensionService creates an instance of this class, and manages its
42 // lifetime. This class should only be used from the UI thread.
43 class PendingExtensionManager {
45 explicit PendingExtensionManager(content::BrowserContext* context);
46 ~PendingExtensionManager();
48 // TODO(skerner): Many of these methods can be private once code in
49 // ExtensionService is moved into methods of this class.
51 // 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);
55 // 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;
59 // Is |id| in the set of pending extensions?
60 bool IsIdPending(const std::string& id) const;
62 // Returns true if there are any extensions pending.
63 bool HasPendingExtensions() const;
65 // Whether there is pending extension install from sync.
66 bool HasPendingExtensionFromSync() const;
68 // Adds an extension in a pending state; the extension with the
69 // given info will be installed on the next auto-update cycle.
70 // 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.
75 // TODO(akalin): Replace |install_silently| with a list of
76 // pre-enabled permissions.
78 const std::string& id,
79 const GURL& update_url,
80 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install,
81 bool install_silently,
83 bool installed_by_custodian);
85 // 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);
91 // Given an extension id and an update URL, schedule the extension
92 // to be fetched, installed, and activated.
93 bool AddFromExternalUpdateUrl(const std::string& id,
94 const std::string& install_parameter,
95 const GURL& update_url,
96 Manifest::Location location,
98 bool mark_acknowledged);
100 // Add a pending extension record for an external CRX file.
101 // Return true if the CRX should be installed, false if an existing
102 // pending record overrides it.
103 bool AddFromExternalFile(
104 const std::string& id,
105 Manifest::Location location,
106 const base::Version& version,
108 bool mark_acknowledged);
110 // Get the list of pending IDs that should be installed from an update URL.
111 // Pending extensions that will be installed from local files will not be
112 // included in the set.
113 void GetPendingIdsForUpdateCheck(
114 std::list<std::string>* out_ids_for_update_check) const;
117 typedef std::list<PendingExtensionInfo> PendingExtensionList;
119 // Assumes an extension with id |id| is not already installed.
120 // Return true if the extension was added.
121 bool AddExtensionImpl(
122 const std::string& id,
123 const std::string& install_parameter,
124 const GURL& update_url,
125 const base::Version& version,
126 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install,
128 bool install_silently,
129 Manifest::Location install_source,
131 bool mark_acknowledged,
132 bool remote_install);
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
137 void AddForTesting(const PendingExtensionInfo& pending_extension_info);
139 // The BrowserContext with which the manager is associated.
140 content::BrowserContext* context_;
142 PendingExtensionList pending_extension_list_;
144 FRIEND_TEST_ALL_PREFIXES(::ExtensionServiceTest,
145 UpdatePendingExtensionAlreadyInstalled);
146 friend class ExtensionUpdaterTest;
147 friend void SetupPendingExtensionManagerForTest(
148 int count, const GURL& update_url,
149 PendingExtensionManager* pending_extension_manager);
151 DISALLOW_COPY_AND_ASSIGN(PendingExtensionManager);
154 } // namespace extensions
156 #endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_