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" |
| 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" | |
|
gayane -on leave until 09-2017
2016/04/01 20:34:44
The only reason we have this dependency is because
Alexei Svitkine (slow)
2016/04/01 20:40:32
Yeah I thought of this too. I'm ok with this, but
| |
| 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 { |
| 26 | 28 |
| 27 // Records the data use of user traffic and various services in UMA histograms. | 29 // Records the data use of user traffic and various services in UMA histograms. |
| 28 // The UMA is broken down by network technology used (Wi-Fi vs cellular). On | 30 // The UMA is broken down by network technology used (Wi-Fi vs cellular). On |
| 29 // Android, the UMA is further broken down by whether the application was in the | 31 // Android, the UMA is further broken down by whether the application was in the |
| 30 // background or foreground during the request. | 32 // background or foreground during the request. |
| 31 // TODO(amohammadkhan): Complete the layered architecture. | 33 // TODO(amohammadkhan): Complete the layered architecture. |
| 32 // http://crbug.com/527460 | 34 // http://crbug.com/527460 |
| 33 class DataUseMeasurement { | 35 class DataUseMeasurement { |
| 34 public: | 36 public: |
| 35 DataUseMeasurement(); | 37 explicit DataUseMeasurement( |
| 38 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder); | |
| 36 ~DataUseMeasurement(); | 39 ~DataUseMeasurement(); |
| 37 | 40 |
| 38 // Records the data use of the |request|, thus |request| must be non-null. | 41 // Records the data use of the |request|, thus |request| must be non-null. |
| 39 void ReportDataUseUMA(const net::URLRequest* request) const; | 42 void ReportDataUseUMA(const net::URLRequest* request) const; |
| 40 | 43 |
| 41 #if defined(OS_ANDROID) | 44 #if defined(OS_ANDROID) |
| 42 // This function should just be used for testing purposes. A change in | 45 // This function should just be used for testing purposes. A change in |
| 43 // application state can be simulated by calling this function. | 46 // application state can be simulated by calling this function. |
| 44 void OnApplicationStateChangeForTesting( | 47 void OnApplicationStateChangeForTesting( |
| 45 base::android::ApplicationState application_state); | 48 base::android::ApplicationState application_state); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 56 // Returns the current application state (Foreground or Background). It always | 59 // Returns the current application state (Foreground or Background). It always |
| 57 // returns Foreground if Chrome is not running on Android. | 60 // returns Foreground if Chrome is not running on Android. |
| 58 AppState CurrentAppState() const; | 61 AppState CurrentAppState() const; |
| 59 | 62 |
| 60 // Makes the full name of the histogram. It is made from |prefix| and suffix | 63 // Makes the full name of the histogram. It is made from |prefix| and suffix |
| 61 // which is made based on network and application status. suffix is a string | 64 // which is made based on network and application status. suffix is a string |
| 62 // representing whether the data use was on the send ("Upstream") or receive | 65 // representing whether the data use was on the send ("Upstream") or receive |
| 63 // ("Downstream") path, whether the app was in the "Foreground" or | 66 // ("Downstream") path, whether the app was in the "Foreground" or |
| 64 // "Background", and whether a "Cellular" or "WiFi" network was use. For | 67 // "Background", and whether a "Cellular" or "WiFi" network was use. For |
| 65 // example, "Prefix.Upstream.Foreground.Cellular" is a possible output. | 68 // example, "Prefix.Upstream.Foreground.Cellular" is a possible output. |
| 66 std::string GetHistogramName(const char* prefix, TrafficDirection dir) const; | 69 std::string GetHistogramName(const char* prefix, |
| 70 TrafficDirection dir, | |
| 71 bool is_conn_cellular) const; | |
| 67 | 72 |
| 68 #if defined(OS_ANDROID) | 73 #if defined(OS_ANDROID) |
| 69 // Called whenever the application transitions from foreground to background | 74 // Called whenever the application transitions from foreground to background |
| 70 // and vice versa. | 75 // and vice versa. |
| 71 void OnApplicationStateChange( | 76 void OnApplicationStateChange( |
| 72 base::android::ApplicationState application_state); | 77 base::android::ApplicationState application_state); |
| 73 #endif | 78 #endif |
| 74 | 79 |
| 75 // A helper function used to record data use of services. It gets the size of | 80 // 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 | 81 // exchanged message, its direction (which is upstream or downstream) and |
| 77 // reports to two histogram groups. DataUse.MessageSize.ServiceName and | 82 // reports to two histogram groups. DataUse.MessageSize.ServiceName and |
| 78 // DataUse.Services.{Dimensions}. In the second one, services are buckets. | 83 // DataUse.Services.{Dimensions}. In the second one, services are buckets. |
| 79 void ReportDataUsageServices( | 84 void ReportDataUsageServices( |
| 80 data_use_measurement::DataUseUserData::ServiceName service, | 85 data_use_measurement::DataUseUserData::ServiceName service, |
| 81 TrafficDirection dir, | 86 TrafficDirection dir, |
| 87 bool is_conn_cellular, | |
| 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 |