Chromium Code Reviews| 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 #include "chromecast/browser/metrics/cast_metrics_service_client.h" | 5 #include "chromecast/browser/metrics/cast_metrics_service_client.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/guid.h" | 8 #include "base/guid.h" |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/prefs/pref_registry_simple.h" | 11 #include "base/prefs/pref_registry_simple.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 15 #include "chromecast/base/cast_sys_info_util.h" | 15 #include "chromecast/base/cast_sys_info_util.h" |
| 16 #include "chromecast/base/chromecast_switches.h" | 16 #include "chromecast/base/chromecast_switches.h" |
| 17 #include "chromecast/base/path_utils.h" | 17 #include "chromecast/base/path_utils.h" |
| 18 #include "chromecast/base/version.h" | 18 #include "chromecast/base/version.h" |
| 19 #include "chromecast/browser/metrics/cast_stability_metrics_provider.h" | 19 #include "chromecast/browser/metrics/cast_stability_metrics_provider.h" |
| 20 #include "chromecast/browser/metrics/platform_metrics_providers.h" | 20 #include "chromecast/browser/metrics/platform_metrics_providers.h" |
| 21 #include "chromecast/common/pref_names.h" | 21 #include "chromecast/common/pref_names.h" |
| 22 #include "chromecast/public/cast_sys_info.h" | 22 #include "chromecast/public/cast_sys_info.h" |
| 23 #include "components/metrics/client_info.h" | 23 #include "components/metrics/client_info.h" |
| 24 #include "components/metrics/gpu/gpu_metrics_provider.h" | 24 #include "components/metrics/gpu/gpu_metrics_provider.h" |
| 25 #include "components/metrics/metrics_pref_names.h" | |
| 25 #include "components/metrics/metrics_provider.h" | 26 #include "components/metrics/metrics_provider.h" |
| 26 #include "components/metrics/metrics_service.h" | 27 #include "components/metrics/metrics_service.h" |
| 27 #include "components/metrics/metrics_state_manager.h" | 28 #include "components/metrics/metrics_state_manager.h" |
| 28 #include "components/metrics/net/net_metrics_log_uploader.h" | 29 #include "components/metrics/net/net_metrics_log_uploader.h" |
| 29 #include "components/metrics/net/network_metrics_provider.h" | 30 #include "components/metrics/net/network_metrics_provider.h" |
| 30 #include "components/metrics/profiler/profiler_metrics_provider.h" | 31 #include "components/metrics/profiler/profiler_metrics_provider.h" |
| 31 #include "components/metrics/url_constants.h" | 32 #include "components/metrics/url_constants.h" |
| 32 #include "content/public/common/content_switches.h" | 33 #include "content/public/common/content_switches.h" |
| 33 | 34 |
| 34 #if defined(OS_LINUX) | 35 #if defined(OS_LINUX) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 } | 88 } |
| 88 | 89 |
| 89 void CastMetricsServiceClient::RegisterPrefs(PrefRegistrySimple* registry) { | 90 void CastMetricsServiceClient::RegisterPrefs(PrefRegistrySimple* registry) { |
| 90 registry->RegisterStringPref(kMetricsOldClientID, std::string()); | 91 registry->RegisterStringPref(kMetricsOldClientID, std::string()); |
| 91 } | 92 } |
| 92 | 93 |
| 93 void CastMetricsServiceClient::SetMetricsClientId( | 94 void CastMetricsServiceClient::SetMetricsClientId( |
| 94 const std::string& client_id) { | 95 const std::string& client_id) { |
| 95 client_id_ = client_id; | 96 client_id_ = client_id; |
| 96 LOG(INFO) << "Metrics client ID set: " << client_id; | 97 LOG(INFO) << "Metrics client ID set: " << client_id; |
| 97 PlatformSetClientID(cast_service_, client_id); | 98 // Ensure |pref_service_| always gets new |client_id| value. |
| 99 pref_service_->SetString(::metrics::prefs::kMetricsClientID, client_id); | |
|
gfhuang
2015/08/19 15:48:27
why this is needed?
we don't want to write to ::m
gunsch
2015/08/19 15:52:50
Sort of a safety mechanism to replace PlatformSetC
| |
| 98 } | 100 } |
| 99 | 101 |
| 100 void CastMetricsServiceClient::OnRecordingDisabled() { | 102 void CastMetricsServiceClient::OnRecordingDisabled() { |
| 101 } | 103 } |
| 102 | 104 |
| 103 void CastMetricsServiceClient::StoreClientInfo( | 105 void CastMetricsServiceClient::StoreClientInfo( |
| 104 const ::metrics::ClientInfo& client_info) { | 106 const ::metrics::ClientInfo& client_info) { |
| 105 const std::string& client_id = client_info.client_id; | 107 const std::string& client_id = client_info.client_id; |
| 106 DCHECK(client_id.empty() || base::IsValidGUID(client_id)); | 108 DCHECK(client_id.empty() || base::IsValidGUID(client_id)); |
| 107 // backup client_id or reset to empty. | 109 // backup client_id or reset to empty. |
| 108 SetMetricsClientId(client_id); | 110 SetMetricsClientId(client_id); |
| 109 } | 111 } |
| 110 | 112 |
| 111 scoped_ptr< ::metrics::ClientInfo> CastMetricsServiceClient::LoadClientInfo() { | 113 scoped_ptr< ::metrics::ClientInfo> CastMetricsServiceClient::LoadClientInfo() { |
| 112 scoped_ptr< ::metrics::ClientInfo> client_info(new ::metrics::ClientInfo); | 114 scoped_ptr< ::metrics::ClientInfo> client_info(new ::metrics::ClientInfo); |
| 115 client_info_loaded_ = true; | |
| 113 | 116 |
| 114 // kMetricsIsNewClientID would be missing if either the device was just | 117 // kMetricsIsNewClientID would be missing if either the device was just |
| 115 // FDR'ed, or it is on pre-v1.2 build. | 118 // FDR'ed, or it is on pre-v1.2 build. |
| 116 if (!pref_service_->GetBoolean(prefs::kMetricsIsNewClientID)) { | 119 if (!pref_service_->GetBoolean(prefs::kMetricsIsNewClientID)) { |
| 117 // If the old client id exists, the device must be on pre-v1.2 build, | 120 // If the old client id exists, the device must be on pre-v1.2 build, |
| 118 // instead of just being FDR'ed. | 121 // instead of just being FDR'ed. |
| 119 if (!pref_service_->GetString(kMetricsOldClientID).empty()) { | 122 if (!pref_service_->GetString(kMetricsOldClientID).empty()) { |
| 120 // Force old client id to be regenerated. See b/9487011. | 123 // Force old client id to be regenerated. See b/9487011. |
| 121 client_info->client_id = base::GenerateGUID(); | 124 client_info->client_id = base::GenerateGUID(); |
| 122 pref_service_->SetBoolean(prefs::kMetricsIsNewClientID, true); | 125 pref_service_->SetBoolean(prefs::kMetricsIsNewClientID, true); |
| 123 return client_info.Pass(); | 126 return client_info.Pass(); |
| 124 } | 127 } |
| 125 // else the device was just FDR'ed, pass through. | 128 // else the device was just FDR'ed, pass through. |
| 126 } | 129 } |
| 127 | 130 |
| 128 const std::string client_id(GetPlatformClientID(cast_service_)); | 131 if (!platform_client_id_.empty() && base::IsValidGUID(platform_client_id_)) { |
| 129 if (!client_id.empty() && base::IsValidGUID(client_id)) { | 132 client_info->client_id = platform_client_id_; |
| 130 client_info->client_id = client_id; | |
| 131 return client_info.Pass(); | 133 return client_info.Pass(); |
| 132 } else { | 134 } else { |
| 133 if (client_id.empty()) { | 135 if (platform_client_id_.empty()) { |
| 134 LOG(WARNING) << "Empty client id from platform," | 136 LOG(WARNING) << "Empty client id from platform," |
| 135 << " assuming this is the first boot up of a new device."; | 137 << " assuming this is the first boot up of a new device."; |
| 136 } else { | 138 } else { |
| 137 LOG(ERROR) << "Invalid client id " << client_id << " from platform."; | 139 LOG(ERROR) << "Invalid client id from platform: " << platform_client_id_ |
| 140 << " from platform."; | |
| 138 } | 141 } |
| 139 return scoped_ptr< ::metrics::ClientInfo>(); | 142 return scoped_ptr< ::metrics::ClientInfo>(); |
| 140 } | 143 } |
| 141 } | 144 } |
| 142 | 145 |
| 143 bool CastMetricsServiceClient::IsOffTheRecordSessionActive() { | 146 bool CastMetricsServiceClient::IsOffTheRecordSessionActive() { |
| 144 // Chromecast behaves as "off the record" w/r/t recording browsing state, | 147 // Chromecast behaves as "off the record" w/r/t recording browsing state, |
| 145 // but this value is about not disabling metrics because of it. | 148 // but this value is about not disabling metrics because of it. |
| 146 return false; | 149 return false; |
| 147 } | 150 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 } | 254 } |
| 252 } | 255 } |
| 253 | 256 |
| 254 CastMetricsServiceClient::CastMetricsServiceClient( | 257 CastMetricsServiceClient::CastMetricsServiceClient( |
| 255 base::TaskRunner* io_task_runner, | 258 base::TaskRunner* io_task_runner, |
| 256 PrefService* pref_service, | 259 PrefService* pref_service, |
| 257 net::URLRequestContextGetter* request_context) | 260 net::URLRequestContextGetter* request_context) |
| 258 : io_task_runner_(io_task_runner), | 261 : io_task_runner_(io_task_runner), |
| 259 pref_service_(pref_service), | 262 pref_service_(pref_service), |
| 260 cast_service_(nullptr), | 263 cast_service_(nullptr), |
| 264 client_info_loaded_(false), | |
| 261 #if defined(OS_LINUX) | 265 #if defined(OS_LINUX) |
| 262 external_metrics_(nullptr), | 266 external_metrics_(nullptr), |
| 263 platform_metrics_(nullptr), | 267 platform_metrics_(nullptr), |
| 264 #endif // defined(OS_LINUX) | 268 #endif // defined(OS_LINUX) |
| 265 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 269 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 266 request_context_(request_context) { | 270 request_context_(request_context) { |
| 267 } | 271 } |
| 268 | 272 |
| 269 CastMetricsServiceClient::~CastMetricsServiceClient() { | 273 CastMetricsServiceClient::~CastMetricsServiceClient() { |
| 270 #if defined(OS_LINUX) | 274 #if defined(OS_LINUX) |
| 271 DCHECK(!external_metrics_); | 275 DCHECK(!external_metrics_); |
| 272 DCHECK(!platform_metrics_); | 276 DCHECK(!platform_metrics_); |
| 273 #endif // defined(OS_LINUX) | 277 #endif // defined(OS_LINUX) |
| 274 } | 278 } |
| 275 | 279 |
| 280 void CastMetricsServiceClient::SetPersistedClientId( | |
| 281 const std::string& client_id) { | |
| 282 DCHECK(!client_info_loaded_) | |
| 283 << "Persisted client ID must be set before client info is loaded."; | |
| 284 platform_client_id_ = client_id; | |
| 285 } | |
| 286 | |
| 276 void CastMetricsServiceClient::Initialize(CastService* cast_service) { | 287 void CastMetricsServiceClient::Initialize(CastService* cast_service) { |
| 277 DCHECK(cast_service); | 288 DCHECK(cast_service); |
| 278 DCHECK(!cast_service_); | 289 DCHECK(!cast_service_); |
| 279 cast_service_ = cast_service; | 290 cast_service_ = cast_service; |
| 280 | 291 |
| 281 metrics_state_manager_ = ::metrics::MetricsStateManager::Create( | 292 metrics_state_manager_ = ::metrics::MetricsStateManager::Create( |
| 282 pref_service_, | 293 pref_service_, |
| 283 base::Bind(&CastMetricsServiceClient::IsReportingEnabled, | 294 base::Bind(&CastMetricsServiceClient::IsReportingEnabled, |
| 284 base::Unretained(this)), | 295 base::Unretained(this)), |
| 285 base::Bind(&CastMetricsServiceClient::StoreClientInfo, | 296 base::Bind(&CastMetricsServiceClient::StoreClientInfo, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 #endif // defined(OS_LINUX) | 366 #endif // defined(OS_LINUX) |
| 356 metrics_service_->Stop(); | 367 metrics_service_->Stop(); |
| 357 } | 368 } |
| 358 | 369 |
| 359 bool CastMetricsServiceClient::IsReportingEnabled() { | 370 bool CastMetricsServiceClient::IsReportingEnabled() { |
| 360 return pref_service_->GetBoolean(prefs::kOptInStats); | 371 return pref_service_->GetBoolean(prefs::kOptInStats); |
| 361 } | 372 } |
| 362 | 373 |
| 363 } // namespace metrics | 374 } // namespace metrics |
| 364 } // namespace chromecast | 375 } // namespace chromecast |
| OLD | NEW |