OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/pending_extension_manager.h" | 5 #include "chrome/browser/extensions/pending_extension_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/version.h" | 10 #include "base/version.h" |
11 #include "chrome/common/extensions/extension_constants.h" | 11 #include "chrome/common/extensions/extension_constants.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "extensions/browser/extension_prefs.h" | 13 #include "extensions/browser/extension_prefs.h" |
14 #include "extensions/browser/extension_registry.h" | 14 #include "extensions/browser/extension_registry.h" |
15 #include "extensions/common/constants.h" | 15 #include "extensions/common/constants.h" |
16 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
18 | 18 |
19 using content::BrowserThread; | 19 using content::BrowserThread; |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 // Install predicate used by AddFromExternalUpdateUrl(). | 23 // Install predicate used by AddFromExternalUpdateUrl(). |
24 bool AlwaysInstall(const extensions::Extension* extension) { | 24 bool AlwaysInstall(const extensions::Extension* extension) { |
25 return true; | 25 return true; |
26 } | 26 } |
27 | 27 |
28 std::string GetVersionString(const base::Version& version) { | 28 std::string GetVersionString(const Version& version) { |
29 return version.IsValid() ? version.GetString() : "invalid"; | 29 return version.IsValid() ? version.GetString() : "invalid"; |
30 } | 30 } |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 namespace extensions { | 34 namespace extensions { |
35 | 35 |
36 PendingExtensionManager::PendingExtensionManager( | 36 PendingExtensionManager::PendingExtensionManager( |
37 content::BrowserContext* context) | 37 content::BrowserContext* context) |
38 : context_(context) {} | 38 : context_(context) {} |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 creation_flags |= Extension::WAS_INSTALLED_BY_CUSTODIAN; | 114 creation_flags |= Extension::WAS_INSTALLED_BY_CUSTODIAN; |
115 } | 115 } |
116 | 116 |
117 static const bool kIsFromSync = true; | 117 static const bool kIsFromSync = true; |
118 static const Manifest::Location kSyncLocation = Manifest::INTERNAL; | 118 static const Manifest::Location kSyncLocation = Manifest::INTERNAL; |
119 static const bool kMarkAcknowledged = false; | 119 static const bool kMarkAcknowledged = false; |
120 | 120 |
121 return AddExtensionImpl(id, | 121 return AddExtensionImpl(id, |
122 std::string(), | 122 std::string(), |
123 update_url, | 123 update_url, |
124 base::Version(), | 124 Version(), |
125 should_allow_install, | 125 should_allow_install, |
126 kIsFromSync, | 126 kIsFromSync, |
127 kSyncLocation, | 127 kSyncLocation, |
128 creation_flags, | 128 creation_flags, |
129 kMarkAcknowledged, | 129 kMarkAcknowledged, |
130 remote_install); | 130 remote_install); |
131 } | 131 } |
132 | 132 |
133 bool PendingExtensionManager::AddFromExtensionImport( | 133 bool PendingExtensionManager::AddFromExtensionImport( |
134 const std::string& id, | 134 const std::string& id, |
135 const GURL& update_url, | 135 const GURL& update_url, |
136 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install) { | 136 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install) { |
137 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 137 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
138 | 138 |
139 if (ExtensionRegistry::Get(context_)->GetExtensionById( | 139 if (ExtensionRegistry::Get(context_)->GetExtensionById( |
140 id, ExtensionRegistry::EVERYTHING)) { | 140 id, ExtensionRegistry::EVERYTHING)) { |
141 LOG(ERROR) << "Trying to add pending extension " << id | 141 LOG(ERROR) << "Trying to add pending extension " << id |
142 << " which already exists"; | 142 << " which already exists"; |
143 return false; | 143 return false; |
144 } | 144 } |
145 | 145 |
146 static const bool kIsFromSync = false; | 146 static const bool kIsFromSync = false; |
147 static const Manifest::Location kManifestLocation = Manifest::INTERNAL; | 147 static const Manifest::Location kManifestLocation = Manifest::INTERNAL; |
148 static const bool kMarkAcknowledged = false; | 148 static const bool kMarkAcknowledged = false; |
149 static const bool kRemoteInstall = false; | 149 static const bool kRemoteInstall = false; |
150 | 150 |
151 return AddExtensionImpl(id, | 151 return AddExtensionImpl(id, |
152 std::string(), | 152 std::string(), |
153 update_url, | 153 update_url, |
154 base::Version(), | 154 Version(), |
155 should_allow_install, | 155 should_allow_install, |
156 kIsFromSync, | 156 kIsFromSync, |
157 kManifestLocation, | 157 kManifestLocation, |
158 Extension::NO_FLAGS, | 158 Extension::NO_FLAGS, |
159 kMarkAcknowledged, | 159 kMarkAcknowledged, |
160 kRemoteInstall); | 160 kRemoteInstall); |
161 } | 161 } |
162 | 162 |
163 bool PendingExtensionManager::AddFromExternalUpdateUrl( | 163 bool PendingExtensionManager::AddFromExternalUpdateUrl( |
164 const std::string& id, | 164 const std::string& id, |
(...skipping 20 matching lines...) Expand all Loading... |
185 if (extension) { | 185 if (extension) { |
186 LOG(DFATAL) << "Trying to add extension " << id | 186 LOG(DFATAL) << "Trying to add extension " << id |
187 << " by external update, but it is already installed."; | 187 << " by external update, but it is already installed."; |
188 return false; | 188 return false; |
189 } | 189 } |
190 } | 190 } |
191 | 191 |
192 return AddExtensionImpl(id, | 192 return AddExtensionImpl(id, |
193 install_parameter, | 193 install_parameter, |
194 update_url, | 194 update_url, |
195 base::Version(), | 195 Version(), |
196 &AlwaysInstall, | 196 &AlwaysInstall, |
197 kIsFromSync, | 197 kIsFromSync, |
198 location, | 198 location, |
199 creation_flags, | 199 creation_flags, |
200 mark_acknowledged, | 200 mark_acknowledged, |
201 kRemoteInstall); | 201 kRemoteInstall); |
202 } | 202 } |
203 | 203 |
| 204 |
204 bool PendingExtensionManager::AddFromExternalFile( | 205 bool PendingExtensionManager::AddFromExternalFile( |
205 const std::string& id, | 206 const std::string& id, |
206 Manifest::Location install_source, | 207 Manifest::Location install_source, |
207 const base::Version& version, | 208 const Version& version, |
208 int creation_flags, | 209 int creation_flags, |
209 bool mark_acknowledged) { | 210 bool mark_acknowledged) { |
210 // TODO(skerner): AddFromSync() checks to see if the extension is | 211 // TODO(skerner): AddFromSync() checks to see if the extension is |
211 // installed, but this method assumes that the caller already | 212 // installed, but this method assumes that the caller already |
212 // made sure it is not installed. Make all AddFrom*() methods | 213 // made sure it is not installed. Make all AddFrom*() methods |
213 // consistent. | 214 // consistent. |
214 const GURL& kUpdateUrl = GURL::EmptyGURL(); | 215 const GURL& kUpdateUrl = GURL::EmptyGURL(); |
215 static const bool kIsFromSync = false; | 216 static const bool kIsFromSync = false; |
216 static const bool kRemoteInstall = false; | 217 static const bool kRemoteInstall = false; |
217 | 218 |
(...skipping 27 matching lines...) Expand all Loading... |
245 } | 246 } |
246 | 247 |
247 out_ids_for_update_check->push_back(iter->id()); | 248 out_ids_for_update_check->push_back(iter->id()); |
248 } | 249 } |
249 } | 250 } |
250 | 251 |
251 bool PendingExtensionManager::AddExtensionImpl( | 252 bool PendingExtensionManager::AddExtensionImpl( |
252 const std::string& id, | 253 const std::string& id, |
253 const std::string& install_parameter, | 254 const std::string& install_parameter, |
254 const GURL& update_url, | 255 const GURL& update_url, |
255 const base::Version& version, | 256 const Version& version, |
256 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, | 257 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, |
257 bool is_from_sync, | 258 bool is_from_sync, |
258 Manifest::Location install_source, | 259 Manifest::Location install_source, |
259 int creation_flags, | 260 int creation_flags, |
260 bool mark_acknowledged, | 261 bool mark_acknowledged, |
261 bool remote_install) { | 262 bool remote_install) { |
262 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 263 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
263 | 264 |
264 PendingExtensionInfo info(id, | 265 PendingExtensionInfo info(id, |
265 install_parameter, | 266 install_parameter, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 | 307 |
307 return true; | 308 return true; |
308 } | 309 } |
309 | 310 |
310 void PendingExtensionManager::AddForTesting( | 311 void PendingExtensionManager::AddForTesting( |
311 const PendingExtensionInfo& pending_extension_info) { | 312 const PendingExtensionInfo& pending_extension_info) { |
312 pending_extension_list_.push_back(pending_extension_info); | 313 pending_extension_list_.push_back(pending_extension_info); |
313 } | 314 } |
314 | 315 |
315 } // namespace extensions | 316 } // namespace extensions |
OLD | NEW |