Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_DATA_USAGE_CORE_DATA_USE_AGGREGATOR_H_ | |
| 6 #define COMPONENTS_DATA_USAGE_CORE_DATA_USE_AGGREGATOR_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "base/observer_list.h" | |
| 14 #include "base/threading/thread_checker.h" | |
| 15 #include "components/data_usage/core/data_use.h" | |
| 16 | |
| 17 namespace net { | |
| 18 class URLRequest; | |
| 19 } | |
| 20 | |
| 21 namespace data_usage { | |
| 22 | |
| 23 // Class that collects and aggregates network usage, reporting the usage to | |
| 24 // observers. Should only be used on the IO thread. | |
| 25 class DataUseAggregator { | |
| 26 public: | |
| 27 class Observer { | |
| 28 public: | |
| 29 virtual ~Observer() {} | |
| 30 // TODO(sclittle): Consider performing some pre-aggregation on the data use. | |
| 31 virtual void OnDataUse(const std::vector<DataUse>& data_use_sequence) = 0; | |
|
tbansal1
2015/10/08 04:22:44
DISALLOW_COPY_AND_ASSIGN?
sclittle
2015/10/08 19:44:13
The subclasses should DISALLOW_COPY_AND_ASSIGN the
| |
| 32 }; | |
| 33 | |
| 34 DataUseAggregator(); | |
| 35 virtual ~DataUseAggregator(); | |
| 36 | |
| 37 void AddObserver(Observer* observer); | |
| 38 void RemoveObserver(Observer* observer); | |
| 39 | |
| 40 // Virtual for testing. | |
| 41 virtual void ReportDataUse(const net::URLRequest& request, | |
| 42 int32_t tab_id, | |
| 43 int64_t tx_bytes, | |
| 44 int64_t rx_bytes); | |
| 45 | |
| 46 // Account for off-the-record data use. This usage is only kept track of here | |
| 47 // so that it can be taken out of any amortized data usage calculations, and a | |
| 48 // per-request breakdown of off-the-record data usage will never leave the | |
| 49 // DataUseAggregator. | |
| 50 // Virtual for testing. | |
| 51 virtual void ReportOffTheRecordDataUse(int64_t tx_bytes, int64_t rx_bytes); | |
| 52 | |
| 53 private: | |
| 54 void NotifyDataUse(const std::vector<DataUse>& data_use_sequence); | |
| 55 | |
| 56 base::ThreadChecker thread_checker_; | |
| 57 base::ObserverList<Observer> observer_list_; | |
| 58 | |
| 59 DISALLOW_COPY_AND_ASSIGN(DataUseAggregator); | |
| 60 }; | |
| 61 | |
| 62 } // namespace data_usage | |
| 63 | |
| 64 #endif // COMPONENTS_DATA_USAGE_CORE_DATA_USE_AGGREGATOR_H_ | |
| OLD | NEW |