| 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 |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "components/ntp_snippets/features.h" |
| 16 #include "components/ntp_snippets/ntp_snippets_constants.h" | 17 #include "components/ntp_snippets/ntp_snippets_constants.h" |
| 17 #include "components/ntp_snippets/pref_names.h" | 18 #include "components/ntp_snippets/pref_names.h" |
| 18 #include "components/prefs/pref_registry_simple.h" | 19 #include "components/prefs/pref_registry_simple.h" |
| 19 #include "components/prefs/pref_service.h" | 20 #include "components/prefs/pref_service.h" |
| 20 #include "components/variations/variations_associated_data.h" | 21 #include "components/variations/variations_associated_data.h" |
| 21 | 22 |
| 22 namespace ntp_snippets { | 23 namespace ntp_snippets { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // RequestCounter::RequestType::CONTENT_SUGGESTION_THUMBNAIL, | 70 // RequestCounter::RequestType::CONTENT_SUGGESTION_THUMBNAIL, |
| 70 {"SuggestionThumbnailFetcher", prefs::kSnippetThumbnailsRequestCount, | 71 {"SuggestionThumbnailFetcher", prefs::kSnippetThumbnailsRequestCount, |
| 71 prefs::kSnippetThumbnailsInteractiveRequestCount, | 72 prefs::kSnippetThumbnailsInteractiveRequestCount, |
| 72 prefs::kSnippetThumbnailsRequestsDay, kUnlimitedQuota, kUnlimitedQuota}}; | 73 prefs::kSnippetThumbnailsRequestsDay, kUnlimitedQuota, kUnlimitedQuota}}; |
| 73 | 74 |
| 74 RequestThrottler::RequestThrottler(PrefService* pref_service, RequestType type) | 75 RequestThrottler::RequestThrottler(PrefService* pref_service, RequestType type) |
| 75 : pref_service_(pref_service), | 76 : pref_service_(pref_service), |
| 76 type_info_(kRequestTypeInfo[static_cast<int>(type)]) { | 77 type_info_(kRequestTypeInfo[static_cast<int>(type)]) { |
| 77 DCHECK(pref_service); | 78 DCHECK(pref_service); |
| 78 | 79 |
| 79 std::string quota = variations::GetVariationParamValue( | 80 std::string quota = variations::GetVariationParamValueByFeature( |
| 80 ntp_snippets::kStudyName, | 81 ntp_snippets::kArticleSuggestionsFeature, |
| 81 base::StringPrintf("quota_%s", GetRequestTypeName())); | 82 base::StringPrintf("quota_%s", GetRequestTypeName())); |
| 82 if (!base::StringToInt(quota, "a_)) { | 83 if (!base::StringToInt(quota, "a_)) { |
| 83 LOG_IF(WARNING, !quota.empty()) | 84 LOG_IF(WARNING, !quota.empty()) |
| 84 << "Invalid variation parameter for quota for " | 85 << "Invalid variation parameter for quota for " |
| 85 << GetRequestTypeName(); | 86 << GetRequestTypeName(); |
| 86 quota_ = type_info_.default_quota; | 87 quota_ = type_info_.default_quota; |
| 87 } | 88 } |
| 88 | 89 |
| 89 std::string interactive_quota = variations::GetVariationParamValue( | 90 std::string interactive_quota = variations::GetVariationParamValueByFeature( |
| 90 ntp_snippets::kStudyName, | 91 ntp_snippets::kArticleSuggestionsFeature, |
| 91 base::StringPrintf("interactive_quota_%s", GetRequestTypeName())); | 92 base::StringPrintf("interactive_quota_%s", GetRequestTypeName())); |
| 92 if (!base::StringToInt(interactive_quota, &interactive_quota_)) { | 93 if (!base::StringToInt(interactive_quota, &interactive_quota_)) { |
| 93 LOG_IF(WARNING, !interactive_quota.empty()) | 94 LOG_IF(WARNING, !interactive_quota.empty()) |
| 94 << "Invalid variation parameter for interactive quota for " | 95 << "Invalid variation parameter for interactive quota for " |
| 95 << GetRequestTypeName(); | 96 << GetRequestTypeName(); |
| 96 interactive_quota_ = type_info_.default_interactive_quota; | 97 interactive_quota_ = type_info_.default_interactive_quota; |
| 97 } | 98 } |
| 98 | 99 |
| 99 // Since the histogram names are dynamic, we cannot use the standard macros | 100 // Since the histogram names are dynamic, we cannot use the standard macros |
| 100 // and we need to lookup the histograms, instead. | 101 // and we need to lookup the histograms, instead. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 203 |
| 203 void RequestThrottler::SetDay(int day) { | 204 void RequestThrottler::SetDay(int day) { |
| 204 pref_service_->SetInteger(type_info_.day_pref, day); | 205 pref_service_->SetInteger(type_info_.day_pref, day); |
| 205 } | 206 } |
| 206 | 207 |
| 207 bool RequestThrottler::HasDay() const { | 208 bool RequestThrottler::HasDay() const { |
| 208 return pref_service_->HasPrefPath(type_info_.day_pref); | 209 return pref_service_->HasPrefPath(type_info_.day_pref); |
| 209 } | 210 } |
| 210 | 211 |
| 211 } // namespace ntp_snippets | 212 } // namespace ntp_snippets |
| OLD | NEW |