Chromium Code Reviews| Index: components/data_usage/core/data_use_aggregator.h |
| diff --git a/components/data_usage/core/data_use_aggregator.h b/components/data_usage/core/data_use_aggregator.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..91f1bef4e7b47bdcffda3654663c46baa30edbe1 |
| --- /dev/null |
| +++ b/components/data_usage/core/data_use_aggregator.h |
| @@ -0,0 +1,88 @@ |
| +// 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. |
| + |
| +#ifndef COMPONENTS_DATA_USAGE_CORE_DATA_USE_AGGREGATOR_H_ |
| +#define COMPONENTS_DATA_USAGE_CORE_DATA_USE_AGGREGATOR_H_ |
| + |
| +#include <stdint.h> |
| + |
| +#include <set> |
| +#include <vector> |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "net/base/network_change_notifier.h" |
| +#include "url/gurl.h" |
| + |
| +namespace data_usage { |
| + |
| +typedef int TabId; |
| + |
| +struct DataUseDelta { |
|
tbansal1
2015/10/01 20:30:43
Might be easier to keep this in a separate CL, wit
tbansal1
2015/10/01 20:30:43
If we need vector of these structs, then may be th
bengr
2015/10/02 19:32:22
I'd be inclined to call this DataUse.
sclittle
2015/10/03 03:27:53
Done.
sclittle
2015/10/03 03:27:53
This struct is part of the plumbing between DataUs
sclittle
2015/10/03 03:27:53
Renamed to DataUse.
|
| + DataUseDelta(); |
| + |
| + GURL url; |
|
tbansal1
2015/10/01 20:30:43
should these variables be all const?
sclittle
2015/10/03 03:27:53
They can't be, since that would disable copy-assig
|
| + GURL first_party_for_cookies; |
| + TabId tab_id; |
| + net::NetworkChangeNotifier::ConnectionType connection_type; |
| + // TODO(sclittle): Add more network info here, e.g. for Android, SIM operator |
| + // and whether the device is roaming. |
| + |
| + int64_t tx_bytes; |
| + int64_t rx_bytes; |
| +}; |
| + |
| +// Class that collects and aggregates network usage, reporting the usage to |
| +// observers. |
| +class DataUseAggregator { |
| + public: |
| + class Observer { |
| + public: |
| + virtual ~Observer(); |
|
tbansal1
2015/10/01 20:30:43
destructor could be private.
sclittle
2015/10/03 03:27:53
I'd prefer not to make it private, since that woul
|
| + // TODO(sclittle): Consider performing some pre-aggregation on the deltas. |
| + virtual void OnDataUse( |
| + const std::vector<DataUseDelta>& data_use_deltas) = 0; |
| + }; |
| + |
| + static scoped_ptr<DataUseAggregator> Create(); |
|
tbansal1
2015/10/01 20:30:43
I guess it would be okay for callers to directly c
sclittle
2015/10/03 03:27:53
Sure, I'll switch it to using a factory-style Crea
|
| + |
| + virtual ~DataUseAggregator(); |
| + |
| + void RegisterObserver(Observer* observer); |
| + void UnregisterObserver(Observer* observer); |
| + |
| + // TODO(sclittle): Consider passing in a struct instead to make it easier to |
| + // add more annotations in the future. |
| + void ReportDataUse(const GURL& url, |
| + const GURL& first_party_for_cookies, |
| + TabId tab_id, |
| + int64_t tx_bytes, |
| + int64_t rx_bytes); |
| + |
| + // Account for off-the-record data use. This usage is only kept track of here |
| + // so that it can be taken out of any amortized data usage calculations, and a |
| + // per-request breakdown of off-the-record data usage will never leave the |
| + // DataUseAggregator. |
| + void ReportOffTheRecordDataUse(int64_t tx_bytes, int64_t rx_bytes); |
| + |
| + base::WeakPtr<DataUseAggregator> GetWeakPtr(); |
| + |
| + protected: |
| + DataUseAggregator(); |
| + |
| + private: |
| + void NotifyDataUse(const std::vector<DataUseDelta>& data_use_deltas); |
| + |
| + std::set<Observer*> observers_; |
|
tbansal1
2015/10/01 20:30:43
Why not ObserverList or ObserverListThreadSafe?
sclittle
2015/10/03 03:27:53
Done.
|
| + std::vector<DataUseDelta> buffered_data_use_deltas_; |
| + |
| + base::WeakPtrFactory<DataUseAggregator> weak_ptr_factory_; |
| + |
|
tbansal1
2015/10/01 20:30:43
thread checker is missing.
sclittle
2015/10/03 03:27:53
Done.
|
| + DISALLOW_COPY_AND_ASSIGN(DataUseAggregator); |
| +}; |
| + |
| +} // namespace data_usage |
| + |
| +#endif // COMPONENTS_DATA_USAGE_CORE_DATA_USE_AGGREGATOR_H_ |