| OLD | NEW |
| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 #include "base/bind.h" | 132 #include "base/bind.h" |
| 133 #include "base/callback.h" | 133 #include "base/callback.h" |
| 134 #include "base/location.h" | 134 #include "base/location.h" |
| 135 #include "base/memory/ptr_util.h" | 135 #include "base/memory/ptr_util.h" |
| 136 #include "base/metrics/histogram_base.h" | 136 #include "base/metrics/histogram_base.h" |
| 137 #include "base/metrics/histogram_macros.h" | 137 #include "base/metrics/histogram_macros.h" |
| 138 #include "base/metrics/histogram_samples.h" | 138 #include "base/metrics/histogram_samples.h" |
| 139 #include "base/metrics/persistent_histogram_allocator.h" | 139 #include "base/metrics/persistent_histogram_allocator.h" |
| 140 #include "base/metrics/sparse_histogram.h" | 140 #include "base/metrics/sparse_histogram.h" |
| 141 #include "base/metrics/statistics_recorder.h" | 141 #include "base/metrics/statistics_recorder.h" |
| 142 #include "base/rand_util.h" | |
| 143 #include "base/single_thread_task_runner.h" | 142 #include "base/single_thread_task_runner.h" |
| 144 #include "base/strings/string_number_conversions.h" | 143 #include "base/strings/string_number_conversions.h" |
| 145 #include "base/strings/utf_string_conversions.h" | 144 #include "base/strings/utf_string_conversions.h" |
| 146 #include "base/threading/platform_thread.h" | 145 #include "base/threading/platform_thread.h" |
| 147 #include "base/threading/thread.h" | 146 #include "base/threading/thread.h" |
| 148 #include "base/threading/thread_restrictions.h" | 147 #include "base/threading/thread_restrictions.h" |
| 149 #include "base/threading/thread_task_runner_handle.h" | 148 #include "base/threading/thread_task_runner_handle.h" |
| 150 #include "base/time/time.h" | 149 #include "base/time/time.h" |
| 151 #include "base/tracked_objects.h" | 150 #include "base/tracked_objects.h" |
| 152 #include "base/values.h" | |
| 153 #include "build/build_config.h" | 151 #include "build/build_config.h" |
| 154 #include "components/metrics/data_use_tracker.h" | 152 #include "components/metrics/data_use_tracker.h" |
| 155 #include "components/metrics/metrics_log.h" | 153 #include "components/metrics/metrics_log.h" |
| 156 #include "components/metrics/metrics_log_manager.h" | 154 #include "components/metrics/metrics_log_manager.h" |
| 157 #include "components/metrics/metrics_log_uploader.h" | 155 #include "components/metrics/metrics_log_uploader.h" |
| 158 #include "components/metrics/metrics_pref_names.h" | 156 #include "components/metrics/metrics_pref_names.h" |
| 159 #include "components/metrics/metrics_reporting_scheduler.h" | 157 #include "components/metrics/metrics_reporting_scheduler.h" |
| 160 #include "components/metrics/metrics_service_client.h" | 158 #include "components/metrics/metrics_service_client.h" |
| 161 #include "components/metrics/metrics_state_manager.h" | 159 #include "components/metrics/metrics_state_manager.h" |
| 162 #include "components/prefs/pref_registry_simple.h" | 160 #include "components/prefs/pref_registry_simple.h" |
| 163 #include "components/prefs/pref_service.h" | 161 #include "components/prefs/pref_service.h" |
| 164 #include "components/variations/entropy_provider.h" | 162 #include "components/variations/entropy_provider.h" |
| 165 #include "components/variations/variations_associated_data.h" | |
| 166 | 163 |
| 167 namespace metrics { | 164 namespace metrics { |
| 168 | 165 |
| 169 namespace { | 166 namespace { |
| 170 | 167 |
| 171 // Check to see that we're being called on only one thread. | 168 // Check to see that we're being called on only one thread. |
| 172 bool IsSingleThreaded() { | 169 bool IsSingleThreaded() { |
| 173 static base::PlatformThreadId thread_id = 0; | 170 static base::PlatformThreadId thread_id = 0; |
| 174 if (!thread_id) | 171 if (!thread_id) |
| 175 thread_id = base::PlatformThread::CurrentId(); | 172 thread_id = base::PlatformThread::CurrentId(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 void MarkAppCleanShutdownAndCommit(CleanExitBeacon* clean_exit_beacon, | 222 void MarkAppCleanShutdownAndCommit(CleanExitBeacon* clean_exit_beacon, |
| 226 PrefService* local_state) { | 223 PrefService* local_state) { |
| 227 clean_exit_beacon->WriteBeaconValue(true); | 224 clean_exit_beacon->WriteBeaconValue(true); |
| 228 local_state->SetInteger(prefs::kStabilityExecutionPhase, | 225 local_state->SetInteger(prefs::kStabilityExecutionPhase, |
| 229 MetricsService::SHUTDOWN_COMPLETE); | 226 MetricsService::SHUTDOWN_COMPLETE); |
| 230 // Start writing right away (write happens on a different thread). | 227 // Start writing right away (write happens on a different thread). |
| 231 local_state->CommitPendingWrite(); | 228 local_state->CommitPendingWrite(); |
| 232 } | 229 } |
| 233 #endif // defined(OS_ANDROID) || defined(OS_IOS) | 230 #endif // defined(OS_ANDROID) || defined(OS_IOS) |
| 234 | 231 |
| 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() { | |
| 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 | 232 } // namespace |
| 251 | 233 |
| 252 // static | 234 // static |
| 253 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ = | 235 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ = |
| 254 MetricsService::CLEANLY_SHUTDOWN; | 236 MetricsService::CLEANLY_SHUTDOWN; |
| 255 | 237 |
| 256 MetricsService::ExecutionPhase MetricsService::execution_phase_ = | 238 MetricsService::ExecutionPhase MetricsService::execution_phase_ = |
| 257 MetricsService::UNINITIALIZED_PHASE; | 239 MetricsService::UNINITIALIZED_PHASE; |
| 258 | 240 |
| 259 // static | 241 // static |
| (...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 } | 960 } |
| 979 | 961 |
| 980 void MetricsService::SendStagedLog() { | 962 void MetricsService::SendStagedLog() { |
| 981 DCHECK(log_manager_.has_staged_log()); | 963 DCHECK(log_manager_.has_staged_log()); |
| 982 if (!log_manager_.has_staged_log()) | 964 if (!log_manager_.has_staged_log()) |
| 983 return; | 965 return; |
| 984 | 966 |
| 985 DCHECK(!log_upload_in_progress_); | 967 DCHECK(!log_upload_in_progress_); |
| 986 log_upload_in_progress_ = true; | 968 log_upload_in_progress_ = true; |
| 987 | 969 |
| 988 if (!ShouldUploadLog()) { | |
| 989 SkipAndDiscardUpload(); | |
| 990 return; | |
| 991 } | |
| 992 | |
| 993 if (!log_uploader_) { | 970 if (!log_uploader_) { |
| 994 log_uploader_ = client_->CreateUploader( | 971 log_uploader_ = client_->CreateUploader( |
| 995 base::Bind(&MetricsService::OnLogUploadComplete, | 972 base::Bind(&MetricsService::OnLogUploadComplete, |
| 996 self_ptr_factory_.GetWeakPtr())); | 973 self_ptr_factory_.GetWeakPtr())); |
| 997 } | 974 } |
| 998 | 975 |
| 999 const std::string hash = | 976 const std::string hash = |
| 1000 base::HexEncode(log_manager_.staged_log_hash().data(), | 977 base::HexEncode(log_manager_.staged_log_hash().data(), |
| 1001 log_manager_.staged_log_hash().size()); | 978 log_manager_.staged_log_hash().size()); |
| 1002 log_uploader_->UploadLog(log_manager_.staged_log(), hash); | 979 log_uploader_->UploadLog(log_manager_.staged_log(), hash); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 base::Time::Now().ToTimeT()); | 1172 base::Time::Now().ToTimeT()); |
| 1196 } | 1173 } |
| 1197 | 1174 |
| 1198 void MetricsService::SkipAndDiscardUpload() { | 1175 void MetricsService::SkipAndDiscardUpload() { |
| 1199 log_manager_.DiscardStagedLog(); | 1176 log_manager_.DiscardStagedLog(); |
| 1200 scheduler_->UploadCancelled(); | 1177 scheduler_->UploadCancelled(); |
| 1201 log_upload_in_progress_ = false; | 1178 log_upload_in_progress_ = false; |
| 1202 } | 1179 } |
| 1203 | 1180 |
| 1204 } // namespace metrics | 1181 } // namespace metrics |
| OLD | NEW |