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 #include "components/data_usage/core/data_use_aggregator.h" | 5 #include "components/data_usage/core/data_use_aggregator.h" |
6 | 6 |
| 7 #include <sstream> |
| 8 #include <string> |
| 9 |
7 #include "base/bind.h" | 10 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
9 #include "net/base/network_change_notifier.h" | 12 #include "net/base/network_change_notifier.h" |
10 #include "net/url_request/url_request.h" | 13 #include "net/url_request/url_request.h" |
11 | 14 |
12 namespace data_usage { | 15 namespace data_usage { |
13 | 16 |
14 DataUseAggregator::DataUseAggregator() | 17 DataUseAggregator::DataUseAggregator( |
15 : off_the_record_tx_bytes_since_last_flush_(0), | 18 scoped_ptr<DataUseAmortizer> data_use_amortizer) |
| 19 : data_use_amortizer_(data_use_amortizer.Pass()), |
| 20 off_the_record_tx_bytes_since_last_flush_(0), |
16 off_the_record_rx_bytes_since_last_flush_(0), | 21 off_the_record_rx_bytes_since_last_flush_(0), |
17 is_flush_pending_(false), | 22 is_flush_pending_(false), |
18 weak_ptr_factory_(this) {} | 23 weak_ptr_factory_(this) {} |
19 | 24 |
20 DataUseAggregator::~DataUseAggregator() {} | 25 DataUseAggregator::~DataUseAggregator() {} |
21 | 26 |
22 void DataUseAggregator::AddObserver(Observer* observer) { | 27 void DataUseAggregator::AddObserver(Observer* observer) { |
23 DCHECK(thread_checker_.CalledOnValidThread()); | 28 DCHECK(thread_checker_.CalledOnValidThread()); |
24 observer_list_.AddObserver(observer); | 29 observer_list_.AddObserver(observer); |
25 } | 30 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 off_the_record_rx_bytes_since_last_flush_ += rx_bytes; | 80 off_the_record_rx_bytes_since_last_flush_ += rx_bytes; |
76 } | 81 } |
77 | 82 |
78 base::WeakPtr<DataUseAggregator> DataUseAggregator::GetWeakPtr() { | 83 base::WeakPtr<DataUseAggregator> DataUseAggregator::GetWeakPtr() { |
79 return weak_ptr_factory_.GetWeakPtr(); | 84 return weak_ptr_factory_.GetWeakPtr(); |
80 } | 85 } |
81 | 86 |
82 void DataUseAggregator::FlushBufferedDataUse() { | 87 void DataUseAggregator::FlushBufferedDataUse() { |
83 DCHECK(thread_checker_.CalledOnValidThread()); | 88 DCHECK(thread_checker_.CalledOnValidThread()); |
84 | 89 |
85 // TODO(sclittle): Amortize data use on supported platforms. | 90 if (data_use_amortizer_) { |
| 91 data_use_amortizer_->Amortize(&buffered_data_use_, |
| 92 off_the_record_tx_bytes_since_last_flush_, |
| 93 off_the_record_rx_bytes_since_last_flush_); |
| 94 } |
86 | 95 |
87 FOR_EACH_OBSERVER(Observer, observer_list_, OnDataUse(buffered_data_use_)); | 96 FOR_EACH_OBSERVER(Observer, observer_list_, OnDataUse(buffered_data_use_)); |
88 | 97 |
89 buffered_data_use_.clear(); | 98 buffered_data_use_.clear(); |
90 off_the_record_tx_bytes_since_last_flush_ = 0; | 99 off_the_record_tx_bytes_since_last_flush_ = 0; |
91 off_the_record_rx_bytes_since_last_flush_ = 0; | 100 off_the_record_rx_bytes_since_last_flush_ = 0; |
92 is_flush_pending_ = false; | 101 is_flush_pending_ = false; |
93 } | 102 } |
94 | 103 |
95 } // namespace data_usage | 104 } // namespace data_usage |
OLD | NEW |