| 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> |
| 9 |
| 10 #include <memory> |
| 11 |
| 12 #include "url/gurl.h" |
| 13 |
| 8 namespace net { | 14 namespace net { |
| 15 class NetworkDelegate; |
| 9 class URLRequest; | 16 class URLRequest; |
| 10 } | 17 } |
| 11 | 18 |
| 12 namespace data_use_measurement { | 19 namespace data_use_measurement { |
| 13 | 20 |
| 14 class DataUseRecorder; | 21 class DataUseRecorder; |
| 15 | 22 |
| 16 // Abstract class that manages instances of DataUseRecorder and maps | 23 // Abstract class that manages instances of DataUseRecorder and maps |
| 17 // a URLRequest instance to its appropriate DataUseRecorder. An embedder | 24 // a URLRequest instance to its appropriate DataUseRecorder. An embedder |
| 18 // should provide an override if it is interested in tracking data usage. Data | 25 // should provide an override if it is interested in tracking data usage. Data |
| 19 // use from all URLRequests mapped to the same DataUseRecorder will be grouped | 26 // use from all URLRequests mapped to the same DataUseRecorder will be grouped |
| 20 // together and reported as a single use. | 27 // together and reported as a single use. |
| 21 class DataUseAscriber { | 28 class DataUseAscriber { |
| 22 public: | 29 public: |
| 23 virtual ~DataUseAscriber() {} | 30 virtual ~DataUseAscriber() {} |
| 24 | 31 |
| 32 // 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> wrapped_network_delegate); |
| 35 |
| 25 // Returns the DataUseRecorder to which data usage for the given URL should | 36 // Returns the DataUseRecorder to which data usage for the given URL should |
| 26 // be ascribed. If no existing DataUseRecorder exists, a new one will be | 37 // be ascribed. If no existing DataUseRecorder exists, a new one will be |
| 27 // created. | 38 // created. |
| 28 virtual DataUseRecorder* GetDataUseRecorder( | 39 virtual DataUseRecorder* GetDataUseRecorder( |
| 29 const net::URLRequest* request) = 0; | 40 const net::URLRequest* request) = 0; |
| 41 |
| 42 // Methods called by DataUseNetworkDelegate to propagate data use information: |
| 43 virtual void OnBeforeUrlRequest(net::URLRequest* request); |
| 44 |
| 45 virtual void OnBeforeRedirect(net::URLRequest* request, |
| 46 const GURL& new_location); |
| 47 |
| 48 virtual void OnNetworkBytesSent(net::URLRequest* request, int64_t bytes_sent); |
| 49 |
| 50 virtual void OnNetworkBytesReceived(net::URLRequest* request, |
| 51 int64_t bytes_received); |
| 52 |
| 53 virtual void OnUrlRequestCompleted(net::URLRequest* request, bool started); |
| 30 }; | 54 }; |
| 31 | 55 |
| 32 } // namespace data_use_measurement | 56 } // namespace data_use_measurement |
| 33 | 57 |
| 34 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CORE_DATA_USE_ASCRIBER_H_ | 58 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CORE_DATA_USE_ASCRIBER_H_ |
| OLD | NEW |