Chromium Code Reviews| 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..3eb0f70f1c71f6c896267746f7ace7a3cca925be |
| --- /dev/null |
| +++ b/components/data_use_measurement/content/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_CONTENT_DATA_USE_MEASUREMENT_H_ |
| +#define COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_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/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 { |
| + 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); |
|
sclittle
2015/08/26 23:08:30
Could you write some simple tests for this method
amohammadkhan
2015/08/29 01:00:59
I tried to have a complete test as much as possibl
|
| + |
| +#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 |
| +}; |
| +} |
|
sclittle
2015/08/26 23:08:30
add a blank line above, and add a comment on the s
amohammadkhan
2015/08/29 01:00:59
Done.
|
| +#endif // COMPONENTS_DATA_USE_MEASUREMENT_CONTENT_DATA_USE_MEASUREMENT_H_ |