Index: components/data_use_measurement/content/data_use_measurement.h |
diff --git a/components/data_use_measurement/content/data_use_measurement.h b/components/data_use_measurement/content/data_use_measurement.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b1154f43ba690aa6bc8da48266fb84e8e30a52a7 |
--- /dev/null |
+++ b/components/data_use_measurement/content/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 COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ |
+#define COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ |
+ |
+#include <stdint.h> |
+#include <string> |
mmenke
2015/08/31 17:41:29
Blank line needed between C++ and C headers.
amohammadkhan
2015/09/01 04:52:48
Done.
|
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "build/build_config.h" |
+#include "components/data_use_measurement/core/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 { |
Alexei Svitkine (slow)
2015/08/31 17:26:31
Class should have a comment.
mmenke
2015/08/31 17:41:29
Need class level docs.
amohammadkhan
2015/09/01 04:52:48
Done.
amohammadkhan
2015/09/01 04:52:49
Done.
|
+ public: |
+ // If the OS is Android, this constructor instantiate a listener object and |
+ // bind its callback. |
Alexei Svitkine (slow)
2015/08/31 17:26:31
This comment is not useful.
First, it seems it's
amohammadkhan
2015/09/01 04:52:48
Done.
|
+ 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); |
mmenke
2015/08/31 17:41:29
If this is only public for tests, I suggest making
amohammadkhan
2015/09/01 04:52:48
Done.
|
+#endif |
Alexei Svitkine (slow)
2015/08/31 17:26:31
Add an empty line after this.
amohammadkhan
2015/09/01 04:52:48
Done.
|
+ 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 GetDimensionForHistogramName(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 |
+}; |
Alexei Svitkine (slow)
2015/08/31 17:26:31
DISALLOW_COPY_AND_ASSIGN
amohammadkhan
2015/09/01 04:52:49
Done.
|
+ |
+} // namespace data_use_measurement |
+#endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ |