OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
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 "base/threading/thread_checker.h" | |
12 #include "components/prefs/pref_registry_simple.h" | |
13 #include "components/prefs/pref_service.h" | |
14 | |
15 namespace metrics { | |
16 | |
17 typedef base::Callback<void(const std::string&, int)> | |
18 UpdateUsagePrefCallbackType; | |
19 | |
20 // Records the data use of user traffic and UMA traffic in user prefs. Taking | |
21 // into account those prefs it can verify whether certain UMA log upload is | |
22 // allowed. | |
23 class DataUseTracker { | |
24 public: | |
25 explicit DataUseTracker(PrefService* local_state); | |
26 ~DataUseTracker(); | |
27 | |
28 // Registers data use prefs using provided |registry|. | |
29 static void RegisterPrefs(PrefRegistrySimple* registry); | |
30 | |
31 // Returns a callback to data use pref updating function attached to | |
32 // |data_use_tracker| weak pointer. Should be called on UI thread. | |
Alexei Svitkine (slow)
2016/04/01 20:38:58
|data_use_tracker| is not a thing. Please update t
gayane -on leave until 09-2017
2016/04/01 21:00:08
Done.
| |
33 UpdateUsagePrefCallbackType GetDataUseForwardingCallback( | |
34 scoped_refptr<base::SequencedTaskRunner> ui_task_runner); | |
35 | |
36 // Returns whether a log with provided |log_bytes| can be uploaded according | |
37 // to data use ratio and UMA quota provided by variations. | |
38 bool ShouldUploadLogOnCellular(int log_bytes); | |
39 | |
40 private: | |
41 FRIEND_TEST_ALL_PREFIXES(DataUseTrackerTest, CheckUpdateUsagePref); | |
42 FRIEND_TEST_ALL_PREFIXES(DataUseTrackerTest, CheckRemoveExpiredEntries); | |
43 FRIEND_TEST_ALL_PREFIXES(DataUseTrackerTest, CheckComputeTotalDataUse); | |
44 FRIEND_TEST_ALL_PREFIXES(DataUseTrackerTest, CheckCanUploadUMALog); | |
45 | |
46 // Updates data usage prefs on UI thread according to what Prefservice | |
47 // expects. | |
48 void UpdateMetricsUsagePrefsOnUIThread(const std::string& service_name, | |
49 int message_size); | |
50 | |
51 // Updates provided |pref_name| for a current date with the given message | |
52 // size. | |
53 void UpdateUsagePref(const std::string& pref_name, int message_size); | |
54 | |
55 // Removes entries from the all data use prefs. | |
56 void RemoveExpiredEntries(); | |
57 | |
58 // Removes entries from the given |pref_name| if they are more than 7 days | |
59 // old. | |
60 void RemoveExpiredEntriesForPref(const std::string& pref_name); | |
61 | |
62 // Computes data usage according to all the entries in the given dictionary | |
63 // pref. | |
64 int ComputeTotalDataUse(std::string pref_name); | |
65 | |
66 virtual bool GetUmaWeeaklyQuota(int* uma_weekly_quota_bytes); | |
Alexei Svitkine (slow)
2016/04/01 20:38:58
Comments please.
gayane -on leave until 09-2017
2016/04/01 21:00:08
Done.
| |
67 virtual bool GetUmaRatio(double* ratio); | |
68 | |
69 // Returns the current date for measurement. | |
70 virtual base::Time GetCurrentMeasurementDate(); | |
71 | |
72 // Returns the current date as a string with a proper formatting. | |
73 virtual std::string GetCurrentMeasurementDateAsString(); | |
74 | |
75 PrefService* local_state_; | |
76 | |
77 std::string date_for_testing_; | |
78 int uma_quota_for_testing_; | |
79 double uma_ratio_for_testing_; | |
80 | |
81 base::ThreadChecker thread_checker_; | |
82 | |
83 base::WeakPtrFactory<DataUseTracker> weak_ptr_factory_; | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(DataUseTracker); | |
86 }; | |
87 | |
88 } // namespace metrics | |
89 #endif // COMPONENTS_METRICS_DATA_USE_TRACKER_H_ | |
OLD | NEW |