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

Unified Diff: components/data_usage/android/traffic_stats_amortizer.h

Issue 1390993005: Amortize data usage using TrafficStats on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@data_use_buffering
Patch Set: 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/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_

Powered by Google App Engine
This is Rietveld 408576698