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

Unified Diff: chrome/browser/net/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: Fix few formatting issues. Created 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/net/data_use_measurement.h
diff --git a/chrome/browser/net/data_use_measurement.h b/chrome/browser/net/data_use_measurement.h
new file mode 100644
index 0000000000000000000000000000000000000000..905ed6042cd0c362f81a54069dc1c95ea87cf3b0
--- /dev/null
+++ b/chrome/browser/net/data_use_measurement.h
@@ -0,0 +1,92 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_NET_DATA_USE_MEASUREMENT_H_
+#define CHROME_BROWSER_NET_DATA_USE_MEASUREMENT_H_
+
+#include <string>
+
+#include "base/memory/ref_counted.h"
+#include "build/build_config.h"
+
+#if defined(OS_ANDROID)
+#include "base/android/application_status_listener.h"
+#endif
+
+namespace net {
+class URLRequest;
+}
+
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.
+// Specifies that data is received or sent, respectively.
+enum TrafficDirection { DOWNLOAD, UPLOAD };
+
+// The state of the application. Only available on Android and on other
+// 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.
+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
+
+// The type of network connection that was used.
+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
+
+// The reason a request was sent. Whether the traffic originates from
+// user's request for a web site or a service is the source of the traffic.
+enum ChromeTrafficType { USER_TRAFFIC, SERVICE_TRAFFIC };
+
+class DataUseMeasurement
+ : 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
+ public:
+ // This constructor initialize the
sclittle 2015/08/19 23:32:39 finish this comment
amohammadkhan 2015/08/21 23:06:32 Done.
+ DataUseMeasurement();
+
+ // Records the data use of the |request|. It is used for recording data use
+ // of User and Non-User Data in ChromeNetworkDelegate. After extracting
+ // necessary data, such as message size in different directions and its source
+ // (Whether it is User or non-user data), it calls the appropriate function
+ // to record the result in DataUse.User.{Dimensions},
+ // DataUse.NotUser.{Dimensions}, and DataUse.Service.ServiceName. The first
+ // histogram is updated if the traffic originated from user's request and the
+ // 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.
+ void ReportDataUseUMA(const net::URLRequest* request);
+
+#if defined(OS_ANDROID)
+ // If a change in application status happens, this function is called and this
+ // function sets app_state_ appropriately.
+ void OnApplicationStateChange(
+ base::android::ApplicationState application_state);
+#endif
+
+ private:
+ friend class base::RefCountedThreadSafe<DataUseMeasurement>;
+ ~DataUseMeasurement(){}
+
+#if defined(OS_ANDROID)
+ // Application listener store the last known state of the application in this
+ // field.
+ base::android::ApplicationState app_state_;
+
+ // ApplicationStatusListener used to monitor that application is in foreground
+ // or in background.
+ 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.
+#endif
+
+ // Helper function used for reporting data use of URLRequests.
+ 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.
+ TrafficDirection dir,
+ int message_size);
+
+ // Helper function used to record data use of services.
+ void ReportDataUsage(const std::string& service_name,
+ TrafficDirection dir,
+ int message_size);
+
+ // 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.
+ std::string DimensionMaker(TrafficDirection dir);
+
+ // Returns the current connection type (Cellular or Not cellular).
+ ConnectionType CurrentConnectionType();
+
+ // Returns the current application state (Foreground or Background). It always
+ // returns Foreground if Chrome is not running on Android.
+ AppState CurrentAppState();
+};
+#endif // CHROME_BROWSER_NET_DATA_USE_MEASUREMENT_H_

Powered by Google App Engine
This is Rietveld 408576698