Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_metrics.cc

Issue 473723002: Update data reduction proxy statistics prefs less often on desktop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tooManyWritesPatch
Patch Set: Removing statistics prefs from Android WebView Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/browser/data_reduction_proxy_metrics.h " 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h "
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/prefs/scoped_user_pref_update.h"
10 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h" 10 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h"
11 #include "components/data_reduction_proxy/browser/data_reduction_proxy_statistic s_prefs.h"
13 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" 12 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h"
14 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names .h" 13 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names .h"
15 #include "net/base/host_port_pair.h" 14 #include "net/base/host_port_pair.h"
16 #include "net/http/http_response_headers.h" 15 #include "net/http/http_response_headers.h"
17 #include "net/proxy/proxy_retry_info.h" 16 #include "net/proxy/proxy_retry_info.h"
18 #include "net/proxy/proxy_service.h" 17 #include "net/proxy/proxy_service.h"
19 #include "net/url_request/url_request_context.h" 18 #include "net/url_request/url_request_context.h"
20 19
21 namespace data_reduction_proxy { 20 namespace data_reduction_proxy {
22 21
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 while (list->GetSize() < length) 184 while (list->GetSize() < length)
186 list->AppendString(base::Int64ToString(0)); 185 list->AppendString(base::Int64ToString(0));
187 DCHECK_EQ(length, list->GetSize()); 186 DCHECK_EQ(length, list->GetSize());
188 } 187 }
189 188
190 // DailyContentLengthUpdate maintains a data saving pref. The pref is a list 189 // DailyContentLengthUpdate maintains a data saving pref. The pref is a list
191 // of |kNumDaysInHistory| elements of daily total content lengths for the past 190 // of |kNumDaysInHistory| elements of daily total content lengths for the past
192 // |kNumDaysInHistory| days. 191 // |kNumDaysInHistory| days.
193 class DailyContentLengthUpdate { 192 class DailyContentLengthUpdate {
194 public: 193 public:
195 DailyContentLengthUpdate( 194 DailyContentLengthUpdate(const char* pref,
196 const char* pref, 195 DataReductionProxyStatisticsPrefs* pref_service)
197 PrefService* pref_service) 196 : update_(pref_service->GetList(pref)) {
198 : update_(pref_service, pref) {
199 } 197 }
200 198
201 void UpdateForDataChange(int days_since_last_update) { 199 void UpdateForDataChange(int days_since_last_update) {
202 // New empty lists may have been created. Maintain the invariant that 200 // New empty lists may have been created. Maintain the invariant that
203 // there should be exactly |kNumDaysInHistory| days in the histories. 201 // there should be exactly |kNumDaysInHistory| days in the histories.
204 MaintainContentLengthPrefsWindow(update_.Get(), kNumDaysInHistory); 202 MaintainContentLengthPrefsWindow(update_, kNumDaysInHistory);
205 if (days_since_last_update) { 203 if (days_since_last_update) {
206 MaintainContentLengthPrefForDateChange(days_since_last_update); 204 MaintainContentLengthPrefForDateChange(days_since_last_update);
207 } 205 }
208 } 206 }
209 207
210 // Update the lengths for the current day. 208 // Update the lengths for the current day.
211 void Add(int content_length) { 209 void Add(int content_length) {
212 AddInt64ToListPref(kNumDaysInHistory - 1, content_length, update_.Get()); 210 AddInt64ToListPref(kNumDaysInHistory - 1, content_length, update_);
213 } 211 }
214 212
215 int64 GetListPrefValue(size_t index) { 213 int64 GetListPrefValue(size_t index) {
216 return ListPrefInt64Value(*update_, index); 214 return ListPrefInt64Value(*update_, index);
217 } 215 }
218 216
219 private: 217 private:
220 // Update the list for date change and ensure the list has exactly |length| 218 // Update the list for date change and ensure the list has exactly |length|
221 // elements. The last entry in the list will be for the current day after 219 // elements. The last entry in the list will be for the current day after
222 // the update. 220 // the update.
(...skipping 18 matching lines...) Expand all
241 // lists longer than kNumDaysInHistory. The additional items will be cut off 239 // lists longer than kNumDaysInHistory. The additional items will be cut off
242 // from the head of the lists by |MaintainContentLengthPrefsWindow|, below. 240 // from the head of the lists by |MaintainContentLengthPrefsWindow|, below.
243 for (int i = 0; 241 for (int i = 0;
244 i < days_since_last_update && i < static_cast<int>(kNumDaysInHistory); 242 i < days_since_last_update && i < static_cast<int>(kNumDaysInHistory);
245 ++i) { 243 ++i) {
246 update_->AppendString(base::Int64ToString(0)); 244 update_->AppendString(base::Int64ToString(0));
247 } 245 }
248 246
249 // Entries for new days may have been appended. Maintain the invariant that 247 // Entries for new days may have been appended. Maintain the invariant that
250 // there should be exactly |kNumDaysInHistory| days in the histories. 248 // there should be exactly |kNumDaysInHistory| days in the histories.
251 MaintainContentLengthPrefsWindow(update_.Get(), kNumDaysInHistory); 249 MaintainContentLengthPrefsWindow(update_, kNumDaysInHistory);
252 } 250 }
253 251
254 ListPrefUpdate update_; 252 base::ListValue* update_;
255 }; 253 };
256 254
257 // DailyDataSavingUpdate maintains a pair of data saving prefs, original_update_ 255 // DailyDataSavingUpdate maintains a pair of data saving prefs, original_update_
258 // and received_update_. pref_original is a list of |kNumDaysInHistory| elements 256 // and received_update_. pref_original is a list of |kNumDaysInHistory| elements
259 // of daily total original content lengths for the past |kNumDaysInHistory| 257 // of daily total original content lengths for the past |kNumDaysInHistory|
260 // days. pref_received is the corresponding list of the daily total received 258 // days. pref_received is the corresponding list of the daily total received
261 // content lengths. 259 // content lengths.
262 class DailyDataSavingUpdate { 260 class DailyDataSavingUpdate {
263 public: 261 public:
264 DailyDataSavingUpdate( 262 DailyDataSavingUpdate(const char* pref_original,
265 const char* pref_original, 263 const char* pref_received,
266 const char* pref_received, 264 DataReductionProxyStatisticsPrefs* prefs)
267 PrefService* pref_service) 265 : original_(pref_original, prefs),
268 : original_(pref_original, pref_service), 266 received_(pref_received, prefs) {
269 received_(pref_received, pref_service) {
270 } 267 }
271 268
272 void UpdateForDataChange(int days_since_last_update) { 269 void UpdateForDataChange(int days_since_last_update) {
273 original_.UpdateForDataChange(days_since_last_update); 270 original_.UpdateForDataChange(days_since_last_update);
274 received_.UpdateForDataChange(days_since_last_update); 271 received_.UpdateForDataChange(days_since_last_update);
275 } 272 }
276 273
277 // Update the lengths for the current day. 274 // Update the lengths for the current day.
278 void Add(int original_content_length, int received_content_length) { 275 void Add(int original_content_length, int received_content_length) {
279 original_.Add(original_content_length); 276 original_.Add(original_content_length);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 return received_content_length; 330 return received_content_length;
334 } 331 }
335 return original_content_length; 332 return original_content_length;
336 } 333 }
337 334
338 void UpdateContentLengthPrefsForDataReductionProxy( 335 void UpdateContentLengthPrefsForDataReductionProxy(
339 int received_content_length, 336 int received_content_length,
340 int original_content_length, 337 int original_content_length,
341 bool with_data_reduction_proxy_enabled, 338 bool with_data_reduction_proxy_enabled,
342 DataReductionProxyRequestType request_type, 339 DataReductionProxyRequestType request_type,
343 base::Time now, PrefService* prefs) { 340 base::Time now,
341 DataReductionProxyStatisticsPrefs* prefs) {
344 // TODO(bengr): Remove this check once the underlying cause of 342 // TODO(bengr): Remove this check once the underlying cause of
345 // http://crbug.com/287821 is fixed. For now, only continue if the current 343 // http://crbug.com/287821 is fixed. For now, only continue if the current
346 // year is reported as being between 1972 and 2970. 344 // year is reported as being between 1972 and 2970.
347 base::TimeDelta time_since_unix_epoch = now - base::Time::UnixEpoch(); 345 base::TimeDelta time_since_unix_epoch = now - base::Time::UnixEpoch();
348 const int kMinDaysSinceUnixEpoch = 365 * 2; // 2 years. 346 const int kMinDaysSinceUnixEpoch = 365 * 2; // 2 years.
349 const int kMaxDaysSinceUnixEpoch = 365 * 1000; // 1000 years. 347 const int kMaxDaysSinceUnixEpoch = 365 * 1000; // 1000 years.
350 if (time_since_unix_epoch.InDays() < kMinDaysSinceUnixEpoch || 348 if (time_since_unix_epoch.InDays() < kMinDaysSinceUnixEpoch ||
351 time_since_unix_epoch.InDays() > kMaxDaysSinceUnixEpoch) { 349 time_since_unix_epoch.InDays() > kMaxDaysSinceUnixEpoch) {
352 return; 350 return;
353 } 351 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 via_proxy.GetOriginalListPrefValue(kNumDaysInHistory - 2), 461 via_proxy.GetOriginalListPrefValue(kNumDaysInHistory - 2),
464 via_proxy.GetReceivedListPrefValue(kNumDaysInHistory - 2), 462 via_proxy.GetReceivedListPrefValue(kNumDaysInHistory - 2),
465 https.GetListPrefValue(kNumDaysInHistory - 2), 463 https.GetListPrefValue(kNumDaysInHistory - 2),
466 short_bypass.GetListPrefValue(kNumDaysInHistory - 2), 464 short_bypass.GetListPrefValue(kNumDaysInHistory - 2),
467 long_bypass.GetListPrefValue(kNumDaysInHistory - 2), 465 long_bypass.GetListPrefValue(kNumDaysInHistory - 2),
468 unknown.GetListPrefValue(kNumDaysInHistory - 2)); 466 unknown.GetListPrefValue(kNumDaysInHistory - 2));
469 } 467 }
470 } 468 }
471 } 469 }
472 470
473 void UpdateContentLengthPrefs( 471 void UpdateContentLengthPrefs(int received_content_length,
474 int received_content_length, 472 int original_content_length,
475 int original_content_length, 473 bool with_data_reduction_proxy_enabled,
476 bool with_data_reduction_proxy_enabled, 474 DataReductionProxyRequestType request_type,
477 DataReductionProxyRequestType request_type, 475 DataReductionProxyStatisticsPrefs* prefs) {
478 PrefService* prefs) {
479 int64 total_received = prefs->GetInt64( 476 int64 total_received = prefs->GetInt64(
480 data_reduction_proxy::prefs::kHttpReceivedContentLength); 477 data_reduction_proxy::prefs::kHttpReceivedContentLength);
481 int64 total_original = prefs->GetInt64( 478 int64 total_original = prefs->GetInt64(
482 data_reduction_proxy::prefs::kHttpOriginalContentLength); 479 data_reduction_proxy::prefs::kHttpOriginalContentLength);
483 total_received += received_content_length; 480 total_received += received_content_length;
484 total_original += original_content_length; 481 total_original += original_content_length;
485 prefs->SetInt64(data_reduction_proxy::prefs::kHttpReceivedContentLength, 482 prefs->SetInt64(data_reduction_proxy::prefs::kHttpReceivedContentLength,
486 total_received); 483 total_received);
487 prefs->SetInt64(data_reduction_proxy::prefs::kHttpOriginalContentLength, 484 prefs->SetInt64(data_reduction_proxy::prefs::kHttpOriginalContentLength,
488 total_original); 485 total_original);
489 486
490 UpdateContentLengthPrefsForDataReductionProxy( 487 UpdateContentLengthPrefsForDataReductionProxy(
491 received_content_length, 488 received_content_length,
492 original_content_length, 489 original_content_length,
493 with_data_reduction_proxy_enabled, 490 with_data_reduction_proxy_enabled,
494 request_type, 491 request_type,
495 base::Time::Now(), 492 base::Time::Now(),
496 prefs); 493 prefs);
497 } 494 }
498 495
499 } // namespace data_reduction_proxy 496 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698