Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / extensions / pending_extension_manager.h
blobf500a8e7b151d5c4f9376fd381ca558a0592766f
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_
8 #include <list>
9 #include <string>
11 #include "chrome/browser/extensions/pending_extension_info.h"
12 #include "extensions/common/manifest.h"
14 class GURL;
16 namespace base {
17 class Version;
20 namespace content {
21 class BrowserContext;
24 FORWARD_DECLARE_TEST(ExtensionServiceTest,
25 UpdatePendingExtensionAlreadyInstalled);
27 namespace extensions {
28 class Extension;
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 {
44 public:
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.
74 // After installation, the extension will be granted permissions iff
75 // |version| is valid and matches the actual installed version.
76 bool AddFromSync(
77 const std::string& id,
78 const GURL& update_url,
79 const base::Version& version,
80 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install,
81 bool remote_install,
82 bool installed_by_custodian);
84 // Adds an extension that was depended on by another extension.
85 bool AddFromExtensionImport(
86 const std::string& id,
87 const GURL& update_url,
88 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install);
90 // Given an extension id and an update URL, schedule the extension
91 // to be fetched, installed, and activated.
92 bool AddFromExternalUpdateUrl(const std::string& id,
93 const std::string& install_parameter,
94 const GURL& update_url,
95 Manifest::Location location,
96 int creation_flags,
97 bool mark_acknowledged);
99 // Add a pending extension record for an external CRX file.
100 // Return true if the CRX should be installed, false if an existing
101 // pending record overrides it.
102 bool AddFromExternalFile(
103 const std::string& id,
104 Manifest::Location location,
105 const base::Version& version,
106 int creation_flags,
107 bool mark_acknowledged);
109 // Get the list of pending IDs that should be installed from an update URL.
110 // Pending extensions that will be installed from local files will not be
111 // included in the set.
112 void GetPendingIdsForUpdateCheck(
113 std::list<std::string>* out_ids_for_update_check) const;
115 private:
116 typedef std::list<PendingExtensionInfo> PendingExtensionList;
118 // Assumes an extension with id |id| is not already installed.
119 // Return true if the extension was added.
120 bool AddExtensionImpl(
121 const std::string& id,
122 const std::string& install_parameter,
123 const GURL& update_url,
124 const base::Version& version,
125 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install,
126 bool is_from_sync,
127 Manifest::Location install_source,
128 int creation_flags,
129 bool mark_acknowledged,
130 bool remote_install);
132 // Add a pending extension record directly. Used for unit tests that need
133 // to set an inital state. Use friendship to allow the tests to call this
134 // method.
135 void AddForTesting(const PendingExtensionInfo& pending_extension_info);
137 // The BrowserContext with which the manager is associated.
138 content::BrowserContext* context_;
140 PendingExtensionList pending_extension_list_;
142 FRIEND_TEST_ALL_PREFIXES(::ExtensionServiceTest,
143 UpdatePendingExtensionAlreadyInstalled);
144 friend class ExtensionUpdaterTest;
145 friend void SetupPendingExtensionManagerForTest(
146 int count, const GURL& update_url,
147 PendingExtensionManager* pending_extension_manager);
149 DISALLOW_COPY_AND_ASSIGN(PendingExtensionManager);
152 } // namespace extensions
154 #endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_