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

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

Issue 1355893004: Complete the layered architecture of data_use_measurement component. Base URL: https://chromium.googlesource.com/chromium/src.git@NewArchServices
Patch Set: Created 5 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 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/core/data_use_measurement.h>
6
7 #include "base/metrics/histogram.h" 6 #include "base/metrics/histogram.h"
8 #include "base/metrics/sparse_histogram.h" 7 #include "base/metrics/sparse_histogram.h"
9 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
10 #include "content/public/browser/resource_request_info.h"
11 #include "net/base/network_change_notifier.h" 9 #include "net/base/network_change_notifier.h"
12 #include "net/base/upload_data_stream.h" 10 #include "net/base/upload_data_stream.h"
13 #include "net/http/http_response_headers.h" 11 #include "net/http/http_response_headers.h"
14 #include "net/url_request/url_request.h" 12 #include "net/url_request/url_request.h"
15 13
16 namespace data_use_measurement { 14 namespace data_use_measurement {
17 15
18 namespace { 16 namespace {
19 17
20 // Records the occurrence of |sample| in |name| histogram. Conventional UMA 18 // Records the occurrence of |sample| in |name| histogram. Conventional UMA
(...skipping 15 matching lines...) Expand all
36 void IncreaseSparseHistogramByValue(const std::string& name, 34 void IncreaseSparseHistogramByValue(const std::string& name,
37 int64_t sample, 35 int64_t sample,
38 int64_t value) { 36 int64_t value) {
39 base::HistogramBase* histogram = base::SparseHistogram::FactoryGet( 37 base::HistogramBase* histogram = base::SparseHistogram::FactoryGet(
40 name, base::HistogramBase::kUmaTargetedHistogramFlag); 38 name, base::HistogramBase::kUmaTargetedHistogramFlag);
41 histogram->AddCount(sample, value); 39 histogram->AddCount(sample, value);
42 } 40 }
43 41
44 } // namespace 42 } // namespace
45 43
46 DataUseMeasurement::DataUseMeasurement() 44 DataUseMeasurement::DataUseMeasurement(
45 DataUseMeasurementDelegate* data_use_measurement_delegate)
46 :
47 #if defined(OS_ANDROID) 47 #if defined(OS_ANDROID)
48 : app_state_(base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES), 48 app_state_(base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES),
49 app_listener_(new base::android::ApplicationStatusListener( 49 app_listener_(new base::android::ApplicationStatusListener(
50 base::Bind(&DataUseMeasurement::OnApplicationStateChange, 50 base::Bind(&DataUseMeasurement::OnApplicationStateChange,
51 base::Unretained(this)))) 51 base::Unretained(this)))),
52 #endif 52 #endif
53 { 53 data_use_measurement_delegate_(data_use_measurement_delegate) {
54 } 54 }
55 55
56 DataUseMeasurement::~DataUseMeasurement(){}; 56 DataUseMeasurement::~DataUseMeasurement(){};
57 57
58 void DataUseMeasurement::ReportDataUseUMA( 58 void DataUseMeasurement::ReportDataUseUMA(
59 const net::URLRequest* request) const { 59 const net::URLRequest* request) const {
60 const content::ResourceRequestInfo* info = 60 bool is_user_traffic =
61 content::ResourceRequestInfo::ForRequest(request); 61 data_use_measurement_delegate_->RequestIsFromUser(request);
62 // Having |info| is the sign of a request for a web content from user. For now
63 // we could add a condition to check ProcessType in info is
64 // content::PROCESS_TYPE_RENDERER, but it won't be compatible with upcoming
65 // PlzNavigate architecture. So just existence of |info| is verified, and the
66 // current check should be compatible with upcoming changes in PlzNavigate.
67 bool is_user_traffic = info != nullptr;
68 62
69 // Counts rely on URLRequest::GetTotalReceivedBytes() and 63 // Counts rely on URLRequest::GetTotalReceivedBytes() and
70 // URLRequest::GetTotalSentBytes(), which does not include the send path, 64 // URLRequest::GetTotalSentBytes(), which does not include the send path,
71 // network layer overhead, TLS overhead, and DNS. 65 // network layer overhead, TLS overhead, and DNS.
72 // TODO(amohammadkhan): Make these measured bytes more in line with number of 66 // TODO(amohammadkhan): Make these measured bytes more in line with number of
73 // bytes in lower levels. 67 // bytes in lower levels.
74 int64_t total_upload_bytes = request->GetTotalSentBytes(); 68 int64_t total_upload_bytes = request->GetTotalSentBytes();
75 int64_t total_received_bytes = request->GetTotalReceivedBytes(); 69 int64_t total_received_bytes = request->GetTotalReceivedBytes();
76 70
77 RecordUMAHistogramCount( 71 RecordUMAHistogramCount(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 "DataUse.MessageSize." + DataUseUserData::GetServiceNameAsString(service), 133 "DataUse.MessageSize." + DataUseUserData::GetServiceNameAsString(service),
140 message_size); 134 message_size);
141 if (message_size > 0) { 135 if (message_size > 0) {
142 IncreaseSparseHistogramByValue( 136 IncreaseSparseHistogramByValue(
143 GetHistogramName("DataUse.MessageSize.AllServices", dir), service, 137 GetHistogramName("DataUse.MessageSize.AllServices", dir), service,
144 message_size); 138 message_size);
145 } 139 }
146 } 140 }
147 141
148 } // namespace data_use_measurement 142 } // namespace data_use_measurement
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698