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" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
15 #include "base/metrics/sparse_histogram.h" | 15 #include "base/metrics/sparse_histogram.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "base/time/default_tick_clock.h" | 21 #include "base/time/default_tick_clock.h" |
22 #include "base/values.h" | 22 #include "base/values.h" |
23 #include "components/data_use_measurement/core/data_use_user_data.h" | 23 #include "components/data_use_measurement/core/data_use_user_data.h" |
24 #include "components/ntp_snippets/category_factory.h" | 24 #include "components/ntp_snippets/category_factory.h" |
25 #include "components/ntp_snippets/features.h" | 25 #include "components/ntp_snippets/features.h" |
26 #include "components/ntp_snippets/ntp_snippets_constants.h" | 26 #include "components/ntp_snippets/ntp_snippets_constants.h" |
27 #include "components/ntp_snippets/user_classifier.h" | |
27 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 28 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
28 #include "components/signin/core/browser/signin_manager.h" | 29 #include "components/signin/core/browser/signin_manager.h" |
29 #include "components/signin/core/browser/signin_manager_base.h" | 30 #include "components/signin/core/browser/signin_manager_base.h" |
30 #include "components/variations/net/variations_http_headers.h" | 31 #include "components/variations/net/variations_http_headers.h" |
31 #include "components/variations/variations_associated_data.h" | 32 #include "components/variations/variations_associated_data.h" |
32 #include "net/base/load_flags.h" | 33 #include "net/base/load_flags.h" |
33 #include "net/http/http_request_headers.h" | 34 #include "net/http/http_request_headers.h" |
34 #include "net/http/http_response_headers.h" | 35 #include "net/http/http_response_headers.h" |
35 #include "net/http/http_status_code.h" | 36 #include "net/http/http_status_code.h" |
36 #include "net/url_request/url_fetcher.h" | 37 #include "net/url_request/url_fetcher.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
62 | 63 |
63 // Constants for possible values of the "fetching_personalization" parameter. | 64 // Constants for possible values of the "fetching_personalization" parameter. |
64 const char kPersonalizationPersonalString[] = "personal"; | 65 const char kPersonalizationPersonalString[] = "personal"; |
65 const char kPersonalizationNonPersonalString[] = "non_personal"; | 66 const char kPersonalizationNonPersonalString[] = "non_personal"; |
66 const char kPersonalizationBothString[] = "both"; // the default value | 67 const char kPersonalizationBothString[] = "both"; // the default value |
67 | 68 |
68 const int kMaxExcludedIds = 100; | 69 const int kMaxExcludedIds = 100; |
69 | 70 |
70 // Variation parameter for sending LanguageModel info to the server. | 71 // Variation parameter for sending LanguageModel info to the server. |
71 const char kSendTopLanguagesName[] = "send_top_languages"; | 72 const char kSendTopLanguagesName[] = "send_top_languages"; |
72 const char kSendTopLanguagesEnabled[] = "true"; | 73 |
73 const char kSendTopLanguagesDisabled[] = "false"; | 74 // Variation parameter for sending UserClassifier info to the server. |
75 const char kSendUserClassName[] = "send_user_class"; | |
76 | |
77 const char kBooleanParameterEnabled[] = "true"; | |
78 const char kBooleanParameterDisabled[] = "false"; | |
74 | 79 |
75 std::string FetchResultToString(NTPSnippetsFetcher::FetchResult result) { | 80 std::string FetchResultToString(NTPSnippetsFetcher::FetchResult result) { |
76 switch (result) { | 81 switch (result) { |
77 case NTPSnippetsFetcher::FetchResult::SUCCESS: | 82 case NTPSnippetsFetcher::FetchResult::SUCCESS: |
78 return "OK"; | 83 return "OK"; |
79 case NTPSnippetsFetcher::FetchResult::DEPRECATED_EMPTY_HOSTS: | 84 case NTPSnippetsFetcher::FetchResult::DEPRECATED_EMPTY_HOSTS: |
80 return "Cannot fetch for empty hosts list."; | 85 return "Cannot fetch for empty hosts list."; |
81 case NTPSnippetsFetcher::FetchResult::URL_REQUEST_STATUS_ERROR: | 86 case NTPSnippetsFetcher::FetchResult::URL_REQUEST_STATUS_ERROR: |
82 return "URLRequestStatus error"; | 87 return "URLRequestStatus error"; |
83 case NTPSnippetsFetcher::FetchResult::HTTP_ERROR: | 88 case NTPSnippetsFetcher::FetchResult::HTTP_ERROR: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 NOTREACHED(); | 122 NOTREACHED(); |
118 return true; | 123 return true; |
119 } | 124 } |
120 | 125 |
121 std::string GetFetchEndpoint() { | 126 std::string GetFetchEndpoint() { |
122 std::string endpoint = variations::GetVariationParamValue( | 127 std::string endpoint = variations::GetVariationParamValue( |
123 ntp_snippets::kStudyName, kContentSuggestionsBackend); | 128 ntp_snippets::kStudyName, kContentSuggestionsBackend); |
124 return endpoint.empty() ? kChromeReaderServer : endpoint; | 129 return endpoint.empty() ? kChromeReaderServer : endpoint; |
125 } | 130 } |
126 | 131 |
132 bool IsBooleanParameterEnabled(std::string param_name, bool default_value) { | |
Marc Treib
2016/10/10 08:01:01
nit: const std::string&
jkrcal
2016/10/10 08:37:16
Oh, again :|
By the way, I am sick of this parsin
| |
133 std::string param_value = variations::GetVariationParamValueByFeature( | |
134 ntp_snippets::kArticleSuggestionsFeature, param_name); | |
135 if (param_value == kBooleanParameterEnabled) | |
136 return true; | |
137 if (param_value == kBooleanParameterDisabled) | |
138 return false; | |
139 if (!param_value.empty()) { | |
140 LOG(WARNING) << "Invalid value \"" << param_value | |
141 << "\" for variation parameter " << param_name; | |
142 } | |
143 return default_value; | |
144 } | |
145 | |
127 bool IsSendingTopLanguagesEnabled() { | 146 bool IsSendingTopLanguagesEnabled() { |
128 std::string send_top_languages = variations::GetVariationParamValueByFeature( | 147 return IsBooleanParameterEnabled(kSendTopLanguagesName, false); |
129 ntp_snippets::kArticleSuggestionsFeature, kSendTopLanguagesName); | 148 } |
130 if (send_top_languages == kSendTopLanguagesEnabled) | 149 |
131 return true; | 150 bool IsSendingUserClassEnabled() { |
132 if (!send_top_languages.empty() && | 151 return IsBooleanParameterEnabled(kSendUserClassName, false); |
133 send_top_languages != kSendTopLanguagesDisabled) { | |
134 LOG(WARNING) << "Invalid value \"" << send_top_languages | |
135 << "\" for variation parameter " << kSendTopLanguagesName; | |
136 } | |
137 return false; | |
138 } | 152 } |
139 | 153 |
140 bool UsesChromeContentSuggestionsAPI(const GURL& endpoint) { | 154 bool UsesChromeContentSuggestionsAPI(const GURL& endpoint) { |
141 if (endpoint == GURL(kChromeReaderServer)) | 155 if (endpoint == GURL(kChromeReaderServer)) |
142 return false; | 156 return false; |
143 | 157 |
144 if (endpoint != GURL(kContentSuggestionsServer) && | 158 if (endpoint != GURL(kContentSuggestionsServer) && |
145 endpoint != GURL(kContentSuggestionsDevServer) && | 159 endpoint != GURL(kContentSuggestionsDevServer) && |
146 endpoint != GURL(kContentSuggestionsAlphaServer)) { | 160 endpoint != GURL(kContentSuggestionsAlphaServer)) { |
147 LOG(WARNING) << "Unknown value for " << kContentSuggestionsBackend << ": " | 161 LOG(WARNING) << "Unknown value for " << kContentSuggestionsBackend << ": " |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 } | 219 } |
206 | 220 |
207 void AppendLanguageInfoToList(base::ListValue* list, | 221 void AppendLanguageInfoToList(base::ListValue* list, |
208 const LanguageModel::LanguageInfo& info) { | 222 const LanguageModel::LanguageInfo& info) { |
209 auto lang = base::MakeUnique<base::DictionaryValue>(); | 223 auto lang = base::MakeUnique<base::DictionaryValue>(); |
210 lang->SetString("language", info.language_code); | 224 lang->SetString("language", info.language_code); |
211 lang->SetDouble("frequency", info.frequency); | 225 lang->SetDouble("frequency", info.frequency); |
212 list->Append(std::move(lang)); | 226 list->Append(std::move(lang)); |
213 } | 227 } |
214 | 228 |
229 std::string GetUserClassString(UserClassifier::UserClass user_class) { | |
230 switch (user_class) { | |
231 case UserClassifier::UserClass::RARE_NTP_USER: | |
232 return "RARE_NTP_USER"; | |
233 case UserClassifier::UserClass::ACTIVE_NTP_USER: | |
234 return "ACTIVE_NTP_USER"; | |
235 case UserClassifier::UserClass::ACTIVE_SUGGESTIONS_CONSUMER: | |
236 return "ACTIVE_SUGGESTIONS_CONSUMER"; | |
237 } | |
238 NOTREACHED(); | |
239 return std::string(); | |
240 } | |
241 | |
215 } // namespace | 242 } // namespace |
216 | 243 |
217 NTPSnippetsFetcher::FetchedCategory::FetchedCategory(Category c) | 244 NTPSnippetsFetcher::FetchedCategory::FetchedCategory(Category c) |
218 : category(c) {} | 245 : category(c) {} |
219 | 246 |
220 NTPSnippetsFetcher::FetchedCategory::FetchedCategory(FetchedCategory&&) = | 247 NTPSnippetsFetcher::FetchedCategory::FetchedCategory(FetchedCategory&&) = |
221 default; | 248 default; |
222 NTPSnippetsFetcher::FetchedCategory::~FetchedCategory() = default; | 249 NTPSnippetsFetcher::FetchedCategory::~FetchedCategory() = default; |
223 NTPSnippetsFetcher::FetchedCategory& NTPSnippetsFetcher::FetchedCategory:: | 250 NTPSnippetsFetcher::FetchedCategory& NTPSnippetsFetcher::FetchedCategory:: |
224 operator=(FetchedCategory&&) = default; | 251 operator=(FetchedCategory&&) = default; |
225 | 252 |
226 NTPSnippetsFetcher::NTPSnippetsFetcher( | 253 NTPSnippetsFetcher::NTPSnippetsFetcher( |
227 SigninManagerBase* signin_manager, | 254 SigninManagerBase* signin_manager, |
228 OAuth2TokenService* token_service, | 255 OAuth2TokenService* token_service, |
229 scoped_refptr<URLRequestContextGetter> url_request_context_getter, | 256 scoped_refptr<URLRequestContextGetter> url_request_context_getter, |
230 PrefService* pref_service, | 257 PrefService* pref_service, |
231 CategoryFactory* category_factory, | 258 CategoryFactory* category_factory, |
232 LanguageModel* language_model, | 259 LanguageModel* language_model, |
233 const ParseJSONCallback& parse_json_callback, | 260 const ParseJSONCallback& parse_json_callback, |
234 const std::string& api_key) | 261 const std::string& api_key, |
262 const UserClassifier* user_classifier) | |
235 : OAuth2TokenService::Consumer("ntp_snippets"), | 263 : OAuth2TokenService::Consumer("ntp_snippets"), |
236 signin_manager_(signin_manager), | 264 signin_manager_(signin_manager), |
237 token_service_(token_service), | 265 token_service_(token_service), |
238 waiting_for_refresh_token_(false), | 266 waiting_for_refresh_token_(false), |
239 url_request_context_getter_(std::move(url_request_context_getter)), | 267 url_request_context_getter_(std::move(url_request_context_getter)), |
240 category_factory_(category_factory), | 268 category_factory_(category_factory), |
241 language_model_(language_model), | 269 language_model_(language_model), |
242 parse_json_callback_(parse_json_callback), | 270 parse_json_callback_(parse_json_callback), |
243 count_to_fetch_(0), | 271 count_to_fetch_(0), |
244 fetch_url_(GetFetchEndpoint()), | 272 fetch_url_(GetFetchEndpoint()), |
245 fetch_api_(UsesChromeContentSuggestionsAPI(fetch_url_) | 273 fetch_api_(UsesChromeContentSuggestionsAPI(fetch_url_) |
246 ? CHROME_CONTENT_SUGGESTIONS_API | 274 ? CHROME_CONTENT_SUGGESTIONS_API |
247 : CHROME_READER_API), | 275 : CHROME_READER_API), |
248 api_key_(api_key), | 276 api_key_(api_key), |
249 interactive_request_(false), | 277 interactive_request_(false), |
250 tick_clock_(new base::DefaultTickClock()), | 278 tick_clock_(new base::DefaultTickClock()), |
251 request_throttler_( | 279 user_classifier_(user_classifier), |
280 request_throttler_rare_ntp_user_( | |
252 pref_service, | 281 pref_service, |
253 RequestThrottler::RequestType::CONTENT_SUGGESTION_FETCHER), | 282 RequestThrottler::RequestType:: |
283 CONTENT_SUGGESTION_FETCHER_RARE_NTP_USER), | |
284 request_throttler_active_ntp_user_( | |
285 pref_service, | |
286 RequestThrottler::RequestType:: | |
287 CONTENT_SUGGESTION_FETCHER_ACTIVE_NTP_USER), | |
288 request_throttler_active_suggestions_consumer_( | |
289 pref_service, | |
290 RequestThrottler::RequestType:: | |
291 CONTENT_SUGGESTION_FETCHER_ACTIVE_SUGGESTIONS_CONSUMER), | |
254 oauth_token_retried_(false), | 292 oauth_token_retried_(false), |
255 weak_ptr_factory_(this) { | 293 weak_ptr_factory_(this) { |
256 // Parse the variation parameters and set the defaults if missing. | 294 // Parse the variation parameters and set the defaults if missing. |
257 std::string personalization = variations::GetVariationParamValue( | 295 std::string personalization = variations::GetVariationParamValue( |
258 ntp_snippets::kStudyName, kPersonalizationName); | 296 ntp_snippets::kStudyName, kPersonalizationName); |
259 if (personalization == kPersonalizationNonPersonalString) { | 297 if (personalization == kPersonalizationNonPersonalString) { |
260 personalization_ = Personalization::kNonPersonal; | 298 personalization_ = Personalization::kNonPersonal; |
261 } else if (personalization == kPersonalizationPersonalString) { | 299 } else if (personalization == kPersonalizationPersonalString) { |
262 personalization_ = Personalization::kPersonal; | 300 personalization_ = Personalization::kPersonal; |
263 } else { | 301 } else { |
(...skipping 14 matching lines...) Expand all Loading... | |
278 const SnippetsAvailableCallback& callback) { | 316 const SnippetsAvailableCallback& callback) { |
279 snippets_available_callback_ = callback; | 317 snippets_available_callback_ = callback; |
280 } | 318 } |
281 | 319 |
282 void NTPSnippetsFetcher::FetchSnippetsFromHosts( | 320 void NTPSnippetsFetcher::FetchSnippetsFromHosts( |
283 const std::set<std::string>& hosts, | 321 const std::set<std::string>& hosts, |
284 const std::string& language_code, | 322 const std::string& language_code, |
285 const std::set<std::string>& excluded_ids, | 323 const std::set<std::string>& excluded_ids, |
286 int count, | 324 int count, |
287 bool interactive_request) { | 325 bool interactive_request) { |
288 if (!request_throttler_.DemandQuotaForRequest(interactive_request)) { | 326 if (!DemandQuotaForRequest(interactive_request)) { |
289 FetchFinished(OptionalFetchedCategories(), | 327 FetchFinished(OptionalFetchedCategories(), |
290 interactive_request | 328 interactive_request |
291 ? FetchResult::INTERACTIVE_QUOTA_ERROR | 329 ? FetchResult::INTERACTIVE_QUOTA_ERROR |
292 : FetchResult::NON_INTERACTIVE_QUOTA_ERROR, | 330 : FetchResult::NON_INTERACTIVE_QUOTA_ERROR, |
293 /*extra_message=*/std::string()); | 331 /*extra_message=*/std::string()); |
294 return; | 332 return; |
295 } | 333 } |
296 | 334 |
297 hosts_ = hosts; | 335 hosts_ = hosts; |
298 fetch_start_time_ = tick_clock_->NowTicks(); | 336 fetch_start_time_ = tick_clock_->NowTicks(); |
(...skipping 23 matching lines...) Expand all Loading... | |
322 } | 360 } |
323 } | 361 } |
324 | 362 |
325 NTPSnippetsFetcher::RequestParams::RequestParams() | 363 NTPSnippetsFetcher::RequestParams::RequestParams() |
326 : fetch_api(), | 364 : fetch_api(), |
327 obfuscated_gaia_id(), | 365 obfuscated_gaia_id(), |
328 only_return_personalized_results(), | 366 only_return_personalized_results(), |
329 user_locale(), | 367 user_locale(), |
330 host_restricts(), | 368 host_restricts(), |
331 count_to_fetch(), | 369 count_to_fetch(), |
332 interactive_request() {} | 370 interactive_request(), |
371 user_class() {} | |
333 | 372 |
334 NTPSnippetsFetcher::RequestParams::~RequestParams() = default; | 373 NTPSnippetsFetcher::RequestParams::~RequestParams() = default; |
335 | 374 |
336 std::string NTPSnippetsFetcher::RequestParams::BuildRequest() { | 375 std::string NTPSnippetsFetcher::RequestParams::BuildRequest() { |
337 auto request = base::MakeUnique<base::DictionaryValue>(); | 376 auto request = base::MakeUnique<base::DictionaryValue>(); |
338 switch (fetch_api) { | 377 switch (fetch_api) { |
339 case CHROME_READER_API: { | 378 case CHROME_READER_API: { |
340 auto content_params = base::MakeUnique<base::DictionaryValue>(); | 379 auto content_params = base::MakeUnique<base::DictionaryValue>(); |
341 content_params->SetBoolean("only_return_personalized_results", | 380 content_params->SetBoolean("only_return_personalized_results", |
342 only_return_personalized_results); | 381 only_return_personalized_results); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 : "BACKGROUND_PREFETCH"); | 437 : "BACKGROUND_PREFETCH"); |
399 | 438 |
400 auto excluded = base::MakeUnique<base::ListValue>(); | 439 auto excluded = base::MakeUnique<base::ListValue>(); |
401 for (const auto& id : excluded_ids) { | 440 for (const auto& id : excluded_ids) { |
402 excluded->AppendString(id); | 441 excluded->AppendString(id); |
403 if (excluded->GetSize() >= kMaxExcludedIds) | 442 if (excluded->GetSize() >= kMaxExcludedIds) |
404 break; | 443 break; |
405 } | 444 } |
406 request->Set("excludedSuggestionIds", std::move(excluded)); | 445 request->Set("excludedSuggestionIds", std::move(excluded)); |
407 | 446 |
447 if (!user_class.empty()) | |
448 request->SetString("user_activeness_class", user_class); | |
Marc Treib
2016/10/10 08:01:01
What's up with the naming conventions here - "excl
jkrcal
2016/10/10 08:37:16
Oh, thanks for spotting it! It's hard to test as t
| |
449 | |
408 if (ui_language.frequency == 0 && other_top_language.frequency == 0) | 450 if (ui_language.frequency == 0 && other_top_language.frequency == 0) |
409 break; | 451 break; |
410 | 452 |
411 auto language_list = base::MakeUnique<base::ListValue>(); | 453 auto language_list = base::MakeUnique<base::ListValue>(); |
412 if (ui_language.frequency > 0) | 454 if (ui_language.frequency > 0) |
413 AppendLanguageInfoToList(language_list.get(), ui_language); | 455 AppendLanguageInfoToList(language_list.get(), ui_language); |
414 if (other_top_language.frequency > 0) | 456 if (other_top_language.frequency > 0) |
415 AppendLanguageInfoToList(language_list.get(), other_top_language); | 457 AppendLanguageInfoToList(language_list.get(), other_top_language); |
416 request->Set("top_languages", std::move(language_list)); | 458 request->Set("top_languages", std::move(language_list)); |
417 | 459 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 } | 510 } |
469 | 511 |
470 void NTPSnippetsFetcher::SetUpCommonFetchingParameters( | 512 void NTPSnippetsFetcher::SetUpCommonFetchingParameters( |
471 RequestParams* params) const { | 513 RequestParams* params) const { |
472 params->fetch_api = fetch_api_; | 514 params->fetch_api = fetch_api_; |
473 params->host_restricts = hosts_; | 515 params->host_restricts = hosts_; |
474 params->user_locale = locale_; | 516 params->user_locale = locale_; |
475 params->excluded_ids = excluded_ids_; | 517 params->excluded_ids = excluded_ids_; |
476 params->count_to_fetch = count_to_fetch_; | 518 params->count_to_fetch = count_to_fetch_; |
477 params->interactive_request = interactive_request_; | 519 params->interactive_request = interactive_request_; |
520 | |
521 if (IsSendingUserClassEnabled()) | |
522 params->user_class = GetUserClassString(user_classifier_->GetUserClass()); | |
523 | |
478 // TODO(jkrcal): add the initializers into the struct and remove it from here | 524 // TODO(jkrcal): add the initializers into the struct and remove it from here |
479 // and from the unit-tests (building the request). | 525 // and from the unit-tests (building the request). |
480 params->ui_language.frequency = 0; | 526 params->ui_language.frequency = 0; |
481 params->other_top_language.frequency = 0; | 527 params->other_top_language.frequency = 0; |
482 | 528 |
483 // TODO(jkrcal): Add language model factory for iOS and add fakes to tests so | 529 // TODO(jkrcal): Add language model factory for iOS and add fakes to tests so |
484 // that |language_model_| is never nullptr. Remove this check and add a DCHECK | 530 // that |language_model_| is never nullptr. Remove this check and add a DCHECK |
485 // into the constructor. | 531 // into the constructor. |
486 if (!language_model_ || !IsSendingTopLanguagesEnabled()) | 532 if (!language_model_ || !IsSendingTopLanguagesEnabled()) |
487 return; | 533 return; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
714 } | 760 } |
715 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Snippets.FetchResult", | 761 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Snippets.FetchResult", |
716 static_cast<int>(result), | 762 static_cast<int>(result), |
717 static_cast<int>(FetchResult::RESULT_MAX)); | 763 static_cast<int>(FetchResult::RESULT_MAX)); |
718 | 764 |
719 DVLOG(1) << "Fetch finished: " << last_status_; | 765 DVLOG(1) << "Fetch finished: " << last_status_; |
720 if (!snippets_available_callback_.is_null()) | 766 if (!snippets_available_callback_.is_null()) |
721 snippets_available_callback_.Run(std::move(fetched_categories)); | 767 snippets_available_callback_.Run(std::move(fetched_categories)); |
722 } | 768 } |
723 | 769 |
770 bool NTPSnippetsFetcher::DemandQuotaForRequest(bool interactive_request) { | |
771 switch (user_classifier_->GetUserClass()) { | |
772 case UserClassifier::UserClass::RARE_NTP_USER: | |
773 return request_throttler_rare_ntp_user_.DemandQuotaForRequest( | |
774 interactive_request); | |
775 case UserClassifier::UserClass::ACTIVE_NTP_USER: | |
776 return request_throttler_active_ntp_user_.DemandQuotaForRequest( | |
777 interactive_request); | |
778 case UserClassifier::UserClass::ACTIVE_SUGGESTIONS_CONSUMER: | |
779 return request_throttler_active_suggestions_consumer_ | |
780 .DemandQuotaForRequest(interactive_request); | |
781 } | |
782 NOTREACHED(); | |
783 return false; | |
784 } | |
785 | |
724 } // namespace ntp_snippets | 786 } // namespace ntp_snippets |
OLD | NEW |