| 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 "components/suggestions/suggestions_service.h" | 5 #include "components/suggestions/suggestions_service.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 #else | 125 #else |
| 126 const char kDeviceType[] = "1"; | 126 const char kDeviceType[] = "1"; |
| 127 #endif | 127 #endif |
| 128 | 128 |
| 129 // Format string for OAuth2 authentication headers. | 129 // Format string for OAuth2 authentication headers. |
| 130 const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s"; | 130 const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s"; |
| 131 | 131 |
| 132 const char kFaviconURL[] = | 132 const char kFaviconURL[] = |
| 133 "https://s2.googleusercontent.com/s2/favicons?domain_url=%s&alt=s&sz=32"; | 133 "https://s2.googleusercontent.com/s2/favicons?domain_url=%s&alt=s&sz=32"; |
| 134 | 134 |
| 135 const char kPingURL[] = | |
| 136 "https://www.google.com/chromesuggestions/click?q=%lld&cd=%d"; | |
| 137 | |
| 138 // The default expiry timeout is 168 hours. | 135 // The default expiry timeout is 168 hours. |
| 139 const int64_t kDefaultExpiryUsec = 168 * base::Time::kMicrosecondsPerHour; | 136 const int64_t kDefaultExpiryUsec = 168 * base::Time::kMicrosecondsPerHour; |
| 140 | 137 |
| 141 } // namespace | 138 } // namespace |
| 142 | 139 |
| 143 // Helper class for fetching OAuth2 access tokens. | 140 // Helper class for fetching OAuth2 access tokens. |
| 144 // To get a token, call |GetAccessToken|. Does not support multiple concurrent | 141 // To get a token, call |GetAccessToken|. Does not support multiple concurrent |
| 145 // token requests, i.e. check |HasPendingRequest| first. | 142 // token requests, i.e. check |HasPendingRequest| first. |
| 146 class SuggestionsService::AccessTokenFetcher | 143 class SuggestionsService::AccessTokenFetcher |
| 147 : public OAuth2TokenService::Consumer { | 144 : public OAuth2TokenService::Consumer { |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 UpdateBlacklistDelay(true); | 498 UpdateBlacklistDelay(true); |
| 502 ScheduleBlacklistUpload(); | 499 ScheduleBlacklistUpload(); |
| 503 } | 500 } |
| 504 | 501 |
| 505 void SuggestionsService::PopulateExtraData(SuggestionsProfile* suggestions) { | 502 void SuggestionsService::PopulateExtraData(SuggestionsProfile* suggestions) { |
| 506 for (int i = 0; i < suggestions->suggestions_size(); ++i) { | 503 for (int i = 0; i < suggestions->suggestions_size(); ++i) { |
| 507 suggestions::ChromeSuggestion* s = suggestions->mutable_suggestions(i); | 504 suggestions::ChromeSuggestion* s = suggestions->mutable_suggestions(i); |
| 508 if (!s->has_favicon_url() || s->favicon_url().empty()) { | 505 if (!s->has_favicon_url() || s->favicon_url().empty()) { |
| 509 s->set_favicon_url(base::StringPrintf(kFaviconURL, s->url().c_str())); | 506 s->set_favicon_url(base::StringPrintf(kFaviconURL, s->url().c_str())); |
| 510 } | 507 } |
| 511 if (!s->has_impression_url() || s->impression_url().empty()) { | |
| 512 s->set_impression_url( | |
| 513 base::StringPrintf( | |
| 514 kPingURL, static_cast<long long>(suggestions->timestamp()), -1)); | |
| 515 } | |
| 516 | |
| 517 if (!s->has_click_url() || s->click_url().empty()) { | |
| 518 s->set_click_url(base::StringPrintf( | |
| 519 kPingURL, static_cast<long long>(suggestions->timestamp()), i)); | |
| 520 } | |
| 521 } | 508 } |
| 522 } | 509 } |
| 523 | 510 |
| 524 void SuggestionsService::Shutdown() { | 511 void SuggestionsService::Shutdown() { |
| 525 // Cancel pending request. | 512 // Cancel pending request. |
| 526 pending_request_.reset(nullptr); | 513 pending_request_.reset(nullptr); |
| 527 } | 514 } |
| 528 | 515 |
| 529 void SuggestionsService::ScheduleBlacklistUpload() { | 516 void SuggestionsService::ScheduleBlacklistUpload() { |
| 530 DCHECK(thread_checker_.CalledOnValidThread()); | 517 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 scheduling_delay_ = TimeDelta::FromSeconds(kDefaultSchedulingDelaySec); | 549 scheduling_delay_ = TimeDelta::FromSeconds(kDefaultSchedulingDelaySec); |
| 563 } else { | 550 } else { |
| 564 TimeDelta candidate_delay = | 551 TimeDelta candidate_delay = |
| 565 scheduling_delay_ * kSchedulingBackoffMultiplier; | 552 scheduling_delay_ * kSchedulingBackoffMultiplier; |
| 566 if (candidate_delay < TimeDelta::FromSeconds(kSchedulingMaxDelaySec)) | 553 if (candidate_delay < TimeDelta::FromSeconds(kSchedulingMaxDelaySec)) |
| 567 scheduling_delay_ = candidate_delay; | 554 scheduling_delay_ = candidate_delay; |
| 568 } | 555 } |
| 569 } | 556 } |
| 570 | 557 |
| 571 } // namespace suggestions | 558 } // namespace suggestions |
| OLD | NEW |