Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(444)

Side by Side Diff: components/metrics/data_use_tracker.h

Issue 1818613002: Implement UMA log throttling for cellular connections (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix build for gn, fix unittests, add comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "components/prefs/pref_registry_simple.h"
12 #include "components/prefs/pref_service.h"
13
14 namespace metrics {
15
16 typedef base::Callback<void(const std::string&, int)>
17 UpdateUsagePrefCallbackType;
18
19 class DataUseTracker {
Alexei Svitkine (slow) 2016/03/31 04:32:25 Add a comment.
gayane -on leave until 09-2017 2016/03/31 17:54:58 Done.
20 public:
21 // Returns a callback to data use pref updating function attached to
22 // |data_use_tracker| weak pointer. Should be called on UI thread.
23 static UpdateUsagePrefCallbackType GetForwardingCallback(
24 base::WeakPtr<DataUseTracker> data_use_tracker,
25 scoped_refptr<base::SequencedTaskRunner> ui_task_runner);
26
27 // Registers data use prefs using provided |registry|.
28 static void RegisterPrefs(PrefRegistrySimple* registry);
29
30 // Returns whether a log with provided |log_bytes| can be uploaded according
31 // to data use ratio and UMA quota provided by finch experiment.
32 bool CanUploadUMALog(int log_bytes);
33
34 base::WeakPtr<DataUseTracker> GetWeakPtr();
35
36 DataUseTracker(PrefService* local_state);
Alexei Svitkine (slow) 2016/03/31 04:32:25 explicit
gayane -on leave until 09-2017 2016/03/31 17:54:58 Done.
37 ~DataUseTracker();
Alexei Svitkine (slow) 2016/03/31 04:32:25 Put ctor and dtor at the top.
gayane -on leave until 09-2017 2016/03/31 17:54:58 Done.
38
39 private:
40 FRIEND_TEST_ALL_PREFIXES(DataUseTrackerTest, CheckUpdateUsagePref);
41 FRIEND_TEST_ALL_PREFIXES(DataUseTrackerTest, CheckRemoveExpiredEntries);
42 FRIEND_TEST_ALL_PREFIXES(DataUseTrackerTest, CheckComputeTotalDataUse);
43 FRIEND_TEST_ALL_PREFIXES(DataUseTrackerTest, CheckCanUploadUMALog);
44
45 // Updates data usage prefs on UI thread according to what Prefservice
46 // expects.
47 void UpdateMetricsUsagePrefsOnUIThread(const std::string& service_name,
48 int message_size);
49
50 // Updates provided |pref_name| for a current date with the given message
51 // size.
52 void UpdateUsagePref(const std::string& pref_name, int message_size);
53
54 // Removes entries from the all data use prefs.
55 void RemoveExpiredEntries();
56
57 // Removes entries from the given |pref_name| if they are more than 7 days
58 // old.
59 void RemoveExpiredEntriesForPref(const std::string& pref_name);
60
61 // Returns the current date as a string with a proper formatting.
62 std::string GetCurrentMeasurementDate();
63
64 // Computes data usage according to all the entries in the given dictionary
65 // pref.
66 int ComputeTotalDataUse(std::string pref_name);
67
68 bool GetUmaQuota(int* quota);
69 bool GetUmaRatio(double* ratio);
70
71 // Only for testing.
72 void SetMeasurementDateForTesting(const std::string& date);
73 void SetUmaQuotaForTesting(int uma_quota);
74 void SetUmaRatioForTesting(double uma_ratio);
75
76 PrefService* local_state_;
77
78 std::string date_for_testing_;
79 int uma_quota_for_testing_;
80 double uma_ratio_for_testing_;
81
82 base::WeakPtrFactory<DataUseTracker> weak_ptr_factory_;
83 };
84
85 } // namespace metrics
86 #endif // COMPONENTS_METRICS_DATA_USE_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698