OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "extensions/browser/updater/extension_downloader.h" | 5 #include "extensions/browser/updater/extension_downloader.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 false, | 78 false, |
79 }; | 79 }; |
80 | 80 |
81 const char kAuthUserQueryKey[] = "authuser"; | 81 const char kAuthUserQueryKey[] = "authuser"; |
82 | 82 |
83 const int kMaxAuthUserValue = 10; | 83 const int kMaxAuthUserValue = 10; |
84 const int kMaxOAuth2Attempts = 3; | 84 const int kMaxOAuth2Attempts = 3; |
85 | 85 |
86 const char kNotFromWebstoreInstallSource[] = "notfromwebstore"; | 86 const char kNotFromWebstoreInstallSource[] = "notfromwebstore"; |
87 const char kDefaultInstallSource[] = ""; | 87 const char kDefaultInstallSource[] = ""; |
| 88 const char kReinstallInstallSource[] = "reinstall"; |
88 | 89 |
89 const char kGoogleDotCom[] = "google.com"; | 90 const char kGoogleDotCom[] = "google.com"; |
90 const char kTokenServiceConsumerId[] = "extension_downloader"; | 91 const char kTokenServiceConsumerId[] = "extension_downloader"; |
91 const char kWebstoreOAuth2Scope[] = | 92 const char kWebstoreOAuth2Scope[] = |
92 "https://www.googleapis.com/auth/chromewebstore.readonly"; | 93 "https://www.googleapis.com/auth/chromewebstore.readonly"; |
93 | 94 |
94 ExtensionDownloaderTestDelegate* g_test_delegate = nullptr; | 95 ExtensionDownloaderTestDelegate* g_test_delegate = nullptr; |
95 | 96 |
96 #define RETRY_HISTOGRAM(name, retry_count, url) \ | 97 #define RETRY_HISTOGRAM(name, retry_count, url) \ |
97 if ((url).DomainIs(kGoogleDotCom)) { \ | 98 if ((url).DomainIs(kGoogleDotCom)) { \ |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 package_hash(package_hash), | 174 package_hash(package_hash), |
174 version(version), | 175 version(version), |
175 request_ids(request_ids), | 176 request_ids(request_ids), |
176 credentials(CREDENTIALS_NONE), | 177 credentials(CREDENTIALS_NONE), |
177 oauth2_attempt_count(0) { | 178 oauth2_attempt_count(0) { |
178 } | 179 } |
179 | 180 |
180 ExtensionDownloader::ExtensionFetch::~ExtensionFetch() { | 181 ExtensionDownloader::ExtensionFetch::~ExtensionFetch() { |
181 } | 182 } |
182 | 183 |
| 184 ExtensionDownloader::ExtraParams::ExtraParams() : is_corrupt_reinstall(false) {} |
| 185 |
183 ExtensionDownloader::ExtensionDownloader( | 186 ExtensionDownloader::ExtensionDownloader( |
184 ExtensionDownloaderDelegate* delegate, | 187 ExtensionDownloaderDelegate* delegate, |
185 net::URLRequestContextGetter* request_context) | 188 net::URLRequestContextGetter* request_context) |
186 : OAuth2TokenService::Consumer(kTokenServiceConsumerId), | 189 : OAuth2TokenService::Consumer(kTokenServiceConsumerId), |
187 delegate_(delegate), | 190 delegate_(delegate), |
188 request_context_(request_context), | 191 request_context_(request_context), |
189 manifests_queue_(&kDefaultBackoffPolicy, | 192 manifests_queue_(&kDefaultBackoffPolicy, |
190 base::Bind(&ExtensionDownloader::CreateManifestFetcher, | 193 base::Bind(&ExtensionDownloader::CreateManifestFetcher, |
191 base::Unretained(this))), | 194 base::Unretained(this))), |
192 extensions_queue_(&kDefaultBackoffPolicy, | 195 extensions_queue_(&kDefaultBackoffPolicy, |
(...skipping 10 matching lines...) Expand all Loading... |
203 | 206 |
204 bool ExtensionDownloader::AddExtension(const Extension& extension, | 207 bool ExtensionDownloader::AddExtension(const Extension& extension, |
205 int request_id) { | 208 int request_id) { |
206 // Skip extensions with empty update URLs converted from user | 209 // Skip extensions with empty update URLs converted from user |
207 // scripts. | 210 // scripts. |
208 if (extension.converted_from_user_script() && | 211 if (extension.converted_from_user_script() && |
209 ManifestURL::GetUpdateURL(&extension).is_empty()) { | 212 ManifestURL::GetUpdateURL(&extension).is_empty()) { |
210 return false; | 213 return false; |
211 } | 214 } |
212 | 215 |
| 216 ExtraParams extra; |
| 217 |
213 // If the extension updates itself from the gallery, ignore any update URL | 218 // If the extension updates itself from the gallery, ignore any update URL |
214 // data. At the moment there is no extra data that an extension can | 219 // data. At the moment there is no extra data that an extension can |
215 // communicate to the the gallery update servers. | 220 // communicate to the the gallery update servers. |
216 std::string update_url_data; | 221 std::string update_url_data; |
217 if (!ManifestURL::UpdatesFromGallery(&extension)) | 222 if (!ManifestURL::UpdatesFromGallery(&extension)) |
218 update_url_data = delegate_->GetUpdateUrlData(extension.id()); | 223 extra.update_url_data = delegate_->GetUpdateUrlData(extension.id()); |
219 | 224 |
220 return AddExtensionData( | 225 return AddExtensionData( |
221 extension.id(), *extension.version(), extension.GetType(), | 226 extension.id(), *extension.version(), extension.GetType(), |
222 ManifestURL::GetUpdateURL(&extension), update_url_data, request_id); | 227 ManifestURL::GetUpdateURL(&extension), extra, request_id); |
223 } | 228 } |
224 | 229 |
225 bool ExtensionDownloader::AddPendingExtension(const std::string& id, | 230 bool ExtensionDownloader::AddPendingExtension(const std::string& id, |
226 const GURL& update_url, | 231 const GURL& update_url, |
| 232 bool is_corrupt_reinstall, |
227 int request_id) { | 233 int request_id) { |
228 // Use a zero version to ensure that a pending extension will always | 234 // Use a zero version to ensure that a pending extension will always |
229 // be updated, and thus installed (assuming all extensions have | 235 // be updated, and thus installed (assuming all extensions have |
230 // non-zero versions). | 236 // non-zero versions). |
231 base::Version version("0.0.0.0"); | 237 base::Version version("0.0.0.0"); |
232 DCHECK(version.IsValid()); | 238 DCHECK(version.IsValid()); |
| 239 ExtraParams extra; |
| 240 if (is_corrupt_reinstall) |
| 241 extra.is_corrupt_reinstall = true; |
233 | 242 |
234 return AddExtensionData(id, version, Manifest::TYPE_UNKNOWN, update_url, | 243 return AddExtensionData(id, version, Manifest::TYPE_UNKNOWN, update_url, |
235 std::string(), request_id); | 244 extra, request_id); |
236 } | 245 } |
237 | 246 |
238 void ExtensionDownloader::StartAllPending(ExtensionCache* cache) { | 247 void ExtensionDownloader::StartAllPending(ExtensionCache* cache) { |
239 if (cache) { | 248 if (cache) { |
240 extension_cache_ = cache; | 249 extension_cache_ = cache; |
241 extension_cache_->Start(base::Bind(&ExtensionDownloader::DoStartAllPending, | 250 extension_cache_->Start(base::Bind(&ExtensionDownloader::DoStartAllPending, |
242 weak_ptr_factory_.GetWeakPtr())); | 251 weak_ptr_factory_.GetWeakPtr())); |
243 } else { | 252 } else { |
244 DoStartAllPending(); | 253 DoStartAllPending(); |
245 } | 254 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 // static | 291 // static |
283 void ExtensionDownloader::set_test_delegate( | 292 void ExtensionDownloader::set_test_delegate( |
284 ExtensionDownloaderTestDelegate* delegate) { | 293 ExtensionDownloaderTestDelegate* delegate) { |
285 g_test_delegate = delegate; | 294 g_test_delegate = delegate; |
286 } | 295 } |
287 | 296 |
288 bool ExtensionDownloader::AddExtensionData(const std::string& id, | 297 bool ExtensionDownloader::AddExtensionData(const std::string& id, |
289 const base::Version& version, | 298 const base::Version& version, |
290 Manifest::Type extension_type, | 299 Manifest::Type extension_type, |
291 const GURL& extension_update_url, | 300 const GURL& extension_update_url, |
292 const std::string& update_url_data, | 301 const ExtraParams& extra, |
293 int request_id) { | 302 int request_id) { |
294 GURL update_url(extension_update_url); | 303 GURL update_url(extension_update_url); |
295 // Skip extensions with non-empty invalid update URLs. | 304 // Skip extensions with non-empty invalid update URLs. |
296 if (!update_url.is_empty() && !update_url.is_valid()) { | 305 if (!update_url.is_empty() && !update_url.is_valid()) { |
297 DLOG(WARNING) << "Extension " << id << " has invalid update url " | 306 DLOG(WARNING) << "Extension " << id << " has invalid update url " |
298 << update_url; | 307 << update_url; |
299 return false; | 308 return false; |
300 } | 309 } |
301 | 310 |
302 // Make sure we use SSL for store-hosted extensions. | 311 // Make sure we use SSL for store-hosted extensions. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 ++url_stats_.pending_count; | 349 ++url_stats_.pending_count; |
341 break; | 350 break; |
342 } | 351 } |
343 | 352 |
344 DCHECK(!update_url.is_empty()); | 353 DCHECK(!update_url.is_empty()); |
345 DCHECK(update_url.is_valid()); | 354 DCHECK(update_url.is_valid()); |
346 | 355 |
347 std::string install_source = extension_urls::IsWebstoreUpdateUrl(update_url) | 356 std::string install_source = extension_urls::IsWebstoreUpdateUrl(update_url) |
348 ? kDefaultInstallSource | 357 ? kDefaultInstallSource |
349 : kNotFromWebstoreInstallSource; | 358 : kNotFromWebstoreInstallSource; |
| 359 if (extra.is_corrupt_reinstall) |
| 360 install_source = kReinstallInstallSource; |
350 | 361 |
351 ManifestFetchData::PingData ping_data; | 362 ManifestFetchData::PingData ping_data; |
352 ManifestFetchData::PingData* optional_ping_data = NULL; | 363 ManifestFetchData::PingData* optional_ping_data = NULL; |
353 if (delegate_->GetPingDataForExtension(id, &ping_data)) | 364 if (delegate_->GetPingDataForExtension(id, &ping_data)) |
354 optional_ping_data = &ping_data; | 365 optional_ping_data = &ping_data; |
355 | 366 |
356 // Find or create a ManifestFetchData to add this extension to. | 367 // Find or create a ManifestFetchData to add this extension to. |
357 bool added = false; | 368 bool added = false; |
358 FetchMap::iterator existing_iter = | 369 FetchMap::iterator existing_iter = |
359 fetches_preparing_.find(std::make_pair(request_id, update_url)); | 370 fetches_preparing_.find(std::make_pair(request_id, update_url)); |
360 if (existing_iter != fetches_preparing_.end() && | 371 if (existing_iter != fetches_preparing_.end() && |
361 !existing_iter->second.empty()) { | 372 !existing_iter->second.empty()) { |
362 // Try to add to the ManifestFetchData at the end of the list. | 373 // Try to add to the ManifestFetchData at the end of the list. |
363 ManifestFetchData* existing_fetch = existing_iter->second.back().get(); | 374 ManifestFetchData* existing_fetch = existing_iter->second.back().get(); |
364 if (existing_fetch->AddExtension(id, version.GetString(), | 375 if (existing_fetch->AddExtension(id, version.GetString(), |
365 optional_ping_data, update_url_data, | 376 optional_ping_data, extra.update_url_data, |
366 install_source)) { | 377 install_source)) { |
367 added = true; | 378 added = true; |
368 } | 379 } |
369 } | 380 } |
370 if (!added) { | 381 if (!added) { |
371 // Otherwise add a new element to the list, if the list doesn't exist or | 382 // Otherwise add a new element to the list, if the list doesn't exist or |
372 // if its last element is already full. | 383 // if its last element is already full. |
373 std::unique_ptr<ManifestFetchData> fetch( | 384 std::unique_ptr<ManifestFetchData> fetch( |
374 CreateManifestFetchData(update_url, request_id)); | 385 CreateManifestFetchData(update_url, request_id)); |
375 ManifestFetchData* fetch_ptr = fetch.get(); | 386 ManifestFetchData* fetch_ptr = fetch.get(); |
376 fetches_preparing_[std::make_pair(request_id, update_url)].push_back( | 387 fetches_preparing_[std::make_pair(request_id, update_url)].push_back( |
377 std::move(fetch)); | 388 std::move(fetch)); |
378 added = fetch_ptr->AddExtension(id, version.GetString(), optional_ping_data, | 389 added = fetch_ptr->AddExtension(id, version.GetString(), optional_ping_data, |
379 update_url_data, install_source); | 390 extra.update_url_data, install_source); |
380 DCHECK(added); | 391 DCHECK(added); |
381 } | 392 } |
382 | 393 |
383 return true; | 394 return true; |
384 } | 395 } |
385 | 396 |
386 void ExtensionDownloader::ReportStats() const { | 397 void ExtensionDownloader::ReportStats() const { |
387 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckExtension", | 398 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckExtension", |
388 url_stats_.extension_count); | 399 url_stats_.extension_count); |
389 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckTheme", | 400 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckTheme", |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 const GURL& update_url, | 952 const GURL& update_url, |
942 int request_id) { | 953 int request_id) { |
943 ManifestFetchData::PingMode ping_mode = ManifestFetchData::NO_PING; | 954 ManifestFetchData::PingMode ping_mode = ManifestFetchData::NO_PING; |
944 if (update_url.DomainIs(ping_enabled_domain_.c_str())) | 955 if (update_url.DomainIs(ping_enabled_domain_.c_str())) |
945 ping_mode = ManifestFetchData::PING_WITH_ENABLED_STATE; | 956 ping_mode = ManifestFetchData::PING_WITH_ENABLED_STATE; |
946 return new ManifestFetchData( | 957 return new ManifestFetchData( |
947 update_url, request_id, brand_code_, manifest_query_params_, ping_mode); | 958 update_url, request_id, brand_code_, manifest_query_params_, ping_mode); |
948 } | 959 } |
949 | 960 |
950 } // namespace extensions | 961 } // namespace extensions |
OLD | NEW |