| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ntp_snippets/remote/ntp_snippets_fetcher.h" | 5 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h" |
| 6 | 6 |
| 7 #include <cstdlib> | 7 #include <cstdlib> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 << "Unknown value for " << kPersonalizationName << ": " | 309 << "Unknown value for " << kPersonalizationName << ": " |
| 310 << personalization; | 310 << personalization; |
| 311 } | 311 } |
| 312 } | 312 } |
| 313 | 313 |
| 314 NTPSnippetsFetcher::~NTPSnippetsFetcher() { | 314 NTPSnippetsFetcher::~NTPSnippetsFetcher() { |
| 315 if (waiting_for_refresh_token_) | 315 if (waiting_for_refresh_token_) |
| 316 token_service_->RemoveObserver(this); | 316 token_service_->RemoveObserver(this); |
| 317 } | 317 } |
| 318 | 318 |
| 319 void NTPSnippetsFetcher::SetCallback( | 319 void NTPSnippetsFetcher::SetCallback(SnippetsAvailableCallback callback) { |
| 320 const SnippetsAvailableCallback& callback) { | 320 snippets_available_callback_ = std::move(callback); |
| 321 snippets_available_callback_ = callback; | |
| 322 } | 321 } |
| 323 | 322 |
| 324 void NTPSnippetsFetcher::FetchSnippetsFromHosts( | 323 void NTPSnippetsFetcher::FetchSnippetsFromHosts( |
| 325 const std::set<std::string>& hosts, | 324 const std::set<std::string>& hosts, |
| 326 const std::string& language_code, | 325 const std::string& language_code, |
| 327 const std::set<std::string>& excluded_ids, | 326 const std::set<std::string>& excluded_ids, |
| 328 int count, | 327 int count, |
| 329 bool interactive_request) { | 328 bool interactive_request) { |
| 330 if (!DemandQuotaForRequest(interactive_request)) { | 329 if (!DemandQuotaForRequest(interactive_request)) { |
| 331 FetchFinished(OptionalFetchedCategories(), | 330 FetchFinished(OptionalFetchedCategories(), |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 if (!IsFetchPreconditionFailed(result)) { | 762 if (!IsFetchPreconditionFailed(result)) { |
| 764 UMA_HISTOGRAM_TIMES("NewTabPage.Snippets.FetchTime", | 763 UMA_HISTOGRAM_TIMES("NewTabPage.Snippets.FetchTime", |
| 765 tick_clock_->NowTicks() - fetch_start_time_); | 764 tick_clock_->NowTicks() - fetch_start_time_); |
| 766 } | 765 } |
| 767 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Snippets.FetchResult", | 766 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Snippets.FetchResult", |
| 768 static_cast<int>(result), | 767 static_cast<int>(result), |
| 769 static_cast<int>(FetchResult::RESULT_MAX)); | 768 static_cast<int>(FetchResult::RESULT_MAX)); |
| 770 | 769 |
| 771 DVLOG(1) << "Fetch finished: " << last_status_; | 770 DVLOG(1) << "Fetch finished: " << last_status_; |
| 772 if (!snippets_available_callback_.is_null()) | 771 if (!snippets_available_callback_.is_null()) |
| 773 snippets_available_callback_.Run(std::move(fetched_categories)); | 772 std::move(snippets_available_callback_).Run(std::move(fetched_categories)); |
| 774 } | 773 } |
| 775 | 774 |
| 776 bool NTPSnippetsFetcher::DemandQuotaForRequest(bool interactive_request) { | 775 bool NTPSnippetsFetcher::DemandQuotaForRequest(bool interactive_request) { |
| 777 switch (user_classifier_->GetUserClass()) { | 776 switch (user_classifier_->GetUserClass()) { |
| 778 case UserClassifier::UserClass::RARE_NTP_USER: | 777 case UserClassifier::UserClass::RARE_NTP_USER: |
| 779 return request_throttler_rare_ntp_user_.DemandQuotaForRequest( | 778 return request_throttler_rare_ntp_user_.DemandQuotaForRequest( |
| 780 interactive_request); | 779 interactive_request); |
| 781 case UserClassifier::UserClass::ACTIVE_NTP_USER: | 780 case UserClassifier::UserClass::ACTIVE_NTP_USER: |
| 782 return request_throttler_active_ntp_user_.DemandQuotaForRequest( | 781 return request_throttler_active_ntp_user_.DemandQuotaForRequest( |
| 783 interactive_request); | 782 interactive_request); |
| 784 case UserClassifier::UserClass::ACTIVE_SUGGESTIONS_CONSUMER: | 783 case UserClassifier::UserClass::ACTIVE_SUGGESTIONS_CONSUMER: |
| 785 return request_throttler_active_suggestions_consumer_ | 784 return request_throttler_active_suggestions_consumer_ |
| 786 .DemandQuotaForRequest(interactive_request); | 785 .DemandQuotaForRequest(interactive_request); |
| 787 } | 786 } |
| 788 NOTREACHED(); | 787 NOTREACHED(); |
| 789 return false; | 788 return false; |
| 790 } | 789 } |
| 791 | 790 |
| 792 } // namespace ntp_snippets | 791 } // namespace ntp_snippets |
| OLD | NEW |