| 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/metrics/sparse_histogram.h" | 17 #include "base/metrics/sparse_histogram.h" |
| 18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 23 #include "base/version.h" | 23 #include "base/version.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
| 26 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 27 #include "extensions/browser/extensions_browser_client.h" | 27 #include "extensions/browser/extensions_browser_client.h" |
| 28 #include "extensions/browser/notification_types.h" | 28 #include "extensions/browser/notification_types.h" |
| 29 #include "extensions/browser/updater/extension_cache.h" | 29 #include "extensions/browser/updater/extension_cache.h" |
| 30 #include "extensions/browser/updater/extension_downloader_test_delegate.h" | |
| 31 #include "extensions/browser/updater/request_queue_impl.h" | 30 #include "extensions/browser/updater/request_queue_impl.h" |
| 32 #include "extensions/browser/updater/safe_manifest_parser.h" | 31 #include "extensions/browser/updater/safe_manifest_parser.h" |
| 33 #include "extensions/common/extension_urls.h" | 32 #include "extensions/common/extension_urls.h" |
| 34 #include "extensions/common/manifest_url_handlers.h" | 33 #include "extensions/common/manifest_url_handlers.h" |
| 35 #include "google_apis/gaia/identity_provider.h" | 34 #include "google_apis/gaia/identity_provider.h" |
| 36 #include "net/base/backoff_entry.h" | 35 #include "net/base/backoff_entry.h" |
| 37 #include "net/base/load_flags.h" | 36 #include "net/base/load_flags.h" |
| 38 #include "net/base/net_errors.h" | 37 #include "net/base/net_errors.h" |
| 39 #include "net/http/http_request_headers.h" | 38 #include "net/http/http_request_headers.h" |
| 40 #include "net/http/http_status_code.h" | 39 #include "net/http/http_status_code.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 const int kMaxOAuth2Attempts = 3; | 83 const int kMaxOAuth2Attempts = 3; |
| 85 | 84 |
| 86 const char kNotFromWebstoreInstallSource[] = "notfromwebstore"; | 85 const char kNotFromWebstoreInstallSource[] = "notfromwebstore"; |
| 87 const char kDefaultInstallSource[] = ""; | 86 const char kDefaultInstallSource[] = ""; |
| 88 | 87 |
| 89 const char kGoogleDotCom[] = "google.com"; | 88 const char kGoogleDotCom[] = "google.com"; |
| 90 const char kTokenServiceConsumerId[] = "extension_downloader"; | 89 const char kTokenServiceConsumerId[] = "extension_downloader"; |
| 91 const char kWebstoreOAuth2Scope[] = | 90 const char kWebstoreOAuth2Scope[] = |
| 92 "https://www.googleapis.com/auth/chromewebstore.readonly"; | 91 "https://www.googleapis.com/auth/chromewebstore.readonly"; |
| 93 | 92 |
| 94 ExtensionDownloaderTestDelegate* g_test_delegate = nullptr; | |
| 95 | |
| 96 #define RETRY_HISTOGRAM(name, retry_count, url) \ | 93 #define RETRY_HISTOGRAM(name, retry_count, url) \ |
| 97 if ((url).DomainIs(kGoogleDotCom)) { \ | 94 if ((url).DomainIs(kGoogleDotCom)) { \ |
| 98 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions." name "RetryCountGoogleUrl", \ | 95 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions." name "RetryCountGoogleUrl", \ |
| 99 retry_count, \ | 96 retry_count, \ |
| 100 1, \ | 97 1, \ |
| 101 kMaxRetries, \ | 98 kMaxRetries, \ |
| 102 kMaxRetries + 1); \ | 99 kMaxRetries + 1); \ |
| 103 } else { \ | 100 } else { \ |
| 104 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions." name "RetryCountOtherUrl", \ | 101 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions." name "RetryCountOtherUrl", \ |
| 105 retry_count, \ | 102 retry_count, \ |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 blacklist_fetch->AddExtension(kBlacklistAppID, version, &ping_data, | 271 blacklist_fetch->AddExtension(kBlacklistAppID, version, &ping_data, |
| 275 std::string(), kDefaultInstallSource); | 272 std::string(), kDefaultInstallSource); |
| 276 StartUpdateCheck(std::move(blacklist_fetch)); | 273 StartUpdateCheck(std::move(blacklist_fetch)); |
| 277 } | 274 } |
| 278 | 275 |
| 279 void ExtensionDownloader::SetWebstoreIdentityProvider( | 276 void ExtensionDownloader::SetWebstoreIdentityProvider( |
| 280 scoped_ptr<IdentityProvider> identity_provider) { | 277 scoped_ptr<IdentityProvider> identity_provider) { |
| 281 identity_provider_.swap(identity_provider); | 278 identity_provider_.swap(identity_provider); |
| 282 } | 279 } |
| 283 | 280 |
| 284 // static | |
| 285 void ExtensionDownloader::set_test_delegate( | |
| 286 ExtensionDownloaderTestDelegate* delegate) { | |
| 287 g_test_delegate = delegate; | |
| 288 } | |
| 289 | |
| 290 bool ExtensionDownloader::AddExtensionData(const std::string& id, | 281 bool ExtensionDownloader::AddExtensionData(const std::string& id, |
| 291 const Version& version, | 282 const Version& version, |
| 292 Manifest::Type extension_type, | 283 Manifest::Type extension_type, |
| 293 const GURL& extension_update_url, | 284 const GURL& extension_update_url, |
| 294 const std::string& update_url_data, | 285 const std::string& update_url_data, |
| 295 int request_id) { | 286 int request_id) { |
| 296 GURL update_url(extension_update_url); | 287 GURL update_url(extension_update_url); |
| 297 // Skip extensions with non-empty invalid update URLs. | 288 // Skip extensions with non-empty invalid update URLs. |
| 298 if (!update_url.is_empty() && !update_url.is_valid()) { | 289 if (!update_url.is_empty() && !update_url.is_valid()) { |
| 299 DLOG(WARNING) << "Extension " << id << " has invalid update url " | 290 DLOG(WARNING) << "Extension " << id << " has invalid update url " |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckGoogleUrl", | 398 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckGoogleUrl", |
| 408 url_stats_.google_url_count); | 399 url_stats_.google_url_count); |
| 409 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckOtherUrl", | 400 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckOtherUrl", |
| 410 url_stats_.other_url_count); | 401 url_stats_.other_url_count); |
| 411 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckNoUrl", | 402 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckNoUrl", |
| 412 url_stats_.no_url_count); | 403 url_stats_.no_url_count); |
| 413 } | 404 } |
| 414 | 405 |
| 415 void ExtensionDownloader::StartUpdateCheck( | 406 void ExtensionDownloader::StartUpdateCheck( |
| 416 scoped_ptr<ManifestFetchData> fetch_data) { | 407 scoped_ptr<ManifestFetchData> fetch_data) { |
| 417 if (g_test_delegate) { | |
| 418 g_test_delegate->StartUpdateCheck(this, delegate_, std::move(fetch_data)); | |
| 419 return; | |
| 420 } | |
| 421 | |
| 422 const std::set<std::string>& id_set(fetch_data->extension_ids()); | 408 const std::set<std::string>& id_set(fetch_data->extension_ids()); |
| 423 | 409 |
| 424 if (!ExtensionsBrowserClient::Get()->IsBackgroundUpdateAllowed()) { | 410 if (!ExtensionsBrowserClient::Get()->IsBackgroundUpdateAllowed()) { |
| 425 NotifyExtensionsDownloadFailed(id_set, | 411 NotifyExtensionsDownloadFailed(id_set, |
| 426 fetch_data->request_ids(), | 412 fetch_data->request_ids(), |
| 427 ExtensionDownloaderDelegate::DISABLED); | 413 ExtensionDownloaderDelegate::DISABLED); |
| 428 return; | 414 return; |
| 429 } | 415 } |
| 430 | 416 |
| 431 RequestQueue<ManifestFetchData>::iterator i; | 417 RequestQueue<ManifestFetchData>::iterator i; |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 const GURL& update_url, | 938 const GURL& update_url, |
| 953 int request_id) { | 939 int request_id) { |
| 954 ManifestFetchData::PingMode ping_mode = ManifestFetchData::NO_PING; | 940 ManifestFetchData::PingMode ping_mode = ManifestFetchData::NO_PING; |
| 955 if (update_url.DomainIs(ping_enabled_domain_.c_str())) | 941 if (update_url.DomainIs(ping_enabled_domain_.c_str())) |
| 956 ping_mode = ManifestFetchData::PING_WITH_ENABLED_STATE; | 942 ping_mode = ManifestFetchData::PING_WITH_ENABLED_STATE; |
| 957 return new ManifestFetchData( | 943 return new ManifestFetchData( |
| 958 update_url, request_id, brand_code_, manifest_query_params_, ping_mode); | 944 update_url, request_id, brand_code_, manifest_query_params_, ping_mode); |
| 959 } | 945 } |
| 960 | 946 |
| 961 } // namespace extensions | 947 } // namespace extensions |
| OLD | NEW |