blob: 44a99c91789dfb1b23cd2f351f1af2f136d46f5c [file] [log] [blame]
[email protected]9060d8b02012-01-13 02:14:301// Copyright (c) 2012 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
5#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
11#include "chrome/browser/extensions/pending_extension_info.h"
12#include "chrome/common/extensions/extension.h"
[email protected]d42c11152013-08-22 19:36:3213#include "extensions/common/manifest.h"
[email protected]b2907fd2011-03-25 16:43:3714
[email protected]2859946f2011-04-04 18:18:0615class ExtensionServiceInterface;
[email protected]b2907fd2011-03-25 16:43:3716class GURL;
[email protected]42a08162012-03-16 18:09:1117class PendingExtensionManager;
[email protected]1f04ef42013-04-22 07:35:5018
19namespace base {
[email protected]e3987852012-05-04 10:06:3020class Version;
[email protected]1f04ef42013-04-22 07:35:5021}
[email protected]42a08162012-03-16 18:09:1122
[email protected]3f213ad2012-07-26 23:39:4123FORWARD_DECLARE_TEST(ExtensionServiceTest,
24 UpdatePendingExtensionAlreadyInstalled);
25
[email protected]42a08162012-03-16 18:09:1126namespace extensions {
27class ExtensionUpdaterTest;
28void SetupPendingExtensionManagerForTest(
29 int count, const GURL& update_url,
30 PendingExtensionManager* pending_extension_manager);
[email protected]b2907fd2011-03-25 16:43:3731
32// Class PendingExtensionManager manages the set of extensions which are
[email protected]75764512011-12-19 19:54:2833// being installed or updated. In general, installation and updates take
[email protected]b2907fd2011-03-25 16:43:3734// time, because they involve downloading, unpacking, and installing.
35// This class allows us to avoid race cases where multiple sources install
36// the same extension.
37// The extensions service creates an instance of this class, and manages
38// its lifetime. This class should only be used from the UI thread.
39class PendingExtensionManager {
40 public:
[email protected]b2907fd2011-03-25 16:43:3741 // |service| is a reference to the ExtensionService whose pending
42 // extensions we are managing. The service creates an instance of
43 // this class on construction, and destroys it on destruction.
44 // The service remains valid over the entire lifetime of this class.
[email protected]2859946f2011-04-04 18:18:0645 explicit PendingExtensionManager(const ExtensionServiceInterface& service);
[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]6cc7dbae2011-04-29 21:18:3381 bool install_silently);
[email protected]b2907fd2011-03-25 16:43:3782
[email protected]9f4e4f082013-06-21 07:11:1983 // Adds an extension that was depended on by another extension.
84 bool AddFromExtensionImport(
85 const std::string& id,
86 const GURL& update_url,
87 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install);
88
[email protected]b2907fd2011-03-25 16:43:3789 // Given an extension id and an update URL, schedule the extension
90 // to be fetched, installed, and activated.
[email protected]9060d8b02012-01-13 02:14:3091 bool AddFromExternalUpdateUrl(const std::string& id,
[email protected]b2907fd2011-03-25 16:43:3792 const GURL& update_url,
[email protected]464213a2013-10-15 01:06:4893 Manifest::Location location,
94 int creation_flags,
95 bool mark_acknowledged);
[email protected]b2907fd2011-03-25 16:43:3796
[email protected]b2907fd2011-03-25 16:43:3797 // Add a pending extension record for an external CRX file.
[email protected]9060d8b02012-01-13 02:14:3098 // Return true if the CRX should be installed, false if an existing
99 // pending record overrides it.
100 bool AddFromExternalFile(
[email protected]b2907fd2011-03-25 16:43:37101 const std::string& id,
[email protected]1d5e58b2013-01-31 08:41:40102 Manifest::Location location,
[email protected]464213a2013-10-15 01:06:48103 const base::Version& version,
104 int creation_flags,
105 bool mark_acknowledged);
[email protected]b2907fd2011-03-25 16:43:37106
[email protected]51a3bf8b2012-06-08 22:53:06107 // Get the list of pending IDs that should be installed from an update URL.
[email protected]9060d8b02012-01-13 02:14:30108 // Pending extensions that will be installed from local files will not be
109 // included in the set.
110 void GetPendingIdsForUpdateCheck(
[email protected]51a3bf8b2012-06-08 22:53:06111 std::list<std::string>* out_ids_for_update_check) const;
[email protected]9060d8b02012-01-13 02:14:30112
[email protected]b2907fd2011-03-25 16:43:37113 private:
[email protected]51a3bf8b2012-06-08 22:53:06114 typedef std::list<PendingExtensionInfo> PendingExtensionList;
[email protected]9060d8b02012-01-13 02:14:30115
[email protected]b2907fd2011-03-25 16:43:37116 // Assumes an extension with id |id| is not already installed.
[email protected]145a317b2011-04-12 16:03:46117 // Return true if the extension was added.
118 bool AddExtensionImpl(
[email protected]b2907fd2011-03-25 16:43:37119 const std::string& id,
120 const GURL& update_url,
[email protected]1f04ef42013-04-22 07:35:50121 const base::Version& version,
[email protected]b2907fd2011-03-25 16:43:37122 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install,
123 bool is_from_sync,
124 bool install_silently,
[email protected]464213a2013-10-15 01:06:48125 Manifest::Location install_source,
126 int creation_flags,
127 bool mark_acknowledged);
[email protected]b2907fd2011-03-25 16:43:37128
129 // Add a pending extension record directly. Used for unit tests that need
130 // to set an inital state. Use friendship to allow the tests to call this
131 // method.
[email protected]51a3bf8b2012-06-08 22:53:06132 void AddForTesting(const PendingExtensionInfo& pending_extension_info);
[email protected]b2907fd2011-03-25 16:43:37133
134 // Reference to the extension service whose pending extensions this class is
135 // managing. Because this class is a member of |service_|, it is created
136 // and destroyed with |service_|. We only use methods from the interface
[email protected]2859946f2011-04-04 18:18:06137 // ExtensionServiceInterface.
138 const ExtensionServiceInterface& service_;
[email protected]b2907fd2011-03-25 16:43:37139
[email protected]51a3bf8b2012-06-08 22:53:06140 PendingExtensionList pending_extension_list_;
[email protected]b2907fd2011-03-25 16:43:37141
[email protected]3f213ad2012-07-26 23:39:41142 FRIEND_TEST_ALL_PREFIXES(::ExtensionServiceTest,
[email protected]b2907fd2011-03-25 16:43:37143 UpdatePendingExtensionAlreadyInstalled);
[email protected]3f213ad2012-07-26 23:39:41144 friend class ExtensionUpdaterTest;
145 friend void SetupPendingExtensionManagerForTest(
[email protected]b2907fd2011-03-25 16:43:37146 int count, const GURL& update_url,
147 PendingExtensionManager* pending_extension_manager);
148
149 DISALLOW_COPY_AND_ASSIGN(PendingExtensionManager);
150};
151
[email protected]3f213ad2012-07-26 23:39:41152} // namespace extensions
153
[email protected]b2907fd2011-03-25 16:43:37154#endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_