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(const std::string& param_name, |
| 133 bool default_value) { |
| 134 std::string param_value = variations::GetVariationParamValueByFeature( |
| 135 ntp_snippets::kArticleSuggestionsFeature, param_name); |
| 136 if (param_value == kBooleanParameterEnabled) |
| 137 return true; |
| 138 if (param_value == kBooleanParameterDisabled) |
| 139 return false; |
| 140 if (!param_value.empty()) { |
| 141 LOG(WARNING) << "Invalid value \"" << param_value |
| 142 << "\" for variation parameter " << param_name; |
| 143 } |
| 144 return default_value; |
| 145 } |
| 146 |
127 bool IsSendingTopLanguagesEnabled() { | 147 bool IsSendingTopLanguagesEnabled() { |
128 std::string send_top_languages = variations::GetVariationParamValueByFeature( | 148 return IsBooleanParameterEnabled(kSendTopLanguagesName, false); |
129 ntp_snippets::kArticleSuggestionsFeature, kSendTopLanguagesName); | 149 } |
130 if (send_top_languages == kSendTopLanguagesEnabled) | 150 |
131 return true; | 151 bool IsSendingUserClassEnabled() { |
132 if (!send_top_languages.empty() && | 152 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 } | 153 } |
139 | 154 |
140 bool UsesChromeContentSuggestionsAPI(const GURL& endpoint) { | 155 bool UsesChromeContentSuggestionsAPI(const GURL& endpoint) { |
141 if (endpoint == GURL(kChromeReaderServer)) | 156 if (endpoint == GURL(kChromeReaderServer)) |
142 return false; | 157 return false; |
143 | 158 |
144 if (endpoint != GURL(kContentSuggestionsServer) && | 159 if (endpoint != GURL(kContentSuggestionsServer) && |
145 endpoint != GURL(kContentSuggestionsDevServer) && | 160 endpoint != GURL(kContentSuggestionsDevServer) && |
146 endpoint != GURL(kContentSuggestionsAlphaServer)) { | 161 endpoint != GURL(kContentSuggestionsAlphaServer)) { |
147 LOG(WARNING) << "Unknown value for " << kContentSuggestionsBackend << ": " | 162 LOG(WARNING) << "Unknown value for " << kContentSuggestionsBackend << ": " |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 } | 220 } |
206 | 221 |
207 void AppendLanguageInfoToList(base::ListValue* list, | 222 void AppendLanguageInfoToList(base::ListValue* list, |
208 const LanguageModel::LanguageInfo& info) { | 223 const LanguageModel::LanguageInfo& info) { |
209 auto lang = base::MakeUnique<base::DictionaryValue>(); | 224 auto lang = base::MakeUnique<base::DictionaryValue>(); |
210 lang->SetString("language", info.language_code); | 225 lang->SetString("language", info.language_code); |
211 lang->SetDouble("frequency", info.frequency); | 226 lang->SetDouble("frequency", info.frequency); |
212 list->Append(std::move(lang)); | 227 list->Append(std::move(lang)); |
213 } | 228 } |
214 | 229 |
| 230 std::string GetUserClassString(UserClassifier::UserClass user_class) { |
| 231 switch (user_class) { |
| 232 case UserClassifier::UserClass::RARE_NTP_USER: |
| 233 return "RARE_NTP_USER"; |
| 234 case UserClassifier::UserClass::ACTIVE_NTP_USER: |
| 235 return "ACTIVE_NTP_USER"; |
| 236 case UserClassifier::UserClass::ACTIVE_SUGGESTIONS_CONSUMER: |
| 237 return "ACTIVE_SUGGESTIONS_CONSUMER"; |
| 238 } |
| 239 NOTREACHED(); |
| 240 return std::string(); |
| 241 } |
| 242 |
215 } // namespace | 243 } // namespace |
216 | 244 |
217 NTPSnippetsFetcher::FetchedCategory::FetchedCategory(Category c) | 245 NTPSnippetsFetcher::FetchedCategory::FetchedCategory(Category c) |
218 : category(c) {} | 246 : category(c) {} |
219 | 247 |
220 NTPSnippetsFetcher::FetchedCategory::FetchedCategory(FetchedCategory&&) = | 248 NTPSnippetsFetcher::FetchedCategory::FetchedCategory(FetchedCategory&&) = |
221 default; | 249 default; |
222 NTPSnippetsFetcher::FetchedCategory::~FetchedCategory() = default; | 250 NTPSnippetsFetcher::FetchedCategory::~FetchedCategory() = default; |
223 NTPSnippetsFetcher::FetchedCategory& NTPSnippetsFetcher::FetchedCategory:: | 251 NTPSnippetsFetcher::FetchedCategory& NTPSnippetsFetcher::FetchedCategory:: |
224 operator=(FetchedCategory&&) = default; | 252 operator=(FetchedCategory&&) = default; |
225 | 253 |
226 NTPSnippetsFetcher::NTPSnippetsFetcher( | 254 NTPSnippetsFetcher::NTPSnippetsFetcher( |
227 SigninManagerBase* signin_manager, | 255 SigninManagerBase* signin_manager, |
228 OAuth2TokenService* token_service, | 256 OAuth2TokenService* token_service, |
229 scoped_refptr<URLRequestContextGetter> url_request_context_getter, | 257 scoped_refptr<URLRequestContextGetter> url_request_context_getter, |
230 PrefService* pref_service, | 258 PrefService* pref_service, |
231 CategoryFactory* category_factory, | 259 CategoryFactory* category_factory, |
232 LanguageModel* language_model, | 260 LanguageModel* language_model, |
233 const ParseJSONCallback& parse_json_callback, | 261 const ParseJSONCallback& parse_json_callback, |
234 const std::string& api_key) | 262 const std::string& api_key, |
| 263 const UserClassifier* user_classifier) |
235 : OAuth2TokenService::Consumer("ntp_snippets"), | 264 : OAuth2TokenService::Consumer("ntp_snippets"), |
236 signin_manager_(signin_manager), | 265 signin_manager_(signin_manager), |
237 token_service_(token_service), | 266 token_service_(token_service), |
238 waiting_for_refresh_token_(false), | 267 waiting_for_refresh_token_(false), |
239 url_request_context_getter_(std::move(url_request_context_getter)), | 268 url_request_context_getter_(std::move(url_request_context_getter)), |
240 category_factory_(category_factory), | 269 category_factory_(category_factory), |
241 language_model_(language_model), | 270 language_model_(language_model), |
242 parse_json_callback_(parse_json_callback), | 271 parse_json_callback_(parse_json_callback), |
243 count_to_fetch_(0), | 272 count_to_fetch_(0), |
244 fetch_url_(GetFetchEndpoint()), | 273 fetch_url_(GetFetchEndpoint()), |
245 fetch_api_(UsesChromeContentSuggestionsAPI(fetch_url_) | 274 fetch_api_(UsesChromeContentSuggestionsAPI(fetch_url_) |
246 ? CHROME_CONTENT_SUGGESTIONS_API | 275 ? CHROME_CONTENT_SUGGESTIONS_API |
247 : CHROME_READER_API), | 276 : CHROME_READER_API), |
248 api_key_(api_key), | 277 api_key_(api_key), |
249 interactive_request_(false), | 278 interactive_request_(false), |
250 tick_clock_(new base::DefaultTickClock()), | 279 tick_clock_(new base::DefaultTickClock()), |
251 request_throttler_( | 280 user_classifier_(user_classifier), |
| 281 request_throttler_rare_ntp_user_( |
252 pref_service, | 282 pref_service, |
253 RequestThrottler::RequestType::CONTENT_SUGGESTION_FETCHER), | 283 RequestThrottler::RequestType:: |
| 284 CONTENT_SUGGESTION_FETCHER_RARE_NTP_USER), |
| 285 request_throttler_active_ntp_user_( |
| 286 pref_service, |
| 287 RequestThrottler::RequestType:: |
| 288 CONTENT_SUGGESTION_FETCHER_ACTIVE_NTP_USER), |
| 289 request_throttler_active_suggestions_consumer_( |
| 290 pref_service, |
| 291 RequestThrottler::RequestType:: |
| 292 CONTENT_SUGGESTION_FETCHER_ACTIVE_SUGGESTIONS_CONSUMER), |
254 oauth_token_retried_(false), | 293 oauth_token_retried_(false), |
255 weak_ptr_factory_(this) { | 294 weak_ptr_factory_(this) { |
256 // Parse the variation parameters and set the defaults if missing. | 295 // Parse the variation parameters and set the defaults if missing. |
257 std::string personalization = variations::GetVariationParamValue( | 296 std::string personalization = variations::GetVariationParamValue( |
258 ntp_snippets::kStudyName, kPersonalizationName); | 297 ntp_snippets::kStudyName, kPersonalizationName); |
259 if (personalization == kPersonalizationNonPersonalString) { | 298 if (personalization == kPersonalizationNonPersonalString) { |
260 personalization_ = Personalization::kNonPersonal; | 299 personalization_ = Personalization::kNonPersonal; |
261 } else if (personalization == kPersonalizationPersonalString) { | 300 } else if (personalization == kPersonalizationPersonalString) { |
262 personalization_ = Personalization::kPersonal; | 301 personalization_ = Personalization::kPersonal; |
263 } else { | 302 } else { |
(...skipping 14 matching lines...) Expand all Loading... |
278 const SnippetsAvailableCallback& callback) { | 317 const SnippetsAvailableCallback& callback) { |
279 snippets_available_callback_ = callback; | 318 snippets_available_callback_ = callback; |
280 } | 319 } |
281 | 320 |
282 void NTPSnippetsFetcher::FetchSnippetsFromHosts( | 321 void NTPSnippetsFetcher::FetchSnippetsFromHosts( |
283 const std::set<std::string>& hosts, | 322 const std::set<std::string>& hosts, |
284 const std::string& language_code, | 323 const std::string& language_code, |
285 const std::set<std::string>& excluded_ids, | 324 const std::set<std::string>& excluded_ids, |
286 int count, | 325 int count, |
287 bool interactive_request) { | 326 bool interactive_request) { |
288 if (!request_throttler_.DemandQuotaForRequest(interactive_request)) { | 327 if (!DemandQuotaForRequest(interactive_request)) { |
289 FetchFinished(OptionalFetchedCategories(), | 328 FetchFinished(OptionalFetchedCategories(), |
290 interactive_request | 329 interactive_request |
291 ? FetchResult::INTERACTIVE_QUOTA_ERROR | 330 ? FetchResult::INTERACTIVE_QUOTA_ERROR |
292 : FetchResult::NON_INTERACTIVE_QUOTA_ERROR, | 331 : FetchResult::NON_INTERACTIVE_QUOTA_ERROR, |
293 /*extra_message=*/std::string()); | 332 /*extra_message=*/std::string()); |
294 return; | 333 return; |
295 } | 334 } |
296 | 335 |
297 hosts_ = hosts; | 336 hosts_ = hosts; |
298 fetch_start_time_ = tick_clock_->NowTicks(); | 337 fetch_start_time_ = tick_clock_->NowTicks(); |
(...skipping 23 matching lines...) Expand all Loading... |
322 } | 361 } |
323 } | 362 } |
324 | 363 |
325 NTPSnippetsFetcher::RequestParams::RequestParams() | 364 NTPSnippetsFetcher::RequestParams::RequestParams() |
326 : fetch_api(), | 365 : fetch_api(), |
327 obfuscated_gaia_id(), | 366 obfuscated_gaia_id(), |
328 only_return_personalized_results(), | 367 only_return_personalized_results(), |
329 user_locale(), | 368 user_locale(), |
330 host_restricts(), | 369 host_restricts(), |
331 count_to_fetch(), | 370 count_to_fetch(), |
332 interactive_request() {} | 371 interactive_request(), |
| 372 user_class() {} |
333 | 373 |
334 NTPSnippetsFetcher::RequestParams::~RequestParams() = default; | 374 NTPSnippetsFetcher::RequestParams::~RequestParams() = default; |
335 | 375 |
336 std::string NTPSnippetsFetcher::RequestParams::BuildRequest() { | 376 std::string NTPSnippetsFetcher::RequestParams::BuildRequest() { |
337 auto request = base::MakeUnique<base::DictionaryValue>(); | 377 auto request = base::MakeUnique<base::DictionaryValue>(); |
338 switch (fetch_api) { | 378 switch (fetch_api) { |
339 case CHROME_READER_API: { | 379 case CHROME_READER_API: { |
340 auto content_params = base::MakeUnique<base::DictionaryValue>(); | 380 auto content_params = base::MakeUnique<base::DictionaryValue>(); |
341 content_params->SetBoolean("only_return_personalized_results", | 381 content_params->SetBoolean("only_return_personalized_results", |
342 only_return_personalized_results); | 382 only_return_personalized_results); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 : "BACKGROUND_PREFETCH"); | 438 : "BACKGROUND_PREFETCH"); |
399 | 439 |
400 auto excluded = base::MakeUnique<base::ListValue>(); | 440 auto excluded = base::MakeUnique<base::ListValue>(); |
401 for (const auto& id : excluded_ids) { | 441 for (const auto& id : excluded_ids) { |
402 excluded->AppendString(id); | 442 excluded->AppendString(id); |
403 if (excluded->GetSize() >= kMaxExcludedIds) | 443 if (excluded->GetSize() >= kMaxExcludedIds) |
404 break; | 444 break; |
405 } | 445 } |
406 request->Set("excludedSuggestionIds", std::move(excluded)); | 446 request->Set("excludedSuggestionIds", std::move(excluded)); |
407 | 447 |
| 448 if (!user_class.empty()) |
| 449 request->SetString("userActivenessClass", user_class); |
| 450 |
408 if (ui_language.frequency == 0 && other_top_language.frequency == 0) | 451 if (ui_language.frequency == 0 && other_top_language.frequency == 0) |
409 break; | 452 break; |
410 | 453 |
411 auto language_list = base::MakeUnique<base::ListValue>(); | 454 auto language_list = base::MakeUnique<base::ListValue>(); |
412 if (ui_language.frequency > 0) | 455 if (ui_language.frequency > 0) |
413 AppendLanguageInfoToList(language_list.get(), ui_language); | 456 AppendLanguageInfoToList(language_list.get(), ui_language); |
414 if (other_top_language.frequency > 0) | 457 if (other_top_language.frequency > 0) |
415 AppendLanguageInfoToList(language_list.get(), other_top_language); | 458 AppendLanguageInfoToList(language_list.get(), other_top_language); |
416 request->Set("top_languages", std::move(language_list)); | 459 request->Set("topLanguages", std::move(language_list)); |
417 | 460 |
418 // TODO(sfiera): support authentication and personalization | 461 // TODO(sfiera): support authentication and personalization |
419 // TODO(sfiera): support count_to_fetch | 462 // TODO(sfiera): support count_to_fetch |
420 break; | 463 break; |
421 } | 464 } |
422 } | 465 } |
423 | 466 |
424 std::string request_json; | 467 std::string request_json; |
425 bool success = base::JSONWriter::WriteWithOptions( | 468 bool success = base::JSONWriter::WriteWithOptions( |
426 *request, base::JSONWriter::OPTIONS_PRETTY_PRINT, &request_json); | 469 *request, base::JSONWriter::OPTIONS_PRETTY_PRINT, &request_json); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 } | 511 } |
469 | 512 |
470 void NTPSnippetsFetcher::SetUpCommonFetchingParameters( | 513 void NTPSnippetsFetcher::SetUpCommonFetchingParameters( |
471 RequestParams* params) const { | 514 RequestParams* params) const { |
472 params->fetch_api = fetch_api_; | 515 params->fetch_api = fetch_api_; |
473 params->host_restricts = hosts_; | 516 params->host_restricts = hosts_; |
474 params->user_locale = locale_; | 517 params->user_locale = locale_; |
475 params->excluded_ids = excluded_ids_; | 518 params->excluded_ids = excluded_ids_; |
476 params->count_to_fetch = count_to_fetch_; | 519 params->count_to_fetch = count_to_fetch_; |
477 params->interactive_request = interactive_request_; | 520 params->interactive_request = interactive_request_; |
| 521 |
| 522 if (IsSendingUserClassEnabled()) |
| 523 params->user_class = GetUserClassString(user_classifier_->GetUserClass()); |
| 524 |
478 // TODO(jkrcal): add the initializers into the struct and remove it from here | 525 // TODO(jkrcal): add the initializers into the struct and remove it from here |
479 // and from the unit-tests (building the request). | 526 // and from the unit-tests (building the request). |
480 params->ui_language.frequency = 0; | 527 params->ui_language.frequency = 0; |
481 params->other_top_language.frequency = 0; | 528 params->other_top_language.frequency = 0; |
482 | 529 |
483 // TODO(jkrcal): Add language model factory for iOS and add fakes to tests so | 530 // 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 | 531 // that |language_model_| is never nullptr. Remove this check and add a DCHECK |
485 // into the constructor. | 532 // into the constructor. |
486 if (!language_model_ || !IsSendingTopLanguagesEnabled()) | 533 if (!language_model_ || !IsSendingTopLanguagesEnabled()) |
487 return; | 534 return; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 } | 761 } |
715 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Snippets.FetchResult", | 762 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Snippets.FetchResult", |
716 static_cast<int>(result), | 763 static_cast<int>(result), |
717 static_cast<int>(FetchResult::RESULT_MAX)); | 764 static_cast<int>(FetchResult::RESULT_MAX)); |
718 | 765 |
719 DVLOG(1) << "Fetch finished: " << last_status_; | 766 DVLOG(1) << "Fetch finished: " << last_status_; |
720 if (!snippets_available_callback_.is_null()) | 767 if (!snippets_available_callback_.is_null()) |
721 snippets_available_callback_.Run(std::move(fetched_categories)); | 768 snippets_available_callback_.Run(std::move(fetched_categories)); |
722 } | 769 } |
723 | 770 |
| 771 bool NTPSnippetsFetcher::DemandQuotaForRequest(bool interactive_request) { |
| 772 switch (user_classifier_->GetUserClass()) { |
| 773 case UserClassifier::UserClass::RARE_NTP_USER: |
| 774 return request_throttler_rare_ntp_user_.DemandQuotaForRequest( |
| 775 interactive_request); |
| 776 case UserClassifier::UserClass::ACTIVE_NTP_USER: |
| 777 return request_throttler_active_ntp_user_.DemandQuotaForRequest( |
| 778 interactive_request); |
| 779 case UserClassifier::UserClass::ACTIVE_SUGGESTIONS_CONSUMER: |
| 780 return request_throttler_active_suggestions_consumer_ |
| 781 .DemandQuotaForRequest(interactive_request); |
| 782 } |
| 783 NOTREACHED(); |
| 784 return false; |
| 785 } |
| 786 |
724 } // namespace ntp_snippets | 787 } // namespace ntp_snippets |
OLD | NEW |