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

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: 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
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. Can be
20 // overridden by variation params.
21 const int kDefaultUMAWeeklyQuotaBytes = 204800;
22 const double kDefaultUMARatio = 0.05;
23
19 // This function is for forwarding metrics usage pref changes to the appropriate 24 // This function is for forwarding metrics usage pref changes to the appropriate
20 // callback on the appropriate thread. 25 // callback on the appropriate thread.
21 // TODO(gayane): Reduce the frequency of posting tasks from IO to UI thread. 26 // TODO(gayane): Reduce the frequency of posting tasks from IO to UI thread.
22 void UpdateMetricsUsagePrefs( 27 void UpdateMetricsUsagePrefs(
23 const UpdateUsagePrefCallbackType& update_on_ui_callback, 28 const UpdateUsagePrefCallbackType& update_on_ui_callback,
24 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, 29 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
25 const std::string& service_name, 30 const std::string& service_name,
26 int message_size, 31 int message_size,
27 bool is_cellular) { 32 bool is_cellular) {
28 ui_task_runner->PostTask( 33 ui_task_runner->PostTask(
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 int value = 0; 168 int value = 0;
164 it.value().GetAsInteger(&value); 169 it.value().GetAsInteger(&value);
165 total_data_use += value; 170 total_data_use += value;
166 } 171 }
167 return total_data_use; 172 return total_data_use;
168 } 173 }
169 174
170 bool DataUseTracker::GetUmaWeeklyQuota(int* uma_weekly_quota_bytes) const { 175 bool DataUseTracker::GetUmaWeeklyQuota(int* uma_weekly_quota_bytes) const {
171 DCHECK(thread_checker_.CalledOnValidThread()); 176 DCHECK(thread_checker_.CalledOnValidThread());
172 177
178 // If user is not in the experiment then there shouldn't be any limitations.
179 std::string experiment_group =
180 base::FieldTrialList::FindFullName("UMA_EnableCellularLogUpload");
Alexei Svitkine (slow) 2016/05/13 20:21:09 We wanted to not have this experiment check anymor
gayane -on leave until 09-2017 2016/05/13 20:43:00 Done.
181 if (experiment_group.empty())
182 return false;
183
173 std::string param_value_str = variations::GetVariationParamValue( 184 std::string param_value_str = variations::GetVariationParamValue(
174 "UMA_EnableCellularLogUpload", "Uma_Quota"); 185 "UMA_EnableCellularLogUpload", "Uma_Quota");
175 if (param_value_str.empty()) 186 if (param_value_str.empty())
176 return false; 187 *uma_weekly_quota_bytes = kDefaultUMAWeeklyQuotaBytes;
177 188 else
178 base::StringToInt(param_value_str, uma_weekly_quota_bytes); 189 base::StringToInt(param_value_str, uma_weekly_quota_bytes);
179 return true; 190 return true;
180 } 191 }
181 192
182 bool DataUseTracker::GetUmaRatio(double* ratio) const { 193 bool DataUseTracker::GetUmaRatio(double* ratio) const {
183 DCHECK(thread_checker_.CalledOnValidThread()); 194 DCHECK(thread_checker_.CalledOnValidThread());
184 195
196 // If user is not in the experiment then there shouldn't be any limitations.
197 std::string experiment_group =
198 base::FieldTrialList::FindFullName("UMA_EnableCellularLogUpload");
199 if (experiment_group.empty())
200 return false;
201
185 std::string param_value_str = variations::GetVariationParamValue( 202 std::string param_value_str = variations::GetVariationParamValue(
186 "UMA_EnableCellularLogUpload", "Uma_Ratio"); 203 "UMA_EnableCellularLogUpload", "Uma_Ratio");
187 if (param_value_str.empty()) 204 if (param_value_str.empty())
188 return false; 205 *ratio = kDefaultUMARatio;
189 base::StringToDouble(param_value_str, ratio); 206 else
207 base::StringToDouble(param_value_str, ratio);
190 return true; 208 return true;
191 } 209 }
192 210
193 base::Time DataUseTracker::GetCurrentMeasurementDate() const { 211 base::Time DataUseTracker::GetCurrentMeasurementDate() const {
194 return base::Time::Now().LocalMidnight(); 212 return base::Time::Now().LocalMidnight();
195 } 213 }
196 214
197 std::string DataUseTracker::GetCurrentMeasurementDateAsString() const { 215 std::string DataUseTracker::GetCurrentMeasurementDateAsString() const {
198 DCHECK(thread_checker_.CalledOnValidThread()); 216 DCHECK(thread_checker_.CalledOnValidThread());
199 217
200 base::Time::Exploded today_exploded; 218 base::Time::Exploded today_exploded;
201 GetCurrentMeasurementDate().LocalExplode(&today_exploded); 219 GetCurrentMeasurementDate().LocalExplode(&today_exploded);
202 return base::StringPrintf("%04d-%02d-%02d", today_exploded.year, 220 return base::StringPrintf("%04d-%02d-%02d", today_exploded.year,
203 today_exploded.month, today_exploded.day_of_month); 221 today_exploded.month, today_exploded.day_of_month);
204 } 222 }
205 223
206 } // namespace metrics 224 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698