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 <string> | 10 #include <string> |
11 | 11 |
| 12 #include "base/callback.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
15 #include "components/data_use_measurement/core/data_use_user_data.h" | 16 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 17 #include "components/metrics/data_use_tracker.h" |
16 | 18 |
17 #if defined(OS_ANDROID) | 19 #if defined(OS_ANDROID) |
18 #include "base/android/application_status_listener.h" | 20 #include "base/android/application_status_listener.h" |
19 #endif | 21 #endif |
20 | 22 |
21 namespace net { | 23 namespace net { |
22 class URLRequest; | 24 class URLRequest; |
23 } | 25 } |
24 | 26 |
25 namespace data_use_measurement { | 27 namespace data_use_measurement { |
(...skipping 12 matching lines...) Expand all Loading... |
38 // Records the data use of the |request|, thus |request| must be non-null. | 40 // Records the data use of the |request|, thus |request| must be non-null. |
39 void ReportDataUseUMA(const net::URLRequest* request) const; | 41 void ReportDataUseUMA(const net::URLRequest* request) const; |
40 | 42 |
41 #if defined(OS_ANDROID) | 43 #if defined(OS_ANDROID) |
42 // This function should just be used for testing purposes. A change in | 44 // This function should just be used for testing purposes. A change in |
43 // application state can be simulated by calling this function. | 45 // application state can be simulated by calling this function. |
44 void OnApplicationStateChangeForTesting( | 46 void OnApplicationStateChangeForTesting( |
45 base::android::ApplicationState application_state); | 47 base::android::ApplicationState application_state); |
46 #endif | 48 #endif |
47 | 49 |
| 50 // Sets callback for updating data use prefs. |
| 51 void SetMetricsDataUseForwarder( |
| 52 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder); |
| 53 |
48 private: | 54 private: |
49 // Specifies that data is received or sent, respectively. | 55 // Specifies that data is received or sent, respectively. |
50 enum TrafficDirection { DOWNSTREAM, UPSTREAM }; | 56 enum TrafficDirection { DOWNSTREAM, UPSTREAM }; |
51 | 57 |
52 // The state of the application. Only available on Android and on other | 58 // The state of the application. Only available on Android and on other |
53 // platforms it is always FOREGROUND. | 59 // platforms it is always FOREGROUND. |
54 enum AppState { BACKGROUND, FOREGROUND }; | 60 enum AppState { BACKGROUND, FOREGROUND }; |
55 | 61 |
56 // Returns the current application state (Foreground or Background). It always | 62 // Returns the current application state (Foreground or Background). It always |
57 // returns Foreground if Chrome is not running on Android. | 63 // returns Foreground if Chrome is not running on Android. |
(...skipping 16 matching lines...) Expand all Loading... |
74 | 80 |
75 // A helper function used to record data use of services. It gets the size of | 81 // A helper function used to record data use of services. It gets the size of |
76 // exchanged message, its direction (which is upstream or downstream) and | 82 // exchanged message, its direction (which is upstream or downstream) and |
77 // reports to two histogram groups. DataUse.MessageSize.ServiceName and | 83 // reports to two histogram groups. DataUse.MessageSize.ServiceName and |
78 // DataUse.Services.{Dimensions}. In the second one, services are buckets. | 84 // DataUse.Services.{Dimensions}. In the second one, services are buckets. |
79 void ReportDataUsageServices( | 85 void ReportDataUsageServices( |
80 data_use_measurement::DataUseUserData::ServiceName service, | 86 data_use_measurement::DataUseUserData::ServiceName service, |
81 TrafficDirection dir, | 87 TrafficDirection dir, |
82 int64_t message_size) const; | 88 int64_t message_size) const; |
83 | 89 |
| 90 // Callback for updating data use prefs. |
| 91 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_; |
| 92 |
84 #if defined(OS_ANDROID) | 93 #if defined(OS_ANDROID) |
85 // Application listener store the last known state of the application in this | 94 // Application listener store the last known state of the application in this |
86 // field. | 95 // field. |
87 base::android::ApplicationState app_state_; | 96 base::android::ApplicationState app_state_; |
88 | 97 |
89 // ApplicationStatusListener used to monitor whether the application is in the | 98 // ApplicationStatusListener used to monitor whether the application is in the |
90 // foreground or in the background. It is owned by DataUseMeasurement. | 99 // foreground or in the background. It is owned by DataUseMeasurement. |
91 scoped_ptr<base::android::ApplicationStatusListener> app_listener_; | 100 scoped_ptr<base::android::ApplicationStatusListener> app_listener_; |
92 #endif | 101 #endif |
93 | 102 |
94 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); | 103 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); |
95 }; | 104 }; |
96 | 105 |
97 } // namespace data_use_measurement | 106 } // namespace data_use_measurement |
98 | 107 |
99 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ | 108 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ |
OLD | NEW |