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

Side by Side Diff: components/data_use_measurement/content/data_use_measurement.cc

Issue 2269833002: Refactor the DataUseMeasurement class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: PS Created 4 years, 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_use_measurement/content/data_use_measurement.h" 5 #include "components/data_use_measurement/content/data_use_measurement.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/metrics/sparse_histogram.h" 8 #include "base/metrics/sparse_histogram.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 app_state_(base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES), 52 app_state_(base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES),
53 app_listener_(new base::android::ApplicationStatusListener( 53 app_listener_(new base::android::ApplicationStatusListener(
54 base::Bind(&DataUseMeasurement::OnApplicationStateChange, 54 base::Bind(&DataUseMeasurement::OnApplicationStateChange,
55 base::Unretained(this)))) 55 base::Unretained(this))))
56 #endif 56 #endif
57 { 57 {
58 } 58 }
59 59
60 DataUseMeasurement::~DataUseMeasurement(){}; 60 DataUseMeasurement::~DataUseMeasurement(){};
61 61
62 void DataUseMeasurement::OnBeforeRedirect(net::URLRequest* request,
63 const GURL& new_location) {
64 // Recording data use of request on redirects.
65 ReportDataUseUMA(request);
66 }
67
68 void DataUseMeasurement::OnCompleted(net::URLRequest* request, bool started) {
69 // TODO(amohammadkhan): Verify that there is no double recording in data use
70 // of redirected requests.
71 ReportDataUseUMA(request);
72 }
73
62 void DataUseMeasurement::ReportDataUseUMA( 74 void DataUseMeasurement::ReportDataUseUMA(
63 const net::URLRequest* request) const { 75 const net::URLRequest* request) const {
64 76
65 // Counts rely on URLRequest::GetTotalReceivedBytes() and 77 // Counts rely on URLRequest::GetTotalReceivedBytes() and
66 // URLRequest::GetTotalSentBytes(), which does not include the send path, 78 // URLRequest::GetTotalSentBytes(), which does not include the send path,
67 // network layer overhead, TLS overhead, and DNS. 79 // network layer overhead, TLS overhead, and DNS.
68 // TODO(amohammadkhan): Make these measured bytes more in line with number of 80 // TODO(amohammadkhan): Make these measured bytes more in line with number of
69 // bytes in lower levels. 81 // bytes in lower levels.
70 int64_t total_upload_bytes = request->GetTotalSentBytes(); 82 int64_t total_upload_bytes = request->GetTotalSentBytes();
71 int64_t total_received_bytes = request->GetTotalReceivedBytes(); 83 int64_t total_received_bytes = request->GetTotalReceivedBytes();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 message_size); 175 message_size);
164 if (message_size > 0) { 176 if (message_size > 0) {
165 IncreaseSparseHistogramByValue( 177 IncreaseSparseHistogramByValue(
166 GetHistogramName("DataUse.MessageSize.AllServices", dir, 178 GetHistogramName("DataUse.MessageSize.AllServices", dir,
167 is_connection_cellular), 179 is_connection_cellular),
168 service, message_size); 180 service, message_size);
169 } 181 }
170 } 182 }
171 183
172 } // namespace data_use_measurement 184 } // namespace data_use_measurement
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698