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

Side by Side Diff: components/metrics/metrics_service.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: change DataUseTracker init logic 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/data_use_tracker.cc ('k') | components/metrics/net/DEPS » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 //------------------------------------------------------------------------------ 5 //------------------------------------------------------------------------------
6 // Description of the life cycle of a instance of MetricsService. 6 // Description of the life cycle of a instance of MetricsService.
7 // 7 //
8 // OVERVIEW 8 // OVERVIEW
9 // 9 //
10 // A MetricsService instance is typically created at application startup. It is 10 // A MetricsService instance is typically created at application startup. It is
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 void MarkAppCleanShutdownAndCommit(CleanExitBeacon* clean_exit_beacon, 225 void MarkAppCleanShutdownAndCommit(CleanExitBeacon* clean_exit_beacon,
226 PrefService* local_state) { 226 PrefService* local_state) {
227 clean_exit_beacon->WriteBeaconValue(true); 227 clean_exit_beacon->WriteBeaconValue(true);
228 local_state->SetInteger(prefs::kStabilityExecutionPhase, 228 local_state->SetInteger(prefs::kStabilityExecutionPhase,
229 MetricsService::SHUTDOWN_COMPLETE); 229 MetricsService::SHUTDOWN_COMPLETE);
230 // Start writing right away (write happens on a different thread). 230 // Start writing right away (write happens on a different thread).
231 local_state->CommitPendingWrite(); 231 local_state->CommitPendingWrite();
232 } 232 }
233 #endif // defined(OS_ANDROID) || defined(OS_IOS) 233 #endif // defined(OS_ANDROID) || defined(OS_IOS)
234 234
235 // Determines if current log should be sent based on sampling rate. Returns true
236 // if the sampling rate is not set.
237 bool ShouldUploadLog() {
Alexei Svitkine (slow) 2016/05/13 21:11:56 Nit: Can you remove some the includes needed for t
gayane -on leave until 09-2017 2016/05/16 15:33:04 Done.
238 std::string probability_str = variations::GetVariationParamValue(
239 "UMA_EnableCellularLogUpload", "Sample_Probability");
240 if (probability_str.empty())
241 return true;
242
243 int probability;
244 // In case specified sampling rate is invalid.
245 if (!base::StringToInt(probability_str, &probability))
246 return true;
247 return base::RandInt(1, 100) <= probability;
248 }
249
250 } // namespace 235 } // namespace
251 236
252 // static 237 // static
253 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ = 238 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ =
254 MetricsService::CLEANLY_SHUTDOWN; 239 MetricsService::CLEANLY_SHUTDOWN;
255 240
256 MetricsService::ExecutionPhase MetricsService::execution_phase_ = 241 MetricsService::ExecutionPhase MetricsService::execution_phase_ =
257 MetricsService::UNINITIALIZED_PHASE; 242 MetricsService::UNINITIALIZED_PHASE;
258 243
259 // static 244 // static
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 } 961 }
977 962
978 void MetricsService::SendStagedLog() { 963 void MetricsService::SendStagedLog() {
979 DCHECK(log_manager_.has_staged_log()); 964 DCHECK(log_manager_.has_staged_log());
980 if (!log_manager_.has_staged_log()) 965 if (!log_manager_.has_staged_log())
981 return; 966 return;
982 967
983 DCHECK(!log_upload_in_progress_); 968 DCHECK(!log_upload_in_progress_);
984 log_upload_in_progress_ = true; 969 log_upload_in_progress_ = true;
985 970
986 if (!ShouldUploadLog()) {
987 SkipAndDiscardUpload();
988 return;
989 }
990
991 if (!log_uploader_) { 971 if (!log_uploader_) {
992 log_uploader_ = client_->CreateUploader( 972 log_uploader_ = client_->CreateUploader(
993 base::Bind(&MetricsService::OnLogUploadComplete, 973 base::Bind(&MetricsService::OnLogUploadComplete,
994 self_ptr_factory_.GetWeakPtr())); 974 self_ptr_factory_.GetWeakPtr()));
995 } 975 }
996 976
997 const std::string hash = 977 const std::string hash =
998 base::HexEncode(log_manager_.staged_log_hash().data(), 978 base::HexEncode(log_manager_.staged_log_hash().data(),
999 log_manager_.staged_log_hash().size()); 979 log_manager_.staged_log_hash().size());
1000 log_uploader_->UploadLog(log_manager_.staged_log(), hash); 980 log_uploader_->UploadLog(log_manager_.staged_log(), hash);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 base::Time::Now().ToTimeT()); 1171 base::Time::Now().ToTimeT());
1192 } 1172 }
1193 1173
1194 void MetricsService::SkipAndDiscardUpload() { 1174 void MetricsService::SkipAndDiscardUpload() {
1195 log_manager_.DiscardStagedLog(); 1175 log_manager_.DiscardStagedLog();
1196 scheduler_->UploadCancelled(); 1176 scheduler_->UploadCancelled();
1197 log_upload_in_progress_ = false; 1177 log_upload_in_progress_ = false;
1198 } 1178 }
1199 1179
1200 } // namespace metrics 1180 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/data_use_tracker.cc ('k') | components/metrics/net/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698