diff options
author | gunsch <gunsch@chromium.org> | 2014-08-23 14:36:42 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-08-23 21:45:11 +0000 |
commit | 0ee038dd6ea4cf91ab50f6f4d459e6f2f5dd10d7 (patch) | |
tree | 25d649a7c3a4f338b00776433181770249c1fc64 /chromecast | |
parent | f7b1cb6926cabc20a89b2713e8c59402e6d260af (diff) | |
download | chromium_src-0ee038dd6ea4cf91ab50f6f4d459e6f2f5dd10d7.zip chromium_src-0ee038dd6ea4cf91ab50f6f4d459e6f2f5dd10d7.tar.gz chromium_src-0ee038dd6ea4cf91ab50f6f4d459e6f2f5dd10d7.tar.bz2 |
Adds CastMetricsServiceClient to Chromecast shell.
Chromecast shell starts up MetricsService but reporting is largely
controlled in platform-specific ways. On the Chromecast dongle, this
occurs via the API that interfaces with the setup application.
R=lcwu@chromium.org,asvitkine@chromium.org,isherman@chromium.org,bryaneyler@chromium.org
BUG=400925
Review URL: https://codereview.chromium.org/482813004
Cr-Commit-Position: refs/heads/master@{#291588}
Diffstat (limited to 'chromecast')
-rw-r--r-- | chromecast/chromecast.gyp | 31 | ||||
-rw-r--r-- | chromecast/common/chromecast_config.cc | 2 | ||||
-rw-r--r-- | chromecast/metrics/DEPS | 3 | ||||
-rw-r--r-- | chromecast/metrics/OWNERS | 5 | ||||
-rw-r--r-- | chromecast/metrics/cast_metrics_prefs.cc | 17 | ||||
-rw-r--r-- | chromecast/metrics/cast_metrics_prefs.h | 18 | ||||
-rw-r--r-- | chromecast/metrics/cast_metrics_service_client.cc | 129 | ||||
-rw-r--r-- | chromecast/metrics/cast_metrics_service_client.h | 74 | ||||
-rw-r--r-- | chromecast/metrics/platform_metrics_providers.h | 36 | ||||
-rw-r--r-- | chromecast/metrics/platform_metrics_providers_simple.cc | 32 | ||||
-rw-r--r-- | chromecast/shell/browser/cast_browser_main_parts.cc | 5 | ||||
-rw-r--r-- | chromecast/shell/browser/cast_browser_main_parts.h | 5 |
12 files changed, 356 insertions, 1 deletions
diff --git a/chromecast/chromecast.gyp b/chromecast/chromecast.gyp index 070ffc7..d171205 100644 --- a/chromecast/chromecast.gyp +++ b/chromecast/chromecast.gyp @@ -42,6 +42,33 @@ ], }, { + 'target_name': 'cast_metrics', + 'type': '<(component)', + 'dependencies': [ + '../components/components.gyp:component_metrics_proto', + '../components/components.gyp:metrics', + '../components/components.gyp:metrics_net', + ], + 'sources': [ + 'metrics/cast_metrics_prefs.cc', + 'metrics/cast_metrics_prefs.h', + 'metrics/cast_metrics_service_client.cc', + 'metrics/cast_metrics_service_client.h', + 'metrics/platform_metrics_providers.h', + ], + 'conditions': [ + ['chromecast_branding=="Chrome"', { + 'dependencies': [ + '<(cast_internal_gyp):cast_metrics_internal', + ], + }, { + 'sources': [ + 'metrics/platform_metrics_providers_simple.cc', + ], + }], + ], + }, + { 'target_name': 'cast_service', 'type': '<(component)', 'dependencies': [ @@ -128,16 +155,18 @@ 'type': 'executable', 'dependencies': [ 'cast_common', + 'cast_metrics', 'cast_service', 'cast_shell_pak', 'cast_shell_resources', 'cast_version_header', 'chromecast_locales.gyp:chromecast_locales_pak', 'chromecast_locales.gyp:chromecast_settings', - '../ui/aura/aura.gyp:aura_test_support', + '../components/components.gyp:component_metrics_proto', '../content/content.gyp:content', '../content/content.gyp:content_app_browser', '../skia/skia.gyp:skia', + '../ui/aura/aura.gyp:aura_test_support', ], 'sources': [ 'net/network_change_notifier_cast.cc', diff --git a/chromecast/common/chromecast_config.cc b/chromecast/common/chromecast_config.cc index dfb3866..0e4261d 100644 --- a/chromecast/common/chromecast_config.cc +++ b/chromecast/common/chromecast_config.cc @@ -17,6 +17,7 @@ #include "base/strings/string_number_conversions.h" #include "chromecast/common/cast_paths.h" #include "chromecast/common/pref_names.h" +#include "chromecast/metrics/cast_metrics_prefs.h" namespace chromecast { @@ -74,6 +75,7 @@ bool ChromecastConfig::Load(PrefRegistrySimple* registry) { VLOG(1) << "Loading config from " << config_path_.value(); registry->RegisterIntegerPref(prefs::kRemoteDebuggingPort, 0); + metrics::RegisterPrefs(registry); RegisterPlatformPrefs(registry); PersistentPrefStore::PrefReadError prefs_read_error = diff --git a/chromecast/metrics/DEPS b/chromecast/metrics/DEPS new file mode 100644 index 0000000..d9ef433 --- /dev/null +++ b/chromecast/metrics/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+components/metrics", +] diff --git a/chromecast/metrics/OWNERS b/chromecast/metrics/OWNERS new file mode 100644 index 0000000..2518ed9 --- /dev/null +++ b/chromecast/metrics/OWNERS @@ -0,0 +1,5 @@ +# components/metrics OWNERS for review of Chromecast metrics code +asvitkine@chromium.org +mpearson@chromium.org +jar@chromium.org +isherman@chromium.org diff --git a/chromecast/metrics/cast_metrics_prefs.cc b/chromecast/metrics/cast_metrics_prefs.cc new file mode 100644 index 0000000..c575f59 --- /dev/null +++ b/chromecast/metrics/cast_metrics_prefs.cc @@ -0,0 +1,17 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chromecast/metrics/cast_metrics_prefs.h" + +#include "components/metrics/metrics_service.h" + +namespace chromecast { +namespace metrics { + +void RegisterPrefs(PrefRegistrySimple* registry) { + MetricsService::RegisterPrefs(registry); +} + +} // namespace metrics +} // namespace chromecast diff --git a/chromecast/metrics/cast_metrics_prefs.h b/chromecast/metrics/cast_metrics_prefs.h new file mode 100644 index 0000000..ff7a973 --- /dev/null +++ b/chromecast/metrics/cast_metrics_prefs.h @@ -0,0 +1,18 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROMECAST_METRICS_CAST_METRICS_PREFS_H_ +#define CHROMECAST_METRICS_CAST_METRICS_PREFS_H_ + +class PrefRegistrySimple; + +namespace chromecast { +namespace metrics { + +void RegisterPrefs(PrefRegistrySimple* registry); + +} // namespace metrics +} // namespace chromecast + +#endif // CHROMECAST_METRICS_CAST_METRICS_PREFS_H_ diff --git a/chromecast/metrics/cast_metrics_service_client.cc b/chromecast/metrics/cast_metrics_service_client.cc new file mode 100644 index 0000000..eb60be0 --- /dev/null +++ b/chromecast/metrics/cast_metrics_service_client.cc @@ -0,0 +1,129 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chromecast/metrics/cast_metrics_service_client.h" + +#include "base/i18n/rtl.h" +#include "chromecast/common/chromecast_config.h" +#include "chromecast/metrics/platform_metrics_providers.h" +#include "components/metrics/metrics_provider.h" +#include "components/metrics/metrics_service.h" +#include "components/metrics/metrics_state_manager.h" +#include "components/metrics/net/net_metrics_log_uploader.h" + +namespace chromecast { +namespace metrics { + +// static +CastMetricsServiceClient* CastMetricsServiceClient::Create( + PrefService* pref_service, + net::URLRequestContextGetter* request_context) { + return new CastMetricsServiceClient(pref_service, request_context); +} + +void CastMetricsServiceClient::SetMetricsClientId( + const std::string& client_id) { + LOG(INFO) << "Metrics client ID set: " << client_id; + PlatformSetClientID(client_id); +} + +bool CastMetricsServiceClient::IsOffTheRecordSessionActive() { + // Chromecast behaves as "off the record" w/r/t recording browsing state, + // but this value is about not disabling metrics because of it. + return false; +} + +std::string CastMetricsServiceClient::GetApplicationLocale() { + return base::i18n::GetConfiguredLocale(); +} + +bool CastMetricsServiceClient::GetBrand(std::string* brand_code) { + return false; +} + +::metrics::SystemProfileProto::Channel CastMetricsServiceClient::GetChannel() { + return GetPlatformReleaseChannel(); +} + +std::string CastMetricsServiceClient::GetVersionString() { + return GetPlatformVersionString(); +} + +void CastMetricsServiceClient::OnLogUploadComplete() { + PlatformOnLogUploadComplete(); +} + +void CastMetricsServiceClient::StartGatheringMetrics( + const base::Closure& done_callback) { + done_callback.Run(); +} + +void CastMetricsServiceClient::CollectFinalMetrics( + const base::Closure& done_callback) { + done_callback.Run(); +} + +scoped_ptr< ::metrics::MetricsLogUploader> +CastMetricsServiceClient::CreateUploader( + const std::string& server_url, + const std::string& mime_type, + const base::Callback<void(int)>& on_upload_complete) { + return scoped_ptr< ::metrics::MetricsLogUploader>( + new ::metrics::NetMetricsLogUploader( + request_context_, + server_url, + mime_type, + on_upload_complete)); +} + +void CastMetricsServiceClient::EnableMetricsService(bool enabled) { + if (enabled) { + metrics_service_->Start(); + } else { + metrics_service_->Stop(); + } +} + +CastMetricsServiceClient::CastMetricsServiceClient( + PrefService* pref_service, + net::URLRequestContextGetter* request_context) + : metrics_state_manager_(::metrics::MetricsStateManager::Create( + pref_service, + base::Bind(&CastMetricsServiceClient::IsReportingEnabled, + base::Unretained(this)), + ::metrics::MetricsStateManager::StoreClientInfoCallback(), + ::metrics::MetricsStateManager::LoadClientInfoCallback())), + metrics_service_(new MetricsService( + metrics_state_manager_.get(), + this, + ChromecastConfig::GetInstance()->pref_service())), + request_context_(request_context) { + // Always create a client id as it may also be used by crash reporting, + // (indirectly) included in feedback, and can be queried during setup. + // For UMA and crash reporting, associated opt-in settings will control + // sending reports as directed by the user. + // For Setup (which also communicates the user's opt-in preferences), + // report the client-id and expect that setup will handle the current opt-in + // value. + metrics_state_manager_->ForceClientIdCreation(); + + // TODO(gunsch): Add the following: GPUMetricsProvider, + // NetworkMetricsProvider, ProfilerMetricsProvider. See: crbug/404791 + RegisterPlatformMetricsProviders(metrics_service_.get()); + + metrics_service_->InitializeMetricsRecordingState(); + + if (IsReportingEnabled()) + metrics_service_->Start(); +} + +CastMetricsServiceClient::~CastMetricsServiceClient() { +} + +bool CastMetricsServiceClient::IsReportingEnabled() { + return PlatformIsReportingEnabled(); +} + +} // namespace metrics +} // namespace chromecast diff --git a/chromecast/metrics/cast_metrics_service_client.h b/chromecast/metrics/cast_metrics_service_client.h new file mode 100644 index 0000000..5ad791d --- /dev/null +++ b/chromecast/metrics/cast_metrics_service_client.h @@ -0,0 +1,74 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROMECAST_METRICS_CAST_METRICS_SERVICE_CLIENT_H_ +#define CHROMECAST_METRICS_CAST_METRICS_SERVICE_CLIENT_H_ + +#include <string> + +#include "base/macros.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "components/metrics/metrics_service_client.h" + +class MetricsService; +class PrefService; + +namespace metrics { +class MetricsStateManager; +} // namespace metrics + +namespace net { +class URLRequestContextGetter; +} // namespace net + +namespace chromecast { +namespace metrics { + +class CastMetricsServiceClient : public ::metrics::MetricsServiceClient { + public: + virtual ~CastMetricsServiceClient(); + + static CastMetricsServiceClient* Create( + PrefService* pref_service, + net::URLRequestContextGetter* request_context); + + // metrics::MetricsServiceClient implementation: + virtual void SetMetricsClientId(const std::string& client_id) OVERRIDE; + virtual bool IsOffTheRecordSessionActive() OVERRIDE; + virtual std::string GetApplicationLocale() OVERRIDE; + virtual bool GetBrand(std::string* brand_code) OVERRIDE; + virtual ::metrics::SystemProfileProto::Channel GetChannel() OVERRIDE; + virtual std::string GetVersionString() OVERRIDE; + virtual void OnLogUploadComplete() OVERRIDE; + virtual void StartGatheringMetrics( + const base::Closure& done_callback) OVERRIDE; + virtual void CollectFinalMetrics(const base::Closure& done_callback) OVERRIDE; + virtual scoped_ptr< ::metrics::MetricsLogUploader> CreateUploader( + const std::string& server_url, + const std::string& mime_type, + const base::Callback<void(int)>& on_upload_complete) OVERRIDE; + + // Starts/stops the metrics service. + void EnableMetricsService(bool enabled); + + private: + explicit CastMetricsServiceClient( + PrefService* pref_service, + net::URLRequestContextGetter* request_context); + + // Returns whether or not metrics reporting is enabled. + bool IsReportingEnabled(); + + scoped_ptr< ::metrics::MetricsStateManager> metrics_state_manager_; + scoped_ptr<MetricsService> metrics_service_; + net::URLRequestContextGetter* request_context_; + + DISALLOW_COPY_AND_ASSIGN(CastMetricsServiceClient); +}; + +} // namespace metrics +} // namespace chromecast + +#endif // CHROMECAST_METRICS_CAST_METRICS_SERVICE_CLIENT_H_ diff --git a/chromecast/metrics/platform_metrics_providers.h b/chromecast/metrics/platform_metrics_providers.h new file mode 100644 index 0000000..d656b39 --- /dev/null +++ b/chromecast/metrics/platform_metrics_providers.h @@ -0,0 +1,36 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROMECAST_METRICS_PLATFORM_METRICS_PROVIDERS_H_ +#define CHROMECAST_METRICS_PLATFORM_METRICS_PROVIDERS_H_ + +#include "components/metrics/proto/system_profile.pb.h" + +class MetricsService; + +namespace chromecast { +namespace metrics { + +// Build-level hook for different platforms to provide data to MetricsService. +void RegisterPlatformMetricsProviders(MetricsService* metrics_service); + +// Returns the current release channel. +::metrics::SystemProfileProto::Channel GetPlatformReleaseChannel(); + +// Returns a string representing this build's version. +std::string GetPlatformVersionString(); + +// Returns whether or not metrics reporting should be on. +bool PlatformIsReportingEnabled(); + +// Called when the UMA client ID has been set. +void PlatformSetClientID(const std::string& client_id); + +// Called when an upload has completed. +void PlatformOnLogUploadComplete(); + +} // namespace metrics +} // namespace chromecast + +#endif // CHROMECAST_METRICS_PLATFORM_METRICS_PROVIDERS_H_ diff --git a/chromecast/metrics/platform_metrics_providers_simple.cc b/chromecast/metrics/platform_metrics_providers_simple.cc new file mode 100644 index 0000000..d3f6ab9 --- /dev/null +++ b/chromecast/metrics/platform_metrics_providers_simple.cc @@ -0,0 +1,32 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chromecast/metrics/platform_metrics_providers.h" + +namespace chromecast { +namespace metrics { + +void RegisterPlatformMetricsProviders(MetricsService* metrics_service) { +} + +::metrics::SystemProfileProto::Channel GetPlatformReleaseChannel() { + return ::metrics::SystemProfileProto::CHANNEL_STABLE; +} + +std::string GetPlatformVersionString() { + return ""; +} + +bool PlatformIsReportingEnabled() { + return false; +} + +void PlatformSetClientID(const std::string& client_id) { +} + +void PlatformOnLogUploadComplete() { +} + +} // namespace metrics +} // namespace chromecast diff --git a/chromecast/shell/browser/cast_browser_main_parts.cc b/chromecast/shell/browser/cast_browser_main_parts.cc index 72c7544..8b98918d 100644 --- a/chromecast/shell/browser/cast_browser_main_parts.cc +++ b/chromecast/shell/browser/cast_browser_main_parts.cc @@ -7,6 +7,7 @@ #include "base/command_line.h" #include "base/prefs/pref_registry_simple.h" #include "chromecast/common/chromecast_config.h" +#include "chromecast/metrics/cast_metrics_service_client.h" #include "chromecast/net/network_change_notifier_cast.h" #include "chromecast/net/network_change_notifier_factory_cast.h" #include "chromecast/service/cast_service.h" @@ -74,6 +75,9 @@ void CastBrowserMainParts::PreMainMessageLoopRun() { url_request_context_factory_->InitializeOnUIThread(); browser_context_.reset(new CastBrowserContext(url_request_context_factory_)); + metrics_service_client_.reset(metrics::CastMetricsServiceClient::Create( + ChromecastConfig::GetInstance()->pref_service(), + browser_context_->GetRequestContext())); dev_tools_.reset(new RemoteDebuggingServer()); InitializeWebUI(); @@ -92,6 +96,7 @@ void CastBrowserMainParts::PostMainMessageLoopRun() { cast_service_.reset(); dev_tools_.reset(); + metrics_service_client_.reset(); browser_context_.reset(); } diff --git a/chromecast/shell/browser/cast_browser_main_parts.h b/chromecast/shell/browser/cast_browser_main_parts.h index 988ceea..6be05ad 100644 --- a/chromecast/shell/browser/cast_browser_main_parts.h +++ b/chromecast/shell/browser/cast_browser_main_parts.h @@ -18,6 +18,10 @@ namespace chromecast { class CastService; +namespace metrics { +class CastMetricsServiceClient; +} // namespace metrics + namespace shell { class CastBrowserContext; @@ -46,6 +50,7 @@ class CastBrowserMainParts : public content::BrowserMainParts { private: scoped_ptr<CastBrowserContext> browser_context_; scoped_ptr<CastService> cast_service_; + scoped_ptr<metrics::CastMetricsServiceClient> metrics_service_client_; scoped_ptr<RemoteDebuggingServer> dev_tools_; URLRequestContextFactory* const url_request_context_factory_; |