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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // A helper function used to record data use of services. It gets the size of | 97 // 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 | 98 // exchanged message, its direction (which is upstream or downstream) and |
94 // reports to two histogram groups. DataUse.MessageSize.ServiceName and | 99 // reports to two histogram groups. DataUse.MessageSize.ServiceName and |
95 // DataUse.Services.{Dimensions}. In the second one, services are buckets. | 100 // DataUse.Services.{Dimensions}. In the second one, services are buckets. |
96 void ReportDataUsageServices( | 101 void ReportDataUsageServices( |
97 data_use_measurement::DataUseUserData::ServiceName service, | 102 data_use_measurement::DataUseUserData::ServiceName service, |
98 TrafficDirection dir, | 103 TrafficDirection dir, |
99 bool is_connection_cellular, | 104 bool is_connection_cellular, |
100 int64_t message_size) const; | 105 int64_t message_size) const; |
101 | 106 |
| 107 // Records the count of bytes received and sent by Chrome on the network as |
| 108 // reported by the operating system. |
| 109 void RecordNetworkBytesReceivedOS(); |
| 110 void RecordNetworkBytesSentOS(); |
| 111 |
102 // Callback for updating data use prefs. | 112 // Callback for updating data use prefs. |
103 // TODO(rajendrant): If a similar mechanism would need be used for components | 113 // 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 | 114 // other than metrics, then the better approach would be to refactor this |
105 // class to support registering arbitrary observers. crbug.com/601185 | 115 // class to support registering arbitrary observers. crbug.com/601185 |
106 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_; | 116 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_; |
107 | 117 |
108 #if defined(OS_ANDROID) | 118 #if defined(OS_ANDROID) |
109 // Application listener store the last known state of the application in this | 119 // Application listener store the last known state of the application in this |
110 // field. | 120 // field. |
111 base::android::ApplicationState app_state_; | 121 base::android::ApplicationState app_state_; |
112 | 122 |
113 // ApplicationStatusListener used to monitor whether the application is in the | 123 // ApplicationStatusListener used to monitor whether the application is in the |
114 // foreground or in the background. It is owned by DataUseMeasurement. | 124 // foreground or in the background. It is owned by DataUseMeasurement. |
115 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; | 125 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; |
| 126 |
| 127 // Number of bytes received and sent by Chromium as reported by the operating |
| 128 // system when it was last queried. Set to 0 if the operating system was never |
| 129 // queried. |
| 130 int64_t rx_bytes_os_; |
| 131 int64_t tx_bytes_os_; |
116 #endif | 132 #endif |
117 | 133 |
118 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); | 134 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); |
119 }; | 135 }; |
120 | 136 |
121 } // namespace data_use_measurement | 137 } // namespace data_use_measurement |
122 | 138 |
123 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ | 139 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ |
OLD | NEW |