| 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 "build/build_config.h" | 16 #include "build/build_config.h" |
| 16 #include "components/data_use_measurement/core/data_use_user_data.h" | 17 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 17 #include "components/metrics/data_use_tracker.h" | 18 #include "components/metrics/data_use_tracker.h" |
| 18 | 19 |
| 19 #if defined(OS_ANDROID) | 20 #if defined(OS_ANDROID) |
| 20 #include "base/android/application_status_listener.h" | 21 #include "base/android/application_status_listener.h" |
| 21 #endif | 22 #endif |
| 22 | 23 |
| 23 class GURL; | 24 class GURL; |
| 24 | 25 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 61 |
| 61 #if defined(OS_ANDROID) | 62 #if defined(OS_ANDROID) |
| 62 // This function should just be used for testing purposes. A change in | 63 // This function should just be used for testing purposes. A change in |
| 63 // application state can be simulated by calling this function. | 64 // application state can be simulated by calling this function. |
| 64 void OnApplicationStateChangeForTesting( | 65 void OnApplicationStateChangeForTesting( |
| 65 base::android::ApplicationState application_state); | 66 base::android::ApplicationState application_state); |
| 66 #endif | 67 #endif |
| 67 | 68 |
| 68 private: | 69 private: |
| 69 friend class DataUseMeasurementTest; | 70 friend class DataUseMeasurementTest; |
| 71 FRIEND_TEST_ALL_PREFIXES(DataUseMeasurementTest, |
| 72 TimeOfBackgroundDownstreamBytes); |
| 70 | 73 |
| 71 // Specifies that data is received or sent, respectively. | 74 // Specifies that data is received or sent, respectively. |
| 72 enum TrafficDirection { DOWNSTREAM, UPSTREAM }; | 75 enum TrafficDirection { DOWNSTREAM, UPSTREAM }; |
| 73 | 76 |
| 74 // Returns the current application state (Foreground or Background). It always | 77 // Returns the current application state (Foreground or Background). It always |
| 75 // returns Foreground if Chrome is not running on Android. | 78 // returns Foreground if Chrome is not running on Android. |
| 76 DataUseUserData::AppState CurrentAppState() const; | 79 DataUseUserData::AppState CurrentAppState() const; |
| 77 | 80 |
| 78 // Makes the full name of the histogram. It is made from |prefix| and suffix | 81 // 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 | 82 // which is made based on network and application status. suffix is a string |
| (...skipping 16 matching lines...) Expand all Loading... |
| 96 | 99 |
| 97 // Records the count of bytes received and sent by Chrome on the network as | 100 // Records the count of bytes received and sent by Chrome on the network as |
| 98 // reported by the operating system. | 101 // reported by the operating system. |
| 99 void MaybeRecordNetworkBytesOS(); | 102 void MaybeRecordNetworkBytesOS(); |
| 100 #endif | 103 #endif |
| 101 | 104 |
| 102 // Records the data use of the |request|, thus |request| must be non-null. | 105 // Records the data use of the |request|, thus |request| must be non-null. |
| 103 // |dir| is the direction (which is upstream or downstream) and |bytes| is the | 106 // |dir| is the direction (which is upstream or downstream) and |bytes| is the |
| 104 // number of bytes in the direction. | 107 // number of bytes in the direction. |
| 105 void ReportDataUseUMA(const net::URLRequest& request, | 108 void ReportDataUseUMA(const net::URLRequest& request, |
| 106 TrafficDirection dir, | 109 TrafficDirection dir, |
| 107 int64_t bytes) const; | 110 int64_t bytes); |
| 108 | 111 |
| 109 // Updates the data use of the |request|, thus |request| must be non-null. | 112 // Updates the data use of the |request|, thus |request| must be non-null. |
| 110 void UpdateDataUsePrefs(const net::URLRequest& request) const; | 113 void UpdateDataUsePrefs(const net::URLRequest& request) const; |
| 111 | 114 |
| 112 // A helper function used to record data use of services. It gets the size of | 115 // A helper function used to record data use of services. It gets the size of |
| 113 // exchanged message, its direction (which is upstream or downstream) and | 116 // exchanged message, its direction (which is upstream or downstream) and |
| 114 // reports to two histogram groups. DataUse.MessageSize.ServiceName and | 117 // reports to two histogram groups. DataUse.MessageSize.ServiceName and |
| 115 // DataUse.Services.{Dimensions}. In the second one, services are buckets. | 118 // DataUse.Services.{Dimensions}. In the second one, services are buckets. |
| 116 // |app_state| indicates the app state which can be foreground, background, or | 119 // |app_state| indicates the app state which can be foreground, background, or |
| 117 // unknown. | 120 // unknown. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 140 // Number of bytes received and sent by Chromium as reported by the operating | 143 // Number of bytes received and sent by Chromium as reported by the operating |
| 141 // system when it was last queried for traffic statistics. Set to 0 if the | 144 // system when it was last queried for traffic statistics. Set to 0 if the |
| 142 // operating system was never queried. | 145 // operating system was never queried. |
| 143 int64_t rx_bytes_os_; | 146 int64_t rx_bytes_os_; |
| 144 int64_t tx_bytes_os_; | 147 int64_t tx_bytes_os_; |
| 145 | 148 |
| 146 // Number of bytes received and sent by Chromium as reported by the network | 149 // Number of bytes received and sent by Chromium as reported by the network |
| 147 // delegate since the operating system was last queried for traffic | 150 // delegate since the operating system was last queried for traffic |
| 148 // statistics. | 151 // statistics. |
| 149 int64_t bytes_transferred_since_last_traffic_stats_query_; | 152 int64_t bytes_transferred_since_last_traffic_stats_query_; |
| 153 |
| 154 // The time at which Chromium app state changed to background. Can be null if |
| 155 // app is not in background. |
| 156 base::TimeTicks last_app_background_time_; |
| 157 |
| 158 // True if app is in background and first network read has not yet happened. |
| 159 bool no_reads_since_background_; |
| 150 #endif | 160 #endif |
| 151 | 161 |
| 152 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); | 162 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); |
| 153 }; | 163 }; |
| 154 | 164 |
| 155 } // namespace data_use_measurement | 165 } // namespace data_use_measurement |
| 156 | 166 |
| 157 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ | 167 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ |
| OLD | NEW |