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

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

Issue 2462983003: Move data use measurement to DataUseNetworkDelegate (Closed)
Patch Set: Rebased and fixed nits Created 4 years, 1 month 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 URLRequestClassifier;
33
32 // Records the data use of user traffic and various services in UMA histograms. 34 // Records the data use of user traffic and various services in UMA histograms.
33 // The UMA is broken down by network technology used (Wi-Fi vs cellular). On 35 // The UMA is broken down by network technology used (Wi-Fi vs cellular). On
34 // Android, the UMA is further broken down by whether the application was in the 36 // Android, the UMA is further broken down by whether the application was in the
35 // background or foreground during the request. 37 // background or foreground during the request.
36 // TODO(amohammadkhan): Complete the layered architecture. 38 // TODO(amohammadkhan): Complete the layered architecture.
37 // http://crbug.com/527460 39 // http://crbug.com/527460
38 class DataUseMeasurement { 40 class DataUseMeasurement {
39 public: 41 public:
40 explicit DataUseMeasurement( 42 DataUseMeasurement(
43 std::unique_ptr<URLRequestClassifier> url_request_classifier,
41 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder); 44 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder);
42 ~DataUseMeasurement(); 45 ~DataUseMeasurement();
43 46
44 // Called before a request is sent. 47 // Called before a request is sent.
45 void OnBeforeURLRequest(net::URLRequest* request); 48 void OnBeforeURLRequest(net::URLRequest* request);
46 49
47 // Called right after a redirect response code was received for |request|. 50 // Called right after a redirect response code was received for |request|.
48 void OnBeforeRedirect(const net::URLRequest& request, 51 void OnBeforeRedirect(const net::URLRequest& request,
49 const GURL& new_location); 52 const GURL& new_location);
50 53
51 // Called when data is received or sent on the network, respectively. 54 // Called when data is received or sent on the network, respectively.
52 void OnNetworkBytesReceived(const net::URLRequest& request, 55 void OnNetworkBytesReceived(const net::URLRequest& request,
53 int64_t bytes_received); 56 int64_t bytes_received);
54 void OnNetworkBytesSent(const net::URLRequest& request, int64_t bytes_sent); 57 void OnNetworkBytesSent(const net::URLRequest& request, int64_t bytes_sent);
55 58
56 // Indicates that |request| has been completed or failed. 59 // Indicates that |request| has been completed or failed.
57 void OnCompleted(const net::URLRequest& request, bool started); 60 void OnCompleted(const net::URLRequest& request, bool started);
58 61
59 // Returns true if the URLRequest |request| is initiated by user traffic.
60 static bool IsUserInitiatedRequest(const net::URLRequest& request);
61
62 #if defined(OS_ANDROID) 62 #if defined(OS_ANDROID)
63 // This function should just be used for testing purposes. A change in 63 // This function should just be used for testing purposes. A change in
64 // application state can be simulated by calling this function. 64 // application state can be simulated by calling this function.
65 void OnApplicationStateChangeForTesting( 65 void OnApplicationStateChangeForTesting(
66 base::android::ApplicationState application_state); 66 base::android::ApplicationState application_state);
67 #endif 67 #endif
68 68
69 private: 69 private:
70 friend class DataUseMeasurementTest; 70 friend class DataUseMeasurementTest;
71 FRIEND_TEST_ALL_PREFIXES(DataUseMeasurementTest, 71 FRIEND_TEST_ALL_PREFIXES(DataUseMeasurementTest,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // Records the data use of the |request|, thus |request| must be non-null. 105 // Records the data use of the |request|, thus |request| must be non-null.
106 // |dir| is the direction (which is upstream or downstream) and |bytes| is the 106 // |dir| is the direction (which is upstream or downstream) and |bytes| is the
107 // number of bytes in the direction. 107 // number of bytes in the direction.
108 void ReportDataUseUMA(const net::URLRequest& request, 108 void ReportDataUseUMA(const net::URLRequest& request,
109 TrafficDirection dir, 109 TrafficDirection dir,
110 int64_t bytes); 110 int64_t bytes);
111 111
112 // Updates the data use of the |request|, thus |request| must be non-null. 112 // Updates the data use of the |request|, thus |request| must be non-null.
113 void UpdateDataUsePrefs(const net::URLRequest& request) const; 113 void UpdateDataUsePrefs(const net::URLRequest& request) const;
114 114
115 // Reports the message size of the service requests.
116 void ReportServicesMessageSizeUMA(const net::URLRequest& request);
117
115 // A helper function used to record data use of services. It gets the size of 118 // A helper function used to record data use of services. It gets the size of
116 // exchanged message, its direction (which is upstream or downstream) and 119 // exchanged message, its direction (which is upstream or downstream) and
117 // reports to two histogram groups. DataUse.MessageSize.ServiceName and 120 // reports to two histogram groups. DataUse.MessageSize.ServiceName and
118 // DataUse.Services.{Dimensions}. In the second one, services are buckets. 121 // DataUse.Services.{Dimensions}. In the second one, services are buckets.
119 // |app_state| indicates the app state which can be foreground, background, or 122 // |app_state| indicates the app state which can be foreground, background, or
120 // unknown. 123 // unknown.
121 void ReportDataUsageServices( 124 void ReportDataUsageServices(
122 data_use_measurement::DataUseUserData::ServiceName service, 125 data_use_measurement::DataUseUserData::ServiceName service,
123 TrafficDirection dir, 126 TrafficDirection dir,
124 DataUseUserData::AppState app_state, 127 DataUseUserData::AppState app_state,
125 bool is_connection_cellular, 128 bool is_connection_cellular,
126 int64_t message_size) const; 129 int64_t message_size) const;
127 130
131 // Classifier for identifying if an URL request is user initiated.
132 std::unique_ptr<URLRequestClassifier> url_request_classifier_;
133
128 // Callback for updating data use prefs. 134 // Callback for updating data use prefs.
129 // TODO(rajendrant): If a similar mechanism would need be used for components 135 // TODO(rajendrant): If a similar mechanism would need be used for components
130 // other than metrics, then the better approach would be to refactor this 136 // other than metrics, then the better approach would be to refactor this
131 // class to support registering arbitrary observers. crbug.com/601185 137 // class to support registering arbitrary observers. crbug.com/601185
132 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_; 138 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_;
133 139
134 #if defined(OS_ANDROID) 140 #if defined(OS_ANDROID)
135 // Application listener store the last known state of the application in this 141 // Application listener store the last known state of the application in this
136 // field. 142 // field.
137 base::android::ApplicationState app_state_; 143 base::android::ApplicationState app_state_;
(...skipping 20 matching lines...) Expand all
158 // True if app is in background and first network read has not yet happened. 164 // True if app is in background and first network read has not yet happened.
159 bool no_reads_since_background_; 165 bool no_reads_since_background_;
160 #endif 166 #endif
161 167
162 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); 168 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement);
163 }; 169 };
164 170
165 } // namespace data_use_measurement 171 } // namespace data_use_measurement
166 172
167 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ 173 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698