Index: components/metrics/data_use_tracker.h |
diff --git a/components/metrics/data_use_tracker.h b/components/metrics/data_use_tracker.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f432db78e71fcbf1d046bf4060d078acb4796326 |
--- /dev/null |
+++ b/components/metrics/data_use_tracker.h |
@@ -0,0 +1,89 @@ |
+// Copyright 2016 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_METRICS_DATA_USE_TRACKER_H_ |
+#define COMPONENTS_METRICS_DATA_USE_TRACKER_H_ |
+ |
+#include "base/callback.h" |
+#include "base/gtest_prod_util.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/threading/thread_checker.h" |
+#include "components/prefs/pref_registry_simple.h" |
+#include "components/prefs/pref_service.h" |
+ |
+namespace metrics { |
+ |
+typedef base::Callback<void(const std::string&, int, bool)> |
mmenke
2016/04/05 20:18:32
include string
gayane -on leave until 09-2017
2016/04/06 18:30:56
Done.
|
+ UpdateUsagePrefCallbackType; |
+ |
+// Records the data use of user traffic and UMA traffic in user prefs. Taking |
+// into account those prefs it can verify whether certain UMA log upload is |
+// allowed. |
+class DataUseTracker { |
+ public: |
+ explicit DataUseTracker(PrefService* local_state); |
+ ~DataUseTracker(); |
+ |
+ // Registers data use prefs using provided |registry|. |
+ static void RegisterPrefs(PrefRegistrySimple* registry); |
+ |
+ // Returns a callback to data use pref updating function. Should be called on |
+ // UI thread. |
+ UpdateUsagePrefCallbackType GetDataUseForwardingCallback( |
+ scoped_refptr<base::SequencedTaskRunner> ui_task_runner); |
mmenke
2016/04/05 20:18:32
include ref_counted.h. Should also include the se
gayane -on leave until 09-2017
2016/04/06 18:30:56
Done.
|
+ |
+ // Returns whether a log with provided |log_bytes| can be uploaded according |
+ // to data use ratio and UMA quota provided by variations. |
+ bool ShouldUploadLogOnCellular(int log_bytes); |
+ |
+ private: |
+ FRIEND_TEST_ALL_PREFIXES(DataUseTrackerTest, CheckUpdateUsagePref); |
+ FRIEND_TEST_ALL_PREFIXES(DataUseTrackerTest, CheckRemoveExpiredEntries); |
+ FRIEND_TEST_ALL_PREFIXES(DataUseTrackerTest, CheckComputeTotalDataUse); |
+ FRIEND_TEST_ALL_PREFIXES(DataUseTrackerTest, CheckCanUploadUMALog); |
+ |
+ // Updates data usage prefs on UI thread according to what Prefservice |
+ // expects. |
+ void UpdateMetricsUsagePrefsOnUIThread(const std::string& service_name, |
+ int message_size, |
+ bool is_cellular); |
+ |
+ // Updates provided |pref_name| for a current date with the given message |
+ // size. |
+ void UpdateUsagePref(const std::string& pref_name, int message_size); |
+ |
+ // Removes entries from the all data use prefs. |
+ void RemoveExpiredEntries(); |
+ |
+ // Removes entries from the given |pref_name| if they are more than 7 days |
+ // old. |
+ void RemoveExpiredEntriesForPref(const std::string& pref_name); |
+ |
+ // Computes data usage according to all the entries in the given dictionary |
+ // pref. |
+ int ComputeTotalDataUse(std::string pref_name); |
mmenke
2016/04/05 20:18:32
const std::string&
gayane -on leave until 09-2017
2016/04/06 18:30:56
Done.
|
+ |
+ // Returns the weekly allowed quota for UMA data use. |
+ virtual bool GetUmaWeeklyQuota(int* uma_weekly_quota_bytes); |
mmenke
2016/04/05 20:18:32
These getters should presumably all be const (thin
gayane -on leave until 09-2017
2016/04/06 18:30:56
Done.
|
+ |
+ // Returns the allowed ratio for UMA data use over overall data use. |
+ virtual bool GetUmaRatio(double* ratio); |
+ |
+ // Returns the current date for measurement. |
+ virtual base::Time GetCurrentMeasurementDate(); |
mmenke
2016/04/05 20:18:32
include time
gayane -on leave until 09-2017
2016/04/06 18:30:56
Done.
|
+ |
+ // Returns the current date as a string with a proper formatting. |
+ virtual std::string GetCurrentMeasurementDateAsString(); |
+ |
+ PrefService* local_state_; |
+ |
+ base::ThreadChecker thread_checker_; |
+ |
+ base::WeakPtrFactory<DataUseTracker> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DataUseTracker); |
mmenke
2016/04/05 20:18:32
include base/macros
gayane -on leave until 09-2017
2016/04/06 18:30:56
Done.
|
+}; |
+ |
+} // namespace metrics |
+#endif // COMPONENTS_METRICS_DATA_USE_TRACKER_H_ |