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 <set> | |
11 #include <vector> | |
12 | |
13 #include "base/macros.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/memory/weak_ptr.h" | |
16 #include "net/base/network_change_notifier.h" | |
17 #include "url/gurl.h" | |
18 | |
19 namespace data_usage { | |
20 | |
21 typedef int TabId; | |
22 | |
23 struct DataUseDelta { | |
tbansal1
2015/10/01 20:30:43
Might be easier to keep this in a separate CL, wit
tbansal1
2015/10/01 20:30:43
If we need vector of these structs, then may be th
bengr
2015/10/02 19:32:22
I'd be inclined to call this DataUse.
sclittle
2015/10/03 03:27:53
Done.
sclittle
2015/10/03 03:27:53
This struct is part of the plumbing between DataUs
sclittle
2015/10/03 03:27:53
Renamed to DataUse.
| |
24 DataUseDelta(); | |
25 | |
26 GURL url; | |
tbansal1
2015/10/01 20:30:43
should these variables be all const?
sclittle
2015/10/03 03:27:53
They can't be, since that would disable copy-assig
| |
27 GURL first_party_for_cookies; | |
28 TabId tab_id; | |
29 net::NetworkChangeNotifier::ConnectionType connection_type; | |
30 // TODO(sclittle): Add more network info here, e.g. for Android, SIM operator | |
31 // and whether the device is roaming. | |
32 | |
33 int64_t tx_bytes; | |
34 int64_t rx_bytes; | |
35 }; | |
36 | |
37 // Class that collects and aggregates network usage, reporting the usage to | |
38 // observers. | |
39 class DataUseAggregator { | |
40 public: | |
41 class Observer { | |
42 public: | |
43 virtual ~Observer(); | |
tbansal1
2015/10/01 20:30:43
destructor could be private.
sclittle
2015/10/03 03:27:53
I'd prefer not to make it private, since that woul
| |
44 // TODO(sclittle): Consider performing some pre-aggregation on the deltas. | |
45 virtual void OnDataUse( | |
46 const std::vector<DataUseDelta>& data_use_deltas) = 0; | |
47 }; | |
48 | |
49 static scoped_ptr<DataUseAggregator> Create(); | |
tbansal1
2015/10/01 20:30:43
I guess it would be okay for callers to directly c
sclittle
2015/10/03 03:27:53
Sure, I'll switch it to using a factory-style Crea
| |
50 | |
51 virtual ~DataUseAggregator(); | |
52 | |
53 void RegisterObserver(Observer* observer); | |
54 void UnregisterObserver(Observer* observer); | |
55 | |
56 // TODO(sclittle): Consider passing in a struct instead to make it easier to | |
57 // add more annotations in the future. | |
58 void ReportDataUse(const GURL& url, | |
59 const GURL& first_party_for_cookies, | |
60 TabId tab_id, | |
61 int64_t tx_bytes, | |
62 int64_t rx_bytes); | |
63 | |
64 // Account for off-the-record data use. This usage is only kept track of here | |
65 // so that it can be taken out of any amortized data usage calculations, and a | |
66 // per-request breakdown of off-the-record data usage will never leave the | |
67 // DataUseAggregator. | |
68 void ReportOffTheRecordDataUse(int64_t tx_bytes, int64_t rx_bytes); | |
69 | |
70 base::WeakPtr<DataUseAggregator> GetWeakPtr(); | |
71 | |
72 protected: | |
73 DataUseAggregator(); | |
74 | |
75 private: | |
76 void NotifyDataUse(const std::vector<DataUseDelta>& data_use_deltas); | |
77 | |
78 std::set<Observer*> observers_; | |
tbansal1
2015/10/01 20:30:43
Why not ObserverList or ObserverListThreadSafe?
sclittle
2015/10/03 03:27:53
Done.
| |
79 std::vector<DataUseDelta> buffered_data_use_deltas_; | |
80 | |
81 base::WeakPtrFactory<DataUseAggregator> weak_ptr_factory_; | |
82 | |
tbansal1
2015/10/01 20:30:43
thread checker is missing.
sclittle
2015/10/03 03:27:53
Done.
| |
83 DISALLOW_COPY_AND_ASSIGN(DataUseAggregator); | |
84 }; | |
85 | |
86 } // namespace data_usage | |
87 | |
88 #endif // COMPONENTS_DATA_USAGE_CORE_DATA_USE_AGGREGATOR_H_ | |
OLD | NEW |