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 #include "components/data_usage/core/data_use_aggregator.h" | |
6 | |
7 #include "net/base/network_change_notifier.h" | |
8 #include "net/url_request/url_request.h" | |
9 | |
10 namespace data_usage { | |
11 | |
12 DataUseAggregator::DataUseAggregator() {} | |
13 | |
14 DataUseAggregator::~DataUseAggregator() {} | |
15 | |
16 void DataUseAggregator::AddObserver(Observer* observer) { | |
17 DCHECK(thread_checker_.CalledOnValidThread()); | |
18 observer_list_.AddObserver(observer); | |
19 } | |
20 | |
21 void DataUseAggregator::RemoveObserver(Observer* observer) { | |
22 DCHECK(thread_checker_.CalledOnValidThread()); | |
23 observer_list_.RemoveObserver(observer); | |
24 } | |
25 | |
26 void DataUseAggregator::ReportDataUse(const net::URLRequest& request, | |
27 int32_t tab_id, | |
28 int64_t tx_bytes, | |
29 int64_t rx_bytes) { | |
30 DCHECK(thread_checker_.CalledOnValidThread()); | |
31 | |
32 // TODO(sclittle): Once actual buffering/aggregation is being done, consider | |
33 // combining consecutive data use entries from the same request. | |
34 DataUse data_use(request.url(), request.request_time(), | |
35 request.first_party_for_cookies(), tab_id, | |
36 net::NetworkChangeNotifier::GetConnectionType(), tx_bytes, | |
37 rx_bytes); | |
38 | |
39 // TODO(sclittle): Buffer and amortize data use on supported platforms. | |
40 NotifyDataUse(std::vector<DataUse>(1, data_use)); | |
41 } | |
42 | |
43 void DataUseAggregator::ReportOffTheRecordDataUse(int64_t tx_bytes, | |
44 int64_t rx_bytes) { | |
45 // TODO(sclittle): Once data usage amortization is implemented, keep track of | |
46 // the off-the-record bytes so that they can be taken out of the amortized | |
47 // data usage calculations if applicable. | |
tbansal1
2015/10/08 04:22:44
DCHECK(thread_checker_.CalledOnValidThread());
sclittle
2015/10/08 19:44:13
Done.
| |
48 } | |
49 | |
50 void DataUseAggregator::NotifyDataUse( | |
51 const std::vector<DataUse>& data_use_sequence) { | |
52 FOR_EACH_OBSERVER(Observer, observer_list_, OnDataUse(data_use_sequence)); | |
53 } | |
54 | |
55 } // namespace data_usage | |
OLD | NEW |