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, bool)> | |
mmenke
2016/04/05 20:18:32
include string
gayane -on leave until 09-2017
2016/04/06 18:30:56
Done.
| |
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. Should be called on | |
32 // UI thread. | |
33 UpdateUsagePrefCallbackType GetDataUseForwardingCallback( | |
34 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.
| |
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 bool is_cellular); | |
51 | |
52 // Updates provided |pref_name| for a current date with the given message | |
53 // size. | |
54 void UpdateUsagePref(const std::string& pref_name, int message_size); | |
55 | |
56 // Removes entries from the all data use prefs. | |
57 void RemoveExpiredEntries(); | |
58 | |
59 // Removes entries from the given |pref_name| if they are more than 7 days | |
60 // old. | |
61 void RemoveExpiredEntriesForPref(const std::string& pref_name); | |
62 | |
63 // Computes data usage according to all the entries in the given dictionary | |
64 // pref. | |
65 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.
| |
66 | |
67 // Returns the weekly allowed quota for UMA data use. | |
68 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.
| |
69 | |
70 // Returns the allowed ratio for UMA data use over overall data use. | |
71 virtual bool GetUmaRatio(double* ratio); | |
72 | |
73 // Returns the current date for measurement. | |
74 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.
| |
75 | |
76 // Returns the current date as a string with a proper formatting. | |
77 virtual std::string GetCurrentMeasurementDateAsString(); | |
78 | |
79 PrefService* local_state_; | |
80 | |
81 base::ThreadChecker thread_checker_; | |
82 | |
83 base::WeakPtrFactory<DataUseTracker> weak_ptr_factory_; | |
84 | |
85 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.
| |
86 }; | |
87 | |
88 } // namespace metrics | |
89 #endif // COMPONENTS_METRICS_DATA_USE_TRACKER_H_ | |
OLD | NEW |