OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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_USAGE_CORE_DATA_USE_AGGREGATOR_H_ | 5 #ifndef COMPONENTS_DATA_USAGE_CORE_DATA_USE_AGGREGATOR_H_ |
6 #define COMPONENTS_DATA_USAGE_CORE_DATA_USE_AGGREGATOR_H_ | 6 #define COMPONENTS_DATA_USAGE_CORE_DATA_USE_AGGREGATOR_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
17 | 17 |
18 namespace net { | 18 class GURL; |
19 class URLRequest; | 19 |
| 20 namespace base { |
| 21 class TimeTicks; |
20 } | 22 } |
21 | 23 |
22 namespace data_usage { | 24 namespace data_usage { |
23 struct DataUse; | 25 struct DataUse; |
24 | 26 |
25 // Class that collects and aggregates network usage, reporting the usage to | 27 // Class that collects and aggregates network usage, reporting the usage to |
26 // observers. Should only be used on the IO thread. | 28 // observers. Should only be used on the IO thread. |
27 class DataUseAggregator { | 29 class DataUseAggregator { |
28 public: | 30 public: |
29 class Observer { | 31 class Observer { |
30 public: | 32 public: |
31 virtual ~Observer() {} | 33 virtual ~Observer() {} |
32 // Each of the elements of |data_use_sequence| are guaranteed to be | 34 // Each of the elements of |data_use_sequence| are guaranteed to be |
33 // non-NULL. | 35 // non-NULL. |
34 virtual void OnDataUse( | 36 virtual void OnDataUse( |
35 const std::vector<const DataUse*>& data_use_sequence) = 0; | 37 const std::vector<const DataUse*>& data_use_sequence) = 0; |
36 }; | 38 }; |
37 | 39 |
38 DataUseAggregator(); | 40 DataUseAggregator(); |
39 virtual ~DataUseAggregator(); | 41 virtual ~DataUseAggregator(); |
40 | 42 |
41 void AddObserver(Observer* observer); | 43 void AddObserver(Observer* observer); |
42 void RemoveObserver(Observer* observer); | 44 void RemoveObserver(Observer* observer); |
43 | 45 |
44 // Virtual for testing. | 46 // Virtual for testing. |
45 virtual void ReportDataUse(const net::URLRequest& request, | 47 virtual void ReportDataUse(int64_t tx_bytes, |
46 int32_t tab_id, | 48 int64_t rx_bytes, |
47 int64_t tx_bytes, | 49 const GURL& url, |
48 int64_t rx_bytes); | 50 const base::TimeTicks& request_start, |
| 51 const GURL& first_party_for_cookies, |
| 52 int32_t tab_id); |
49 | 53 |
50 // Account for off-the-record data use. This usage is only kept track of here | 54 // Account for off-the-record data use. This usage is only kept track of here |
51 // so that it can be taken out of any amortized data usage calculations, and a | 55 // so that it can be taken out of any amortized data usage calculations, and a |
52 // per-request breakdown of off-the-record data usage will never leave the | 56 // per-request breakdown of off-the-record data usage will never leave the |
53 // DataUseAggregator. | 57 // DataUseAggregator. |
54 // Virtual for testing. | 58 // Virtual for testing. |
55 virtual void ReportOffTheRecordDataUse(int64_t tx_bytes, int64_t rx_bytes); | 59 virtual void ReportOffTheRecordDataUse(int64_t tx_bytes, int64_t rx_bytes); |
56 | 60 |
57 base::WeakPtr<DataUseAggregator> GetWeakPtr(); | 61 base::WeakPtr<DataUseAggregator> GetWeakPtr(); |
58 | 62 |
(...skipping 17 matching lines...) Expand all Loading... |
76 bool is_flush_pending_; | 80 bool is_flush_pending_; |
77 | 81 |
78 base::WeakPtrFactory<DataUseAggregator> weak_ptr_factory_; | 82 base::WeakPtrFactory<DataUseAggregator> weak_ptr_factory_; |
79 | 83 |
80 DISALLOW_COPY_AND_ASSIGN(DataUseAggregator); | 84 DISALLOW_COPY_AND_ASSIGN(DataUseAggregator); |
81 }; | 85 }; |
82 | 86 |
83 } // namespace data_usage | 87 } // namespace data_usage |
84 | 88 |
85 #endif // COMPONENTS_DATA_USAGE_CORE_DATA_USE_AGGREGATOR_H_ | 89 #endif // COMPONENTS_DATA_USAGE_CORE_DATA_USE_AGGREGATOR_H_ |
OLD | NEW |