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

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

Powered by Google App Engine
This is Rietveld 408576698