Chromium Code Reviews| Index: components/data_usage/android/traffic_stats_amortizer.h |
| diff --git a/components/data_usage/android/traffic_stats_amortizer.h b/components/data_usage/android/traffic_stats_amortizer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..43b17beac432bcdca81940f0a119e97c10e3c94a |
| --- /dev/null |
| +++ b/components/data_usage/android/traffic_stats_amortizer.h |
| @@ -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. |
| + |
| +#ifndef COMPONENTS_DATA_USAGE_ANDROID_TRAFFIC_STATS_AMORTIZER_H_ |
| +#define COMPONENTS_DATA_USAGE_ANDROID_TRAFFIC_STATS_AMORTIZER_H_ |
| + |
| +#include <stdint.h> |
| + |
| +#include <vector> |
| + |
| +#include "base/macros.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "components/data_usage/core/data_use.h" |
| +#include "components/data_usage/core/data_use_amortizer.h" |
| + |
| +namespace data_usage { |
| +namespace android { |
| + |
| +// Class that uses Android TrafficStats to amortize the data usage stats |
| +// produced by the network stack. Should only be used on the IO thread. |
| +class TrafficStatsAmortizer : public DataUseAmortizer { |
| + public: |
| + TrafficStatsAmortizer(); |
| + ~TrafficStatsAmortizer() override; |
| + |
| + void Amortize(std::vector<DataUse>* data_use_sequence, |
| + int64_t extra_tx_bytes, |
| + int64_t extra_rx_bytes) override; |
| + |
| + protected: |
| + // Virtual for testing. |
| + virtual bool GetTrafficStatsTxBytes(int64_t* tx_bytes) const; |
| + // Virtual for testing. |
| + virtual bool GetTrafficStatsRxBytes(int64_t* rx_bytes) const; |
| + |
| + private: |
| + void RefreshTrafficStats(); |
| + |
| + base::ThreadChecker thread_checker_; |
| + |
| + // Indicates whether or not |traffic_stats_tx_bytes_| and |
| + // |traffic_stats_rx_bytes_| were available the last time they were refreshed. |
| + bool are_traffic_stats_available_; |
|
bengr
2015/10/12 21:33:08
were_... ?
|
| + |
| + int64_t traffic_stats_tx_bytes_; |
| + int64_t traffic_stats_rx_bytes_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TrafficStatsAmortizer); |
| +}; |
| + |
| +} // namespace android |
| +} // namespace data_usage |
| + |
| +#endif // COMPONENTS_DATA_USAGE_ANDROID_TRAFFIC_STATS_AMORTIZER_H_ |