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

Side by Side Diff: components/suggestions/suggestions_service.cc

Issue 1549993003: Switch to standard integer types in components/, part 4 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 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 "components/suggestions/suggestions_service.h" 5 #include "components/suggestions/suggestions_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/feature_list.h" 9 #include "base/feature_list.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/metrics/sparse_histogram.h" 12 #include "base/metrics/sparse_histogram.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/thread_task_runner_handle.h" 17 #include "base/thread_task_runner_handle.h"
18 #include "build/build_config.h"
18 #include "components/data_use_measurement/core/data_use_user_data.h" 19 #include "components/data_use_measurement/core/data_use_user_data.h"
19 #include "components/pref_registry/pref_registry_syncable.h" 20 #include "components/pref_registry/pref_registry_syncable.h"
20 #include "components/signin/core/browser/signin_manager_base.h" 21 #include "components/signin/core/browser/signin_manager_base.h"
21 #include "components/suggestions/blacklist_store.h" 22 #include "components/suggestions/blacklist_store.h"
22 #include "components/suggestions/suggestions_store.h" 23 #include "components/suggestions/suggestions_store.h"
23 #include "components/variations/net/variations_http_headers.h" 24 #include "components/variations/net/variations_http_headers.h"
24 #include "google_apis/gaia/gaia_constants.h" 25 #include "google_apis/gaia/gaia_constants.h"
25 #include "google_apis/gaia/oauth2_token_service.h" 26 #include "google_apis/gaia/oauth2_token_service.h"
26 #include "net/base/escape.h" 27 #include "net/base/escape.h"
27 #include "net/base/load_flags.h" 28 #include "net/base/load_flags.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // Format string for OAuth2 authentication headers. 97 // Format string for OAuth2 authentication headers.
97 const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s"; 98 const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s";
98 99
99 const char kFaviconURL[] = 100 const char kFaviconURL[] =
100 "https://s2.googleusercontent.com/s2/favicons?domain_url=%s&alt=s&sz=32"; 101 "https://s2.googleusercontent.com/s2/favicons?domain_url=%s&alt=s&sz=32";
101 102
102 const char kPingURL[] = 103 const char kPingURL[] =
103 "https://www.google.com/chromesuggestions/click?q=%lld&cd=%d"; 104 "https://www.google.com/chromesuggestions/click?q=%lld&cd=%d";
104 105
105 // The default expiry timeout is 168 hours. 106 // The default expiry timeout is 168 hours.
106 const int64 kDefaultExpiryUsec = 168 * base::Time::kMicrosecondsPerHour; 107 const int64_t kDefaultExpiryUsec = 168 * base::Time::kMicrosecondsPerHour;
107 108
108 const base::Feature kOAuth2AuthenticationFeature { 109 const base::Feature kOAuth2AuthenticationFeature {
109 "SuggestionsServiceOAuth2", base::FEATURE_DISABLED_BY_DEFAULT 110 "SuggestionsServiceOAuth2", base::FEATURE_DISABLED_BY_DEFAULT
110 }; 111 };
111 112
112 } // namespace 113 } // namespace
113 114
114 // Helper class for fetching OAuth2 access tokens. 115 // Helper class for fetching OAuth2 access tokens.
115 // To get a token, call |GetAccessToken|. Does not support multiple concurrent 116 // To get a token, call |GetAccessToken|. Does not support multiple concurrent
116 // token requests, i.e. check |HasPendingRequest| first. 117 // token requests, i.e. check |HasPendingRequest| first.
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 net::EscapeQueryParamValue(candidate_url.spec(), true)); 318 net::EscapeQueryParamValue(candidate_url.spec(), true));
318 } 319 }
319 320
320 // static 321 // static
321 GURL SuggestionsService::BuildSuggestionsBlacklistClearURL() { 322 GURL SuggestionsService::BuildSuggestionsBlacklistClearURL() {
322 return GURL(base::StringPrintf(kSuggestionsBlacklistClearURLFormat, 323 return GURL(base::StringPrintf(kSuggestionsBlacklistClearURLFormat,
323 kDeviceType)); 324 kDeviceType));
324 } 325 }
325 326
326 void SuggestionsService::SetDefaultExpiryTimestamp( 327 void SuggestionsService::SetDefaultExpiryTimestamp(
327 SuggestionsProfile* suggestions, int64 default_timestamp_usec) { 328 SuggestionsProfile* suggestions,
329 int64_t default_timestamp_usec) {
328 for (int i = 0; i < suggestions->suggestions_size(); ++i) { 330 for (int i = 0; i < suggestions->suggestions_size(); ++i) {
329 ChromeSuggestion* suggestion = suggestions->mutable_suggestions(i); 331 ChromeSuggestion* suggestion = suggestions->mutable_suggestions(i);
330 // Do not set expiry if the server has already provided a more specific 332 // Do not set expiry if the server has already provided a more specific
331 // expiry time for this suggestion. 333 // expiry time for this suggestion.
332 if (!suggestion->has_expiry_ts()) { 334 if (!suggestion->has_expiry_ts()) {
333 suggestion->set_expiry_ts(default_timestamp_usec); 335 suggestion->set_expiry_ts(default_timestamp_usec);
334 } 336 }
335 } 337 }
336 } 338 }
337 339
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 DCHECK(success); 439 DCHECK(success);
438 440
439 // Parse the received suggestions and update the cache, or take proper action 441 // Parse the received suggestions and update the cache, or take proper action
440 // in the case of invalid response. 442 // in the case of invalid response.
441 SuggestionsProfile suggestions; 443 SuggestionsProfile suggestions;
442 if (suggestions_data.empty()) { 444 if (suggestions_data.empty()) {
443 LogResponseState(RESPONSE_EMPTY); 445 LogResponseState(RESPONSE_EMPTY);
444 suggestions_store_->ClearSuggestions(); 446 suggestions_store_->ClearSuggestions();
445 } else if (suggestions.ParseFromString(suggestions_data)) { 447 } else if (suggestions.ParseFromString(suggestions_data)) {
446 LogResponseState(RESPONSE_VALID); 448 LogResponseState(RESPONSE_VALID);
447 int64 now_usec = (base::Time::NowFromSystemTime() - base::Time::UnixEpoch()) 449 int64_t now_usec =
448 .ToInternalValue(); 450 (base::Time::NowFromSystemTime() - base::Time::UnixEpoch())
451 .ToInternalValue();
449 SetDefaultExpiryTimestamp(&suggestions, now_usec + kDefaultExpiryUsec); 452 SetDefaultExpiryTimestamp(&suggestions, now_usec + kDefaultExpiryUsec);
450 PopulateExtraData(&suggestions); 453 PopulateExtraData(&suggestions);
451 suggestions_store_->StoreSuggestions(suggestions); 454 suggestions_store_->StoreSuggestions(suggestions);
452 } else { 455 } else {
453 LogResponseState(RESPONSE_INVALID); 456 LogResponseState(RESPONSE_INVALID);
454 } 457 }
455 458
456 UpdateBlacklistDelay(true); 459 UpdateBlacklistDelay(true);
457 ScheduleBlacklistUpload(); 460 ScheduleBlacklistUpload();
458 } 461 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 scheduling_delay_ = TimeDelta::FromSeconds(kDefaultSchedulingDelaySec); 534 scheduling_delay_ = TimeDelta::FromSeconds(kDefaultSchedulingDelaySec);
532 } else { 535 } else {
533 TimeDelta candidate_delay = 536 TimeDelta candidate_delay =
534 scheduling_delay_ * kSchedulingBackoffMultiplier; 537 scheduling_delay_ * kSchedulingBackoffMultiplier;
535 if (candidate_delay < TimeDelta::FromSeconds(kSchedulingMaxDelaySec)) 538 if (candidate_delay < TimeDelta::FromSeconds(kSchedulingMaxDelaySec))
536 scheduling_delay_ = candidate_delay; 539 scheduling_delay_ = candidate_delay;
537 } 540 }
538 } 541 }
539 542
540 } // namespace suggestions 543 } // namespace suggestions
OLDNEW
« no previous file with comments | « components/suggestions/suggestions_service.h ('k') | components/suggestions/suggestions_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698