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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // Returns the current application state (Foreground or Background). It always | 74 // Returns the current application state (Foreground or Background). It always |
75 // returns Foreground if Chrome is not running on Android. | 75 // returns Foreground if Chrome is not running on Android. |
76 DataUseUserData::AppState CurrentAppState() const; | 76 DataUseUserData::AppState CurrentAppState() const; |
77 | 77 |
78 // Makes the full name of the histogram. It is made from |prefix| and suffix | 78 // Makes the full name of the histogram. It is made from |prefix| and suffix |
79 // which is made based on network and application status. suffix is a string | 79 // which is made based on network and application status. suffix is a string |
80 // representing whether the data use was on the send ("Upstream") or receive | 80 // representing whether the data use was on the send ("Upstream") or receive |
81 // ("Downstream") path, whether the app was in the "Foreground" or | 81 // ("Downstream") path, whether the app was in the "Foreground" or |
82 // "Background", and whether a "Cellular" or "WiFi" network was use. For | 82 // "Background", and whether a "Cellular" or "WiFi" network was use. For |
83 // example, "Prefix.Upstream.Foreground.Cellular" is a possible output. | 83 // example, "Prefix.Upstream.Foreground.Cellular" is a possible output. |
84 // |started_in_foreground| indicates if the request started when the app was | 84 // |app_state| indicates the app state which can be foreground, background, or |
85 // in foreground. | 85 // unknown. |
86 std::string GetHistogramName(const char* prefix, | 86 std::string GetHistogramName(const char* prefix, |
87 TrafficDirection dir, | 87 TrafficDirection dir, |
88 bool started_in_foreground, | 88 DataUseUserData::AppState app_state, |
89 bool is_connection_cellular) const; | 89 bool is_connection_cellular) const; |
90 | 90 |
91 #if defined(OS_ANDROID) | 91 #if defined(OS_ANDROID) |
92 // Called whenever the application transitions from foreground to background | 92 // Called whenever the application transitions from foreground to background |
93 // and vice versa. | 93 // and vice versa. |
94 void OnApplicationStateChange( | 94 void OnApplicationStateChange( |
95 base::android::ApplicationState application_state); | 95 base::android::ApplicationState application_state); |
96 | 96 |
97 // Records the count of bytes received and sent by Chrome on the network as | 97 // Records the count of bytes received and sent by Chrome on the network as |
98 // reported by the operating system. | 98 // reported by the operating system. |
99 void MaybeRecordNetworkBytesOS(); | 99 void MaybeRecordNetworkBytesOS(); |
100 #endif | 100 #endif |
101 | 101 |
102 // Records the data use of the |request|, thus |request| must be non-null. | 102 // Records the data use of the |request|, thus |request| must be non-null. |
103 void ReportDataUseUMA(const net::URLRequest& request) const; | 103 // |dir| is the direction (which is upstream or downstream) and |bytes| is the |
| 104 // number of bytes in the direction. |
| 105 void ReportDataUseUMA(const net::URLRequest& request, |
| 106 TrafficDirection dir, |
| 107 int64_t bytes) const; |
| 108 |
| 109 // Updates the data use of the |request|, thus |request| must be non-null. |
| 110 void UpdateDataUsePrefs(const net::URLRequest& request) const; |
104 | 111 |
105 // A helper function used to record data use of services. It gets the size of | 112 // A helper function used to record data use of services. It gets the size of |
106 // exchanged message, its direction (which is upstream or downstream) and | 113 // exchanged message, its direction (which is upstream or downstream) and |
107 // reports to two histogram groups. DataUse.MessageSize.ServiceName and | 114 // reports to two histogram groups. DataUse.MessageSize.ServiceName and |
108 // DataUse.Services.{Dimensions}. In the second one, services are buckets. | 115 // DataUse.Services.{Dimensions}. In the second one, services are buckets. |
109 // |started_in_foreground| indicates if the request started when the app was | 116 // |app_state| indicates the app state which can be foreground, background, or |
110 // in foreground. | 117 // unknown. |
111 void ReportDataUsageServices( | 118 void ReportDataUsageServices( |
112 data_use_measurement::DataUseUserData::ServiceName service, | 119 data_use_measurement::DataUseUserData::ServiceName service, |
113 TrafficDirection dir, | 120 TrafficDirection dir, |
114 bool started_in_foreground, | 121 DataUseUserData::AppState app_state, |
115 bool is_connection_cellular, | 122 bool is_connection_cellular, |
116 int64_t message_size) const; | 123 int64_t message_size) const; |
117 | 124 |
118 // Callback for updating data use prefs. | 125 // Callback for updating data use prefs. |
119 // TODO(rajendrant): If a similar mechanism would need be used for components | 126 // TODO(rajendrant): If a similar mechanism would need be used for components |
120 // other than metrics, then the better approach would be to refactor this | 127 // other than metrics, then the better approach would be to refactor this |
121 // class to support registering arbitrary observers. crbug.com/601185 | 128 // class to support registering arbitrary observers. crbug.com/601185 |
122 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_; | 129 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_; |
123 | 130 |
124 #if defined(OS_ANDROID) | 131 #if defined(OS_ANDROID) |
(...skipping 16 matching lines...) Expand all Loading... |
141 // statistics. | 148 // statistics. |
142 int64_t bytes_transferred_since_last_traffic_stats_query_; | 149 int64_t bytes_transferred_since_last_traffic_stats_query_; |
143 #endif | 150 #endif |
144 | 151 |
145 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); | 152 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); |
146 }; | 153 }; |
147 | 154 |
148 } // namespace data_use_measurement | 155 } // namespace data_use_measurement |
149 | 156 |
150 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ | 157 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ |
OLD | NEW |