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

Side by Side Diff: components/data_usage/core/data_use_aggregator.h

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 nits 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 unified diff | Download patch
OLDNEW
(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 <vector>
11
12 #include "base/macros.h"
13 #include "base/observer_list.h"
14 #include "base/threading/thread_checker.h"
15 #include "components/data_usage/core/data_use.h"
16
17 namespace net {
18 class URLRequest;
19 }
20
21 namespace data_usage {
22
23 // Class that collects and aggregates network usage, reporting the usage to
24 // observers. Should only be used on the IO thread.
25 class DataUseAggregator {
26 public:
27 class Observer {
28 public:
29 virtual ~Observer() {}
30 // TODO(sclittle): Consider performing some pre-aggregation on the data use.
31 virtual void OnDataUse(const std::vector<DataUse>& data_use_sequence) = 0;
32 };
33
34 DataUseAggregator();
35 virtual ~DataUseAggregator();
36
37 void AddObserver(Observer* observer);
38 void RemoveObserver(Observer* observer);
39
40 // Virtual for testing.
41 virtual void ReportDataUse(const net::URLRequest& request,
42 int32_t tab_id,
43 int64_t tx_bytes,
44 int64_t rx_bytes);
45
46 // Account for off-the-record data use. This usage is only kept track of here
47 // so that it can be taken out of any amortized data usage calculations, and a
48 // per-request breakdown of off-the-record data usage will never leave the
49 // DataUseAggregator.
50 // Virtual for testing.
51 virtual void ReportOffTheRecordDataUse(int64_t tx_bytes, int64_t rx_bytes);
52
53 private:
54 void NotifyDataUse(const std::vector<DataUse>& data_use_sequence);
55
56 base::ThreadChecker thread_checker_;
57 base::ObserverList<Observer> observer_list_;
58
59 DISALLOW_COPY_AND_ASSIGN(DataUseAggregator);
60 };
61
62 } // namespace data_usage
63
64 #endif // COMPONENTS_DATA_USAGE_CORE_DATA_USE_AGGREGATOR_H_
OLDNEW
« no previous file with comments | « components/data_usage/core/data_use.cc ('k') | components/data_usage/core/data_use_aggregator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698