Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: components/data_use_measurement/content/data_use_measurement.h

Issue 1279543002: Support needed to measure user and service traffic in Chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@NewHistogram
Patch Set: Addressing reviewers' comments. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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"
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 // Records the data use of user traffic and various services in UMA histograms.
27 // The UMA is broken down by network technology used (Wi-Fi vs cellular). On
28 // Android, the UMA is further broken down by whether the application was in the
29 // background or foreground during the request.
30 class DataUseMeasurement {
31 public:
32 DataUseMeasurement();
33
Alexei Svitkine (slow) 2015/09/01 20:04:04 Nit: No empty line.
amohammadkhan 2015/09/01 23:02:43 Done.
34 ~DataUseMeasurement();
35
36 // Records the data use of the |request|, thus |request| must be non-null.
37 void ReportDataUseUMA(const net::URLRequest* request);
38
39 #if defined(OS_ANDROID)
40 // This function should just be used for testing purposes. A change in
41 // application state can be simulated by calling this function.
42 void OnApplicationStateChangeForTesting(
43 base::android::ApplicationState application_state);
44 #endif
45
46 private:
47 // Specifies that data is received or sent, respectively.
48 enum TrafficDirection { DOWNSTREAM, UPSTREAM };
49
50 // The state of the application. Only available on Android and on other
51 // platforms it is always FOREGROUND.
52 enum AppState { BACKGROUND, FOREGROUND };
53
54 // The request is from a user or from a service.
55 enum RequestInitiator { REQUEST_INITIATOR_USER, REQUEST_INITIATOR_SERVICE };
56
57 // Returns the current application state (Foreground or Background). It always
58 // returns Foreground if Chrome is not running on Android.
59 AppState CurrentAppState();
60
61 // Produces a string representing whether the data use was on the send
62 // ("Upstream") or receive ("Downstream") path, whether the app was in the
63 // "Foreground" or "Background", and whether a "Cellular" or "WiFi" network
64 // was use. For example, "Upstream.Foreground.Cellular" is a possible output.
65 std::string GetSuffixForHistogramName(TrafficDirection dir);
66
67 #if defined(OS_ANDROID)
68 // Called whenever the application transitions from foreground to background
69 // and
70 // vice versa.
71 void OnApplicationStateChange(
72 base::android::ApplicationState application_state);
73 #endif
74
75 // 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
77 // reports to two histogram groups. DataUse.MessageSize.ServiceName and
78 // DataUse.Services.{Dimensions}. In the second one, services are buckets.
79 void ReportDataUsageServices(
80 data_use_measurement::DataUseUserData::ServiceType service,
81 TrafficDirection dir,
82 int64_t message_size);
83
84 // A helper function used for reporting data use of user and all the services
85 // as a single group. Two histogram groups are updated by this function. The
86 // first one is DataUse.User.{Dimensions} and the second one is
87 // DataUse.NotUser.{Dimensions}. Based on |service_type| one of these groups
88 // is selected and updated.
89 void ReportDataUsageGeneral(RequestInitiator service_type,
90 TrafficDirection dir,
91 int64_t message_size);
92
93 #if defined(OS_ANDROID)
94 // Application listener store the last known state of the application in this
95 // field.
96 base::android::ApplicationState app_state_;
97
98 // ApplicationStatusListener used to monitor whether the application is in the
99 // foreground or in the background. It is owned by DataUseMeasurement
100 scoped_ptr<base::android::ApplicationStatusListener> app_listener_;
101 #endif
102
103 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement);
104 };
105
106 } // namespace data_use_measurement
107
108 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698