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 CHROME_BROWSER_NET_DATA_USE_MEASUREMENT_H_ | |
6 #define CHROME_BROWSER_NET_DATA_USE_MEASUREMENT_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/memory/ref_counted.h" | |
11 #include "build/build_config.h" | |
12 | |
13 #if defined(OS_ANDROID) | |
14 #include "base/android/application_status_listener.h" | |
15 #endif | |
16 | |
17 namespace net { | |
18 class URLRequest; | |
19 } | |
20 | |
sclittle
2015/08/19 23:32:39
Put all the new classes and stuff in a namespace l
amohammadkhan
2015/08/21 23:06:32
Done.
| |
21 // Specifies that data is received or sent, respectively. | |
22 enum TrafficDirection { DOWNLOAD, UPLOAD }; | |
23 | |
24 // The state of the application. Only available on Android and on other | |
25 // platforms it is always FOREGROUND. | |
sclittle
2015/08/19 23:32:40
These enums should be moved below into the DataUse
amohammadkhan
2015/08/21 23:06:32
Done.
| |
26 enum AppState { BACKGROUND, FOREGROUND }; | |
sclittle
2015/08/19 23:32:39
Why is this enum needed? Could you just use a bool
amohammadkhan
2015/08/21 23:06:32
You are right a bool may be enough, but basically
| |
27 | |
28 // The type of network connection that was used. | |
29 enum ConnectionType { CELLULAR, NOT_CELLULAR }; | |
sclittle
2015/08/19 23:32:40
Why is this enum needed? Could you just use a bool
amohammadkhan
2015/08/21 23:06:32
The similar reason to AppState enum. Again the con
brettw
2015/09/11 19:53:44
I like the enums even for binary states in many ca
mmenke
2015/09/11 19:57:07
You're looking at the wrong patch set.
amohammadkhan
2015/09/11 20:11:26
I totally agree with you and as mmenke@ said they
| |
30 | |
31 // The reason a request was sent. Whether the traffic originates from | |
32 // user's request for a web site or a service is the source of the traffic. | |
33 enum ChromeTrafficType { USER_TRAFFIC, SERVICE_TRAFFIC }; | |
34 | |
35 class DataUseMeasurement | |
36 : public base::RefCountedThreadSafe<DataUseMeasurement> { | |
sclittle
2015/08/19 23:32:40
Why does this class need to be refcounted?
amohammadkhan
2015/08/21 23:06:31
I think I was over cautious because of callback fu
| |
37 public: | |
38 // This constructor initialize the | |
sclittle
2015/08/19 23:32:39
finish this comment
amohammadkhan
2015/08/21 23:06:32
Done.
| |
39 DataUseMeasurement(); | |
40 | |
41 // Records the data use of the |request|. It is used for recording data use | |
42 // of User and Non-User Data in ChromeNetworkDelegate. After extracting | |
43 // necessary data, such as message size in different directions and its source | |
44 // (Whether it is User or non-user data), it calls the appropriate function | |
45 // to record the result in DataUse.User.{Dimensions}, | |
46 // DataUse.NotUser.{Dimensions}, and DataUse.Service.ServiceName. The first | |
47 // histogram is updated if the traffic originated from user's request and the | |
48 // latter two are used if traffic is originated from a service. | |
sclittle
2015/08/19 23:32:40
This comment is too wordy, could you cut this down
amohammadkhan
2015/08/21 23:06:31
Done.
| |
49 void ReportDataUseUMA(const net::URLRequest* request); | |
50 | |
51 #if defined(OS_ANDROID) | |
52 // If a change in application status happens, this function is called and this | |
53 // function sets app_state_ appropriately. | |
54 void OnApplicationStateChange( | |
55 base::android::ApplicationState application_state); | |
56 #endif | |
57 | |
58 private: | |
59 friend class base::RefCountedThreadSafe<DataUseMeasurement>; | |
60 ~DataUseMeasurement(){} | |
61 | |
62 #if defined(OS_ANDROID) | |
63 // Application listener store the last known state of the application in this | |
64 // field. | |
65 base::android::ApplicationState app_state_; | |
66 | |
67 // ApplicationStatusListener used to monitor that application is in foreground | |
68 // or in background. | |
69 base::android::ApplicationStatusListener* app_listener_; | |
sclittle
2015/08/19 23:32:40
What owns this object? Please comment that here.
amohammadkhan
2015/08/21 23:06:31
Done.
| |
70 #endif | |
71 | |
72 // Helper function used for reporting data use of URLRequests. | |
73 void ReportDataUsageURLRequest(ChromeTrafficType service_type, | |
sclittle
2015/08/19 23:32:40
Move these functions above the private attributes.
amohammadkhan
2015/08/21 23:06:32
Done.
| |
74 TrafficDirection dir, | |
75 int message_size); | |
76 | |
77 // Helper function used to record data use of services. | |
78 void ReportDataUsage(const std::string& service_name, | |
79 TrafficDirection dir, | |
80 int message_size); | |
81 | |
82 // Making the current dimension of measured data traffic. | |
sclittle
2015/08/19 23:32:39
I don't understand this comment.
amohammadkhan
2015/08/21 23:06:32
Done.
| |
83 std::string DimensionMaker(TrafficDirection dir); | |
84 | |
85 // Returns the current connection type (Cellular or Not cellular). | |
86 ConnectionType CurrentConnectionType(); | |
87 | |
88 // Returns the current application state (Foreground or Background). It always | |
89 // returns Foreground if Chrome is not running on Android. | |
90 AppState CurrentAppState(); | |
91 }; | |
92 #endif // CHROME_BROWSER_NET_DATA_USE_MEASUREMENT_H_ | |
OLD | NEW |