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

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: Minor updates in dep files. 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/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "build/build_config.h"
15 #include "components/data_use_measurement/core/data_use_user_data.h"
16
17 #if defined(OS_ANDROID)
18 #include "base/android/application_status_listener.h"
19 #endif
20
21 namespace net {
22 class URLRequest;
23 }
24
25 namespace data_use_measurement {
26
27 // Records the data use of user traffic and various services in UMA histograms.
28 // The UMA is broken down by network technology used (Wi-Fi vs cellular). On
29 // Android, the UMA is further broken down by whether the application was in the
30 // background or foreground during the request.
31 // TODO(amohammadkhan): Complete the layered architecture.
32 // http://crbug.com/527460
33 class DataUseMeasurement {
34 public:
35 DataUseMeasurement();
36 ~DataUseMeasurement();
37
38 // Records the data use of the |request|, thus |request| must be non-null.
39 void ReportDataUseUMA(const net::URLRequest* request) const;
40
41 #if defined(OS_ANDROID)
42 // This function should just be used for testing purposes. A change in
43 // application state can be simulated by calling this function.
44 void OnApplicationStateChangeForTesting(
45 base::android::ApplicationState application_state);
46 #endif
47
48 private:
49 // Specifies that data is received or sent, respectively.
50 enum TrafficDirection { DOWNSTREAM, UPSTREAM };
51
52 // The state of the application. Only available on Android and on other
53 // platforms it is always FOREGROUND.
54 enum AppState { BACKGROUND, FOREGROUND };
55
56 // The request is from a user or from a service.
57 enum RequestInitiator { REQUEST_INITIATOR_USER, REQUEST_INITIATOR_SERVICE };
58
59 // Returns the current application state (Foreground or Background). It always
60 // returns Foreground if Chrome is not running on Android.
61 AppState CurrentAppState() const;
62
63 // Produces a string representing whether the data use was on the send
64 // ("Upstream") or receive ("Downstream") path, whether the app was in the
65 // "Foreground" or "Background", and whether a "Cellular" or "WiFi" network
66 // was use. For example, "Upstream.Foreground.Cellular" is a possible output.
67 std::string GetSuffixForHistogramName(TrafficDirection dir) const;
68
69 #if defined(OS_ANDROID)
70 // Called whenever the application transitions from foreground to background
71 // and vice versa.
72 void OnApplicationStateChange(
73 base::android::ApplicationState application_state);
74 #endif
75
76 // A helper function used to record data use of services. It gets the size of
77 // exchanged message, its direction (which is upstream or downstream) and
78 // reports to two histogram groups. DataUse.MessageSize.ServiceName and
79 // DataUse.Services.{Dimensions}. In the second one, services are buckets.
80 void ReportDataUsageServices(
81 data_use_measurement::DataUseUserData::ServiceName service,
82 TrafficDirection dir,
83 int64_t message_size) const;
84
85 // A helper function used for reporting data use of user and all the services
86 // as a single group. Two histogram groups are updated by this function. The
87 // first one is DataUse.TrafficSize.User.{Dimensions} and the second one is
88 // DataUse.TrafficSize.System.{Dimensions}. Based on |service_name| one of
89 // these groups is selected and updated.
90 void ReportDataUsageGeneral(RequestInitiator request_initiator,
91 TrafficDirection dir,
92 int64_t message_size) const;
93
94 #if defined(OS_ANDROID)
95 // Application listener store the last known state of the application in this
96 // field.
97 base::android::ApplicationState app_state_;
98
99 // ApplicationStatusListener used to monitor whether the application is in the
100 // foreground or in the background. It is owned by DataUseMeasurement.
101 scoped_ptr<base::android::ApplicationStatusListener> app_listener_;
102 #endif
103
104 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement);
105 };
106
107 } // namespace data_use_measurement
108
109 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698