| 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 26 matching lines...) Expand all Loading... |
| 37 class DataUseMeasurement { | 37 class DataUseMeasurement { |
| 38 public: | 38 public: |
| 39 explicit DataUseMeasurement( | 39 explicit DataUseMeasurement( |
| 40 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder); | 40 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder); |
| 41 ~DataUseMeasurement(); | 41 ~DataUseMeasurement(); |
| 42 | 42 |
| 43 // Called right after a redirect response code was received for |request|. | 43 // Called right after a redirect response code was received for |request|. |
| 44 void OnBeforeRedirect(const net::URLRequest& request, | 44 void OnBeforeRedirect(const net::URLRequest& request, |
| 45 const GURL& new_location); | 45 const GURL& new_location); |
| 46 | 46 |
| 47 // Called when data is received or sent on the network, respectively. |
| 48 void OnNetworkBytesReceived(const net::URLRequest& request, |
| 49 int64_t bytes_received); |
| 50 void OnNetworkBytesSent(const net::URLRequest& request, int64_t bytes_sent); |
| 51 |
| 47 // Indicates that |request| has been completed or failed. | 52 // Indicates that |request| has been completed or failed. |
| 48 void OnCompleted(const net::URLRequest& request, bool started); | 53 void OnCompleted(const net::URLRequest& request, bool started); |
| 49 | 54 |
| 50 // Returns true if the URLRequest |request| is initiated by user traffic. | 55 // Returns true if the URLRequest |request| is initiated by user traffic. |
| 51 static bool IsUserInitiatedRequest(const net::URLRequest& request); | 56 static bool IsUserInitiatedRequest(const net::URLRequest& request); |
| 52 | 57 |
| 53 #if defined(OS_ANDROID) | 58 #if defined(OS_ANDROID) |
| 54 // This function should just be used for testing purposes. A change in | 59 // This function should just be used for testing purposes. A change in |
| 55 // application state can be simulated by calling this function. | 60 // application state can be simulated by calling this function. |
| 56 void OnApplicationStateChangeForTesting( | 61 void OnApplicationStateChangeForTesting( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 77 // example, "Prefix.Upstream.Foreground.Cellular" is a possible output. | 82 // example, "Prefix.Upstream.Foreground.Cellular" is a possible output. |
| 78 std::string GetHistogramName(const char* prefix, | 83 std::string GetHistogramName(const char* prefix, |
| 79 TrafficDirection dir, | 84 TrafficDirection dir, |
| 80 bool is_connection_cellular) const; | 85 bool is_connection_cellular) const; |
| 81 | 86 |
| 82 #if defined(OS_ANDROID) | 87 #if defined(OS_ANDROID) |
| 83 // Called whenever the application transitions from foreground to background | 88 // Called whenever the application transitions from foreground to background |
| 84 // and vice versa. | 89 // and vice versa. |
| 85 void OnApplicationStateChange( | 90 void OnApplicationStateChange( |
| 86 base::android::ApplicationState application_state); | 91 base::android::ApplicationState application_state); |
| 92 |
| 93 // Records the count of bytes received and sent by Chrome on the network as |
| 94 // reported by the operating system. |
| 95 void MaybeRecordNetworkBytesOS(); |
| 87 #endif | 96 #endif |
| 88 | 97 |
| 89 // Records the data use of the |request|, thus |request| must be non-null. | 98 // Records the data use of the |request|, thus |request| must be non-null. |
| 90 void ReportDataUseUMA(const net::URLRequest& request) const; | 99 void ReportDataUseUMA(const net::URLRequest& request) const; |
| 91 | 100 |
| 92 // A helper function used to record data use of services. It gets the size of | 101 // A helper function used to record data use of services. It gets the size of |
| 93 // exchanged message, its direction (which is upstream or downstream) and | 102 // exchanged message, its direction (which is upstream or downstream) and |
| 94 // reports to two histogram groups. DataUse.MessageSize.ServiceName and | 103 // reports to two histogram groups. DataUse.MessageSize.ServiceName and |
| 95 // DataUse.Services.{Dimensions}. In the second one, services are buckets. | 104 // DataUse.Services.{Dimensions}. In the second one, services are buckets. |
| 96 void ReportDataUsageServices( | 105 void ReportDataUsageServices( |
| 97 data_use_measurement::DataUseUserData::ServiceName service, | 106 data_use_measurement::DataUseUserData::ServiceName service, |
| 98 TrafficDirection dir, | 107 TrafficDirection dir, |
| 99 bool is_connection_cellular, | 108 bool is_connection_cellular, |
| 100 int64_t message_size) const; | 109 int64_t message_size) const; |
| 101 | 110 |
| 102 // Callback for updating data use prefs. | 111 // Callback for updating data use prefs. |
| 103 // TODO(rajendrant): If a similar mechanism would need be used for components | 112 // TODO(rajendrant): If a similar mechanism would need be used for components |
| 104 // other than metrics, then the better approach would be to refactor this | 113 // other than metrics, then the better approach would be to refactor this |
| 105 // class to support registering arbitrary observers. crbug.com/601185 | 114 // class to support registering arbitrary observers. crbug.com/601185 |
| 106 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_; | 115 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_; |
| 107 | 116 |
| 108 #if defined(OS_ANDROID) | 117 #if defined(OS_ANDROID) |
| 109 // Application listener store the last known state of the application in this | 118 // Application listener store the last known state of the application in this |
| 110 // field. | 119 // field. |
| 111 base::android::ApplicationState app_state_; | 120 base::android::ApplicationState app_state_; |
| 112 | 121 |
| 113 // ApplicationStatusListener used to monitor whether the application is in the | 122 // ApplicationStatusListener used to monitor whether the application is in the |
| 114 // foreground or in the background. It is owned by DataUseMeasurement. | 123 // foreground or in the background. It is owned by DataUseMeasurement. |
| 115 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; | 124 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; |
| 125 |
| 126 // Number of bytes received and sent by Chromium as reported by the operating |
| 127 // system when it was last queried for traffic statistics. Set to 0 if the |
| 128 // operating system was never queried. |
| 129 int64_t rx_bytes_os_; |
| 130 int64_t tx_bytes_os_; |
| 131 |
| 132 // Number of bytes received and sent by Chromium as reported by the network |
| 133 // delegate since the operating system was last queried for traffic |
| 134 // statistics. |
| 135 int64_t bytes_transferred_since_last_traffic_stats_query_; |
| 116 #endif | 136 #endif |
| 117 | 137 |
| 118 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); | 138 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); |
| 119 }; | 139 }; |
| 120 | 140 |
| 121 } // namespace data_use_measurement | 141 } // namespace data_use_measurement |
| 122 | 142 |
| 123 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ | 143 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ |
| OLD | NEW |