Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Unified Diff: components/data_usage/core/data_use_aggregator.cc

Issue 1373373002: Create component to expose network usage stats to consumers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/data_usage/core/data_use_aggregator.cc
diff --git a/components/data_usage/core/data_use_aggregator.cc b/components/data_usage/core/data_use_aggregator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..802d304002e8a29d8871c1d85e82e520dce7ab44
--- /dev/null
+++ b/components/data_usage/core/data_use_aggregator.cc
@@ -0,0 +1,55 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/data_usage/core/data_use_aggregator.h"
+
+#include "net/base/network_change_notifier.h"
+#include "net/url_request/url_request.h"
+
+namespace data_usage {
+
+DataUseAggregator::DataUseAggregator() {}
+
+DataUseAggregator::~DataUseAggregator() {}
+
+void DataUseAggregator::AddObserver(Observer* observer) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ observer_list_.AddObserver(observer);
+}
+
+void DataUseAggregator::RemoveObserver(Observer* observer) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ observer_list_.RemoveObserver(observer);
+}
+
+void DataUseAggregator::ReportDataUse(const net::URLRequest& request,
+ int32_t tab_id,
+ int64_t tx_bytes,
+ int64_t rx_bytes) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ // TODO(sclittle): Once actual buffering/aggregation is being done, consider
+ // combining consecutive data use entries from the same request.
+ DataUse data_use(request.url(), request.request_time(),
+ request.first_party_for_cookies(), tab_id,
+ net::NetworkChangeNotifier::GetConnectionType(), tx_bytes,
+ rx_bytes);
+
+ // TODO(sclittle): Buffer and amortize data use on supported platforms.
+ NotifyDataUse(std::vector<DataUse>(1, data_use));
+}
+
+void DataUseAggregator::ReportOffTheRecordDataUse(int64_t tx_bytes,
+ int64_t rx_bytes) {
+ // TODO(sclittle): Once data usage amortization is implemented, keep track of
+ // the off-the-record bytes so that they can be taken out of the amortized
+ // data usage calculations if applicable.
tbansal1 2015/10/08 04:22:44 DCHECK(thread_checker_.CalledOnValidThread());
sclittle 2015/10/08 19:44:13 Done.
+}
+
+void DataUseAggregator::NotifyDataUse(
+ const std::vector<DataUse>& data_use_sequence) {
+ FOR_EACH_OBSERVER(Observer, observer_list_, OnDataUse(data_use_sequence));
+}
+
+} // namespace data_usage

Powered by Google App Engine
This is Rietveld 408576698