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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 } else { | 146 } else { |
147 histogram_request_status_->Add( | 147 histogram_request_status_->Add( |
148 static_cast<int>(available ? RequestStatus::BACKGROUND_QUOTA_GRANTED | 148 static_cast<int>(available ? RequestStatus::BACKGROUND_QUOTA_GRANTED |
149 : RequestStatus::BACKGROUND_QUOTA_EXCEEDED)); | 149 : RequestStatus::BACKGROUND_QUOTA_EXCEEDED)); |
150 } | 150 } |
151 return available; | 151 return available; |
152 } | 152 } |
153 | 153 |
154 void RequestThrottler::ResetCounterIfDayChanged() { | 154 void RequestThrottler::ResetCounterIfDayChanged() { |
155 // Get the date, "concatenated" into an int in "YYYYMMDD" format. | 155 // Get the date, "concatenated" into an int in "YYYYMMDD" format. |
156 base::Time::Exploded now_exploded; | 156 base::Time::Exploded now_exploded{}; |
157 base::Time::Now().LocalExplode(&now_exploded); | 157 base::Time::Now().LocalExplode(&now_exploded); |
158 int now_day = 10000 * now_exploded.year + 100 * now_exploded.month + | 158 int now_day = 10000 * now_exploded.year + 100 * now_exploded.month + |
159 now_exploded.day_of_month; | 159 now_exploded.day_of_month; |
160 | 160 |
161 if (!HasDay()) { | 161 if (!HasDay()) { |
162 // The counter is used for the first time in this profile. | 162 // The counter is used for the first time in this profile. |
163 SetDay(now_day); | 163 SetDay(now_day); |
164 } else if (now_day != GetDay()) { | 164 } else if (now_day != GetDay()) { |
165 // Day has changed - report the number of requests from the previous day. | 165 // Day has changed - report the number of requests from the previous day. |
166 histogram_per_day_background_->Add(GetCount(/*interactive_request=*/false)); | 166 histogram_per_day_background_->Add(GetCount(/*interactive_request=*/false)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 201 |
202 void RequestThrottler::SetDay(int day) { | 202 void RequestThrottler::SetDay(int day) { |
203 pref_service_->SetInteger(type_info_.day_pref, day); | 203 pref_service_->SetInteger(type_info_.day_pref, day); |
204 } | 204 } |
205 | 205 |
206 bool RequestThrottler::HasDay() const { | 206 bool RequestThrottler::HasDay() const { |
207 return pref_service_->HasPrefPath(type_info_.day_pref); | 207 return pref_service_->HasPrefPath(type_info_.day_pref); |
208 } | 208 } |
209 | 209 |
210 } // namespace ntp_snippets | 210 } // namespace ntp_snippets |
OLD | NEW |