OLD | NEW |
---|---|
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 Loading... | |
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( |
44 DataUseAscriber* ascriber, | |
43 std::unique_ptr<URLRequestClassifier> url_request_classifier, | 45 std::unique_ptr<URLRequestClassifier> url_request_classifier, |
44 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder); | 46 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder); |
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); |
(...skipping 14 matching lines...) Expand all Loading... | |
67 #endif | 69 #endif |
68 | 70 |
69 private: | 71 private: |
70 friend class DataUseMeasurementTest; | 72 friend class DataUseMeasurementTest; |
71 FRIEND_TEST_ALL_PREFIXES(DataUseMeasurementTest, | 73 FRIEND_TEST_ALL_PREFIXES(DataUseMeasurementTest, |
72 TimeOfBackgroundDownstreamBytes); | 74 TimeOfBackgroundDownstreamBytes); |
73 | 75 |
74 // Specifies that data is received or sent, respectively. | 76 // Specifies that data is received or sent, respectively. |
75 enum TrafficDirection { DOWNSTREAM, UPSTREAM }; | 77 enum TrafficDirection { DOWNSTREAM, UPSTREAM }; |
76 | 78 |
79 enum TabState { FOREGROUND, BACKGROUND, UNKNOWN }; | |
RyanSturm
2016/12/16 16:26:10
Is this enum really necessary, you treat it as boo
Raj
2016/12/16 19:59:10
Done.
| |
80 | |
77 // Returns the current application state (Foreground or Background). It always | 81 // Returns the current application state (Foreground or Background). It always |
78 // returns Foreground if Chrome is not running on Android. | 82 // returns Foreground if Chrome is not running on Android. |
79 DataUseUserData::AppState CurrentAppState() const; | 83 DataUseUserData::AppState CurrentAppState() const; |
80 | 84 |
81 // Makes the full name of the histogram. It is made from |prefix| and suffix | 85 // Makes the full name of the histogram. It is made from |prefix| and suffix |
82 // which is made based on network and application status. suffix is a string | 86 // which is made based on network and application status. suffix is a string |
83 // representing whether the data use was on the send ("Upstream") or receive | 87 // representing whether the data use was on the send ("Upstream") or receive |
84 // ("Downstream") path, whether the app was in the "Foreground" or | 88 // ("Downstream") path, whether the app was in the "Foreground" or |
85 // "Background", and whether a "Cellular" or "WiFi" network was use. For | 89 // "Background", and whether a "Cellular" or "WiFi" network was use. For |
86 // example, "Prefix.Upstream.Foreground.Cellular" is a possible output. | 90 // example, "Prefix.Upstream.Foreground.Cellular" is a possible output. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 // DataUse.Services.{Dimensions}. In the second one, services are buckets. | 125 // DataUse.Services.{Dimensions}. In the second one, services are buckets. |
122 // |app_state| indicates the app state which can be foreground, background, or | 126 // |app_state| indicates the app state which can be foreground, background, or |
123 // unknown. | 127 // unknown. |
124 void ReportDataUsageServices( | 128 void ReportDataUsageServices( |
125 data_use_measurement::DataUseUserData::ServiceName service, | 129 data_use_measurement::DataUseUserData::ServiceName service, |
126 TrafficDirection dir, | 130 TrafficDirection dir, |
127 DataUseUserData::AppState app_state, | 131 DataUseUserData::AppState app_state, |
128 bool is_connection_cellular, | 132 bool is_connection_cellular, |
129 int64_t message_size) const; | 133 int64_t message_size) const; |
130 | 134 |
135 // A helper function used to record the app and tab state when data use | |
RyanSturm
2016/12/16 16:26:11
How about "Records data use histograms split on Tr
Raj
2016/12/16 19:59:10
Done.
| |
136 // happens. | |
137 void RecordTabStateHistogram(TrafficDirection dir, | |
138 DataUseUserData::AppState app_state, | |
139 TabState tab_state, | |
140 int64_t bytes); | |
141 | |
131 // Classifier for identifying if an URL request is user initiated. | 142 // Classifier for identifying if an URL request is user initiated. |
132 std::unique_ptr<URLRequestClassifier> url_request_classifier_; | 143 std::unique_ptr<URLRequestClassifier> url_request_classifier_; |
133 | 144 |
134 // Callback for updating data use prefs. | 145 // Callback for updating data use prefs. |
135 // TODO(rajendrant): If a similar mechanism would need be used for components | 146 // 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 | 147 // other than metrics, then the better approach would be to refactor this |
137 // class to support registering arbitrary observers. crbug.com/601185 | 148 // class to support registering arbitrary observers. crbug.com/601185 |
138 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_; | 149 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_; |
139 | 150 |
151 // DataUseAscriber used to get the attributes of data use. Not owned by | |
RyanSturm
2016/12/16 16:26:11
I don't think you need to say "Not owned by |this|
Raj
2016/12/16 19:59:10
Done.
| |
152 // |this|. | |
153 DataUseAscriber* ascriber_; | |
154 | |
140 #if defined(OS_ANDROID) | 155 #if defined(OS_ANDROID) |
141 // Application listener store the last known state of the application in this | 156 // Application listener store the last known state of the application in this |
142 // field. | 157 // field. |
143 base::android::ApplicationState app_state_; | 158 base::android::ApplicationState app_state_; |
144 | 159 |
145 // ApplicationStatusListener used to monitor whether the application is in the | 160 // ApplicationStatusListener used to monitor whether the application is in the |
146 // foreground or in the background. It is owned by DataUseMeasurement. | 161 // foreground or in the background. It is owned by DataUseMeasurement. |
147 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; | 162 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; |
148 | 163 |
149 // Number of bytes received and sent by Chromium as reported by the operating | 164 // Number of bytes received and sent by Chromium as reported by the operating |
(...skipping 14 matching lines...) Expand all Loading... | |
164 // True if app is in background and first network read has not yet happened. | 179 // True if app is in background and first network read has not yet happened. |
165 bool no_reads_since_background_; | 180 bool no_reads_since_background_; |
166 #endif | 181 #endif |
167 | 182 |
168 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); | 183 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); |
169 }; | 184 }; |
170 | 185 |
171 } // namespace data_use_measurement | 186 } // namespace data_use_measurement |
172 | 187 |
173 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ | 188 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ |
OLD | NEW |