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 <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 "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #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" | 17 #include "components/metrics/data_use_tracker.h" |
| 18 | 18 |
| 19 #if defined(OS_ANDROID) | 19 #if defined(OS_ANDROID) |
| 20 #include "base/android/application_status_listener.h" | 20 #include "base/android/application_status_listener.h" |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 class GURL; | |
| 24 | |
| 23 namespace net { | 25 namespace net { |
| 24 class URLRequest; | 26 class URLRequest; |
| 25 } | 27 } |
| 26 | 28 |
| 27 namespace data_use_measurement { | 29 namespace data_use_measurement { |
| 28 | 30 |
| 29 // Records the data use of user traffic and various services in UMA histograms. | 31 // Records the data use of user traffic and various services in UMA histograms. |
| 30 // The UMA is broken down by network technology used (Wi-Fi vs cellular). On | 32 // The UMA is broken down by network technology used (Wi-Fi vs cellular). On |
| 31 // Android, the UMA is further broken down by whether the application was in the | 33 // Android, the UMA is further broken down by whether the application was in the |
| 32 // background or foreground during the request. | 34 // background or foreground during the request. |
| 33 // TODO(amohammadkhan): Complete the layered architecture. | 35 // TODO(amohammadkhan): Complete the layered architecture. |
| 34 // http://crbug.com/527460 | 36 // http://crbug.com/527460 |
| 35 class DataUseMeasurement { | 37 class DataUseMeasurement { |
| 36 public: | 38 public: |
| 37 explicit DataUseMeasurement( | 39 explicit DataUseMeasurement( |
| 38 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder); | 40 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder); |
| 39 ~DataUseMeasurement(); | 41 ~DataUseMeasurement(); |
| 40 | 42 |
| 41 // Records the data use of the |request|, thus |request| must be non-null. | 43 // Called right after a redirect response code was received for |request|. |
| 42 void ReportDataUseUMA(const net::URLRequest* request) const; | 44 void OnBeforeRedirect(net::URLRequest* request, const GURL& new_location); |
|
sclittle
2016/08/23 00:49:28
nit: could you pass in |request| by const ref? Sam
tbansal1
2016/08/23 00:58:51
Done.
| |
| 45 | |
| 46 // Indicates that |request| has been completed or failed. | |
| 47 void OnCompleted(net::URLRequest* request, bool started); | |
| 43 | 48 |
| 44 // Returns true if the URLRequest |request| is initiated by user traffic. | 49 // Returns true if the URLRequest |request| is initiated by user traffic. |
| 45 static bool IsUserInitiatedRequest(const net::URLRequest* request); | 50 static bool IsUserInitiatedRequest(const net::URLRequest* request); |
| 46 | 51 |
| 47 #if defined(OS_ANDROID) | 52 #if defined(OS_ANDROID) |
| 48 // This function should just be used for testing purposes. A change in | 53 // This function should just be used for testing purposes. A change in |
| 49 // application state can be simulated by calling this function. | 54 // application state can be simulated by calling this function. |
| 50 void OnApplicationStateChangeForTesting( | 55 void OnApplicationStateChangeForTesting( |
| 51 base::android::ApplicationState application_state); | 56 base::android::ApplicationState application_state); |
| 52 #endif | 57 #endif |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 73 TrafficDirection dir, | 78 TrafficDirection dir, |
| 74 bool is_connection_cellular) const; | 79 bool is_connection_cellular) const; |
| 75 | 80 |
| 76 #if defined(OS_ANDROID) | 81 #if defined(OS_ANDROID) |
| 77 // Called whenever the application transitions from foreground to background | 82 // Called whenever the application transitions from foreground to background |
| 78 // and vice versa. | 83 // and vice versa. |
| 79 void OnApplicationStateChange( | 84 void OnApplicationStateChange( |
| 80 base::android::ApplicationState application_state); | 85 base::android::ApplicationState application_state); |
| 81 #endif | 86 #endif |
| 82 | 87 |
| 88 // Records the data use of the |request|, thus |request| must be non-null. | |
| 89 void ReportDataUseUMA(const net::URLRequest* request) const; | |
| 90 | |
| 83 // A helper function used to record data use of services. It gets the size of | 91 // A helper function used to record data use of services. It gets the size of |
| 84 // exchanged message, its direction (which is upstream or downstream) and | 92 // exchanged message, its direction (which is upstream or downstream) and |
| 85 // reports to two histogram groups. DataUse.MessageSize.ServiceName and | 93 // reports to two histogram groups. DataUse.MessageSize.ServiceName and |
| 86 // DataUse.Services.{Dimensions}. In the second one, services are buckets. | 94 // DataUse.Services.{Dimensions}. In the second one, services are buckets. |
| 87 void ReportDataUsageServices( | 95 void ReportDataUsageServices( |
| 88 data_use_measurement::DataUseUserData::ServiceName service, | 96 data_use_measurement::DataUseUserData::ServiceName service, |
| 89 TrafficDirection dir, | 97 TrafficDirection dir, |
| 90 bool is_connection_cellular, | 98 bool is_connection_cellular, |
| 91 int64_t message_size) const; | 99 int64_t message_size) const; |
| 92 | 100 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 105 // foreground or in the background. It is owned by DataUseMeasurement. | 113 // foreground or in the background. It is owned by DataUseMeasurement. |
| 106 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; | 114 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; |
| 107 #endif | 115 #endif |
| 108 | 116 |
| 109 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); | 117 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); |
| 110 }; | 118 }; |
| 111 | 119 |
| 112 } // namespace data_use_measurement | 120 } // namespace data_use_measurement |
| 113 | 121 |
| 114 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ | 122 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ |
| OLD | NEW |