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

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

Issue 1974593002: Make the launch params the default client behavior for UMA 3g (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix build presubmit warning Created 4 years, 7 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
« no previous file with comments | « components/metrics/BUILD.gn ('k') | components/metrics/metrics_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/metrics/data_use_tracker.h" 5 #include "components/metrics/data_use_tracker.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "components/metrics/metrics_pref_names.h" 11 #include "components/metrics/metrics_pref_names.h"
12 #include "components/prefs/scoped_user_pref_update.h" 12 #include "components/prefs/scoped_user_pref_update.h"
13 #include "components/variations/variations_associated_data.h" 13 #include "components/variations/variations_associated_data.h"
14 14
15 namespace metrics { 15 namespace metrics {
16 16
17 namespace { 17 namespace {
18 18
19 // Default weekly quota and allowed UMA ratio for UMA log uploads for Android.
20 // These defaults will not be used for non-Android as |DataUseTracker| will not
21 // be initialized. Default values can be overridden by variation params.
22 const int kDefaultUMAWeeklyQuotaBytes = 204800;
23 const double kDefaultUMARatio = 0.05;
24
19 // This function is for forwarding metrics usage pref changes to the appropriate 25 // This function is for forwarding metrics usage pref changes to the appropriate
20 // callback on the appropriate thread. 26 // callback on the appropriate thread.
21 // TODO(gayane): Reduce the frequency of posting tasks from IO to UI thread. 27 // TODO(gayane): Reduce the frequency of posting tasks from IO to UI thread.
22 void UpdateMetricsUsagePrefs( 28 void UpdateMetricsUsagePrefs(
23 const UpdateUsagePrefCallbackType& update_on_ui_callback, 29 const UpdateUsagePrefCallbackType& update_on_ui_callback,
24 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, 30 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
25 const std::string& service_name, 31 const std::string& service_name,
26 int message_size, 32 int message_size,
27 bool is_cellular) { 33 bool is_cellular) {
28 ui_task_runner->PostTask( 34 ui_task_runner->PostTask(
29 FROM_HERE, base::Bind(update_on_ui_callback, service_name, message_size, 35 FROM_HERE, base::Bind(update_on_ui_callback, service_name, message_size,
30 is_cellular)); 36 is_cellular));
31 } 37 }
32 38
33 } // namespace 39 } // namespace
34 40
35 DataUseTracker::DataUseTracker(PrefService* local_state) 41 DataUseTracker::DataUseTracker(PrefService* local_state)
36 : local_state_(local_state), weak_ptr_factory_(this) {} 42 : local_state_(local_state), weak_ptr_factory_(this) {}
37 43
38 DataUseTracker::~DataUseTracker() {} 44 DataUseTracker::~DataUseTracker() {}
39 45
40 // static 46 // static
41 std::unique_ptr<DataUseTracker> DataUseTracker::Create( 47 std::unique_ptr<DataUseTracker> DataUseTracker::Create(
42 PrefService* local_state) { 48 PrefService* local_state) {
43 std::unique_ptr<DataUseTracker> data_use_tracker; 49 std::unique_ptr<DataUseTracker> data_use_tracker;
44 if (variations::GetVariationParamValue("UMA_EnableCellularLogUpload", 50 #if defined(OS_ANDROID)
45 "Uma_Quota") != "" && 51 data_use_tracker.reset(new DataUseTracker(local_state));
46 variations::GetVariationParamValue("UMA_EnableCellularLogUpload", 52 #endif
47 "Uma_Ratio") != "") {
48 data_use_tracker.reset(new DataUseTracker(local_state));
49 }
50 return data_use_tracker; 53 return data_use_tracker;
51 } 54 }
52 55
53 // static 56 // static
54 void DataUseTracker::RegisterPrefs(PrefRegistrySimple* registry) { 57 void DataUseTracker::RegisterPrefs(PrefRegistrySimple* registry) {
55 registry->RegisterDictionaryPref(metrics::prefs::kUserCellDataUse); 58 registry->RegisterDictionaryPref(metrics::prefs::kUserCellDataUse);
56 registry->RegisterDictionaryPref(metrics::prefs::kUmaCellDataUse); 59 registry->RegisterDictionaryPref(metrics::prefs::kUmaCellDataUse);
57 } 60 }
58 61
59 UpdateUsagePrefCallbackType DataUseTracker::GetDataUseForwardingCallback( 62 UpdateUsagePrefCallbackType DataUseTracker::GetDataUseForwardingCallback(
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } 169 }
167 return total_data_use; 170 return total_data_use;
168 } 171 }
169 172
170 bool DataUseTracker::GetUmaWeeklyQuota(int* uma_weekly_quota_bytes) const { 173 bool DataUseTracker::GetUmaWeeklyQuota(int* uma_weekly_quota_bytes) const {
171 DCHECK(thread_checker_.CalledOnValidThread()); 174 DCHECK(thread_checker_.CalledOnValidThread());
172 175
173 std::string param_value_str = variations::GetVariationParamValue( 176 std::string param_value_str = variations::GetVariationParamValue(
174 "UMA_EnableCellularLogUpload", "Uma_Quota"); 177 "UMA_EnableCellularLogUpload", "Uma_Quota");
175 if (param_value_str.empty()) 178 if (param_value_str.empty())
176 return false; 179 *uma_weekly_quota_bytes = kDefaultUMAWeeklyQuotaBytes;
177 180 else
178 base::StringToInt(param_value_str, uma_weekly_quota_bytes); 181 base::StringToInt(param_value_str, uma_weekly_quota_bytes);
179 return true; 182 return true;
180 } 183 }
181 184
182 bool DataUseTracker::GetUmaRatio(double* ratio) const { 185 bool DataUseTracker::GetUmaRatio(double* ratio) const {
183 DCHECK(thread_checker_.CalledOnValidThread()); 186 DCHECK(thread_checker_.CalledOnValidThread());
184 187
185 std::string param_value_str = variations::GetVariationParamValue( 188 std::string param_value_str = variations::GetVariationParamValue(
186 "UMA_EnableCellularLogUpload", "Uma_Ratio"); 189 "UMA_EnableCellularLogUpload", "Uma_Ratio");
187 if (param_value_str.empty()) 190 if (param_value_str.empty())
188 return false; 191 *ratio = kDefaultUMARatio;
189 base::StringToDouble(param_value_str, ratio); 192 else
193 base::StringToDouble(param_value_str, ratio);
190 return true; 194 return true;
191 } 195 }
192 196
193 base::Time DataUseTracker::GetCurrentMeasurementDate() const { 197 base::Time DataUseTracker::GetCurrentMeasurementDate() const {
194 return base::Time::Now().LocalMidnight(); 198 return base::Time::Now().LocalMidnight();
195 } 199 }
196 200
197 std::string DataUseTracker::GetCurrentMeasurementDateAsString() const { 201 std::string DataUseTracker::GetCurrentMeasurementDateAsString() const {
198 DCHECK(thread_checker_.CalledOnValidThread()); 202 DCHECK(thread_checker_.CalledOnValidThread());
199 203
200 base::Time::Exploded today_exploded; 204 base::Time::Exploded today_exploded;
201 GetCurrentMeasurementDate().LocalExplode(&today_exploded); 205 GetCurrentMeasurementDate().LocalExplode(&today_exploded);
202 return base::StringPrintf("%04d-%02d-%02d", today_exploded.year, 206 return base::StringPrintf("%04d-%02d-%02d", today_exploded.year,
203 today_exploded.month, today_exploded.day_of_month); 207 today_exploded.month, today_exploded.day_of_month);
204 } 208 }
205 209
206 } // namespace metrics 210 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/BUILD.gn ('k') | components/metrics/metrics_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698