Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: extensions/browser/updater/extension_downloader.cc

Issue 1887253002: Rate limit programmatic update checks for extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix for idleness waiting problem caused by crrev.com/388245 Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
30 #include "extensions/browser/updater/request_queue_impl.h" 31 #include "extensions/browser/updater/request_queue_impl.h"
31 #include "extensions/browser/updater/safe_manifest_parser.h" 32 #include "extensions/browser/updater/safe_manifest_parser.h"
32 #include "extensions/common/extension_urls.h" 33 #include "extensions/common/extension_urls.h"
33 #include "extensions/common/manifest_url_handlers.h" 34 #include "extensions/common/manifest_url_handlers.h"
34 #include "google_apis/gaia/identity_provider.h" 35 #include "google_apis/gaia/identity_provider.h"
35 #include "net/base/backoff_entry.h" 36 #include "net/base/backoff_entry.h"
36 #include "net/base/load_flags.h" 37 #include "net/base/load_flags.h"
37 #include "net/base/net_errors.h" 38 #include "net/base/net_errors.h"
38 #include "net/http/http_request_headers.h" 39 #include "net/http/http_request_headers.h"
39 #include "net/http/http_status_code.h" 40 #include "net/http/http_status_code.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 const int kMaxOAuth2Attempts = 3; 84 const int kMaxOAuth2Attempts = 3;
84 85
85 const char kNotFromWebstoreInstallSource[] = "notfromwebstore"; 86 const char kNotFromWebstoreInstallSource[] = "notfromwebstore";
86 const char kDefaultInstallSource[] = ""; 87 const char kDefaultInstallSource[] = "";
87 88
88 const char kGoogleDotCom[] = "google.com"; 89 const char kGoogleDotCom[] = "google.com";
89 const char kTokenServiceConsumerId[] = "extension_downloader"; 90 const char kTokenServiceConsumerId[] = "extension_downloader";
90 const char kWebstoreOAuth2Scope[] = 91 const char kWebstoreOAuth2Scope[] =
91 "https://www.googleapis.com/auth/chromewebstore.readonly"; 92 "https://www.googleapis.com/auth/chromewebstore.readonly";
92 93
94 ExtensionDownloaderTestDelegate* g_test_delegate = nullptr;
95
93 #define RETRY_HISTOGRAM(name, retry_count, url) \ 96 #define RETRY_HISTOGRAM(name, retry_count, url) \
94 if ((url).DomainIs(kGoogleDotCom)) { \ 97 if ((url).DomainIs(kGoogleDotCom)) { \
95 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions." name "RetryCountGoogleUrl", \ 98 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions." name "RetryCountGoogleUrl", \
96 retry_count, \ 99 retry_count, \
97 1, \ 100 1, \
98 kMaxRetries, \ 101 kMaxRetries, \
99 kMaxRetries + 1); \ 102 kMaxRetries + 1); \
100 } else { \ 103 } else { \
101 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions." name "RetryCountOtherUrl", \ 104 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions." name "RetryCountOtherUrl", \
102 retry_count, \ 105 retry_count, \
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 blacklist_fetch->AddExtension(kBlacklistAppID, version, &ping_data, 274 blacklist_fetch->AddExtension(kBlacklistAppID, version, &ping_data,
272 std::string(), kDefaultInstallSource); 275 std::string(), kDefaultInstallSource);
273 StartUpdateCheck(std::move(blacklist_fetch)); 276 StartUpdateCheck(std::move(blacklist_fetch));
274 } 277 }
275 278
276 void ExtensionDownloader::SetWebstoreIdentityProvider( 279 void ExtensionDownloader::SetWebstoreIdentityProvider(
277 scoped_ptr<IdentityProvider> identity_provider) { 280 scoped_ptr<IdentityProvider> identity_provider) {
278 identity_provider_.swap(identity_provider); 281 identity_provider_.swap(identity_provider);
279 } 282 }
280 283
284 // static
285 void ExtensionDownloader::set_test_delegate(
286 ExtensionDownloaderTestDelegate* delegate) {
287 g_test_delegate = delegate;
288 }
289
281 bool ExtensionDownloader::AddExtensionData(const std::string& id, 290 bool ExtensionDownloader::AddExtensionData(const std::string& id,
282 const Version& version, 291 const Version& version,
283 Manifest::Type extension_type, 292 Manifest::Type extension_type,
284 const GURL& extension_update_url, 293 const GURL& extension_update_url,
285 const std::string& update_url_data, 294 const std::string& update_url_data,
286 int request_id) { 295 int request_id) {
287 GURL update_url(extension_update_url); 296 GURL update_url(extension_update_url);
288 // Skip extensions with non-empty invalid update URLs. 297 // Skip extensions with non-empty invalid update URLs.
289 if (!update_url.is_empty() && !update_url.is_valid()) { 298 if (!update_url.is_empty() && !update_url.is_valid()) {
290 DLOG(WARNING) << "Extension " << id << " has invalid update url " 299 DLOG(WARNING) << "Extension " << id << " has invalid update url "
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckGoogleUrl", 407 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckGoogleUrl",
399 url_stats_.google_url_count); 408 url_stats_.google_url_count);
400 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckOtherUrl", 409 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckOtherUrl",
401 url_stats_.other_url_count); 410 url_stats_.other_url_count);
402 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckNoUrl", 411 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckNoUrl",
403 url_stats_.no_url_count); 412 url_stats_.no_url_count);
404 } 413 }
405 414
406 void ExtensionDownloader::StartUpdateCheck( 415 void ExtensionDownloader::StartUpdateCheck(
407 scoped_ptr<ManifestFetchData> fetch_data) { 416 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
408 const std::set<std::string>& id_set(fetch_data->extension_ids()); 422 const std::set<std::string>& id_set(fetch_data->extension_ids());
409 423
410 if (!ExtensionsBrowserClient::Get()->IsBackgroundUpdateAllowed()) { 424 if (!ExtensionsBrowserClient::Get()->IsBackgroundUpdateAllowed()) {
411 NotifyExtensionsDownloadFailed(id_set, 425 NotifyExtensionsDownloadFailed(id_set,
412 fetch_data->request_ids(), 426 fetch_data->request_ids(),
413 ExtensionDownloaderDelegate::DISABLED); 427 ExtensionDownloaderDelegate::DISABLED);
414 return; 428 return;
415 } 429 }
416 430
417 RequestQueue<ManifestFetchData>::iterator i; 431 RequestQueue<ManifestFetchData>::iterator i;
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 const GURL& update_url, 952 const GURL& update_url,
939 int request_id) { 953 int request_id) {
940 ManifestFetchData::PingMode ping_mode = ManifestFetchData::NO_PING; 954 ManifestFetchData::PingMode ping_mode = ManifestFetchData::NO_PING;
941 if (update_url.DomainIs(ping_enabled_domain_.c_str())) 955 if (update_url.DomainIs(ping_enabled_domain_.c_str()))
942 ping_mode = ManifestFetchData::PING_WITH_ENABLED_STATE; 956 ping_mode = ManifestFetchData::PING_WITH_ENABLED_STATE;
943 return new ManifestFetchData( 957 return new ManifestFetchData(
944 update_url, request_id, brand_code_, manifest_query_params_, ping_mode); 958 update_url, request_id, brand_code_, manifest_query_params_, ping_mode);
945 } 959 }
946 960
947 } // namespace extensions 961 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/updater/extension_downloader.h ('k') | extensions/browser/updater/extension_downloader_test_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698