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_comp
ression_stats.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_comp
ression_stats.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | |
11 #include "base/bind.h" | 10 #include "base/bind.h" |
12 #include "base/command_line.h" | 11 #include "base/command_line.h" |
13 #include "base/location.h" | 12 #include "base/location.h" |
14 #include "base/logging.h" | 13 #include "base/logging.h" |
15 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
16 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
17 #include "base/prefs/pref_change_registrar.h" | 16 #include "base/prefs/pref_change_registrar.h" |
18 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
19 #include "base/prefs/scoped_user_pref_update.h" | 18 #include "base/prefs/scoped_user_pref_update.h" |
20 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
(...skipping 10 matching lines...) Expand all Loading... |
31 | 30 |
32 namespace { | 31 namespace { |
33 | 32 |
34 #define CONCAT(a, b) a##b | 33 #define CONCAT(a, b) a##b |
35 // CONCAT1 provides extra level of indirection so that __LINE__ macro expands. | 34 // CONCAT1 provides extra level of indirection so that __LINE__ macro expands. |
36 #define CONCAT1(a, b) CONCAT(a, b) | 35 #define CONCAT1(a, b) CONCAT(a, b) |
37 #define UNIQUE_VARNAME CONCAT1(var_, __LINE__) | 36 #define UNIQUE_VARNAME CONCAT1(var_, __LINE__) |
38 // We need to use a macro instead of a method because UMA_HISTOGRAM_COUNTS | 37 // We need to use a macro instead of a method because UMA_HISTOGRAM_COUNTS |
39 // requires its first argument to be an inline string and not a variable. | 38 // requires its first argument to be an inline string and not a variable. |
40 #define RECORD_INT64PREF_TO_HISTOGRAM(pref, uma) \ | 39 #define RECORD_INT64PREF_TO_HISTOGRAM(pref, uma) \ |
41 int64 UNIQUE_VARNAME = GetInt64(pref); \ | 40 int64_t UNIQUE_VARNAME = GetInt64(pref); \ |
42 if (UNIQUE_VARNAME > 0) { \ | 41 if (UNIQUE_VARNAME > 0) { \ |
43 UMA_HISTOGRAM_COUNTS(uma, UNIQUE_VARNAME >> 10); \ | 42 UMA_HISTOGRAM_COUNTS(uma, UNIQUE_VARNAME >> 10); \ |
44 } | 43 } |
45 | 44 |
46 // Returns the value at |index| of |list_value| as an int64. | 45 // Returns the value at |index| of |list_value| as an int64_t. |
47 int64 GetInt64PrefValue(const base::ListValue& list_value, size_t index) { | 46 int64_t GetInt64PrefValue(const base::ListValue& list_value, size_t index) { |
48 int64 val = 0; | 47 int64_t val = 0; |
49 std::string pref_value; | 48 std::string pref_value; |
50 bool rv = list_value.GetString(index, &pref_value); | 49 bool rv = list_value.GetString(index, &pref_value); |
51 DCHECK(rv); | 50 DCHECK(rv); |
52 if (rv) { | 51 if (rv) { |
53 rv = base::StringToInt64(pref_value, &val); | 52 rv = base::StringToInt64(pref_value, &val); |
54 DCHECK(rv); | 53 DCHECK(rv); |
55 } | 54 } |
56 return val; | 55 return val; |
57 } | 56 } |
58 | 57 |
59 // Ensure list has exactly |length| elements, either by truncating at the | 58 // Ensure list has exactly |length| elements, either by truncating at the |
60 // front, or appending "0"'s to the back. | 59 // front, or appending "0"'s to the back. |
61 void MaintainContentLengthPrefsWindow(base::ListValue* list, size_t length) { | 60 void MaintainContentLengthPrefsWindow(base::ListValue* list, size_t length) { |
62 // Remove data for old days from the front. | 61 // Remove data for old days from the front. |
63 while (list->GetSize() > length) | 62 while (list->GetSize() > length) |
64 list->Remove(0, NULL); | 63 list->Remove(0, NULL); |
65 // Newly added lists are empty. Add entries to back to fill the window, | 64 // Newly added lists are empty. Add entries to back to fill the window, |
66 // each initialized to zero. | 65 // each initialized to zero. |
67 while (list->GetSize() < length) | 66 while (list->GetSize() < length) |
68 list->AppendString(base::Int64ToString(0)); | 67 list->AppendString(base::Int64ToString(0)); |
69 DCHECK_EQ(length, list->GetSize()); | 68 DCHECK_EQ(length, list->GetSize()); |
70 } | 69 } |
71 | 70 |
72 // Increments an int64, stored as a string, in a ListPref at the specified | 71 // Increments an int64_t, stored as a string, in a ListPref at the specified |
73 // index. The value must already exist and be a string representation of a | 72 // index. The value must already exist and be a string representation of a |
74 // number. | 73 // number. |
75 void AddInt64ToListPref(size_t index, | 74 void AddInt64ToListPref(size_t index, |
76 int64 length, | 75 int64_t length, |
77 base::ListValue* list_update) { | 76 base::ListValue* list_update) { |
78 int64 value = 0; | 77 int64_t value = 0; |
79 std::string old_string_value; | 78 std::string old_string_value; |
80 bool rv = list_update->GetString(index, &old_string_value); | 79 bool rv = list_update->GetString(index, &old_string_value); |
81 DCHECK(rv); | 80 DCHECK(rv); |
82 if (rv) { | 81 if (rv) { |
83 rv = base::StringToInt64(old_string_value, &value); | 82 rv = base::StringToInt64(old_string_value, &value); |
84 DCHECK(rv); | 83 DCHECK(rv); |
85 } | 84 } |
86 value += length; | 85 value += length; |
87 list_update->Set(index, new base::StringValue(base::Int64ToString(value))); | 86 list_update->Set(index, new base::StringValue(base::Int64ToString(value))); |
88 } | 87 } |
89 | 88 |
90 int64 ListPrefInt64Value(const base::ListValue& list_update, size_t index) { | 89 int64_t ListPrefInt64Value(const base::ListValue& list_update, size_t index) { |
91 std::string string_value; | 90 std::string string_value; |
92 if (!list_update.GetString(index, &string_value)) { | 91 if (!list_update.GetString(index, &string_value)) { |
93 NOTREACHED(); | 92 NOTREACHED(); |
94 return 0; | 93 return 0; |
95 } | 94 } |
96 | 95 |
97 int64 value = 0; | 96 int64_t value = 0; |
98 bool rv = base::StringToInt64(string_value, &value); | 97 bool rv = base::StringToInt64(string_value, &value); |
99 DCHECK(rv); | 98 DCHECK(rv); |
100 return value; | 99 return value; |
101 } | 100 } |
102 | 101 |
103 // DailyContentLengthUpdate maintains a data saving pref. The pref is a list | 102 // DailyContentLengthUpdate maintains a data saving pref. The pref is a list |
104 // of |kNumDaysInHistory| elements of daily total content lengths for the past | 103 // of |kNumDaysInHistory| elements of daily total content lengths for the past |
105 // |kNumDaysInHistory| days. | 104 // |kNumDaysInHistory| days. |
106 void RecordDailyContentLengthHistograms( | 105 void RecordDailyContentLengthHistograms( |
107 int64 original_length, | 106 int64_t original_length, |
108 int64 received_length, | 107 int64_t received_length, |
109 int64 original_length_with_data_reduction_enabled, | 108 int64_t original_length_with_data_reduction_enabled, |
110 int64 received_length_with_data_reduction_enabled, | 109 int64_t received_length_with_data_reduction_enabled, |
111 int64 original_length_via_data_reduction_proxy, | 110 int64_t original_length_via_data_reduction_proxy, |
112 int64 received_length_via_data_reduction_proxy, | 111 int64_t received_length_via_data_reduction_proxy, |
113 int64 https_length_with_data_reduction_enabled, | 112 int64_t https_length_with_data_reduction_enabled, |
114 int64 short_bypass_length_with_data_reduction_enabled, | 113 int64_t short_bypass_length_with_data_reduction_enabled, |
115 int64 long_bypass_length_with_data_reduction_enabled, | 114 int64_t long_bypass_length_with_data_reduction_enabled, |
116 int64 unknown_length_with_data_reduction_enabled) { | 115 int64_t unknown_length_with_data_reduction_enabled) { |
117 // Report daily UMA only for days having received content. | 116 // Report daily UMA only for days having received content. |
118 if (original_length <= 0 || received_length <= 0) | 117 if (original_length <= 0 || received_length <= 0) |
119 return; | 118 return; |
120 | 119 |
121 // Record metrics in KB. | 120 // Record metrics in KB. |
122 UMA_HISTOGRAM_COUNTS( | 121 UMA_HISTOGRAM_COUNTS( |
123 "Net.DailyOriginalContentLength", original_length >> 10); | 122 "Net.DailyOriginalContentLength", original_length >> 10); |
124 UMA_HISTOGRAM_COUNTS( | 123 UMA_HISTOGRAM_COUNTS( |
125 "Net.DailyContentLength", received_length >> 10); | 124 "Net.DailyContentLength", received_length >> 10); |
126 | 125 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 void UpdateForDataChange(int days_since_last_update) { | 253 void UpdateForDataChange(int days_since_last_update) { |
255 // New empty lists may have been created. Maintain the invariant that | 254 // New empty lists may have been created. Maintain the invariant that |
256 // there should be exactly |kNumDaysInHistory| days in the histories. | 255 // there should be exactly |kNumDaysInHistory| days in the histories. |
257 MaintainContentLengthPrefsWindow(update_, kNumDaysInHistory); | 256 MaintainContentLengthPrefsWindow(update_, kNumDaysInHistory); |
258 if (days_since_last_update) { | 257 if (days_since_last_update) { |
259 MaintainContentLengthPrefForDateChange(days_since_last_update); | 258 MaintainContentLengthPrefForDateChange(days_since_last_update); |
260 } | 259 } |
261 } | 260 } |
262 | 261 |
263 // Update the lengths for the current day. | 262 // Update the lengths for the current day. |
264 void Add(int64 content_length) { | 263 void Add(int64_t content_length) { |
265 AddInt64ToListPref(kNumDaysInHistory - 1, content_length, update_); | 264 AddInt64ToListPref(kNumDaysInHistory - 1, content_length, update_); |
266 } | 265 } |
267 | 266 |
268 int64 GetListPrefValue(size_t index) { | 267 int64_t GetListPrefValue(size_t index) { |
269 return ListPrefInt64Value(*update_, index); | 268 return ListPrefInt64Value(*update_, index); |
270 } | 269 } |
271 | 270 |
272 private: | 271 private: |
273 // Update the list for date change and ensure the list has exactly |length| | 272 // Update the list for date change and ensure the list has exactly |length| |
274 // elements. The last entry in the list will be for the current day after | 273 // elements. The last entry in the list will be for the current day after |
275 // the update. | 274 // the update. |
276 void MaintainContentLengthPrefForDateChange(int days_since_last_update) { | 275 void MaintainContentLengthPrefForDateChange(int days_since_last_update) { |
277 if (days_since_last_update == -1) { | 276 if (days_since_last_update == -1) { |
278 // The system may go backwards in time by up to a day for legitimate | 277 // The system may go backwards in time by up to a day for legitimate |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 base::ListValue* received) | 317 base::ListValue* received) |
319 : original_(original), | 318 : original_(original), |
320 received_(received) {} | 319 received_(received) {} |
321 | 320 |
322 void UpdateForDataChange(int days_since_last_update) { | 321 void UpdateForDataChange(int days_since_last_update) { |
323 original_.UpdateForDataChange(days_since_last_update); | 322 original_.UpdateForDataChange(days_since_last_update); |
324 received_.UpdateForDataChange(days_since_last_update); | 323 received_.UpdateForDataChange(days_since_last_update); |
325 } | 324 } |
326 | 325 |
327 // Update the lengths for the current day. | 326 // Update the lengths for the current day. |
328 void Add(int64 original_content_length, int64 received_content_length) { | 327 void Add(int64_t original_content_length, int64_t received_content_length) { |
329 original_.Add(original_content_length); | 328 original_.Add(original_content_length); |
330 received_.Add(received_content_length); | 329 received_.Add(received_content_length); |
331 } | 330 } |
332 | 331 |
333 int64 GetOriginalListPrefValue(size_t index) { | 332 int64_t GetOriginalListPrefValue(size_t index) { |
334 return original_.GetListPrefValue(index); | 333 return original_.GetListPrefValue(index); |
335 } | 334 } |
336 int64 GetReceivedListPrefValue(size_t index) { | 335 int64_t GetReceivedListPrefValue(size_t index) { |
337 return received_.GetListPrefValue(index); | 336 return received_.GetListPrefValue(index); |
338 } | 337 } |
339 | 338 |
340 private: | 339 private: |
341 DailyContentLengthUpdate original_; | 340 DailyContentLengthUpdate original_; |
342 DailyContentLengthUpdate received_; | 341 DailyContentLengthUpdate received_; |
343 }; | 342 }; |
344 | 343 |
345 // Report UMA metrics for daily data reductions. | 344 // Report UMA metrics for daily data reductions. |
346 } // namespace | 345 } // namespace |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 weak_factory_.GetWeakPtr())); | 388 weak_factory_.GetWeakPtr())); |
390 } | 389 } |
391 | 390 |
392 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 391 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
393 connection_type_ = | 392 connection_type_ = |
394 StoredConnectionType(net::NetworkChangeNotifier::GetConnectionType()); | 393 StoredConnectionType(net::NetworkChangeNotifier::GetConnectionType()); |
395 | 394 |
396 if (delay_ == base::TimeDelta()) | 395 if (delay_ == base::TimeDelta()) |
397 return; | 396 return; |
398 | 397 |
399 // Init all int64 prefs. | 398 // Init all int64_t prefs. |
400 InitInt64Pref(prefs::kDailyHttpContentLengthLastUpdateDate); | 399 InitInt64Pref(prefs::kDailyHttpContentLengthLastUpdateDate); |
401 InitInt64Pref(prefs::kHttpReceivedContentLength); | 400 InitInt64Pref(prefs::kHttpReceivedContentLength); |
402 InitInt64Pref(prefs::kHttpOriginalContentLength); | 401 InitInt64Pref(prefs::kHttpOriginalContentLength); |
403 | 402 |
404 InitInt64Pref(prefs::kDailyHttpOriginalContentLengthApplication); | 403 InitInt64Pref(prefs::kDailyHttpOriginalContentLengthApplication); |
405 InitInt64Pref(prefs::kDailyHttpOriginalContentLengthVideo); | 404 InitInt64Pref(prefs::kDailyHttpOriginalContentLengthVideo); |
406 InitInt64Pref(prefs::kDailyHttpOriginalContentLengthUnknown); | 405 InitInt64Pref(prefs::kDailyHttpOriginalContentLengthUnknown); |
407 InitInt64Pref(prefs::kDailyHttpReceivedContentLengthApplication); | 406 InitInt64Pref(prefs::kDailyHttpReceivedContentLengthApplication); |
408 InitInt64Pref(prefs::kDailyHttpReceivedContentLengthVideo); | 407 InitInt64Pref(prefs::kDailyHttpReceivedContentLengthVideo); |
409 InitInt64Pref(prefs::kDailyHttpReceivedContentLengthUnknown); | 408 InitInt64Pref(prefs::kDailyHttpReceivedContentLengthUnknown); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 void DataReductionProxyCompressionStats::OnUpdateContentLengths() { | 455 void DataReductionProxyCompressionStats::OnUpdateContentLengths() { |
457 DCHECK(thread_checker_.CalledOnValidThread()); | 456 DCHECK(thread_checker_.CalledOnValidThread()); |
458 if (!pref_service_->GetBoolean(prefs::kUpdateDailyReceivedContentLengths)) | 457 if (!pref_service_->GetBoolean(prefs::kUpdateDailyReceivedContentLengths)) |
459 return; | 458 return; |
460 | 459 |
461 WritePrefs(); | 460 WritePrefs(); |
462 pref_service_->SetBoolean(prefs::kUpdateDailyReceivedContentLengths, false); | 461 pref_service_->SetBoolean(prefs::kUpdateDailyReceivedContentLengths, false); |
463 } | 462 } |
464 | 463 |
465 void DataReductionProxyCompressionStats::UpdateContentLengths( | 464 void DataReductionProxyCompressionStats::UpdateContentLengths( |
466 int64 data_used, | 465 int64_t data_used, |
467 int64 original_size, | 466 int64_t original_size, |
468 bool data_reduction_proxy_enabled, | 467 bool data_reduction_proxy_enabled, |
469 DataReductionProxyRequestType request_type, | 468 DataReductionProxyRequestType request_type, |
470 const std::string& data_usage_host, | 469 const std::string& data_usage_host, |
471 const std::string& mime_type) { | 470 const std::string& mime_type) { |
472 DCHECK(thread_checker_.CalledOnValidThread()); | 471 DCHECK(thread_checker_.CalledOnValidThread()); |
473 TRACE_EVENT0("loader", | 472 TRACE_EVENT0("loader", |
474 "DataReductionProxyCompressionStats::UpdateContentLengths") | 473 "DataReductionProxyCompressionStats::UpdateContentLengths") |
475 int64 total_received = GetInt64( | 474 int64_t total_received = |
476 data_reduction_proxy::prefs::kHttpReceivedContentLength); | 475 GetInt64(data_reduction_proxy::prefs::kHttpReceivedContentLength); |
477 int64 total_original = GetInt64( | 476 int64_t total_original = |
478 data_reduction_proxy::prefs::kHttpOriginalContentLength); | 477 GetInt64(data_reduction_proxy::prefs::kHttpOriginalContentLength); |
479 total_received += data_used; | 478 total_received += data_used; |
480 total_original += original_size; | 479 total_original += original_size; |
481 SetInt64(data_reduction_proxy::prefs::kHttpReceivedContentLength, | 480 SetInt64(data_reduction_proxy::prefs::kHttpReceivedContentLength, |
482 total_received); | 481 total_received); |
483 SetInt64(data_reduction_proxy::prefs::kHttpOriginalContentLength, | 482 SetInt64(data_reduction_proxy::prefs::kHttpOriginalContentLength, |
484 total_original); | 483 total_original); |
485 | 484 |
486 RecordDataUsage(data_usage_host, data_used, original_size, base::Time::Now()); | 485 RecordDataUsage(data_usage_host, data_used, original_size, base::Time::Now()); |
487 RecordRequestSizePrefs(data_used, original_size, data_reduction_proxy_enabled, | 486 RecordRequestSizePrefs(data_used, original_size, data_reduction_proxy_enabled, |
488 request_type, mime_type, base::Time::Now()); | 487 request_type, mime_type, base::Time::Now()); |
489 } | 488 } |
490 | 489 |
491 void DataReductionProxyCompressionStats::InitInt64Pref(const char* pref) { | 490 void DataReductionProxyCompressionStats::InitInt64Pref(const char* pref) { |
492 int64 pref_value = pref_service_->GetInt64(pref); | 491 int64_t pref_value = pref_service_->GetInt64(pref); |
493 pref_map_[pref] = pref_value; | 492 pref_map_[pref] = pref_value; |
494 } | 493 } |
495 | 494 |
496 void DataReductionProxyCompressionStats::InitListPref(const char* pref) { | 495 void DataReductionProxyCompressionStats::InitListPref(const char* pref) { |
497 scoped_ptr<base::ListValue> pref_value = scoped_ptr<base::ListValue>( | 496 scoped_ptr<base::ListValue> pref_value = scoped_ptr<base::ListValue>( |
498 pref_service_->GetList(pref)->DeepCopy()); | 497 pref_service_->GetList(pref)->DeepCopy()); |
499 list_pref_map_.add(pref, pref_value.Pass()); | 498 list_pref_map_.add(pref, pref_value.Pass()); |
500 } | 499 } |
501 | 500 |
502 int64 DataReductionProxyCompressionStats::GetInt64(const char* pref_path) { | 501 int64_t DataReductionProxyCompressionStats::GetInt64(const char* pref_path) { |
503 if (delay_ == base::TimeDelta()) | 502 if (delay_ == base::TimeDelta()) |
504 return pref_service_->GetInt64(pref_path); | 503 return pref_service_->GetInt64(pref_path); |
505 | 504 |
506 DataReductionProxyPrefMap::iterator iter = pref_map_.find(pref_path); | 505 DataReductionProxyPrefMap::iterator iter = pref_map_.find(pref_path); |
507 return iter->second; | 506 return iter->second; |
508 } | 507 } |
509 | 508 |
510 void DataReductionProxyCompressionStats::SetInt64(const char* pref_path, | 509 void DataReductionProxyCompressionStats::SetInt64(const char* pref_path, |
511 int64 pref_value) { | 510 int64_t pref_value) { |
512 if (delay_ == base::TimeDelta()) { | 511 if (delay_ == base::TimeDelta()) { |
513 pref_service_->SetInt64(pref_path, pref_value); | 512 pref_service_->SetInt64(pref_path, pref_value); |
514 return; | 513 return; |
515 } | 514 } |
516 | 515 |
517 DelayedWritePrefs(); | 516 DelayedWritePrefs(); |
518 pref_map_[pref_path] = pref_value; | 517 pref_map_[pref_path] = pref_value; |
519 } | 518 } |
520 | 519 |
521 void DataReductionProxyCompressionStats::IncrementInt64Pref( | 520 void DataReductionProxyCompressionStats::IncrementInt64Pref( |
(...skipping 24 matching lines...) Expand all Loading... |
546 for (DataReductionProxyListPrefMap::iterator iter = list_pref_map_.begin(); | 545 for (DataReductionProxyListPrefMap::iterator iter = list_pref_map_.begin(); |
547 iter != list_pref_map_.end(); ++iter) { | 546 iter != list_pref_map_.end(); ++iter) { |
548 TransferList(*(iter->second), | 547 TransferList(*(iter->second), |
549 ListPrefUpdate(pref_service_, iter->first).Get()); | 548 ListPrefUpdate(pref_service_, iter->first).Get()); |
550 } | 549 } |
551 } | 550 } |
552 | 551 |
553 base::Value* | 552 base::Value* |
554 DataReductionProxyCompressionStats::HistoricNetworkStatsInfoToValue() { | 553 DataReductionProxyCompressionStats::HistoricNetworkStatsInfoToValue() { |
555 DCHECK(thread_checker_.CalledOnValidThread()); | 554 DCHECK(thread_checker_.CalledOnValidThread()); |
556 int64 total_received = GetInt64(prefs::kHttpReceivedContentLength); | 555 int64_t total_received = GetInt64(prefs::kHttpReceivedContentLength); |
557 int64 total_original = GetInt64(prefs::kHttpOriginalContentLength); | 556 int64_t total_original = GetInt64(prefs::kHttpOriginalContentLength); |
558 | 557 |
559 base::DictionaryValue* dict = new base::DictionaryValue(); | 558 base::DictionaryValue* dict = new base::DictionaryValue(); |
560 // Use strings to avoid overflow. base::Value only supports 32-bit integers. | 559 // Use strings to avoid overflow. base::Value only supports 32-bit integers. |
561 dict->SetString("historic_received_content_length", | 560 dict->SetString("historic_received_content_length", |
562 base::Int64ToString(total_received)); | 561 base::Int64ToString(total_received)); |
563 dict->SetString("historic_original_content_length", | 562 dict->SetString("historic_original_content_length", |
564 base::Int64ToString(total_original)); | 563 base::Int64ToString(total_original)); |
565 return dict; | 564 return dict; |
566 } | 565 } |
567 | 566 |
568 int64 DataReductionProxyCompressionStats::GetLastUpdateTime() { | 567 int64_t DataReductionProxyCompressionStats::GetLastUpdateTime() { |
569 int64 last_update_internal = GetInt64( | 568 int64_t last_update_internal = |
570 prefs::kDailyHttpContentLengthLastUpdateDate); | 569 GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate); |
571 base::Time last_update = base::Time::FromInternalValue(last_update_internal); | 570 base::Time last_update = base::Time::FromInternalValue(last_update_internal); |
572 return static_cast<int64>(last_update.ToJsTime()); | 571 return static_cast<int64_t>(last_update.ToJsTime()); |
573 } | 572 } |
574 | 573 |
575 void DataReductionProxyCompressionStats::ResetStatistics() { | 574 void DataReductionProxyCompressionStats::ResetStatistics() { |
576 base::ListValue* original_update = | 575 base::ListValue* original_update = |
577 GetList(prefs::kDailyHttpOriginalContentLength); | 576 GetList(prefs::kDailyHttpOriginalContentLength); |
578 base::ListValue* received_update = | 577 base::ListValue* received_update = |
579 GetList(prefs::kDailyHttpReceivedContentLength); | 578 GetList(prefs::kDailyHttpReceivedContentLength); |
580 original_update->Clear(); | 579 original_update->Clear(); |
581 received_update->Clear(); | 580 received_update->Clear(); |
582 for (size_t i = 0; i < kNumDaysInHistory; ++i) { | 581 for (size_t i = 0; i < kNumDaysInHistory; ++i) { |
583 original_update->AppendString(base::Int64ToString(0)); | 582 original_update->AppendString(base::Int64ToString(0)); |
584 received_update->AppendString(base::Int64ToString(0)); | 583 received_update->AppendString(base::Int64ToString(0)); |
585 } | 584 } |
586 } | 585 } |
587 | 586 |
588 ContentLengthList DataReductionProxyCompressionStats::GetDailyContentLengths( | 587 ContentLengthList DataReductionProxyCompressionStats::GetDailyContentLengths( |
589 const char* pref_name) { | 588 const char* pref_name) { |
590 ContentLengthList content_lengths; | 589 ContentLengthList content_lengths; |
591 const base::ListValue* list_value = GetList(pref_name); | 590 const base::ListValue* list_value = GetList(pref_name); |
592 if (list_value->GetSize() == kNumDaysInHistory) { | 591 if (list_value->GetSize() == kNumDaysInHistory) { |
593 for (size_t i = 0; i < kNumDaysInHistory; ++i) | 592 for (size_t i = 0; i < kNumDaysInHistory; ++i) |
594 content_lengths.push_back(GetInt64PrefValue(*list_value, i)); | 593 content_lengths.push_back(GetInt64PrefValue(*list_value, i)); |
595 } | 594 } |
596 return content_lengths; | 595 return content_lengths; |
597 } | 596 } |
598 | 597 |
599 void DataReductionProxyCompressionStats::GetContentLengths( | 598 void DataReductionProxyCompressionStats::GetContentLengths( |
600 unsigned int days, | 599 unsigned int days, |
601 int64* original_content_length, | 600 int64_t* original_content_length, |
602 int64* received_content_length, | 601 int64_t* received_content_length, |
603 int64* last_update_time) { | 602 int64_t* last_update_time) { |
604 DCHECK_LE(days, kNumDaysInHistory); | 603 DCHECK_LE(days, kNumDaysInHistory); |
605 | 604 |
606 const base::ListValue* original_list = | 605 const base::ListValue* original_list = |
607 GetList(prefs::kDailyHttpOriginalContentLength); | 606 GetList(prefs::kDailyHttpOriginalContentLength); |
608 const base::ListValue* received_list = | 607 const base::ListValue* received_list = |
609 GetList(prefs::kDailyHttpReceivedContentLength); | 608 GetList(prefs::kDailyHttpReceivedContentLength); |
610 | 609 |
611 if (original_list->GetSize() != kNumDaysInHistory || | 610 if (original_list->GetSize() != kNumDaysInHistory || |
612 received_list->GetSize() != kNumDaysInHistory) { | 611 received_list->GetSize() != kNumDaysInHistory) { |
613 *original_content_length = 0L; | 612 *original_content_length = 0L; |
614 *received_content_length = 0L; | 613 *received_content_length = 0L; |
615 *last_update_time = 0L; | 614 *last_update_time = 0L; |
616 return; | 615 return; |
617 } | 616 } |
618 | 617 |
619 int64 orig = 0L; | 618 int64_t orig = 0L; |
620 int64 recv = 0L; | 619 int64_t recv = 0L; |
621 // Include days from the end of the list going backwards. | 620 // Include days from the end of the list going backwards. |
622 for (size_t i = kNumDaysInHistory - days; | 621 for (size_t i = kNumDaysInHistory - days; |
623 i < kNumDaysInHistory; ++i) { | 622 i < kNumDaysInHistory; ++i) { |
624 orig += GetInt64PrefValue(*original_list, i); | 623 orig += GetInt64PrefValue(*original_list, i); |
625 recv += GetInt64PrefValue(*received_list, i); | 624 recv += GetInt64PrefValue(*received_list, i); |
626 } | 625 } |
627 *original_content_length = orig; | 626 *original_content_length = orig; |
628 *received_content_length = recv; | 627 *received_content_length = recv; |
629 *last_update_time = GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate); | 628 *last_update_time = GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate); |
630 } | 629 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 void DataReductionProxyCompressionStats::TransferList( | 724 void DataReductionProxyCompressionStats::TransferList( |
726 const base::ListValue& from_list, | 725 const base::ListValue& from_list, |
727 base::ListValue* to_list) { | 726 base::ListValue* to_list) { |
728 to_list->Clear(); | 727 to_list->Clear(); |
729 for (size_t i = 0; i < from_list.GetSize(); ++i) { | 728 for (size_t i = 0; i < from_list.GetSize(); ++i) { |
730 to_list->Set(i, new base::StringValue(base::Int64ToString( | 729 to_list->Set(i, new base::StringValue(base::Int64ToString( |
731 GetListPrefInt64Value(from_list, i)))); | 730 GetListPrefInt64Value(from_list, i)))); |
732 } | 731 } |
733 } | 732 } |
734 | 733 |
735 int64 DataReductionProxyCompressionStats::GetListPrefInt64Value( | 734 int64_t DataReductionProxyCompressionStats::GetListPrefInt64Value( |
736 const base::ListValue& list, | 735 const base::ListValue& list, |
737 size_t index) { | 736 size_t index) { |
738 std::string string_value; | 737 std::string string_value; |
739 if (!list.GetString(index, &string_value)) { | 738 if (!list.GetString(index, &string_value)) { |
740 NOTREACHED(); | 739 NOTREACHED(); |
741 return 0; | 740 return 0; |
742 } | 741 } |
743 | 742 |
744 int64 value = 0; | 743 int64_t value = 0; |
745 bool rv = base::StringToInt64(string_value, &value); | 744 bool rv = base::StringToInt64(string_value, &value); |
746 DCHECK(rv); | 745 DCHECK(rv); |
747 return value; | 746 return value; |
748 } | 747 } |
749 | 748 |
750 void DataReductionProxyCompressionStats::RecordRequestSizePrefs( | 749 void DataReductionProxyCompressionStats::RecordRequestSizePrefs( |
751 int64 data_used, | 750 int64_t data_used, |
752 int64 original_size, | 751 int64_t original_size, |
753 bool with_data_reduction_proxy_enabled, | 752 bool with_data_reduction_proxy_enabled, |
754 DataReductionProxyRequestType request_type, | 753 DataReductionProxyRequestType request_type, |
755 const std::string& mime_type, | 754 const std::string& mime_type, |
756 const base::Time& now) { | 755 const base::Time& now) { |
757 // TODO(bengr): Remove this check once the underlying cause of | 756 // TODO(bengr): Remove this check once the underlying cause of |
758 // http://crbug.com/287821 is fixed. For now, only continue if the current | 757 // http://crbug.com/287821 is fixed. For now, only continue if the current |
759 // year is reported as being between 1972 and 2970. | 758 // year is reported as being between 1972 and 2970. |
760 base::TimeDelta time_since_unix_epoch = now - base::Time::UnixEpoch(); | 759 base::TimeDelta time_since_unix_epoch = now - base::Time::UnixEpoch(); |
761 const int kMinDaysSinceUnixEpoch = 365 * 2; // 2 years. | 760 const int kMinDaysSinceUnixEpoch = 365 * 2; // 2 years. |
762 const int kMaxDaysSinceUnixEpoch = 365 * 1000; // 1000 years. | 761 const int kMaxDaysSinceUnixEpoch = 365 * 1000; // 1000 years. |
763 if (time_since_unix_epoch.InDays() < kMinDaysSinceUnixEpoch || | 762 if (time_since_unix_epoch.InDays() < kMinDaysSinceUnixEpoch || |
764 time_since_unix_epoch.InDays() > kMaxDaysSinceUnixEpoch) { | 763 time_since_unix_epoch.InDays() > kMaxDaysSinceUnixEpoch) { |
765 return; | 764 return; |
766 } | 765 } |
767 | 766 |
768 // Determine how many days it has been since the last update. | 767 // Determine how many days it has been since the last update. |
769 int64 then_internal = GetInt64( | 768 int64_t then_internal = GetInt64( |
770 data_reduction_proxy::prefs::kDailyHttpContentLengthLastUpdateDate); | 769 data_reduction_proxy::prefs::kDailyHttpContentLengthLastUpdateDate); |
771 | 770 |
772 // Local midnight could have been shifted due to time zone change. | 771 // Local midnight could have been shifted due to time zone change. |
773 // If time is null then don't care if midnight will be wrong shifted due to | 772 // If time is null then don't care if midnight will be wrong shifted due to |
774 // time zone change because it's still too much time ago. | 773 // time zone change because it's still too much time ago. |
775 base::Time then_midnight = base::Time::FromInternalValue(then_internal); | 774 base::Time then_midnight = base::Time::FromInternalValue(then_internal); |
776 if (!then_midnight.is_null()) { | 775 if (!then_midnight.is_null()) { |
777 then_midnight = then_midnight.LocalMidnight(); | 776 then_midnight = then_midnight.LocalMidnight(); |
778 } | 777 } |
779 base::Time midnight = now.LocalMidnight(); | 778 base::Time midnight = now.LocalMidnight(); |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 IncrementInt64Pref(recevied_size_with_proxy_enabled_pref, received_size); | 1089 IncrementInt64Pref(recevied_size_with_proxy_enabled_pref, received_size); |
1091 } | 1090 } |
1092 | 1091 |
1093 if (via_data_reduction_proxy) { | 1092 if (via_data_reduction_proxy) { |
1094 IncrementInt64Pref(original_size_via_proxy_pref, original_size); | 1093 IncrementInt64Pref(original_size_via_proxy_pref, original_size); |
1095 IncrementInt64Pref(received_size_via_proxy_pref, received_size); | 1094 IncrementInt64Pref(received_size_via_proxy_pref, received_size); |
1096 } | 1095 } |
1097 } | 1096 } |
1098 | 1097 |
1099 void DataReductionProxyCompressionStats::RecordUserVisibleDataSavings() { | 1098 void DataReductionProxyCompressionStats::RecordUserVisibleDataSavings() { |
1100 int64 original_content_length; | 1099 int64_t original_content_length; |
1101 int64 received_content_length; | 1100 int64_t received_content_length; |
1102 int64 last_update_internal; | 1101 int64_t last_update_internal; |
1103 GetContentLengths(kNumDaysInHistorySummary, &original_content_length, | 1102 GetContentLengths(kNumDaysInHistorySummary, &original_content_length, |
1104 &received_content_length, &last_update_internal); | 1103 &received_content_length, &last_update_internal); |
1105 | 1104 |
1106 if (original_content_length == 0) | 1105 if (original_content_length == 0) |
1107 return; | 1106 return; |
1108 | 1107 |
1109 int64 user_visible_savings_bytes = | 1108 int64_t user_visible_savings_bytes = |
1110 original_content_length - received_content_length; | 1109 original_content_length - received_content_length; |
1111 int user_visible_savings_percent = | 1110 int user_visible_savings_percent = |
1112 user_visible_savings_bytes * 100 / original_content_length; | 1111 user_visible_savings_bytes * 100 / original_content_length; |
1113 UMA_HISTOGRAM_PERCENTAGE( | 1112 UMA_HISTOGRAM_PERCENTAGE( |
1114 "Net.DailyUserVisibleSavingsPercent_DataReductionProxyEnabled", | 1113 "Net.DailyUserVisibleSavingsPercent_DataReductionProxyEnabled", |
1115 user_visible_savings_percent); | 1114 user_visible_savings_percent); |
1116 UMA_HISTOGRAM_COUNTS( | 1115 UMA_HISTOGRAM_COUNTS( |
1117 "Net.DailyUserVisibleSavingsSize_DataReductionProxyEnabled", | 1116 "Net.DailyUserVisibleSavingsSize_DataReductionProxyEnabled", |
1118 user_visible_savings_bytes >> 10); | 1117 user_visible_savings_bytes >> 10); |
1119 } | 1118 } |
1120 | 1119 |
1121 void DataReductionProxyCompressionStats::RecordDataUsage( | 1120 void DataReductionProxyCompressionStats::RecordDataUsage( |
1122 const std::string& data_usage_host, | 1121 const std::string& data_usage_host, |
1123 int64 data_used, | 1122 int64_t data_used, |
1124 int64 original_size, | 1123 int64_t original_size, |
1125 const base::Time& time) { | 1124 const base::Time& time) { |
1126 if (current_data_usage_load_status_ != LOADED) | 1125 if (current_data_usage_load_status_ != LOADED) |
1127 return; | 1126 return; |
1128 | 1127 |
1129 DCHECK(data_usage_reporting_enabled_.GetValue()); | 1128 DCHECK(data_usage_reporting_enabled_.GetValue()); |
1130 | 1129 |
1131 if (!DataUsageStore::AreInSameInterval(data_usage_map_last_updated_, time)) { | 1130 if (!DataUsageStore::AreInSameInterval(data_usage_map_last_updated_, time)) { |
1132 PersistDataUsage(); | 1131 PersistDataUsage(); |
1133 data_usage_map_.clear(); | 1132 data_usage_map_.clear(); |
1134 data_usage_map_last_updated_ = base::Time(); | 1133 data_usage_map_last_updated_ = base::Time(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 std::string DataReductionProxyCompressionStats::NormalizeHostname( | 1230 std::string DataReductionProxyCompressionStats::NormalizeHostname( |
1232 const std::string& host) { | 1231 const std::string& host) { |
1233 size_t pos = host.find("://"); | 1232 size_t pos = host.find("://"); |
1234 if (pos != std::string::npos) | 1233 if (pos != std::string::npos) |
1235 return host.substr(pos + 3); | 1234 return host.substr(pos + 3); |
1236 | 1235 |
1237 return host; | 1236 return host; |
1238 } | 1237 } |
1239 | 1238 |
1240 } // namespace data_reduction_proxy | 1239 } // namespace data_reduction_proxy |
OLD | NEW |