Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ | |
| 6 #define COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "build/build_config.h" | |
| 13 #include "components/data_use_measurement/core/data_use_user_data.h" | |
| 14 | |
| 15 #if defined(OS_ANDROID) | |
| 16 #include "base/android/application_status_listener.h" | |
| 17 #endif | |
| 18 | |
| 19 namespace net { | |
| 20 class URLRequest; | |
| 21 } | |
| 22 | |
| 23 namespace data_use_measurement { | |
| 24 | |
| 25 class DataUseMeasurement { | |
| 26 public: | |
| 27 // This constructor instantiate a listener object and bind its callback. | |
| 28 DataUseMeasurement(); | |
| 29 | |
| 30 ~DataUseMeasurement(); | |
| 31 | |
| 32 // Records the data use of the |request|. | |
| 33 void ReportDataUseUMA(const net::URLRequest* request); | |
|
sclittle
2015/08/26 23:08:30
Could you write some simple tests for this method
amohammadkhan
2015/08/29 01:00:59
I tried to have a complete test as much as possibl
| |
| 34 | |
| 35 #if defined(OS_ANDROID) | |
| 36 // If a change in application status happens, this function is called and this | |
| 37 // function sets app_state_ appropriately. | |
| 38 void OnApplicationStateChange( | |
| 39 base::android::ApplicationState application_state); | |
| 40 #endif | |
| 41 private: | |
| 42 // Specifies that data is received or sent, respectively. | |
| 43 enum TrafficDirection { DOWNLOAD, UPLOAD }; | |
| 44 | |
| 45 // The state of the application. Only available on Android and on other | |
| 46 // platforms it is always FOREGROUND. | |
| 47 enum AppState { BACKGROUND, FOREGROUND }; | |
| 48 | |
| 49 // The type of network connection that was used. | |
| 50 enum ConnectionType { CELLULAR, NOT_CELLULAR }; | |
| 51 | |
| 52 // The reason a request was sent. Whether the traffic originates from | |
| 53 // user's request for a web site or a service is the source of the traffic. | |
| 54 enum ChromeTrafficType { USER_TRAFFIC, SERVICE_TRAFFIC }; | |
| 55 | |
| 56 // Returns the current application state (Foreground or Background). It always | |
| 57 // returns Foreground if Chrome is not running on Android. | |
| 58 AppState CurrentAppState(); | |
| 59 | |
| 60 // Returns the current connection type (Cellular or Not cellular). | |
| 61 ConnectionType CurrentConnectionType(); | |
| 62 | |
| 63 // The function produces a string representing the status of the Chrome when | |
| 64 // recording is done. Its output is in following form: dir.appState.ConnState | |
| 65 // for example: Upload.Foreground.Cellular is one of its possible outputs. | |
| 66 std::string DimensionMaker(TrafficDirection dir); | |
| 67 | |
| 68 // Helper function used to record data use of services. | |
| 69 void ReportDataUsage( | |
| 70 data_use_measurement::DataUseUserData::ServiceType service, | |
| 71 TrafficDirection dir, | |
| 72 int64_t message_size); | |
| 73 | |
| 74 // Helper function used for reporting data use of URLRequests. | |
| 75 void ReportDataUsageURLRequest(ChromeTrafficType service_type, | |
| 76 TrafficDirection dir, | |
| 77 int64_t message_size); | |
| 78 | |
| 79 #if defined(OS_ANDROID) | |
| 80 // Application listener store the last known state of the application in this | |
| 81 // field. | |
| 82 base::android::ApplicationState app_state_; | |
| 83 | |
| 84 // ApplicationStatusListener used to monitor that application is in foreground | |
| 85 // or in background. It is owned by DataUseMeasurement | |
| 86 scoped_ptr<base::android::ApplicationStatusListener> app_listener_; | |
| 87 #endif | |
| 88 }; | |
| 89 } | |
|
sclittle
2015/08/26 23:08:30
add a blank line above, and add a comment on the s
amohammadkhan
2015/08/29 01:00:59
Done.
| |
| 90 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ | |
| OLD | NEW |