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 | |
10 #include <string> | |
11 | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "build/build_config.h" | |
bengr
2015/09/01 17:00:11
Why do you need this?
amohammadkhan
2015/09/01 19:38:14
I was getting some errors, because OS_ANDROID was
| |
14 #include "components/data_use_measurement/core/data_use_user_data.h" | |
15 | |
16 #if defined(OS_ANDROID) | |
17 #include "base/android/application_status_listener.h" | |
18 #endif | |
19 | |
20 namespace net { | |
21 class URLRequest; | |
22 } | |
23 | |
24 namespace data_use_measurement { | |
25 | |
26 // The class records the data use of different services and user in according | |
bengr
2015/09/01 17:00:11
// Records the data use of user traffic and variou
amohammadkhan
2015/09/01 19:38:15
At the end of request.
| |
27 // UMA histograms. It also considers application state and connection state when | |
28 // it records a usage. | |
29 class DataUseMeasurement { | |
bengr
2015/09/01 17:00:11
Is this an IO-thread object?
amohammadkhan
2015/09/01 19:38:14
I think it is (If ChromeNetworkDelegate is IO-thre
| |
30 public: | |
31 DataUseMeasurement(); | |
32 | |
33 ~DataUseMeasurement(); | |
34 | |
35 // Records the data use of the |request|. | |
bengr
2015/09/01 17:00:11
, thus |request| must be non-null.
mmenke
2015/09/01 19:26:17
Or could take it as const net::URLRequest& request
amohammadkhan
2015/09/01 19:38:14
Done.
| |
36 void ReportDataUseUMA(const net::URLRequest* request); | |
37 | |
38 #if defined(OS_ANDROID) | |
39 // If a change in application status happens, this function is called and this | |
40 // function sets app_state_ appropriately. | |
41 void OnApplicationStateChangeForTesting( | |
bengr
2015/09/01 17:00:11
// Called whenever the application transitions fro
amohammadkhan
2015/09/01 19:38:15
Done.
| |
42 base::android::ApplicationState application_state); | |
43 #endif | |
44 | |
45 private: | |
46 #if defined(OS_ANDROID) | |
47 // If a change in application status happens, this function is called and this | |
48 // function sets app_state_ appropriately. | |
49 void OnApplicationStateChange( | |
bengr
2015/09/01 17:00:11
Why is there a separate method for testing?
amohammadkhan
2015/09/01 19:38:14
To have the testing method public while this metho
| |
50 base::android::ApplicationState application_state); | |
51 #endif | |
52 | |
53 // Specifies that data is received or sent, respectively. | |
54 enum TrafficDirection { DOWNSTREAM, UPSTREAM }; | |
55 | |
56 // The state of the application. Only available on Android and on other | |
57 // platforms it is always FOREGROUND. | |
58 enum AppState { BACKGROUND, FOREGROUND }; | |
bengr
2015/09/01 17:00:11
Does this really need to be an enum?
amohammadkhan
2015/09/01 19:38:15
Basically apps have 4 states, but we are using 2 o
| |
59 | |
60 // The reason a request was sent. Whether the traffic originates from | |
bengr
2015/09/01 17:00:11
The comment is more confusing than the enum.
// T
amohammadkhan
2015/09/01 19:38:14
Done.
| |
61 // user's request for a web site or a service is the source of the traffic. | |
62 enum ChromeTrafficType { USER_TRAFFIC, SERVICE_TRAFFIC }; | |
bengr
2015/09/01 17:00:11
Can you name this RequestInitiator { REQUEST_INITI
amohammadkhan
2015/09/01 19:38:14
Done.
| |
63 | |
64 // Returns the current application state (Foreground or Background). It always | |
65 // returns Foreground if Chrome is not running on Android. | |
66 AppState CurrentAppState(); | |
bengr
2015/09/01 17:00:11
Can't this just return a bool? IsAppInBackground()
amohammadkhan
2015/09/01 19:38:14
similar reason to having the enum for it.
| |
67 | |
68 // The function produces a string representing the status of the Chrome when | |
bengr
2015/09/01 17:00:11
// Produces a string representing whether the data
amohammadkhan
2015/09/01 19:38:14
Done.
| |
69 // recording is done. Its output is in following form: dir.appState.ConnState | |
70 // for example: Upload.Foreground.Cellular is one of its possible outputs. | |
71 std::string GetSuffixForHistogramName(TrafficDirection dir); | |
72 | |
73 // Helper function used to record data use of services. | |
bengr
2015/09/01 17:00:11
Describe what these helper functions do and what t
amohammadkhan
2015/09/01 19:38:14
Done.
| |
74 void ReportDataUsage( | |
75 data_use_measurement::DataUseUserData::ServiceType service, | |
76 TrafficDirection dir, | |
77 int64_t message_size); | |
78 | |
79 // Helper function used for reporting data use of URLRequests. | |
80 void ReportDataUsageURLRequest(ChromeTrafficType service_type, | |
81 TrafficDirection dir, | |
82 int64_t message_size); | |
83 | |
84 #if defined(OS_ANDROID) | |
85 // Application listener store the last known state of the application in this | |
86 // field. | |
87 base::android::ApplicationState app_state_; | |
88 | |
89 // ApplicationStatusListener used to monitor that application is in foreground | |
bengr
2015/09/01 17:00:11
that -> whether the
in foreground or in background
amohammadkhan
2015/09/01 19:38:14
Done.
| |
90 // or in background. It is owned by DataUseMeasurement | |
91 scoped_ptr<base::android::ApplicationStatusListener> app_listener_; | |
92 #endif | |
93 | |
94 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); | |
95 }; | |
96 | |
97 } // namespace data_use_measurement | |
98 | |
99 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ | |
OLD | NEW |