OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chromecast/metrics/cast_metrics_service_client.h" |
| 6 |
| 7 #include "base/i18n/rtl.h" |
| 8 #include "chromecast/common/chromecast_config.h" |
| 9 #include "chromecast/metrics/platform_metrics_providers.h" |
| 10 #include "components/metrics/metrics_provider.h" |
| 11 #include "components/metrics/metrics_service.h" |
| 12 #include "components/metrics/metrics_state_manager.h" |
| 13 #include "components/metrics/net/net_metrics_log_uploader.h" |
| 14 |
| 15 namespace chromecast { |
| 16 namespace metrics { |
| 17 |
| 18 // static |
| 19 CastMetricsServiceClient* CastMetricsServiceClient::Create( |
| 20 PrefService* pref_service, |
| 21 net::URLRequestContextGetter* request_context) { |
| 22 return new CastMetricsServiceClient(pref_service, request_context); |
| 23 } |
| 24 |
| 25 void CastMetricsServiceClient::SetMetricsClientId( |
| 26 const std::string& client_id) { |
| 27 LOG(INFO) << "Metrics client ID set: " << client_id; |
| 28 PlatformSetClientID(client_id); |
| 29 } |
| 30 |
| 31 bool CastMetricsServiceClient::IsOffTheRecordSessionActive() { |
| 32 // Chromecast behaves as "off the record" w/r/t recording browsing state, |
| 33 // but this value is about not disabling metrics because of it. |
| 34 return false; |
| 35 } |
| 36 |
| 37 std::string CastMetricsServiceClient::GetApplicationLocale() { |
| 38 return base::i18n::GetConfiguredLocale(); |
| 39 } |
| 40 |
| 41 bool CastMetricsServiceClient::GetBrand(std::string* brand_code) { |
| 42 return false; |
| 43 } |
| 44 |
| 45 ::metrics::SystemProfileProto::Channel CastMetricsServiceClient::GetChannel() { |
| 46 return GetPlatformReleaseChannel(); |
| 47 } |
| 48 |
| 49 std::string CastMetricsServiceClient::GetVersionString() { |
| 50 return GetPlatformVersionString(); |
| 51 } |
| 52 |
| 53 void CastMetricsServiceClient::OnLogUploadComplete() { |
| 54 PlatformOnLogUploadComplete(); |
| 55 } |
| 56 |
| 57 void CastMetricsServiceClient::StartGatheringMetrics( |
| 58 const base::Closure& done_callback) { |
| 59 done_callback.Run(); |
| 60 } |
| 61 |
| 62 void CastMetricsServiceClient::CollectFinalMetrics( |
| 63 const base::Closure& done_callback) { |
| 64 done_callback.Run(); |
| 65 } |
| 66 |
| 67 scoped_ptr< ::metrics::MetricsLogUploader> |
| 68 CastMetricsServiceClient::CreateUploader( |
| 69 const std::string& server_url, |
| 70 const std::string& mime_type, |
| 71 const base::Callback<void(int)>& on_upload_complete) { |
| 72 return scoped_ptr< ::metrics::MetricsLogUploader>( |
| 73 new ::metrics::NetMetricsLogUploader( |
| 74 request_context_, |
| 75 server_url, |
| 76 mime_type, |
| 77 on_upload_complete)); |
| 78 } |
| 79 |
| 80 void CastMetricsServiceClient::EnableMetricsService(bool enabled) { |
| 81 if (enabled) { |
| 82 metrics_service_->Start(); |
| 83 } else { |
| 84 metrics_service_->Stop(); |
| 85 } |
| 86 } |
| 87 |
| 88 CastMetricsServiceClient::CastMetricsServiceClient( |
| 89 PrefService* pref_service, |
| 90 net::URLRequestContextGetter* request_context) |
| 91 : metrics_state_manager_(::metrics::MetricsStateManager::Create( |
| 92 pref_service, |
| 93 base::Bind(&CastMetricsServiceClient::IsReportingEnabled, |
| 94 base::Unretained(this)), |
| 95 ::metrics::MetricsStateManager::StoreClientInfoCallback(), |
| 96 ::metrics::MetricsStateManager::LoadClientInfoCallback())), |
| 97 metrics_service_(new MetricsService( |
| 98 metrics_state_manager_.get(), |
| 99 this, |
| 100 ChromecastConfig::GetInstance()->pref_service())), |
| 101 request_context_(request_context) { |
| 102 // Always create a client id as it may also be used by crash reporting, |
| 103 // (indirectly) included in feedback, and can be queried during setup. |
| 104 // For UMA and crash reporting, associated opt-in settings will control |
| 105 // sending reports as directed by the user. |
| 106 // For Setup (which also communicates the user's opt-in preferences), |
| 107 // report the client-id and expect that setup will handle the current opt-in |
| 108 // value. |
| 109 metrics_state_manager_->ForceClientIdCreation(); |
| 110 |
| 111 // TODO(gunsch): Add the following: GPUMetricsProvider, |
| 112 // NetworkMetricsProvider, ProfilerMetricsProvider. See: crbug/404791 |
| 113 RegisterPlatformMetricsProviders(metrics_service_.get()); |
| 114 |
| 115 metrics_service_->InitializeMetricsRecordingState(); |
| 116 |
| 117 if (IsReportingEnabled()) |
| 118 metrics_service_->Start(); |
| 119 } |
| 120 |
| 121 CastMetricsServiceClient::~CastMetricsServiceClient() { |
| 122 } |
| 123 |
| 124 bool CastMetricsServiceClient::IsReportingEnabled() { |
| 125 return PlatformIsReportingEnabled(); |
| 126 } |
| 127 |
| 128 } // namespace metrics |
| 129 } // namespace chromecast |
OLD | NEW |