| 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> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "components/data_use_measurement/core/data_use_user_data.h" | 17 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 18 #include "components/metrics/data_use_tracker.h" | 18 #include "components/metrics/data_use_tracker.h" |
| 19 | 19 |
| 20 #if defined(OS_ANDROID) | 20 #if defined(OS_ANDROID) |
| 21 #include "base/android/application_status_listener.h" | 21 #include "base/android/application_status_listener.h" |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 class GURL; | 24 class GURL; |
| 25 | 25 |
| 26 namespace net { | 26 namespace net { |
| 27 class HttpResponseHeaders; |
| 27 class URLRequest; | 28 class URLRequest; |
| 28 } | 29 } |
| 29 | 30 |
| 30 namespace data_use_measurement { | 31 namespace data_use_measurement { |
| 31 | 32 |
| 32 class DataUseAscriber; | 33 class DataUseAscriber; |
| 33 class URLRequestClassifier; | 34 class URLRequestClassifier; |
| 34 | 35 |
| 35 // Records the data use of user traffic and various services in UMA histograms. | 36 // Records the data use of user traffic and various services in UMA histograms. |
| 36 // The UMA is broken down by network technology used (Wi-Fi vs cellular). On | 37 // The UMA is broken down by network technology used (Wi-Fi vs cellular). On |
| 37 // Android, the UMA is further broken down by whether the application was in the | 38 // Android, the UMA is further broken down by whether the application was in the |
| 38 // background or foreground during the request. | 39 // background or foreground during the request. |
| 39 // TODO(amohammadkhan): Complete the layered architecture. | 40 // TODO(amohammadkhan): Complete the layered architecture. |
| 40 // http://crbug.com/527460 | 41 // http://crbug.com/527460 |
| 41 class DataUseMeasurement { | 42 class DataUseMeasurement { |
| 42 public: | 43 public: |
| 43 DataUseMeasurement( | 44 DataUseMeasurement( |
| 44 std::unique_ptr<URLRequestClassifier> url_request_classifier, | 45 std::unique_ptr<URLRequestClassifier> url_request_classifier, |
| 45 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder, | 46 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder, |
| 46 DataUseAscriber* ascriber); | 47 DataUseAscriber* ascriber); |
| 47 ~DataUseMeasurement(); | 48 ~DataUseMeasurement(); |
| 48 | 49 |
| 49 // Called before a request is sent. | 50 // Called before a request is sent. |
| 50 void OnBeforeURLRequest(net::URLRequest* request); | 51 void OnBeforeURLRequest(net::URLRequest* request); |
| 51 | 52 |
| 52 // Called right after a redirect response code was received for |request|. | 53 // Called right after a redirect response code was received for |request|. |
| 53 void OnBeforeRedirect(const net::URLRequest& request, | 54 void OnBeforeRedirect(const net::URLRequest& request, |
| 54 const GURL& new_location); | 55 const GURL& new_location); |
| 55 | 56 |
| 57 // Called when response headers are received for |request|. |
| 58 void OnHeadersReceived(net::URLRequest* request, |
| 59 const net::HttpResponseHeaders* response_headers); |
| 60 |
| 56 // Called when data is received or sent on the network, respectively. | 61 // Called when data is received or sent on the network, respectively. |
| 57 void OnNetworkBytesReceived(const net::URLRequest& request, | 62 void OnNetworkBytesReceived(const net::URLRequest& request, |
| 58 int64_t bytes_received); | 63 int64_t bytes_received); |
| 59 void OnNetworkBytesSent(const net::URLRequest& request, int64_t bytes_sent); | 64 void OnNetworkBytesSent(const net::URLRequest& request, int64_t bytes_sent); |
| 60 | 65 |
| 61 // Indicates that |request| has been completed or failed. | 66 // Indicates that |request| has been completed or failed. |
| 62 void OnCompleted(const net::URLRequest& request, bool started); | 67 void OnCompleted(const net::URLRequest& request, bool started); |
| 63 | 68 |
| 64 #if defined(OS_ANDROID) | 69 #if defined(OS_ANDROID) |
| 65 // This function should just be used for testing purposes. A change in | 70 // This function should just be used for testing purposes. A change in |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 bool is_connection_cellular, | 135 bool is_connection_cellular, |
| 131 int64_t message_size) const; | 136 int64_t message_size) const; |
| 132 | 137 |
| 133 // Records data use histograms split on TrafficDirection, AppState and | 138 // Records data use histograms split on TrafficDirection, AppState and |
| 134 // TabState. | 139 // TabState. |
| 135 void RecordTabStateHistogram(TrafficDirection dir, | 140 void RecordTabStateHistogram(TrafficDirection dir, |
| 136 DataUseUserData::AppState app_state, | 141 DataUseUserData::AppState app_state, |
| 137 bool is_tab_visible, | 142 bool is_tab_visible, |
| 138 int64_t bytes); | 143 int64_t bytes); |
| 139 | 144 |
| 145 // Records data use histograms of user traffic and services traffic split on |
| 146 // content type, AppState and TabState. |
| 147 void RecordContentTypeHistogram(DataUseUserData::ContentType content_type, |
| 148 bool is_user_traffic, |
| 149 DataUseUserData::AppState app_state, |
| 150 bool is_tab_visible, |
| 151 int64_t bytes); |
| 152 |
| 140 // Classifier for identifying if an URL request is user initiated. | 153 // Classifier for identifying if an URL request is user initiated. |
| 141 std::unique_ptr<URLRequestClassifier> url_request_classifier_; | 154 std::unique_ptr<URLRequestClassifier> url_request_classifier_; |
| 142 | 155 |
| 143 // Callback for updating data use prefs. | 156 // Callback for updating data use prefs. |
| 144 // TODO(rajendrant): If a similar mechanism would need be used for components | 157 // TODO(rajendrant): If a similar mechanism would need be used for components |
| 145 // other than metrics, then the better approach would be to refactor this | 158 // other than metrics, then the better approach would be to refactor this |
| 146 // class to support registering arbitrary observers. crbug.com/601185 | 159 // class to support registering arbitrary observers. crbug.com/601185 |
| 147 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_; | 160 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_; |
| 148 | 161 |
| 149 // DataUseAscriber used to get the attributes of data use. | 162 // DataUseAscriber used to get the attributes of data use. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 176 // True if app is in background and first network read has not yet happened. | 189 // True if app is in background and first network read has not yet happened. |
| 177 bool no_reads_since_background_; | 190 bool no_reads_since_background_; |
| 178 #endif | 191 #endif |
| 179 | 192 |
| 180 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); | 193 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); |
| 181 }; | 194 }; |
| 182 | 195 |
| 183 } // namespace data_use_measurement | 196 } // namespace data_use_measurement |
| 184 | 197 |
| 185 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ | 198 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ |
| OLD | NEW |