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

Unified Diff: components/data_use_measurement/core/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: Removing few commented lines. 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: components/data_use_measurement/core/data_use_measurement.h
diff --git a/components/data_use_measurement/core/data_use_measurement.h b/components/data_use_measurement/core/data_use_measurement.h
new file mode 100644
index 0000000000000000000000000000000000000000..fa4d724d374ce7cc6134969a2faf22f940300d26
--- /dev/null
+++ b/components/data_use_measurement/core/data_use_measurement.h
@@ -0,0 +1,86 @@
+// 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 COMPONENTS_DATA_USE_MEASUREMENT_H_
sclittle 2015/08/21 23:55:34 Change this to the full path, e.g. COMPONENTS_DATA
amohammadkhan 2015/08/24 23:18:48 Done.
+#define COMPONENTS_DATA_USE_MEASUREMENT_H_
sclittle 2015/08/21 23:55:34 Move this file and its .cc to the "data_use_measur
amohammadkhan 2015/08/26 22:28:41 Done.
+
sclittle 2015/08/21 23:55:34 Add "#include <stdint.h>" for int64_t.
amohammadkhan 2015/08/24 23:18:48 Done.
+#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;
+}
+
+namespace data_use_measurement {
+
+class DataUseMeasurement {
+ public:
+ // This constructor instantiate a listener object and bind its callback.
+ DataUseMeasurement();
+
+ // Records the data use of the |request|.
+ 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:
+ // 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.
+ enum AppState { BACKGROUND, FOREGROUND };
+
+ // The type of network connection that was used.
+ enum ConnectionType { CELLULAR, NOT_CELLULAR };
+
+ // 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 };
+
+ // Returns the current application state (Foreground or Background). It always
+ // returns Foreground if Chrome is not running on Android.
+ AppState CurrentAppState();
+
+ // Returns the current connection type (Cellular or Not cellular).
+ ConnectionType CurrentConnectionType();
sclittle 2015/08/21 23:55:34 nit: indentation, please run "git cl format" to fo
amohammadkhan 2015/08/24 23:18:48 Done.
+
+ // The function produces a string representing the status of the Chrome when
+ // recording is done. Its output is in following form: dir.appState.ConnState
+ // for example: Upload.Foreground.Cellular is one of its possible outputs.
+ std::string DimensionMaker(TrafficDirection dir);
+
+ // Helper function used to record data use of services.
+ void ReportDataUsage(const std::string& service_name,
+ TrafficDirection dir,
+ int64_t message_size);
+
+ // Helper function used for reporting data use of URLRequests.
+ void ReportDataUsageURLRequest(ChromeTrafficType service_type,
+ TrafficDirection dir,
+ int64_t message_size);
+
+#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. It is owned by DataUseMeasurement
+ base::android::ApplicationStatusListener app_listener_;
sclittle 2015/08/21 23:55:34 Make this a scoped_ptr, and call reset() on it to
amohammadkhan 2015/08/24 23:18:48 Done.
+#endif
+
+};
+}
+#endif // COMPONENTS_DATA_USE_MEASUREMENT_H_

Powered by Google App Engine
This is Rietveld 408576698