| 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 19 matching lines...) Expand all Loading... |
| 30 namespace data_use_measurement { | 30 namespace data_use_measurement { |
| 31 | 31 |
| 32 // Records the data use of user traffic and various services in UMA histograms. | 32 // 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 | 33 // 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 | 34 // Android, the UMA is further broken down by whether the application was in the |
| 35 // background or foreground during the request. | 35 // background or foreground during the request. |
| 36 // TODO(amohammadkhan): Complete the layered architecture. | 36 // TODO(amohammadkhan): Complete the layered architecture. |
| 37 // http://crbug.com/527460 | 37 // http://crbug.com/527460 |
| 38 class DataUseMeasurement { | 38 class DataUseMeasurement { |
| 39 public: | 39 public: |
| 40 explicit DataUseMeasurement( | 40 typedef base::Callback<bool(const net::URLRequest&)> |
| 41 IsUserInitiatedRequestCallbackType; |
| 42 |
| 43 DataUseMeasurement( |
| 44 const IsUserInitiatedRequestCallbackType& |
| 45 is_user_initiated_request_callback, |
| 41 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder); | 46 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder); |
| 42 ~DataUseMeasurement(); | 47 ~DataUseMeasurement(); |
| 43 | 48 |
| 44 // Called before a request is sent. | 49 // Called before a request is sent. |
| 45 void OnBeforeURLRequest(net::URLRequest* request); | 50 void OnBeforeURLRequest(net::URLRequest* request); |
| 46 | 51 |
| 47 // Called right after a redirect response code was received for |request|. | 52 // Called right after a redirect response code was received for |request|. |
| 48 void OnBeforeRedirect(const net::URLRequest& request, | 53 void OnBeforeRedirect(const net::URLRequest& request, |
| 49 const GURL& new_location); | 54 const GURL& new_location); |
| 50 | 55 |
| 51 // Called when data is received or sent on the network, respectively. | 56 // Called when data is received or sent on the network, respectively. |
| 52 void OnNetworkBytesReceived(const net::URLRequest& request, | 57 void OnNetworkBytesReceived(const net::URLRequest& request, |
| 53 int64_t bytes_received); | 58 int64_t bytes_received); |
| 54 void OnNetworkBytesSent(const net::URLRequest& request, int64_t bytes_sent); | 59 void OnNetworkBytesSent(const net::URLRequest& request, int64_t bytes_sent); |
| 55 | 60 |
| 56 // Indicates that |request| has been completed or failed. | 61 // Indicates that |request| has been completed or failed. |
| 57 void OnCompleted(const net::URLRequest& request, bool started); | 62 void OnCompleted(const net::URLRequest& request, bool started); |
| 58 | 63 |
| 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) | 64 #if defined(OS_ANDROID) |
| 63 // This function should just be used for testing purposes. A change in | 65 // This function should just be used for testing purposes. A change in |
| 64 // application state can be simulated by calling this function. | 66 // application state can be simulated by calling this function. |
| 65 void OnApplicationStateChangeForTesting( | 67 void OnApplicationStateChangeForTesting( |
| 66 base::android::ApplicationState application_state); | 68 base::android::ApplicationState application_state); |
| 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, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // DataUse.Services.{Dimensions}. In the second one, services are buckets. | 120 // DataUse.Services.{Dimensions}. In the second one, services are buckets. |
| 119 // |app_state| indicates the app state which can be foreground, background, or | 121 // |app_state| indicates the app state which can be foreground, background, or |
| 120 // unknown. | 122 // unknown. |
| 121 void ReportDataUsageServices( | 123 void ReportDataUsageServices( |
| 122 data_use_measurement::DataUseUserData::ServiceName service, | 124 data_use_measurement::DataUseUserData::ServiceName service, |
| 123 TrafficDirection dir, | 125 TrafficDirection dir, |
| 124 DataUseUserData::AppState app_state, | 126 DataUseUserData::AppState app_state, |
| 125 bool is_connection_cellular, | 127 bool is_connection_cellular, |
| 126 int64_t message_size) const; | 128 int64_t message_size) const; |
| 127 | 129 |
| 130 // Callback for identifying if an URL request is user initiated. |
| 131 const IsUserInitiatedRequestCallbackType is_user_initiated_request_callback_; |
| 132 |
| 128 // Callback for updating data use prefs. | 133 // Callback for updating data use prefs. |
| 129 // TODO(rajendrant): If a similar mechanism would need be used for components | 134 // 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 | 135 // other than metrics, then the better approach would be to refactor this |
| 131 // class to support registering arbitrary observers. crbug.com/601185 | 136 // class to support registering arbitrary observers. crbug.com/601185 |
| 132 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_; | 137 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_; |
| 133 | 138 |
| 134 #if defined(OS_ANDROID) | 139 #if defined(OS_ANDROID) |
| 135 // Application listener store the last known state of the application in this | 140 // Application listener store the last known state of the application in this |
| 136 // field. | 141 // field. |
| 137 base::android::ApplicationState app_state_; | 142 base::android::ApplicationState app_state_; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 158 // True if app is in background and first network read has not yet happened. | 163 // True if app is in background and first network read has not yet happened. |
| 159 bool no_reads_since_background_; | 164 bool no_reads_since_background_; |
| 160 #endif | 165 #endif |
| 161 | 166 |
| 162 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); | 167 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); |
| 163 }; | 168 }; |
| 164 | 169 |
| 165 } // namespace data_use_measurement | 170 } // namespace data_use_measurement |
| 166 | 171 |
| 167 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ | 172 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ |
| OLD | NEW |