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

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

Issue 2583703002: Record the tab state during data use (Closed)
Patch Set: minor fix Created 3 years, 12 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 #ifndef COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ 5 #ifndef COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_
6 #define COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ 6 #define COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 11 matching lines...) Expand all
22 #endif 22 #endif
23 23
24 class GURL; 24 class GURL;
25 25
26 namespace net { 26 namespace net {
27 class URLRequest; 27 class URLRequest;
28 } 28 }
29 29
30 namespace data_use_measurement { 30 namespace data_use_measurement {
31 31
32 class DataUseAscriber;
32 class URLRequestClassifier; 33 class URLRequestClassifier;
33 34
34 // Records the data use of user traffic and various services in UMA histograms. 35 // Records the data use of user traffic and various services in UMA histograms.
35 // The UMA is broken down by network technology used (Wi-Fi vs cellular). On 36 // The UMA is broken down by network technology used (Wi-Fi vs cellular). On
36 // Android, the UMA is further broken down by whether the application was in the 37 // Android, the UMA is further broken down by whether the application was in the
37 // background or foreground during the request. 38 // background or foreground during the request.
38 // TODO(amohammadkhan): Complete the layered architecture. 39 // TODO(amohammadkhan): Complete the layered architecture.
39 // http://crbug.com/527460 40 // http://crbug.com/527460
40 class DataUseMeasurement { 41 class DataUseMeasurement {
41 public: 42 public:
42 DataUseMeasurement( 43 DataUseMeasurement(
43 std::unique_ptr<URLRequestClassifier> url_request_classifier, 44 std::unique_ptr<URLRequestClassifier> url_request_classifier,
44 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder); 45 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder,
46 DataUseAscriber* ascriber);
45 ~DataUseMeasurement(); 47 ~DataUseMeasurement();
46 48
47 // Called before a request is sent. 49 // Called before a request is sent.
48 void OnBeforeURLRequest(net::URLRequest* request); 50 void OnBeforeURLRequest(net::URLRequest* request);
49 51
50 // Called right after a redirect response code was received for |request|. 52 // Called right after a redirect response code was received for |request|.
51 void OnBeforeRedirect(const net::URLRequest& request, 53 void OnBeforeRedirect(const net::URLRequest& request,
52 const GURL& new_location); 54 const GURL& new_location);
53 55
54 // Called when data is received or sent on the network, respectively. 56 // Called when data is received or sent on the network, respectively.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 void ReportDataUseUMA(const net::URLRequest& request, 110 void ReportDataUseUMA(const net::URLRequest& request,
109 TrafficDirection dir, 111 TrafficDirection dir,
110 int64_t bytes); 112 int64_t bytes);
111 113
112 // Updates the data use of the |request|, thus |request| must be non-null. 114 // Updates the data use of the |request|, thus |request| must be non-null.
113 void UpdateDataUsePrefs(const net::URLRequest& request) const; 115 void UpdateDataUsePrefs(const net::URLRequest& request) const;
114 116
115 // Reports the message size of the service requests. 117 // Reports the message size of the service requests.
116 void ReportServicesMessageSizeUMA(const net::URLRequest& request); 118 void ReportServicesMessageSizeUMA(const net::URLRequest& request);
117 119
118 // A helper function used to record data use of services. It gets the size of 120 // Records data use histograms of services. It gets the size of exchanged
119 // exchanged message, its direction (which is upstream or downstream) and 121 // message, its direction (which is upstream or downstream) and reports to two
120 // reports to two histogram groups. DataUse.MessageSize.ServiceName and 122 // histogram groups. DataUse.MessageSize.ServiceName and
121 // DataUse.Services.{Dimensions}. In the second one, services are buckets. 123 // DataUse.Services.{Dimensions}. In the second one, services are buckets.
122 // |app_state| indicates the app state which can be foreground, background, or 124 // |app_state| indicates the app state which can be foreground, background, or
123 // unknown. 125 // unknown.
124 void ReportDataUsageServices( 126 void ReportDataUsageServices(
125 data_use_measurement::DataUseUserData::ServiceName service, 127 data_use_measurement::DataUseUserData::ServiceName service,
126 TrafficDirection dir, 128 TrafficDirection dir,
127 DataUseUserData::AppState app_state, 129 DataUseUserData::AppState app_state,
128 bool is_connection_cellular, 130 bool is_connection_cellular,
129 int64_t message_size) const; 131 int64_t message_size) const;
130 132
133 // Records data use histograms split on TrafficDirection, AppState and
134 // TabState.
135 void RecordTabStateHistogram(TrafficDirection dir,
136 DataUseUserData::AppState app_state,
137 bool is_tab_visible,
138 int64_t bytes);
139
131 // Classifier for identifying if an URL request is user initiated. 140 // Classifier for identifying if an URL request is user initiated.
132 std::unique_ptr<URLRequestClassifier> url_request_classifier_; 141 std::unique_ptr<URLRequestClassifier> url_request_classifier_;
133 142
134 // Callback for updating data use prefs. 143 // Callback for updating data use prefs.
135 // TODO(rajendrant): If a similar mechanism would need be used for components 144 // TODO(rajendrant): If a similar mechanism would need be used for components
136 // other than metrics, then the better approach would be to refactor this 145 // other than metrics, then the better approach would be to refactor this
137 // class to support registering arbitrary observers. crbug.com/601185 146 // class to support registering arbitrary observers. crbug.com/601185
138 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_; 147 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_;
139 148
149 // DataUseAscriber used to get the attributes of data use.
150 DataUseAscriber* ascriber_;
151
140 #if defined(OS_ANDROID) 152 #if defined(OS_ANDROID)
141 // Application listener store the last known state of the application in this 153 // Application listener store the last known state of the application in this
142 // field. 154 // field.
143 base::android::ApplicationState app_state_; 155 base::android::ApplicationState app_state_;
144 156
145 // ApplicationStatusListener used to monitor whether the application is in the 157 // ApplicationStatusListener used to monitor whether the application is in the
146 // foreground or in the background. It is owned by DataUseMeasurement. 158 // foreground or in the background. It is owned by DataUseMeasurement.
147 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; 159 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_;
148 160
149 // Number of bytes received and sent by Chromium as reported by the operating 161 // Number of bytes received and sent by Chromium as reported by the operating
(...skipping 14 matching lines...) Expand all
164 // True if app is in background and first network read has not yet happened. 176 // True if app is in background and first network read has not yet happened.
165 bool no_reads_since_background_; 177 bool no_reads_since_background_;
166 #endif 178 #endif
167 179
168 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); 180 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement);
169 }; 181 };
170 182
171 } // namespace data_use_measurement 183 } // namespace data_use_measurement
172 184
173 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ 185 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698