| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_DATA_USE_MEASUREMENT_CORE_DATA_USE_ASCRIBER_H_ | 5 #ifndef COMPONENTS_DATA_USE_MEASUREMENT_CORE_DATA_USE_ASCRIBER_H_ |
| 6 #define COMPONENTS_DATA_USE_MEASUREMENT_CORE_DATA_USE_ASCRIBER_H_ | 6 #define COMPONENTS_DATA_USE_MEASUREMENT_CORE_DATA_USE_ASCRIBER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "components/metrics/data_use_tracker.h" |
| 12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 13 | 14 |
| 14 namespace net { | 15 namespace net { |
| 15 class NetworkDelegate; | 16 class NetworkDelegate; |
| 16 class URLRequest; | 17 class URLRequest; |
| 17 } | 18 } |
| 18 | 19 |
| 19 namespace data_use_measurement { | 20 namespace data_use_measurement { |
| 20 | 21 |
| 21 class DataUseRecorder; | 22 class DataUseRecorder; |
| 22 | 23 |
| 23 // Abstract class that manages instances of DataUseRecorder and maps | 24 // Abstract class that manages instances of DataUseRecorder and maps |
| 24 // a URLRequest instance to its appropriate DataUseRecorder. An embedder | 25 // a URLRequest instance to its appropriate DataUseRecorder. An embedder |
| 25 // should provide an override if it is interested in tracking data usage. Data | 26 // should provide an override if it is interested in tracking data usage. Data |
| 26 // use from all URLRequests mapped to the same DataUseRecorder will be grouped | 27 // use from all URLRequests mapped to the same DataUseRecorder will be grouped |
| 27 // together and reported as a single use. | 28 // together and reported as a single use. |
| 28 class DataUseAscriber { | 29 class DataUseAscriber { |
| 29 public: | 30 public: |
| 30 virtual ~DataUseAscriber() {} | 31 virtual ~DataUseAscriber() {} |
| 31 | 32 |
| 32 // Creates a network delegate that will be used to track data use. | 33 // Creates a network delegate that will be used to track data use. |
| 33 std::unique_ptr<net::NetworkDelegate> CreateNetworkDelegate( | 34 std::unique_ptr<net::NetworkDelegate> CreateNetworkDelegate( |
| 34 std::unique_ptr<net::NetworkDelegate> wrapped_network_delegate); | 35 std::unique_ptr<net::NetworkDelegate> wrapped_network_delegate, |
| 36 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder); |
| 35 | 37 |
| 36 // Returns the DataUseRecorder to which data usage for the given URL should | 38 // Returns the DataUseRecorder to which data usage for the given URL should |
| 37 // be ascribed. If no existing DataUseRecorder exists, a new one will be | 39 // be ascribed. If no existing DataUseRecorder exists, a new one will be |
| 38 // created. | 40 // created. |
| 39 virtual DataUseRecorder* GetDataUseRecorder(net::URLRequest* request) = 0; | 41 virtual DataUseRecorder* GetDataUseRecorder(net::URLRequest* request) = 0; |
| 40 | 42 |
| 41 // Methods called by DataUseNetworkDelegate to propagate data use information: | 43 // Methods called by DataUseNetworkDelegate to propagate data use information: |
| 42 virtual void OnBeforeUrlRequest(net::URLRequest* request); | 44 virtual void OnBeforeUrlRequest(net::URLRequest* request); |
| 43 | 45 |
| 44 virtual void OnBeforeRedirect(net::URLRequest* request, | 46 virtual void OnBeforeRedirect(net::URLRequest* request, |
| 45 const GURL& new_location); | 47 const GURL& new_location); |
| 46 | 48 |
| 47 virtual void OnNetworkBytesSent(net::URLRequest* request, int64_t bytes_sent); | 49 virtual void OnNetworkBytesSent(net::URLRequest* request, int64_t bytes_sent); |
| 48 | 50 |
| 49 virtual void OnNetworkBytesReceived(net::URLRequest* request, | 51 virtual void OnNetworkBytesReceived(net::URLRequest* request, |
| 50 int64_t bytes_received); | 52 int64_t bytes_received); |
| 51 | 53 |
| 52 virtual void OnUrlRequestCompleted(net::URLRequest* request, bool started); | 54 virtual void OnUrlRequestCompleted(net::URLRequest* request, bool started); |
| 53 }; | 55 }; |
| 54 | 56 |
| 55 } // namespace data_use_measurement | 57 } // namespace data_use_measurement |
| 56 | 58 |
| 57 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CORE_DATA_USE_ASCRIBER_H_ | 59 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CORE_DATA_USE_ASCRIBER_H_ |
| OLD | NEW |