| 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/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 | 170 |
| 171 CastMetricsServiceClient::CastMetricsServiceClient( | 171 CastMetricsServiceClient::CastMetricsServiceClient( |
| 172 base::TaskRunner* io_task_runner, | 172 base::TaskRunner* io_task_runner, |
| 173 PrefService* pref_service, | 173 PrefService* pref_service, |
| 174 net::URLRequestContextGetter* request_context) | 174 net::URLRequestContextGetter* request_context) |
| 175 : io_task_runner_(io_task_runner), | 175 : io_task_runner_(io_task_runner), |
| 176 pref_service_(pref_service), | 176 pref_service_(pref_service), |
| 177 cast_service_(NULL), | 177 cast_service_(NULL), |
| 178 external_metrics_(NULL), |
| 178 metrics_service_loop_(base::MessageLoopProxy::current()), | 179 metrics_service_loop_(base::MessageLoopProxy::current()), |
| 179 request_context_(request_context) { | 180 request_context_(request_context) { |
| 180 } | 181 } |
| 181 | 182 |
| 182 CastMetricsServiceClient::~CastMetricsServiceClient() { | 183 CastMetricsServiceClient::~CastMetricsServiceClient() { |
| 184 DCHECK(!external_metrics_); |
| 183 } | 185 } |
| 184 | 186 |
| 185 void CastMetricsServiceClient::Initialize(CastService* cast_service) { | 187 void CastMetricsServiceClient::Initialize(CastService* cast_service) { |
| 186 DCHECK(cast_service); | 188 DCHECK(cast_service); |
| 187 DCHECK(!cast_service_); | 189 DCHECK(!cast_service_); |
| 188 cast_service_ = cast_service; | 190 cast_service_ = cast_service; |
| 189 | 191 |
| 190 metrics_state_manager_ = ::metrics::MetricsStateManager::Create( | 192 metrics_state_manager_ = ::metrics::MetricsStateManager::Create( |
| 191 pref_service_, | 193 pref_service_, |
| 192 base::Bind(&CastMetricsServiceClient::IsReportingEnabled, | 194 base::Bind(&CastMetricsServiceClient::IsReportingEnabled, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 // Reset clean_shutdown bit after InitializeMetricsRecordingState(). | 235 // Reset clean_shutdown bit after InitializeMetricsRecordingState(). |
| 234 metrics_service_->LogNeedForCleanShutdown(); | 236 metrics_service_->LogNeedForCleanShutdown(); |
| 235 #endif // !defined(OS_ANDROID) | 237 #endif // !defined(OS_ANDROID) |
| 236 | 238 |
| 237 if (IsReportingEnabled()) | 239 if (IsReportingEnabled()) |
| 238 metrics_service_->Start(); | 240 metrics_service_->Start(); |
| 239 | 241 |
| 240 // Start external metrics collection, which feeds data from external | 242 // Start external metrics collection, which feeds data from external |
| 241 // processes into the main external metrics. | 243 // processes into the main external metrics. |
| 242 #if defined(OS_LINUX) | 244 #if defined(OS_LINUX) |
| 243 external_metrics_.reset(new ExternalMetrics(stability_provider)); | 245 external_metrics_ = new ExternalMetrics(stability_provider); |
| 244 external_metrics_->Start(); | 246 external_metrics_->Start(); |
| 245 #endif // defined(OS_LINUX) | 247 #endif // defined(OS_LINUX) |
| 246 } | 248 } |
| 247 | 249 |
| 248 void CastMetricsServiceClient::Finalize() { | 250 void CastMetricsServiceClient::Finalize() { |
| 249 #if !defined(OS_ANDROID) | 251 #if !defined(OS_ANDROID) |
| 250 // Set clean_shutdown bit. | 252 // Set clean_shutdown bit. |
| 251 metrics_service_->RecordCompletedSessionEnd(); | 253 metrics_service_->RecordCompletedSessionEnd(); |
| 252 #endif // !defined(OS_ANDROID) | 254 #endif // !defined(OS_ANDROID) |
| 255 |
| 256 // Stop metrics service cleanly before destructing CastMetricsServiceClient. |
| 257 #if defined(OS_LINUX) |
| 258 external_metrics_->StopAndDestroy(); |
| 259 external_metrics_ = NULL; |
| 260 #endif // defined(OS_LINUX) |
| 261 metrics_service_->Stop(); |
| 253 } | 262 } |
| 254 | 263 |
| 255 bool CastMetricsServiceClient::IsReportingEnabled() { | 264 bool CastMetricsServiceClient::IsReportingEnabled() { |
| 256 return PlatformIsReportingEnabled(cast_service_); | 265 return PlatformIsReportingEnabled(cast_service_); |
| 257 } | 266 } |
| 258 | 267 |
| 259 } // namespace metrics | 268 } // namespace metrics |
| 260 } // namespace chromecast | 269 } // namespace chromecast |
| OLD | NEW |