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"
14 class ExtensionServiceInterface
;
25 FORWARD_DECLARE_TEST(ExtensionServiceTest
,
26 UpdatePendingExtensionAlreadyInstalled
);
28 namespace extensions
{
30 class PendingExtensionManager
;
32 class ExtensionUpdaterTest
;
33 void SetupPendingExtensionManagerForTest(
34 int count
, const GURL
& update_url
,
35 PendingExtensionManager
* pending_extension_manager
);
37 // Class PendingExtensionManager manages the set of extensions which are
38 // being installed or updated. In general, installation and updates take
39 // 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.
42 // The extensions service creates an instance of this class, and manages
43 // its lifetime. This class should only be used from the UI thread.
44 class PendingExtensionManager
{
46 // |service| is a reference to the ExtensionService whose pending
47 // extensions we are managing. The service creates an instance of
48 // this class on construction, and destroys it on destruction.
49 // The service remains valid over the entire lifetime of this class.
50 explicit PendingExtensionManager(const ExtensionServiceInterface
& service
,
51 content::BrowserContext
* context
);
52 ~PendingExtensionManager();
54 // TODO(skerner): Many of these methods can be private once code in
55 // ExtensionService is moved into methods of this class.
57 // Remove extension with id |id| from the set of pending extensions. Returns
58 // true if such an extension was found and removed, false otherwise.
59 bool Remove(const std::string
& id
);
61 // Get the information for a pending extension. Returns a pointer to the
62 // pending extension with id |id|, or NULL if there is no such extension.
63 const PendingExtensionInfo
* GetById(const std::string
& id
) const;
65 // Is |id| in the set of pending extensions?
66 bool IsIdPending(const std::string
& id
) const;
68 // Returns true if there are any extensions pending.
69 bool HasPendingExtensions() const;
71 // Whether there is pending extension install from sync.
72 bool HasPendingExtensionFromSync() const;
74 // Adds an extension in a pending state; the extension with the
75 // given info will be installed on the next auto-update cycle.
76 // Return true if the extension was added. Will return false
77 // if the extension is pending from another source which overrides
78 // sync installs (such as a policy extension) or if the extension
79 // is already installed.
81 // TODO(akalin): Replace |install_silently| with a list of
82 // pre-enabled permissions.
84 const std::string
& id
,
85 const GURL
& update_url
,
86 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install
,
87 bool install_silently
);
89 // Adds an extension that was depended on by another extension.
90 bool AddFromExtensionImport(
91 const std::string
& id
,
92 const GURL
& update_url
,
93 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install
);
95 // Given an extension id and an update URL, schedule the extension
96 // to be fetched, installed, and activated.
97 bool AddFromExternalUpdateUrl(const std::string
& id
,
98 const std::string
& install_parameter
,
99 const GURL
& update_url
,
100 Manifest::Location location
,
102 bool mark_acknowledged
);
104 // Add a pending extension record for an external CRX file.
105 // Return true if the CRX should be installed, false if an existing
106 // pending record overrides it.
107 bool AddFromExternalFile(
108 const std::string
& id
,
109 Manifest::Location location
,
110 const base::Version
& version
,
112 bool mark_acknowledged
);
114 // Get the list of pending IDs that should be installed from an update URL.
115 // Pending extensions that will be installed from local files will not be
116 // included in the set.
117 void GetPendingIdsForUpdateCheck(
118 std::list
<std::string
>* out_ids_for_update_check
) const;
121 typedef std::list
<PendingExtensionInfo
> PendingExtensionList
;
123 // Assumes an extension with id |id| is not already installed.
124 // Return true if the extension was added.
125 bool AddExtensionImpl(
126 const std::string
& id
,
127 const std::string
& install_parameter
,
128 const GURL
& update_url
,
129 const base::Version
& version
,
130 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install
,
132 bool install_silently
,
133 Manifest::Location install_source
,
135 bool mark_acknowledged
);
137 // Add a pending extension record directly. Used for unit tests that need
138 // to set an inital state. Use friendship to allow the tests to call this
140 void AddForTesting(const PendingExtensionInfo
& pending_extension_info
);
142 // Reference to the extension service whose pending extensions this class is
143 // managing. Because this class is a member of |service_|, it is created
144 // and destroyed with |service_|. We only use methods from the interface
145 // ExtensionServiceInterface.
146 const ExtensionServiceInterface
& service_
;
148 // The BrowserContext with which the manager is associated.
149 content::BrowserContext
* context_
;
151 PendingExtensionList pending_extension_list_
;
153 FRIEND_TEST_ALL_PREFIXES(::ExtensionServiceTest
,
154 UpdatePendingExtensionAlreadyInstalled
);
155 friend class ExtensionUpdaterTest
;
156 friend void SetupPendingExtensionManagerForTest(
157 int count
, const GURL
& update_url
,
158 PendingExtensionManager
* pending_extension_manager
);
160 DISALLOW_COPY_AND_ASSIGN(PendingExtensionManager
);
163 } // namespace extensions
165 #endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_