OLD | NEW |
---|---|
(Empty) | |
1 // 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.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_METRICS_DATA_USE_TRACKER_H_ | |
6 #define COMPONENTS_METRICS_DATA_USE_TRACKER_H_ | |
7 | |
8 #include "base/callback.h" | |
9 #include "base/gtest_prod_util.h" | |
10 #include "base/memory/weak_ptr.h" | |
11 #include "components/prefs/pref_registry_simple.h" | |
12 #include "components/prefs/pref_service.h" | |
13 | |
14 namespace metrics { | |
15 | |
16 class DataUseTracker { | |
17 public: | |
18 static void GetForwardingCallback( | |
19 base::WeakPtr<DataUseTracker> data_use_tracker, | |
20 base::Callback<void(base::Callback<void(const std::string&, int)>)> | |
21 reply_callback); | |
22 | |
23 // Should be called on UI thread | |
24 static base::Callback<void(const std::string&, int)> | |
25 GetForwardingCallbackOnUIThread( | |
26 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.
| |
27 | |
28 static void RegisterPrefs(PrefRegistrySimple* registry); | |
29 | |
30 static void RunOnUI(base::Callback<void(const std::string&, int)> callback, | |
31 const std::string& service_name, | |
32 int message_size); | |
33 | |
34 bool CanUploadUMALog(int log_bytes); | |
35 | |
36 base::WeakPtr<DataUseTracker> GetWeakPtr(); | |
37 | |
38 DataUseTracker(PrefService* local_state); | |
39 ~DataUseTracker(); | |
40 | |
41 private: | |
42 FRIEND_TEST_ALL_PREFIXES(DataUseTrackerTest, CheckUpdateUsagePref); | |
43 FRIEND_TEST_ALL_PREFIXES(DataUseTrackerTest, CheckRemoveExpiredEntries); | |
44 FRIEND_TEST_ALL_PREFIXES(DataUseTrackerTest, CheckComputeTotalDataUse); | |
45 FRIEND_TEST_ALL_PREFIXES(DataUseTrackerTest, CheckCanUploadUMALog); | |
46 | |
47 // Updates data usage prefs on UI thread as the request comes from net which | |
48 // is on IO thread, but Prefservice expects UI thread. | |
49 void UpdateMetricsUsagePrefsOnUIThread(const std::string& service_name, | |
50 int message_size); | |
51 | |
52 // Removes entries from the dictionary prefs if they are more than 7 days old. | |
53 void RemoveExpiredEntries(); | |
54 | |
55 // Updates data usage prefs for a current date with the given message size. | |
56 void UpdateUsagePref(const std::string& pref_name, int message_size); | |
57 | |
58 // Returns the current date as a string with a proper formatting. | |
59 std::string GetCurrentMeasurementDate(); | |
60 | |
61 // Computes data usage according to all the entries in the given dictionary | |
62 // prefs. | |
63 int ComputeTotalDataUse(std::string pref_name); | |
64 | |
65 void RemoveExpiredEntriesForPref(const std::string& pref_name); | |
66 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.
| |
67 bool GetUmaRatio(double* ratio); | |
68 | |
69 // Only for testing. | |
70 void SetMeasurementDateForTesting(const std::string& date); | |
71 void SetUmaQoutaForTesting(int uma_qouta); | |
72 void SetUmaRatioForTesting(double uma_ratio); | |
73 | |
74 PrefService* local_state_; | |
75 | |
76 std::string date_for_testing_; | |
77 int uma_qouta_for_testing_; | |
78 double uma_ratio_for_testing_; | |
79 | |
80 base::WeakPtrFactory<DataUseTracker> weak_ptr_factory_; | |
81 }; | |
82 | |
83 } // namespace metrics | |
84 #endif // COMPONENTS_METRICS_DATA_USE_TRACKER_H_ | |
OLD | NEW |