OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/data_reduction_proxy/core/browser/data_reduction_proxy_sett
ings.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett
ings.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/prefs/pref_member.h" | 10 #include "base/prefs/pref_member.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_comp
ression_stats.h" |
14 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig.h" | 15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig.h" |
15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d
ata.h" | 16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d
ata.h" |
16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv
ice.h" | 17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv
ice.h" |
17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_stat
istics_prefs.h" | |
18 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" | 18 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" |
19 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" | 19 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" |
20 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc
hes.h" | 20 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc
hes.h" |
21 | 21 |
22 namespace { | 22 namespace { |
23 // Key of the UMA DataReductionProxy.StartupState histogram. | 23 // Key of the UMA DataReductionProxy.StartupState histogram. |
24 const char kUMAProxyStartupStateHistogram[] = | 24 const char kUMAProxyStartupStateHistogram[] = |
25 "DataReductionProxy.StartupState"; | 25 "DataReductionProxy.StartupState"; |
26 | 26 |
27 int64 GetInt64PrefValue(const base::ListValue& list_value, size_t index) { | 27 int64 GetInt64PrefValue(const base::ListValue& list_value, size_t index) { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 if (!alternative_allowed_) | 159 if (!alternative_allowed_) |
160 return; | 160 return; |
161 if (data_reduction_proxy_alternative_enabled_.GetValue() != enabled) { | 161 if (data_reduction_proxy_alternative_enabled_.GetValue() != enabled) { |
162 data_reduction_proxy_alternative_enabled_.SetValue(enabled); | 162 data_reduction_proxy_alternative_enabled_.SetValue(enabled); |
163 OnProxyAlternativeEnabledPrefChange(); | 163 OnProxyAlternativeEnabledPrefChange(); |
164 } | 164 } |
165 } | 165 } |
166 | 166 |
167 int64 DataReductionProxySettings::GetDataReductionLastUpdateTime() { | 167 int64 DataReductionProxySettings::GetDataReductionLastUpdateTime() { |
168 DCHECK(thread_checker_.CalledOnValidThread()); | 168 DCHECK(thread_checker_.CalledOnValidThread()); |
169 DCHECK(data_reduction_proxy_service_->statistics_prefs()); | 169 DCHECK(data_reduction_proxy_service_->compression_stats()); |
170 int64 last_update_internal = | 170 int64 last_update_internal = |
171 data_reduction_proxy_service_->statistics_prefs()->GetInt64( | 171 data_reduction_proxy_service_->compression_stats()->GetInt64( |
172 prefs::kDailyHttpContentLengthLastUpdateDate); | 172 prefs::kDailyHttpContentLengthLastUpdateDate); |
173 base::Time last_update = base::Time::FromInternalValue(last_update_internal); | 173 base::Time last_update = base::Time::FromInternalValue(last_update_internal); |
174 return static_cast<int64>(last_update.ToJsTime()); | 174 return static_cast<int64>(last_update.ToJsTime()); |
175 } | 175 } |
176 | 176 |
177 DataReductionProxySettings::ContentLengthList | 177 DataReductionProxySettings::ContentLengthList |
178 DataReductionProxySettings::GetDailyOriginalContentLengths() { | 178 DataReductionProxySettings::GetDailyOriginalContentLengths() { |
179 DCHECK(thread_checker_.CalledOnValidThread()); | 179 DCHECK(thread_checker_.CalledOnValidThread()); |
180 return GetDailyContentLengths(prefs::kDailyHttpOriginalContentLength); | 180 return GetDailyContentLengths(prefs::kDailyHttpOriginalContentLength); |
181 } | 181 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 | 229 |
230 void DataReductionProxySettings::OnProxyAlternativeEnabledPrefChange() { | 230 void DataReductionProxySettings::OnProxyAlternativeEnabledPrefChange() { |
231 DCHECK(thread_checker_.CalledOnValidThread()); | 231 DCHECK(thread_checker_.CalledOnValidThread()); |
232 if (!alternative_allowed_) | 232 if (!alternative_allowed_) |
233 return; | 233 return; |
234 MaybeActivateDataReductionProxy(false); | 234 MaybeActivateDataReductionProxy(false); |
235 } | 235 } |
236 | 236 |
237 void DataReductionProxySettings::ResetDataReductionStatistics() { | 237 void DataReductionProxySettings::ResetDataReductionStatistics() { |
238 DCHECK(thread_checker_.CalledOnValidThread()); | 238 DCHECK(thread_checker_.CalledOnValidThread()); |
239 DCHECK(data_reduction_proxy_service_->statistics_prefs()); | 239 DCHECK(data_reduction_proxy_service_->compression_stats()); |
240 base::ListValue* original_update = | 240 base::ListValue* original_update = |
241 data_reduction_proxy_service_->statistics_prefs()->GetList( | 241 data_reduction_proxy_service_->compression_stats()->GetList( |
242 prefs::kDailyHttpOriginalContentLength); | 242 prefs::kDailyHttpOriginalContentLength); |
243 base::ListValue* received_update = | 243 base::ListValue* received_update = |
244 data_reduction_proxy_service_->statistics_prefs()->GetList( | 244 data_reduction_proxy_service_->compression_stats()->GetList( |
245 prefs::kDailyHttpReceivedContentLength); | 245 prefs::kDailyHttpReceivedContentLength); |
246 original_update->Clear(); | 246 original_update->Clear(); |
247 received_update->Clear(); | 247 received_update->Clear(); |
248 for (size_t i = 0; i < kNumDaysInHistory; ++i) { | 248 for (size_t i = 0; i < kNumDaysInHistory; ++i) { |
249 original_update->AppendString(base::Int64ToString(0)); | 249 original_update->AppendString(base::Int64ToString(0)); |
250 received_update->AppendString(base::Int64ToString(0)); | 250 received_update->AppendString(base::Int64ToString(0)); |
251 } | 251 } |
252 } | 252 } |
253 | 253 |
254 void DataReductionProxySettings::MaybeActivateDataReductionProxy( | 254 void DataReductionProxySettings::MaybeActivateDataReductionProxy( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 void DataReductionProxySettings::RecordStartupState(ProxyStartupState state) { | 289 void DataReductionProxySettings::RecordStartupState(ProxyStartupState state) { |
290 UMA_HISTOGRAM_ENUMERATION(kUMAProxyStartupStateHistogram, | 290 UMA_HISTOGRAM_ENUMERATION(kUMAProxyStartupStateHistogram, |
291 state, | 291 state, |
292 PROXY_STARTUP_STATE_COUNT); | 292 PROXY_STARTUP_STATE_COUNT); |
293 } | 293 } |
294 | 294 |
295 DataReductionProxySettings::ContentLengthList | 295 DataReductionProxySettings::ContentLengthList |
296 DataReductionProxySettings::GetDailyContentLengths(const char* pref_name) { | 296 DataReductionProxySettings::GetDailyContentLengths(const char* pref_name) { |
297 DCHECK(thread_checker_.CalledOnValidThread()); | 297 DCHECK(thread_checker_.CalledOnValidThread()); |
298 DataReductionProxySettings::ContentLengthList content_lengths; | 298 DataReductionProxySettings::ContentLengthList content_lengths; |
299 DCHECK(data_reduction_proxy_service_->statistics_prefs()); | 299 DCHECK(data_reduction_proxy_service_->compression_stats()); |
300 const base::ListValue* list_value = | 300 const base::ListValue* list_value = |
301 data_reduction_proxy_service_->statistics_prefs()->GetList(pref_name); | 301 data_reduction_proxy_service_->compression_stats()->GetList(pref_name); |
302 if (list_value->GetSize() == kNumDaysInHistory) { | 302 if (list_value->GetSize() == kNumDaysInHistory) { |
303 for (size_t i = 0; i < kNumDaysInHistory; ++i) { | 303 for (size_t i = 0; i < kNumDaysInHistory; ++i) { |
304 content_lengths.push_back(GetInt64PrefValue(*list_value, i)); | 304 content_lengths.push_back(GetInt64PrefValue(*list_value, i)); |
305 } | 305 } |
306 } | 306 } |
307 return content_lengths; | 307 return content_lengths; |
308 } | 308 } |
309 | 309 |
310 void DataReductionProxySettings::GetContentLengths( | 310 void DataReductionProxySettings::GetContentLengths( |
311 unsigned int days, | 311 unsigned int days, |
312 int64* original_content_length, | 312 int64* original_content_length, |
313 int64* received_content_length, | 313 int64* received_content_length, |
314 int64* last_update_time) { | 314 int64* last_update_time) { |
315 DCHECK(thread_checker_.CalledOnValidThread()); | 315 DCHECK(thread_checker_.CalledOnValidThread()); |
316 DCHECK_LE(days, kNumDaysInHistory); | 316 DCHECK_LE(days, kNumDaysInHistory); |
317 DCHECK(data_reduction_proxy_service_->statistics_prefs()); | 317 DCHECK(data_reduction_proxy_service_->compression_stats()); |
318 | 318 |
319 const base::ListValue* original_list = | 319 const base::ListValue* original_list = |
320 data_reduction_proxy_service_->statistics_prefs()->GetList( | 320 data_reduction_proxy_service_->compression_stats()->GetList( |
321 prefs::kDailyHttpOriginalContentLength); | 321 prefs::kDailyHttpOriginalContentLength); |
322 const base::ListValue* received_list = | 322 const base::ListValue* received_list = |
323 data_reduction_proxy_service_->statistics_prefs()->GetList( | 323 data_reduction_proxy_service_->compression_stats()->GetList( |
324 prefs::kDailyHttpReceivedContentLength); | 324 prefs::kDailyHttpReceivedContentLength); |
325 | 325 |
326 if (original_list->GetSize() != kNumDaysInHistory || | 326 if (original_list->GetSize() != kNumDaysInHistory || |
327 received_list->GetSize() != kNumDaysInHistory) { | 327 received_list->GetSize() != kNumDaysInHistory) { |
328 *original_content_length = 0L; | 328 *original_content_length = 0L; |
329 *received_content_length = 0L; | 329 *received_content_length = 0L; |
330 *last_update_time = 0L; | 330 *last_update_time = 0L; |
331 return; | 331 return; |
332 } | 332 } |
333 | 333 |
334 int64 orig = 0L; | 334 int64 orig = 0L; |
335 int64 recv = 0L; | 335 int64 recv = 0L; |
336 // Include days from the end of the list going backwards. | 336 // Include days from the end of the list going backwards. |
337 for (size_t i = kNumDaysInHistory - days; | 337 for (size_t i = kNumDaysInHistory - days; |
338 i < kNumDaysInHistory; ++i) { | 338 i < kNumDaysInHistory; ++i) { |
339 orig += GetInt64PrefValue(*original_list, i); | 339 orig += GetInt64PrefValue(*original_list, i); |
340 recv += GetInt64PrefValue(*received_list, i); | 340 recv += GetInt64PrefValue(*received_list, i); |
341 } | 341 } |
342 *original_content_length = orig; | 342 *original_content_length = orig; |
343 *received_content_length = recv; | 343 *received_content_length = recv; |
344 *last_update_time = | 344 *last_update_time = |
345 data_reduction_proxy_service_->statistics_prefs()->GetInt64( | 345 data_reduction_proxy_service_->compression_stats()->GetInt64( |
346 prefs::kDailyHttpContentLengthLastUpdateDate); | 346 prefs::kDailyHttpContentLengthLastUpdateDate); |
347 } | 347 } |
348 | 348 |
349 } // namespace data_reduction_proxy | 349 } // namespace data_reduction_proxy |
OLD | NEW |