| 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/memory/ptr_util.h" |
| 11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 14 #include "chromecast/base/cast_sys_info_util.h" | 15 #include "chromecast/base/cast_sys_info_util.h" |
| 15 #include "chromecast/base/chromecast_switches.h" | 16 #include "chromecast/base/chromecast_switches.h" |
| 16 #include "chromecast/base/path_utils.h" | 17 #include "chromecast/base/path_utils.h" |
| 17 #include "chromecast/base/pref_names.h" | 18 #include "chromecast/base/pref_names.h" |
| 18 #include "chromecast/base/version.h" | 19 #include "chromecast/base/version.h" |
| 19 #include "chromecast/browser/cast_browser_process.h" | 20 #include "chromecast/browser/cast_browser_process.h" |
| 20 #include "chromecast/browser/cast_content_browser_client.h" | 21 #include "chromecast/browser/cast_content_browser_client.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 81 } |
| 81 | 82 |
| 82 // Any non-empty channel name is considered beta channel | 83 // Any non-empty channel name is considered beta channel |
| 83 return ::metrics::SystemProfileProto::CHANNEL_BETA; | 84 return ::metrics::SystemProfileProto::CHANNEL_BETA; |
| 84 } | 85 } |
| 85 #endif // !defined(OS_ANDROID) | 86 #endif // !defined(OS_ANDROID) |
| 86 | 87 |
| 87 } // namespace | 88 } // namespace |
| 88 | 89 |
| 89 // static | 90 // static |
| 90 scoped_ptr<CastMetricsServiceClient> CastMetricsServiceClient::Create( | 91 std::unique_ptr<CastMetricsServiceClient> CastMetricsServiceClient::Create( |
| 91 base::TaskRunner* io_task_runner, | 92 base::TaskRunner* io_task_runner, |
| 92 PrefService* pref_service, | 93 PrefService* pref_service, |
| 93 net::URLRequestContextGetter* request_context) { | 94 net::URLRequestContextGetter* request_context) { |
| 94 return make_scoped_ptr(new CastMetricsServiceClient( | 95 return base::WrapUnique(new CastMetricsServiceClient( |
| 95 io_task_runner, pref_service, request_context)); | 96 io_task_runner, pref_service, request_context)); |
| 96 } | 97 } |
| 97 | 98 |
| 98 void CastMetricsServiceClient::RegisterPrefs(PrefRegistrySimple* registry) { | 99 void CastMetricsServiceClient::RegisterPrefs(PrefRegistrySimple* registry) { |
| 99 registry->RegisterStringPref(kMetricsOldClientID, std::string()); | 100 registry->RegisterStringPref(kMetricsOldClientID, std::string()); |
| 100 } | 101 } |
| 101 | 102 |
| 102 ::metrics::MetricsService* CastMetricsServiceClient::GetMetricsService() { | 103 ::metrics::MetricsService* CastMetricsServiceClient::GetMetricsService() { |
| 103 return metrics_service_.get(); | 104 return metrics_service_.get(); |
| 104 } | 105 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 118 } | 119 } |
| 119 | 120 |
| 120 void CastMetricsServiceClient::StoreClientInfo( | 121 void CastMetricsServiceClient::StoreClientInfo( |
| 121 const ::metrics::ClientInfo& client_info) { | 122 const ::metrics::ClientInfo& client_info) { |
| 122 const std::string& client_id = client_info.client_id; | 123 const std::string& client_id = client_info.client_id; |
| 123 DCHECK(client_id.empty() || base::IsValidGUID(client_id)); | 124 DCHECK(client_id.empty() || base::IsValidGUID(client_id)); |
| 124 // backup client_id or reset to empty. | 125 // backup client_id or reset to empty. |
| 125 SetMetricsClientId(client_id); | 126 SetMetricsClientId(client_id); |
| 126 } | 127 } |
| 127 | 128 |
| 128 scoped_ptr< ::metrics::ClientInfo> CastMetricsServiceClient::LoadClientInfo() { | 129 std::unique_ptr<::metrics::ClientInfo> |
| 129 scoped_ptr< ::metrics::ClientInfo> client_info(new ::metrics::ClientInfo); | 130 CastMetricsServiceClient::LoadClientInfo() { |
| 131 std::unique_ptr<::metrics::ClientInfo> client_info(new ::metrics::ClientInfo); |
| 130 client_info_loaded_ = true; | 132 client_info_loaded_ = true; |
| 131 | 133 |
| 132 // kMetricsIsNewClientID would be missing if either the device was just | 134 // kMetricsIsNewClientID would be missing if either the device was just |
| 133 // FDR'ed, or it is on pre-v1.2 build. | 135 // FDR'ed, or it is on pre-v1.2 build. |
| 134 if (!pref_service_->GetBoolean(prefs::kMetricsIsNewClientID)) { | 136 if (!pref_service_->GetBoolean(prefs::kMetricsIsNewClientID)) { |
| 135 // If the old client id exists, the device must be on pre-v1.2 build, | 137 // If the old client id exists, the device must be on pre-v1.2 build, |
| 136 // instead of just being FDR'ed. | 138 // instead of just being FDR'ed. |
| 137 if (!pref_service_->GetString(kMetricsOldClientID).empty()) { | 139 if (!pref_service_->GetString(kMetricsOldClientID).empty()) { |
| 138 // Force old client id to be regenerated. See b/9487011. | 140 // Force old client id to be regenerated. See b/9487011. |
| 139 client_info->client_id = base::GenerateGUID(); | 141 client_info->client_id = base::GenerateGUID(); |
| 140 pref_service_->SetBoolean(prefs::kMetricsIsNewClientID, true); | 142 pref_service_->SetBoolean(prefs::kMetricsIsNewClientID, true); |
| 141 return client_info; | 143 return client_info; |
| 142 } | 144 } |
| 143 // else the device was just FDR'ed, pass through. | 145 // else the device was just FDR'ed, pass through. |
| 144 } | 146 } |
| 145 | 147 |
| 146 // Use "forced" client ID if available. | 148 // Use "forced" client ID if available. |
| 147 if (!force_client_id_.empty() && base::IsValidGUID(force_client_id_)) { | 149 if (!force_client_id_.empty() && base::IsValidGUID(force_client_id_)) { |
| 148 client_info->client_id = force_client_id_; | 150 client_info->client_id = force_client_id_; |
| 149 return client_info; | 151 return client_info; |
| 150 } | 152 } |
| 151 | 153 |
| 152 if (force_client_id_.empty()) { | 154 if (force_client_id_.empty()) { |
| 153 LOG(WARNING) << "Empty client id from platform," | 155 LOG(WARNING) << "Empty client id from platform," |
| 154 << " assuming this is the first boot up of a new device."; | 156 << " assuming this is the first boot up of a new device."; |
| 155 } else { | 157 } else { |
| 156 LOG(ERROR) << "Invalid client id from platform: " << force_client_id_ | 158 LOG(ERROR) << "Invalid client id from platform: " << force_client_id_ |
| 157 << " from platform."; | 159 << " from platform."; |
| 158 } | 160 } |
| 159 return scoped_ptr< ::metrics::ClientInfo>(); | 161 return std::unique_ptr<::metrics::ClientInfo>(); |
| 160 } | 162 } |
| 161 | 163 |
| 162 bool CastMetricsServiceClient::IsOffTheRecordSessionActive() { | 164 bool CastMetricsServiceClient::IsOffTheRecordSessionActive() { |
| 163 // Chromecast behaves as "off the record" w/r/t recording browsing state, | 165 // Chromecast behaves as "off the record" w/r/t recording browsing state, |
| 164 // but this value is about not disabling metrics because of it. | 166 // but this value is about not disabling metrics because of it. |
| 165 return false; | 167 return false; |
| 166 } | 168 } |
| 167 | 169 |
| 168 int32_t CastMetricsServiceClient::GetProduct() { | 170 int32_t CastMetricsServiceClient::GetProduct() { |
| 169 // Chromecast currently uses the same product identifier as Chrome. | 171 // Chromecast currently uses the same product identifier as Chrome. |
| 170 return ::metrics::ChromeUserMetricsExtension::CHROME; | 172 return ::metrics::ChromeUserMetricsExtension::CHROME; |
| 171 } | 173 } |
| 172 | 174 |
| 173 std::string CastMetricsServiceClient::GetApplicationLocale() { | 175 std::string CastMetricsServiceClient::GetApplicationLocale() { |
| 174 return base::i18n::GetConfiguredLocale(); | 176 return base::i18n::GetConfiguredLocale(); |
| 175 } | 177 } |
| 176 | 178 |
| 177 bool CastMetricsServiceClient::GetBrand(std::string* brand_code) { | 179 bool CastMetricsServiceClient::GetBrand(std::string* brand_code) { |
| 178 return false; | 180 return false; |
| 179 } | 181 } |
| 180 | 182 |
| 181 ::metrics::SystemProfileProto::Channel CastMetricsServiceClient::GetChannel() { | 183 ::metrics::SystemProfileProto::Channel CastMetricsServiceClient::GetChannel() { |
| 182 scoped_ptr<CastSysInfo> sys_info = CreateSysInfo(); | 184 std::unique_ptr<CastSysInfo> sys_info = CreateSysInfo(); |
| 183 | 185 |
| 184 #if defined(OS_ANDROID) | 186 #if defined(OS_ANDROID) |
| 185 switch (sys_info->GetBuildType()) { | 187 switch (sys_info->GetBuildType()) { |
| 186 case CastSysInfo::BUILD_ENG: | 188 case CastSysInfo::BUILD_ENG: |
| 187 return ::metrics::SystemProfileProto::CHANNEL_UNKNOWN; | 189 return ::metrics::SystemProfileProto::CHANNEL_UNKNOWN; |
| 188 case CastSysInfo::BUILD_BETA: | 190 case CastSysInfo::BUILD_BETA: |
| 189 return ::metrics::SystemProfileProto::CHANNEL_BETA; | 191 return ::metrics::SystemProfileProto::CHANNEL_BETA; |
| 190 case CastSysInfo::BUILD_PRODUCTION: | 192 case CastSysInfo::BUILD_PRODUCTION: |
| 191 return ::metrics::SystemProfileProto::CHANNEL_STABLE; | 193 return ::metrics::SystemProfileProto::CHANNEL_STABLE; |
| 192 } | 194 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 void CastMetricsServiceClient::InitializeSystemProfileMetrics( | 233 void CastMetricsServiceClient::InitializeSystemProfileMetrics( |
| 232 const base::Closure& done_callback) { | 234 const base::Closure& done_callback) { |
| 233 done_callback.Run(); | 235 done_callback.Run(); |
| 234 } | 236 } |
| 235 | 237 |
| 236 void CastMetricsServiceClient::CollectFinalMetricsForLog( | 238 void CastMetricsServiceClient::CollectFinalMetricsForLog( |
| 237 const base::Closure& done_callback) { | 239 const base::Closure& done_callback) { |
| 238 done_callback.Run(); | 240 done_callback.Run(); |
| 239 } | 241 } |
| 240 | 242 |
| 241 scoped_ptr< ::metrics::MetricsLogUploader> | 243 std::unique_ptr<::metrics::MetricsLogUploader> |
| 242 CastMetricsServiceClient::CreateUploader( | 244 CastMetricsServiceClient::CreateUploader( |
| 243 const base::Callback<void(int)>& on_upload_complete) { | 245 const base::Callback<void(int)>& on_upload_complete) { |
| 244 std::string uma_server_url(::metrics::kDefaultMetricsServerUrl); | 246 std::string uma_server_url(::metrics::kDefaultMetricsServerUrl); |
| 245 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 247 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 246 if (command_line->HasSwitch(switches::kOverrideMetricsUploadUrl)) { | 248 if (command_line->HasSwitch(switches::kOverrideMetricsUploadUrl)) { |
| 247 uma_server_url.assign( | 249 uma_server_url.assign( |
| 248 command_line->GetSwitchValueASCII(switches::kOverrideMetricsUploadUrl)); | 250 command_line->GetSwitchValueASCII(switches::kOverrideMetricsUploadUrl)); |
| 249 } | 251 } |
| 250 DCHECK(!uma_server_url.empty()); | 252 DCHECK(!uma_server_url.empty()); |
| 251 return scoped_ptr< ::metrics::MetricsLogUploader>( | 253 return std::unique_ptr<::metrics::MetricsLogUploader>( |
| 252 new ::metrics::NetMetricsLogUploader(request_context_, | 254 new ::metrics::NetMetricsLogUploader(request_context_, uma_server_url, |
| 253 uma_server_url, | |
| 254 ::metrics::kDefaultMetricsMimeType, | 255 ::metrics::kDefaultMetricsMimeType, |
| 255 on_upload_complete)); | 256 on_upload_complete)); |
| 256 } | 257 } |
| 257 | 258 |
| 258 base::TimeDelta CastMetricsServiceClient::GetStandardUploadInterval() { | 259 base::TimeDelta CastMetricsServiceClient::GetStandardUploadInterval() { |
| 259 return base::TimeDelta::FromMinutes(kStandardUploadIntervalMinutes); | 260 return base::TimeDelta::FromMinutes(kStandardUploadIntervalMinutes); |
| 260 } | 261 } |
| 261 | 262 |
| 262 void CastMetricsServiceClient::EnableMetricsService(bool enabled) { | 263 void CastMetricsServiceClient::EnableMetricsService(bool enabled) { |
| 263 if (!task_runner_->BelongsToCurrentThread()) { | 264 if (!task_runner_->BelongsToCurrentThread()) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 // For UMA and crash reporting, associated opt-in settings will control | 341 // For UMA and crash reporting, associated opt-in settings will control |
| 341 // sending reports as directed by the user. | 342 // sending reports as directed by the user. |
| 342 // For Setup (which also communicates the user's opt-in preferences), | 343 // For Setup (which also communicates the user's opt-in preferences), |
| 343 // report the client-id and expect that setup will handle the current opt-in | 344 // report the client-id and expect that setup will handle the current opt-in |
| 344 // value. | 345 // value. |
| 345 metrics_state_manager_->ForceClientIdCreation(); | 346 metrics_state_manager_->ForceClientIdCreation(); |
| 346 | 347 |
| 347 CastStabilityMetricsProvider* stability_provider = | 348 CastStabilityMetricsProvider* stability_provider = |
| 348 new CastStabilityMetricsProvider(metrics_service_.get()); | 349 new CastStabilityMetricsProvider(metrics_service_.get()); |
| 349 metrics_service_->RegisterMetricsProvider( | 350 metrics_service_->RegisterMetricsProvider( |
| 350 scoped_ptr< ::metrics::MetricsProvider>(stability_provider)); | 351 std::unique_ptr<::metrics::MetricsProvider>(stability_provider)); |
| 351 | 352 |
| 352 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 353 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 353 if (!command_line->HasSwitch(switches::kDisableGpu)) { | 354 if (!command_line->HasSwitch(switches::kDisableGpu)) { |
| 354 metrics_service_->RegisterMetricsProvider( | 355 metrics_service_->RegisterMetricsProvider( |
| 355 scoped_ptr< ::metrics::MetricsProvider>( | 356 std::unique_ptr<::metrics::MetricsProvider>( |
| 356 new ::metrics::GPUMetricsProvider)); | 357 new ::metrics::GPUMetricsProvider)); |
| 357 | 358 |
| 358 // TODO(gfhuang): Does ChromeCast actually need metrics about screen info? | 359 // TODO(gfhuang): Does ChromeCast actually need metrics about screen info? |
| 359 // crbug.com/541577 | 360 // crbug.com/541577 |
| 360 metrics_service_->RegisterMetricsProvider( | 361 metrics_service_->RegisterMetricsProvider( |
| 361 scoped_ptr< ::metrics::MetricsProvider>( | 362 std::unique_ptr<::metrics::MetricsProvider>( |
| 362 new ::metrics::ScreenInfoMetricsProvider)); | 363 new ::metrics::ScreenInfoMetricsProvider)); |
| 363 } | 364 } |
| 364 metrics_service_->RegisterMetricsProvider( | 365 metrics_service_->RegisterMetricsProvider( |
| 365 scoped_ptr< ::metrics::MetricsProvider>( | 366 std::unique_ptr<::metrics::MetricsProvider>( |
| 366 new ::metrics::NetworkMetricsProvider(io_task_runner_))); | 367 new ::metrics::NetworkMetricsProvider(io_task_runner_))); |
| 367 metrics_service_->RegisterMetricsProvider( | 368 metrics_service_->RegisterMetricsProvider( |
| 368 scoped_ptr< ::metrics::MetricsProvider>( | 369 std::unique_ptr<::metrics::MetricsProvider>( |
| 369 new ::metrics::ProfilerMetricsProvider)); | 370 new ::metrics::ProfilerMetricsProvider)); |
| 370 shell::CastBrowserProcess::GetInstance()->browser_client()-> | 371 shell::CastBrowserProcess::GetInstance()->browser_client()-> |
| 371 RegisterMetricsProviders(metrics_service_.get()); | 372 RegisterMetricsProviders(metrics_service_.get()); |
| 372 | 373 |
| 373 metrics_service_->InitializeMetricsRecordingState(); | 374 metrics_service_->InitializeMetricsRecordingState(); |
| 374 #if !defined(OS_ANDROID) | 375 #if !defined(OS_ANDROID) |
| 375 // Reset clean_shutdown bit after InitializeMetricsRecordingState(). | 376 // Reset clean_shutdown bit after InitializeMetricsRecordingState(). |
| 376 metrics_service_->LogNeedForCleanShutdown(); | 377 metrics_service_->LogNeedForCleanShutdown(); |
| 377 #endif // !defined(OS_ANDROID) | 378 #endif // !defined(OS_ANDROID) |
| 378 | 379 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 408 #endif // defined(OS_LINUX) | 409 #endif // defined(OS_LINUX) |
| 409 metrics_service_->Stop(); | 410 metrics_service_->Stop(); |
| 410 } | 411 } |
| 411 | 412 |
| 412 bool CastMetricsServiceClient::IsReportingEnabled() { | 413 bool CastMetricsServiceClient::IsReportingEnabled() { |
| 413 return pref_service_->GetBoolean(prefs::kOptInStats); | 414 return pref_service_->GetBoolean(prefs::kOptInStats); |
| 414 } | 415 } |
| 415 | 416 |
| 416 } // namespace metrics | 417 } // namespace metrics |
| 417 } // namespace chromecast | 418 } // namespace chromecast |
| OLD | NEW |