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

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: Addressing reviewer's comments but the ones related to making component 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..8907febf95afea372428d497d06c7b5de292c3c9
--- /dev/null
+++ b/components/data_use_measurement/core/data_use_measurement.h
@@ -0,0 +1,90 @@
+// 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_CORE_DATA_USE_MEASUREMENT_H_
+#define COMPONENTS_DATA_USE_MEASUREMENT_CORE_DATA_USE_MEASUREMENT_H_
+
+#include <stdint.h>
+#include <string>
+
+#include "base/memory/scoped_ptr.h"
+#include "build/build_config.h"
+#include "components/data_use_measurement/content/data_use_user_data.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();
+
+ ~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();
+
+ // 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(
+ data_use_measurement::DataUseUserData::ServiceType service,
+ 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
+ scoped_ptr<base::android::ApplicationStatusListener> app_listener_;
+#endif
+};
+}
+#endif // COMPONENTS_DATA_USE_MEASUREMENT_CORE_DATA_USE_MEASUREMENT_H_

Powered by Google App Engine
This is Rietveld 408576698