Chromium Code Reviews| 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" |
| 15 #include "base/memory/weak_ptr.h" | |
| 14 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 15 #include "components/data_use_measurement/core/data_use_user_data.h" | 17 #include "components/data_use_measurement/core/data_use_user_data.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 } |
| (...skipping 14 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 void SetMetricsDataUseForwarder( | |
| 51 base::Callback<void(const std::string&, int)> metrics_data_use_forwarder); | |
| 52 | |
| 53 base::WeakPtr<DataUseMeasurement> GetWeakPtr(); | |
| 54 | |
| 48 private: | 55 private: |
| 49 // Specifies that data is received or sent, respectively. | 56 // Specifies that data is received or sent, respectively. |
| 50 enum TrafficDirection { DOWNSTREAM, UPSTREAM }; | 57 enum TrafficDirection { DOWNSTREAM, UPSTREAM }; |
| 51 | 58 |
| 52 // The state of the application. Only available on Android and on other | 59 // The state of the application. Only available on Android and on other |
| 53 // platforms it is always FOREGROUND. | 60 // platforms it is always FOREGROUND. |
| 54 enum AppState { BACKGROUND, FOREGROUND }; | 61 enum AppState { BACKGROUND, FOREGROUND }; |
| 55 | 62 |
| 56 // Returns the current application state (Foreground or Background). It always | 63 // Returns the current application state (Foreground or Background). It always |
| 57 // returns Foreground if Chrome is not running on Android. | 64 // returns Foreground if Chrome is not running on Android. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 74 | 81 |
| 75 // A helper function used to record data use of services. It gets the size of | 82 // 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 | 83 // exchanged message, its direction (which is upstream or downstream) and |
| 77 // reports to two histogram groups. DataUse.MessageSize.ServiceName and | 84 // reports to two histogram groups. DataUse.MessageSize.ServiceName and |
| 78 // DataUse.Services.{Dimensions}. In the second one, services are buckets. | 85 // DataUse.Services.{Dimensions}. In the second one, services are buckets. |
| 79 void ReportDataUsageServices( | 86 void ReportDataUsageServices( |
| 80 data_use_measurement::DataUseUserData::ServiceName service, | 87 data_use_measurement::DataUseUserData::ServiceName service, |
| 81 TrafficDirection dir, | 88 TrafficDirection dir, |
| 82 int64_t message_size) const; | 89 int64_t message_size) const; |
| 83 | 90 |
| 91 base::Callback<void(const std::string&, int)> 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 |
| 103 base::WeakPtrFactory<DataUseMeasurement> weak_ptr_factory_; | |
| 94 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); | 104 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); |
|
Alexei Svitkine (slow)
2016/03/29 16:29:10
Add an empty line above it.
gayane -on leave until 09-2017
2016/03/31 01:38:24
Done.
| |
| 95 }; | 105 }; |
| 96 | 106 |
| 97 } // namespace data_use_measurement | 107 } // namespace data_use_measurement |
| 98 | 108 |
| 99 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ | 109 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ |
| OLD | NEW |