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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // | 160 // |
161 // | 161 // |
162 //------------------------------------------------------------------------------ | 162 //------------------------------------------------------------------------------ |
163 | 163 |
164 #include "components/metrics/metrics_service.h" | 164 #include "components/metrics/metrics_service.h" |
165 | 165 |
166 #include <algorithm> | 166 #include <algorithm> |
167 | 167 |
168 #include "base/bind.h" | 168 #include "base/bind.h" |
169 #include "base/callback.h" | 169 #include "base/callback.h" |
| 170 #include "base/command_line.h" |
170 #include "base/metrics/histogram.h" | 171 #include "base/metrics/histogram.h" |
171 #include "base/metrics/histogram_base.h" | 172 #include "base/metrics/histogram_base.h" |
172 #include "base/metrics/histogram_samples.h" | 173 #include "base/metrics/histogram_samples.h" |
173 #include "base/metrics/sparse_histogram.h" | 174 #include "base/metrics/sparse_histogram.h" |
174 #include "base/metrics/statistics_recorder.h" | 175 #include "base/metrics/statistics_recorder.h" |
175 #include "base/prefs/pref_registry_simple.h" | 176 #include "base/prefs/pref_registry_simple.h" |
176 #include "base/prefs/pref_service.h" | 177 #include "base/prefs/pref_service.h" |
177 #include "base/strings/string_number_conversions.h" | 178 #include "base/strings/string_number_conversions.h" |
178 #include "base/strings/utf_string_conversions.h" | 179 #include "base/strings/utf_string_conversions.h" |
179 #include "base/threading/platform_thread.h" | 180 #include "base/threading/platform_thread.h" |
180 #include "base/threading/thread.h" | 181 #include "base/threading/thread.h" |
181 #include "base/threading/thread_restrictions.h" | 182 #include "base/threading/thread_restrictions.h" |
182 #include "base/time/time.h" | 183 #include "base/time/time.h" |
183 #include "base/tracked_objects.h" | 184 #include "base/tracked_objects.h" |
184 #include "base/values.h" | 185 #include "base/values.h" |
185 #include "components/metrics/metrics_log.h" | 186 #include "components/metrics/metrics_log.h" |
186 #include "components/metrics/metrics_log_manager.h" | 187 #include "components/metrics/metrics_log_manager.h" |
187 #include "components/metrics/metrics_log_uploader.h" | 188 #include "components/metrics/metrics_log_uploader.h" |
188 #include "components/metrics/metrics_pref_names.h" | 189 #include "components/metrics/metrics_pref_names.h" |
189 #include "components/metrics/metrics_reporting_scheduler.h" | 190 #include "components/metrics/metrics_reporting_scheduler.h" |
190 #include "components/metrics/metrics_service_client.h" | 191 #include "components/metrics/metrics_service_client.h" |
191 #include "components/metrics/metrics_state_manager.h" | 192 #include "components/metrics/metrics_state_manager.h" |
| 193 #include "components/metrics/metrics_switches.h" |
192 #include "components/variations/entropy_provider.h" | 194 #include "components/variations/entropy_provider.h" |
193 | 195 |
194 namespace metrics { | 196 namespace metrics { |
195 | 197 |
196 namespace { | 198 namespace { |
197 | 199 |
198 // Check to see that we're being called on only one thread. | 200 // Check to see that we're being called on only one thread. |
199 bool IsSingleThreaded() { | 201 bool IsSingleThreaded() { |
200 static base::PlatformThreadId thread_id = 0; | 202 static base::PlatformThreadId thread_id = 0; |
201 if (!thread_id) | 203 if (!thread_id) |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 | 1015 |
1014 void MetricsService::SendStagedLog() { | 1016 void MetricsService::SendStagedLog() { |
1015 DCHECK(log_manager_.has_staged_log()); | 1017 DCHECK(log_manager_.has_staged_log()); |
1016 if (!log_manager_.has_staged_log()) | 1018 if (!log_manager_.has_staged_log()) |
1017 return; | 1019 return; |
1018 | 1020 |
1019 DCHECK(!log_upload_in_progress_); | 1021 DCHECK(!log_upload_in_progress_); |
1020 log_upload_in_progress_ = true; | 1022 log_upload_in_progress_ = true; |
1021 | 1023 |
1022 if (!log_uploader_) { | 1024 if (!log_uploader_) { |
| 1025 std::string server_url(kServerUrl); |
| 1026 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 1027 if (command_line->HasSwitch(switches::kOverrideMetricsUploadUrl)) { |
| 1028 server_url = command_line->GetSwitchValueASCII( |
| 1029 switches::kOverrideMetricsUploadUrl); |
| 1030 DCHECK(!server_url.empty()); |
| 1031 } |
| 1032 |
1023 log_uploader_ = client_->CreateUploader( | 1033 log_uploader_ = client_->CreateUploader( |
1024 kServerUrl, kMimeType, | 1034 server_url, kMimeType, |
1025 base::Bind(&MetricsService::OnLogUploadComplete, | 1035 base::Bind(&MetricsService::OnLogUploadComplete, |
1026 self_ptr_factory_.GetWeakPtr())); | 1036 self_ptr_factory_.GetWeakPtr())); |
1027 } | 1037 } |
1028 | 1038 |
1029 const std::string hash = | 1039 const std::string hash = |
1030 base::HexEncode(log_manager_.staged_log_hash().data(), | 1040 base::HexEncode(log_manager_.staged_log_hash().data(), |
1031 log_manager_.staged_log_hash().size()); | 1041 log_manager_.staged_log_hash().size()); |
1032 bool success = log_uploader_->UploadLog(log_manager_.staged_log(), hash); | 1042 bool success = log_uploader_->UploadLog(log_manager_.staged_log(), hash); |
1033 UMA_HISTOGRAM_BOOLEAN("UMA.UploadCreation", success); | 1043 UMA_HISTOGRAM_BOOLEAN("UMA.UploadCreation", success); |
1034 if (!success) { | 1044 if (!success) { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 local_state_->SetBoolean(path, value); | 1267 local_state_->SetBoolean(path, value); |
1258 RecordCurrentState(local_state_); | 1268 RecordCurrentState(local_state_); |
1259 } | 1269 } |
1260 | 1270 |
1261 void MetricsService::RecordCurrentState(PrefService* pref) { | 1271 void MetricsService::RecordCurrentState(PrefService* pref) { |
1262 pref->SetInt64(prefs::kStabilityLastTimestampSec, | 1272 pref->SetInt64(prefs::kStabilityLastTimestampSec, |
1263 base::Time::Now().ToTimeT()); | 1273 base::Time::Now().ToTimeT()); |
1264 } | 1274 } |
1265 | 1275 |
1266 } // namespace metrics | 1276 } // namespace metrics |
OLD | NEW |