| 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/request_throttler.h" | 5 #include "components/ntp_snippets/remote/request_throttler.h" |
| 6 | 6 |
| 7 #include <climits> | 7 #include <climits> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 INTERACTIVE_QUOTA_EXCEEDED, | 34 INTERACTIVE_QUOTA_EXCEEDED, |
| 35 REQUEST_STATUS_COUNT | 35 REQUEST_STATUS_COUNT |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 // Quota value to use if no quota should be applied (by default). | 38 // Quota value to use if no quota should be applied (by default). |
| 39 const int kUnlimitedQuota = INT_MAX; | 39 const int kUnlimitedQuota = INT_MAX; |
| 40 | 40 |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 struct RequestThrottler::RequestTypeInfo { | 43 struct RequestThrottler::RequestTypeInfo { |
| 44 const char* name; | 44 const char* name; |
| 45 const char* count_pref; | 45 const char* count_pref; |
| 46 const char* interactive_count_pref; | 46 const char* interactive_count_pref; |
| 47 const char* day_pref; | 47 const char* day_pref; |
| 48 const int default_quota; | 48 const int default_quota; |
| 49 const int default_interactive_quota; | 49 const int default_interactive_quota; |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 // When adding a new type here, extend also the "RequestThrottlerTypes" | 52 // When adding a new type here, extend also the "RequestThrottlerTypes" |
| 53 // <histogram_suffixes> in histograms.xml with the |name| string. | 53 // <histogram_suffixes> in histograms.xml with the |name| string. |
| 54 const RequestThrottler::RequestTypeInfo RequestThrottler::kRequestTypeInfo[] = { | 54 const RequestThrottler::RequestTypeInfo RequestThrottler::kRequestTypeInfo[] = { |
| 55 // The following three types share the same prefs. They differ in quota | 55 // The following three types share the same prefs. They differ in quota |
| 56 // values (and UMA histograms). | 56 // values (and UMA histograms). |
| 57 // RequestCounter::RequestType::CONTENT_SUGGESTION_FETCHER_RARE_NTP_USER, | 57 // RequestCounter::RequestType::CONTENT_SUGGESTION_FETCHER_RARE_NTP_USER, |
| 58 {"SuggestionFetcherRareNTPUser", prefs::kSnippetFetcherRequestCount, | 58 {"SuggestionFetcherRareNTPUser", prefs::kSnippetFetcherRequestCount, |
| 59 prefs::kSnippetFetcherInteractiveRequestCount, | 59 prefs::kSnippetFetcherInteractiveRequestCount, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 75 RequestThrottler::RequestThrottler(PrefService* pref_service, RequestType type) | 75 RequestThrottler::RequestThrottler(PrefService* pref_service, RequestType type) |
| 76 : pref_service_(pref_service), | 76 : pref_service_(pref_service), |
| 77 type_info_(kRequestTypeInfo[static_cast<int>(type)]) { | 77 type_info_(kRequestTypeInfo[static_cast<int>(type)]) { |
| 78 DCHECK(pref_service); | 78 DCHECK(pref_service); |
| 79 | 79 |
| 80 std::string quota = variations::GetVariationParamValueByFeature( | 80 std::string quota = variations::GetVariationParamValueByFeature( |
| 81 ntp_snippets::kArticleSuggestionsFeature, | 81 ntp_snippets::kArticleSuggestionsFeature, |
| 82 base::StringPrintf("quota_%s", GetRequestTypeName())); | 82 base::StringPrintf("quota_%s", GetRequestTypeName())); |
| 83 if (!base::StringToInt(quota, "a_)) { | 83 if (!base::StringToInt(quota, "a_)) { |
| 84 LOG_IF(WARNING, !quota.empty()) | 84 LOG_IF(WARNING, !quota.empty()) |
| 85 << "Invalid variation parameter for quota for " | 85 << "Invalid variation parameter for quota for " << GetRequestTypeName(); |
| 86 << GetRequestTypeName(); | |
| 87 quota_ = type_info_.default_quota; | 86 quota_ = type_info_.default_quota; |
| 88 } | 87 } |
| 89 | 88 |
| 90 std::string interactive_quota = variations::GetVariationParamValueByFeature( | 89 std::string interactive_quota = variations::GetVariationParamValueByFeature( |
| 91 ntp_snippets::kArticleSuggestionsFeature, | 90 ntp_snippets::kArticleSuggestionsFeature, |
| 92 base::StringPrintf("interactive_quota_%s", GetRequestTypeName())); | 91 base::StringPrintf("interactive_quota_%s", GetRequestTypeName())); |
| 93 if (!base::StringToInt(interactive_quota, &interactive_quota_)) { | 92 if (!base::StringToInt(interactive_quota, &interactive_quota_)) { |
| 94 LOG_IF(WARNING, !interactive_quota.empty()) | 93 LOG_IF(WARNING, !interactive_quota.empty()) |
| 95 << "Invalid variation parameter for interactive quota for " | 94 << "Invalid variation parameter for interactive quota for " |
| 96 << GetRequestTypeName(); | 95 << GetRequestTypeName(); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 202 |
| 204 void RequestThrottler::SetDay(int day) { | 203 void RequestThrottler::SetDay(int day) { |
| 205 pref_service_->SetInteger(type_info_.day_pref, day); | 204 pref_service_->SetInteger(type_info_.day_pref, day); |
| 206 } | 205 } |
| 207 | 206 |
| 208 bool RequestThrottler::HasDay() const { | 207 bool RequestThrottler::HasDay() const { |
| 209 return pref_service_->HasPrefPath(type_info_.day_pref); | 208 return pref_service_->HasPrefPath(type_info_.day_pref); |
| 210 } | 209 } |
| 211 | 210 |
| 212 } // namespace ntp_snippets | 211 } // namespace ntp_snippets |
| OLD | NEW |