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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 void RequestThrottler::RegisterProfilePrefs(PrefRegistrySimple* registry) { | 121 void RequestThrottler::RegisterProfilePrefs(PrefRegistrySimple* registry) { |
122 // Collect all pref keys in a set to make sure we register each key exactly | 122 // Collect all pref keys in a set to make sure we register each key exactly |
123 // once, even if they repeat. | 123 // once, even if they repeat. |
124 std::set<std::string> keys_to_register; | 124 std::set<std::string> keys_to_register; |
125 for (const RequestTypeInfo& info : kRequestTypeInfo) { | 125 for (const RequestTypeInfo& info : kRequestTypeInfo) { |
126 keys_to_register.insert(info.day_pref); | 126 keys_to_register.insert(info.day_pref); |
127 keys_to_register.insert(info.count_pref); | 127 keys_to_register.insert(info.count_pref); |
128 keys_to_register.insert(info.interactive_count_pref); | 128 keys_to_register.insert(info.interactive_count_pref); |
129 } | 129 } |
130 | 130 |
131 for (const std::string& key : keys_to_register) | 131 for (const std::string& key : keys_to_register) { |
132 registry->RegisterIntegerPref(key, 0); | 132 registry->RegisterIntegerPref(key, 0); |
| 133 } |
133 } | 134 } |
134 | 135 |
135 bool RequestThrottler::DemandQuotaForRequest(bool interactive_request) { | 136 bool RequestThrottler::DemandQuotaForRequest(bool interactive_request) { |
136 ResetCounterIfDayChanged(); | 137 ResetCounterIfDayChanged(); |
137 | 138 |
138 int new_count = GetCount(interactive_request) + 1; | 139 int new_count = GetCount(interactive_request) + 1; |
139 SetCount(interactive_request, new_count); | 140 SetCount(interactive_request, new_count); |
140 bool available = (new_count <= GetQuota(interactive_request)); | 141 bool available = (new_count <= GetQuota(interactive_request)); |
141 | 142 |
142 if (interactive_request) { | 143 if (interactive_request) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 202 |
202 void RequestThrottler::SetDay(int day) { | 203 void RequestThrottler::SetDay(int day) { |
203 pref_service_->SetInteger(type_info_.day_pref, day); | 204 pref_service_->SetInteger(type_info_.day_pref, day); |
204 } | 205 } |
205 | 206 |
206 bool RequestThrottler::HasDay() const { | 207 bool RequestThrottler::HasDay() const { |
207 return pref_service_->HasPrefPath(type_info_.day_pref); | 208 return pref_service_->HasPrefPath(type_info_.day_pref); |
208 } | 209 } |
209 | 210 |
210 } // namespace ntp_snippets | 211 } // namespace ntp_snippets |
OLD | NEW |