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..20d81449eb2eea67100a8a926b2a7713a54f6e3c |
--- /dev/null |
+++ b/components/metrics/data_use_tracker.h |
@@ -0,0 +1,84 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
Alexei Svitkine (slow)
2016/03/29 16:29:10
2016
gayane -on leave until 09-2017
2016/03/31 01:38:24
Done.
|
+// 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 "components/prefs/pref_registry_simple.h" |
+#include "components/prefs/pref_service.h" |
+ |
+namespace metrics { |
+ |
+class DataUseTracker { |
+ public: |
+ static void GetForwardingCallback( |
+ base::WeakPtr<DataUseTracker> data_use_tracker, |
+ base::Callback<void(base::Callback<void(const std::string&, int)>)> |
+ reply_callback); |
+ |
+ // Should be called on UI thread |
+ static base::Callback<void(const std::string&, int)> |
+ GetForwardingCallbackOnUIThread( |
+ base::WeakPtr<DataUseTracker> data_use_tracker); |
Alexei Svitkine (slow)
2016/03/29 16:29:10
This doesn't need to be exposed in the header - so
gayane -on leave until 09-2017
2016/03/31 01:38:24
Done.
|
+ |
+ static void RegisterPrefs(PrefRegistrySimple* registry); |
+ |
+ static void RunOnUI(base::Callback<void(const std::string&, int)> callback, |
+ const std::string& service_name, |
+ int message_size); |
+ |
+ bool CanUploadUMALog(int log_bytes); |
+ |
+ base::WeakPtr<DataUseTracker> GetWeakPtr(); |
+ |
+ DataUseTracker(PrefService* local_state); |
+ ~DataUseTracker(); |
+ |
+ 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 as the request comes from net which |
+ // is on IO thread, but Prefservice expects UI thread. |
+ void UpdateMetricsUsagePrefsOnUIThread(const std::string& service_name, |
+ int message_size); |
+ |
+ // Removes entries from the dictionary prefs if they are more than 7 days old. |
+ void RemoveExpiredEntries(); |
+ |
+ // Updates data usage prefs for a current date with the given message size. |
+ void UpdateUsagePref(const std::string& pref_name, int message_size); |
+ |
+ // Returns the current date as a string with a proper formatting. |
+ std::string GetCurrentMeasurementDate(); |
+ |
+ // Computes data usage according to all the entries in the given dictionary |
+ // prefs. |
+ int ComputeTotalDataUse(std::string pref_name); |
+ |
+ void RemoveExpiredEntriesForPref(const std::string& pref_name); |
+ bool GetUmaQouta(int* qouta); |
Alexei Svitkine (slow)
2016/03/29 16:29:10
Qouta -> Quota
gayane -on leave until 09-2017
2016/03/31 01:38:24
Done.
|
+ bool GetUmaRatio(double* ratio); |
+ |
+ // Only for testing. |
+ void SetMeasurementDateForTesting(const std::string& date); |
+ void SetUmaQoutaForTesting(int uma_qouta); |
+ void SetUmaRatioForTesting(double uma_ratio); |
+ |
+ PrefService* local_state_; |
+ |
+ std::string date_for_testing_; |
+ int uma_qouta_for_testing_; |
+ double uma_ratio_for_testing_; |
+ |
+ base::WeakPtrFactory<DataUseTracker> weak_ptr_factory_; |
+}; |
+ |
+} // namespace metrics |
+#endif // COMPONENTS_METRICS_DATA_USE_TRACKER_H_ |