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

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

Powered by Google App Engine
This is Rietveld 408576698