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

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

Issue 2269833002: Refactor the DataUseMeasurement class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More mechanical changes Created 4 years, 4 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ 5 #ifndef COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_
6 #define COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ 6 #define COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "components/data_use_measurement/core/data_use_user_data.h" 16 #include "components/data_use_measurement/core/data_use_user_data.h"
17 #include "components/metrics/data_use_tracker.h" 17 #include "components/metrics/data_use_tracker.h"
18 18
19 #if defined(OS_ANDROID) 19 #if defined(OS_ANDROID)
20 #include "base/android/application_status_listener.h" 20 #include "base/android/application_status_listener.h"
21 #endif 21 #endif
22 22
23 class GURL;
24
23 namespace net { 25 namespace net {
24 class URLRequest; 26 class URLRequest;
25 } 27 }
26 28
27 namespace data_use_measurement { 29 namespace data_use_measurement {
28 30
29 // Records the data use of user traffic and various services in UMA histograms. 31 // Records the data use of user traffic and various services in UMA histograms.
30 // The UMA is broken down by network technology used (Wi-Fi vs cellular). On 32 // The UMA is broken down by network technology used (Wi-Fi vs cellular). On
31 // Android, the UMA is further broken down by whether the application was in the 33 // Android, the UMA is further broken down by whether the application was in the
32 // background or foreground during the request. 34 // background or foreground during the request.
33 // TODO(amohammadkhan): Complete the layered architecture. 35 // TODO(amohammadkhan): Complete the layered architecture.
34 // http://crbug.com/527460 36 // http://crbug.com/527460
35 class DataUseMeasurement { 37 class DataUseMeasurement {
36 public: 38 public:
37 explicit DataUseMeasurement( 39 explicit DataUseMeasurement(
38 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder); 40 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder);
39 ~DataUseMeasurement(); 41 ~DataUseMeasurement();
40 42
41 // Records the data use of the |request|, thus |request| must be non-null. 43 // Called right after a redirect response code was received for |request|.
42 void ReportDataUseUMA(const net::URLRequest* request) const; 44 void OnBeforeRedirect(const net::URLRequest& request,
45 const GURL& new_location);
46
47 // Indicates that |request| has been completed or failed.
48 void OnCompleted(const net::URLRequest& request, bool started);
43 49
44 // Returns true if the URLRequest |request| is initiated by user traffic. 50 // Returns true if the URLRequest |request| is initiated by user traffic.
45 static bool IsUserInitiatedRequest(const net::URLRequest* request); 51 static bool IsUserInitiatedRequest(const net::URLRequest& request);
46 52
47 #if defined(OS_ANDROID) 53 #if defined(OS_ANDROID)
48 // This function should just be used for testing purposes. A change in 54 // This function should just be used for testing purposes. A change in
49 // application state can be simulated by calling this function. 55 // application state can be simulated by calling this function.
50 void OnApplicationStateChangeForTesting( 56 void OnApplicationStateChangeForTesting(
51 base::android::ApplicationState application_state); 57 base::android::ApplicationState application_state);
52 #endif 58 #endif
53 59
54 private: 60 private:
55 // Specifies that data is received or sent, respectively. 61 // Specifies that data is received or sent, respectively.
(...skipping 17 matching lines...) Expand all
73 TrafficDirection dir, 79 TrafficDirection dir,
74 bool is_connection_cellular) const; 80 bool is_connection_cellular) const;
75 81
76 #if defined(OS_ANDROID) 82 #if defined(OS_ANDROID)
77 // Called whenever the application transitions from foreground to background 83 // Called whenever the application transitions from foreground to background
78 // and vice versa. 84 // and vice versa.
79 void OnApplicationStateChange( 85 void OnApplicationStateChange(
80 base::android::ApplicationState application_state); 86 base::android::ApplicationState application_state);
81 #endif 87 #endif
82 88
89 // Records the data use of the |request|, thus |request| must be non-null.
90 void ReportDataUseUMA(const net::URLRequest& request) const;
91
83 // A helper function used to record data use of services. It gets the size of 92 // A helper function used to record data use of services. It gets the size of
84 // exchanged message, its direction (which is upstream or downstream) and 93 // exchanged message, its direction (which is upstream or downstream) and
85 // reports to two histogram groups. DataUse.MessageSize.ServiceName and 94 // reports to two histogram groups. DataUse.MessageSize.ServiceName and
86 // DataUse.Services.{Dimensions}. In the second one, services are buckets. 95 // DataUse.Services.{Dimensions}. In the second one, services are buckets.
87 void ReportDataUsageServices( 96 void ReportDataUsageServices(
88 data_use_measurement::DataUseUserData::ServiceName service, 97 data_use_measurement::DataUseUserData::ServiceName service,
89 TrafficDirection dir, 98 TrafficDirection dir,
90 bool is_connection_cellular, 99 bool is_connection_cellular,
91 int64_t message_size) const; 100 int64_t message_size) const;
92 101
(...skipping 12 matching lines...) Expand all
105 // foreground or in the background. It is owned by DataUseMeasurement. 114 // foreground or in the background. It is owned by DataUseMeasurement.
106 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; 115 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_;
107 #endif 116 #endif
108 117
109 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement); 118 DISALLOW_COPY_AND_ASSIGN(DataUseMeasurement);
110 }; 119 };
111 120
112 } // namespace data_use_measurement 121 } // namespace data_use_measurement
113 122
114 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ 123 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_
OLDNEW
« no previous file with comments | « chrome/browser/precache/precache_util.cc ('k') | components/data_use_measurement/content/data_use_measurement.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698