diff options
author | gunsch <gunsch@chromium.org> | 2015-08-19 17:09:06 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-20 00:10:25 +0000 |
commit | 24edba4890dd86ffda6223048211520267a130a0 (patch) | |
tree | 5d35b3641066e2a1753e5cecbd2728d774f10701 /chromecast | |
parent | eed6b7c7555211113c0c92d5934c48a9fab3b8c8 (diff) | |
download | chromium_src-24edba4890dd86ffda6223048211520267a130a0.zip chromium_src-24edba4890dd86ffda6223048211520267a130a0.tar.gz chromium_src-24edba4890dd86ffda6223048211520267a130a0.tar.bz2 |
[Chromecast] Moves metrics client ID/providers to CastContentBrowserClient.
This removes platform_metrics_providers.h and its link-time implementations.
R=byungchul@chromium.org,gfhuang@chromium.org,halliwell@chromium.org
BUG=internal b/20121400
Review URL: https://codereview.chromium.org/1298473004
Cr-Commit-Position: refs/heads/master@{#344371}
Diffstat (limited to 'chromecast')
-rw-r--r-- | chromecast/browser/BUILD.gn | 2 | ||||
-rw-r--r-- | chromecast/browser/cast_browser_process.cc | 9 | ||||
-rw-r--r-- | chromecast/browser/cast_browser_process.h | 6 | ||||
-rw-r--r-- | chromecast/browser/cast_content_browser_client.cc | 16 | ||||
-rw-r--r-- | chromecast/browser/cast_content_browser_client.h | 13 | ||||
-rw-r--r-- | chromecast/browser/metrics/BUILD.gn | 4 | ||||
-rw-r--r-- | chromecast/browser/metrics/cast_metrics_service_client.cc | 40 | ||||
-rw-r--r-- | chromecast/browser/metrics/cast_metrics_service_client.h | 6 | ||||
-rw-r--r-- | chromecast/browser/metrics/platform_metrics_providers.h | 35 | ||||
-rw-r--r-- | chromecast/browser/metrics/platform_metrics_providers_simple.cc | 29 | ||||
-rw-r--r-- | chromecast/chromecast.gyp | 4 |
11 files changed, 71 insertions, 93 deletions
diff --git a/chromecast/browser/BUILD.gn b/chromecast/browser/BUILD.gn index c6236a4d..cc4b29a 100644 --- a/chromecast/browser/BUILD.gn +++ b/chromecast/browser/BUILD.gn @@ -43,7 +43,6 @@ source_set("browser") { "metrics/cast_metrics_service_client.h", "metrics/cast_stability_metrics_provider.cc", "metrics/cast_stability_metrics_provider.h", - "metrics/platform_metrics_providers.h", "pref_service_helper.cc", "pref_service_helper.h", "service/cast_service.cc", @@ -64,7 +63,6 @@ source_set("browser") { if (!is_android) { sources += [ - "metrics/platform_metrics_providers_simple.cc", "service/cast_service_simple.cc", "service/cast_service_simple.h", ] diff --git a/chromecast/browser/cast_browser_process.cc b/chromecast/browser/cast_browser_process.cc index d3cfbfa..be83d00 100644 --- a/chromecast/browser/cast_browser_process.cc +++ b/chromecast/browser/cast_browser_process.cc @@ -36,7 +36,8 @@ CastBrowserProcess* CastBrowserProcess::GetInstance() { } CastBrowserProcess::CastBrowserProcess() - : net_log_(nullptr) { + : cast_content_browser_client_(nullptr), + net_log_(nullptr) { DCHECK(!g_instance); g_instance = this; } @@ -54,6 +55,12 @@ void CastBrowserProcess::SetBrowserContext( browser_context_.swap(browser_context); } +void CastBrowserProcess::SetCastContentBrowserClient( + CastContentBrowserClient* cast_content_browser_client) { + DCHECK(!cast_content_browser_client_); + cast_content_browser_client_ = cast_content_browser_client; +} + void CastBrowserProcess::SetCastService(scoped_ptr<CastService> cast_service) { DCHECK(!cast_service_); cast_service_.swap(cast_service); diff --git a/chromecast/browser/cast_browser_process.h b/chromecast/browser/cast_browser_process.h index 2af917a..422bd49 100644 --- a/chromecast/browser/cast_browser_process.h +++ b/chromecast/browser/cast_browser_process.h @@ -31,6 +31,7 @@ class CastMetricsServiceClient; namespace shell { class CastBrowserContext; +class CastContentBrowserClient; class CastResourceDispatcherHostDelegate; class RemoteDebuggingServer; @@ -44,6 +45,7 @@ class CastBrowserProcess { virtual ~CastBrowserProcess(); void SetBrowserContext(scoped_ptr<CastBrowserContext> browser_context); + void SetCastContentBrowserClient(CastContentBrowserClient* browser_client); void SetCastService(scoped_ptr<CastService> cast_service); #if defined(USE_AURA) void SetCastScreen(scoped_ptr<CastScreen> cast_screen); @@ -64,6 +66,9 @@ class CastBrowserProcess { scoped_refptr<ConnectivityChecker> connectivity_checker); void SetNetLog(net::NetLog* net_log); + CastContentBrowserClient* browser_client() const { + return cast_content_browser_client_; + } CastBrowserContext* browser_context() const { return browser_context_.get(); } CastService* cast_service() const { return cast_service_.get(); } #if defined(USE_AURA) @@ -100,6 +105,7 @@ class CastBrowserProcess { #endif // defined(OS_ANDROID) scoped_ptr<RemoteDebuggingServer> remote_debugging_server_; + CastContentBrowserClient* cast_content_browser_client_; net::NetLog* net_log_; // Note: CastService must be destroyed before others. diff --git a/chromecast/browser/cast_content_browser_client.cc b/chromecast/browser/cast_content_browser_client.cc index 96a06fe..1dc6b81 100644 --- a/chromecast/browser/cast_content_browser_client.cc +++ b/chromecast/browser/cast_content_browser_client.cc @@ -95,11 +95,21 @@ void CastContentBrowserClient::ProcessExiting() { FROM_HERE, base::Bind(&media::CastMediaShlib::Finalize)); } +void CastContentBrowserClient::SetMetricsClientId( + const std::string& client_id) { +} + +void CastContentBrowserClient::RegisterMetricsProviders( + ::metrics::MetricsService* metrics_service) { +} + content::BrowserMainParts* CastContentBrowserClient::CreateBrowserMainParts( const content::MainFunctionParams& parameters) { - return new CastBrowserMainParts(parameters, - url_request_context_factory_.get(), - CreateAudioManagerFactory()); + content::BrowserMainParts* parts = new CastBrowserMainParts( + parameters, url_request_context_factory_.get(), + CreateAudioManagerFactory()); + CastBrowserProcess::GetInstance()->SetCastContentBrowserClient(this); + return parts; } void CastContentBrowserClient::RenderProcessWillLaunch( diff --git a/chromecast/browser/cast_content_browser_client.h b/chromecast/browser/cast_content_browser_client.h index 9a1d10a..25ca3f9 100644 --- a/chromecast/browser/cast_content_browser_client.h +++ b/chromecast/browser/cast_content_browser_client.h @@ -25,8 +25,8 @@ namespace media { class AudioManagerFactory; } -namespace net { -class HostResolver; +namespace metrics { +class MetricsService; } namespace chromecast { @@ -40,7 +40,7 @@ namespace shell { class CastBrowserMainParts; class URLRequestContextFactory; -class CastContentBrowserClient: public content::ContentBrowserClient { +class CastContentBrowserClient : public content::ContentBrowserClient { public: // Creates an implementation of CastContentBrowserClient. Platform should // link in an implementation as needed. @@ -69,6 +69,13 @@ class CastContentBrowserClient: public content::ContentBrowserClient { // Performs cleanup for process exit (but before AtExitManager cleanup). void ProcessExiting(); + // Invoked when the metrics client ID changes. + virtual void SetMetricsClientId(const std::string& client_id); + + // Allows registration of extra metrics providers. + virtual void RegisterMetricsProviders( + ::metrics::MetricsService* metrics_service); + // content::ContentBrowserClient implementation: content::BrowserMainParts* CreateBrowserMainParts( const content::MainFunctionParams& parameters) override; diff --git a/chromecast/browser/metrics/BUILD.gn b/chromecast/browser/metrics/BUILD.gn index a07fbdf..81233e8 100644 --- a/chromecast/browser/metrics/BUILD.gn +++ b/chromecast/browser/metrics/BUILD.gn @@ -10,7 +10,6 @@ source_set("metrics") { "cast_metrics_service_client.h", "cast_stability_metrics_provider.cc", "cast_stability_metrics_provider.h", - "platform_metrics_providers.h", ] deps = [ @@ -35,7 +34,4 @@ source_set("metrics") { deps += [ "//components/metrics:serialization" ] } - - # TODO(kmackay) add source "platform_metrics_providers_simple.cc" - # according to condition (chromecast_branding != "Chrome") } diff --git a/chromecast/browser/metrics/cast_metrics_service_client.cc b/chromecast/browser/metrics/cast_metrics_service_client.cc index 21ac10b5..aa6076c 100644 --- a/chromecast/browser/metrics/cast_metrics_service_client.cc +++ b/chromecast/browser/metrics/cast_metrics_service_client.cc @@ -17,8 +17,9 @@ #include "chromecast/base/path_utils.h" #include "chromecast/base/pref_names.h" #include "chromecast/base/version.h" +#include "chromecast/browser/cast_browser_process.h" +#include "chromecast/browser/cast_content_browser_client.h" #include "chromecast/browser/metrics/cast_stability_metrics_provider.h" -#include "chromecast/browser/metrics/platform_metrics_providers.h" #include "chromecast/public/cast_sys_info.h" #include "components/metrics/client_info.h" #include "components/metrics/gpu/gpu_metrics_provider.h" @@ -94,7 +95,8 @@ void CastMetricsServiceClient::SetMetricsClientId( const std::string& client_id) { client_id_ = client_id; LOG(INFO) << "Metrics client ID set: " << client_id; - PlatformSetClientID(cast_service_, client_id); + shell::CastBrowserProcess::GetInstance()->browser_client()-> + SetMetricsClientId(client_id); } void CastMetricsServiceClient::OnRecordingDisabled() { @@ -110,6 +112,7 @@ void CastMetricsServiceClient::StoreClientInfo( scoped_ptr< ::metrics::ClientInfo> CastMetricsServiceClient::LoadClientInfo() { scoped_ptr< ::metrics::ClientInfo> client_info(new ::metrics::ClientInfo); + client_info_loaded_ = true; // kMetricsIsNewClientID would be missing if either the device was just // FDR'ed, or it is on pre-v1.2 build. @@ -125,19 +128,20 @@ scoped_ptr< ::metrics::ClientInfo> CastMetricsServiceClient::LoadClientInfo() { // else the device was just FDR'ed, pass through. } - const std::string client_id(GetPlatformClientID(cast_service_)); - if (!client_id.empty() && base::IsValidGUID(client_id)) { - client_info->client_id = client_id; + // Use "forced" client ID if available. + if (!force_client_id_.empty() && base::IsValidGUID(force_client_id_)) { + client_info->client_id = force_client_id_; return client_info.Pass(); + } + + if (force_client_id_.empty()) { + LOG(WARNING) << "Empty client id from platform," + << " assuming this is the first boot up of a new device."; } else { - if (client_id.empty()) { - LOG(WARNING) << "Empty client id from platform," - << " assuming this is the first boot up of a new device."; - } else { - LOG(ERROR) << "Invalid client id " << client_id << " from platform."; - } - return scoped_ptr< ::metrics::ClientInfo>(); + LOG(ERROR) << "Invalid client id from platform: " << force_client_id_ + << " from platform."; } + return scoped_ptr< ::metrics::ClientInfo>(); } bool CastMetricsServiceClient::IsOffTheRecordSessionActive() { @@ -258,6 +262,7 @@ CastMetricsServiceClient::CastMetricsServiceClient( : io_task_runner_(io_task_runner), pref_service_(pref_service), cast_service_(nullptr), + client_info_loaded_(false), #if defined(OS_LINUX) external_metrics_(nullptr), platform_metrics_(nullptr), @@ -277,6 +282,14 @@ void CastMetricsServiceClient::OnApplicationNotIdle() { metrics_service_->OnApplicationNotIdle(); } +void CastMetricsServiceClient::SetForceClientId( + const std::string& client_id) { + DCHECK(force_client_id_.empty()); + DCHECK(!client_info_loaded_) + << "Force client ID must be set before client info is loaded."; + force_client_id_ = client_id; +} + void CastMetricsServiceClient::Initialize(CastService* cast_service) { DCHECK(cast_service); DCHECK(!cast_service_); @@ -319,7 +332,8 @@ void CastMetricsServiceClient::Initialize(CastService* cast_service) { metrics_service_->RegisterMetricsProvider( scoped_ptr< ::metrics::MetricsProvider>( new ::metrics::ProfilerMetricsProvider)); - RegisterPlatformMetricsProviders(metrics_service_.get(), cast_service_); + shell::CastBrowserProcess::GetInstance()->browser_client()-> + RegisterMetricsProviders(metrics_service_.get()); metrics_service_->InitializeMetricsRecordingState(); #if !defined(OS_ANDROID) diff --git a/chromecast/browser/metrics/cast_metrics_service_client.h b/chromecast/browser/metrics/cast_metrics_service_client.h index 98db073..bbc2244 100644 --- a/chromecast/browser/metrics/cast_metrics_service_client.h +++ b/chromecast/browser/metrics/cast_metrics_service_client.h @@ -48,7 +48,11 @@ class CastMetricsServiceClient : public ::metrics::MetricsServiceClient { net::URLRequestContextGetter* request_context); static void RegisterPrefs(PrefRegistrySimple* registry); + // Use |client_id| when starting MetricsService instead of generating a new + // client ID. If used, SetForceClientId must be called before Initialize. + void SetForceClientId(const std::string& client_id); void OnApplicationNotIdle(); + void Initialize(CastService* cast_service); void Finalize(); @@ -88,6 +92,8 @@ class CastMetricsServiceClient : public ::metrics::MetricsServiceClient { PrefService* const pref_service_; CastService* cast_service_; std::string client_id_; + std::string force_client_id_; + bool client_info_loaded_; #if defined(OS_LINUX) ExternalMetrics* external_metrics_; diff --git a/chromecast/browser/metrics/platform_metrics_providers.h b/chromecast/browser/metrics/platform_metrics_providers.h deleted file mode 100644 index 41225ab..0000000 --- a/chromecast/browser/metrics/platform_metrics_providers.h +++ /dev/null @@ -1,35 +0,0 @@ -// 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_BROWSER_METRICS_PLATFORM_METRICS_PROVIDERS_H_ -#define CHROMECAST_BROWSER_METRICS_PLATFORM_METRICS_PROVIDERS_H_ - -#include "components/metrics/proto/system_profile.pb.h" - -namespace metrics { -class MetricsService; -} - -namespace chromecast { - -class CastService; - -namespace metrics { - -// Build-level hook for different platforms to provide data to MetricsService. -void RegisterPlatformMetricsProviders( - ::metrics::MetricsService* metrics_service, - CastService* cast_servce); - -// Returns UMA client ID persisted in the platform. -const std::string GetPlatformClientID(CastService* cast_servce); - -// Called when the UMA client ID has been set. -void PlatformSetClientID(CastService* cast_servce, - const std::string& client_id); - -} // namespace metrics -} // namespace chromecast - -#endif // CHROMECAST_BROWSER_METRICS_PLATFORM_METRICS_PROVIDERS_H_ diff --git a/chromecast/browser/metrics/platform_metrics_providers_simple.cc b/chromecast/browser/metrics/platform_metrics_providers_simple.cc deleted file mode 100644 index c51caa3..0000000 --- a/chromecast/browser/metrics/platform_metrics_providers_simple.cc +++ /dev/null @@ -1,29 +0,0 @@ -// 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/browser/metrics/platform_metrics_providers.h" - -namespace chromecast { -namespace metrics { - -void RegisterPlatformMetricsProviders( - ::metrics::MetricsService* metrics_service, - CastService* cast_servce) { -} - -const std::string GetPlatformClientID(CastService* cast_servce) { - return ""; -} - -::metrics::SystemProfileProto::Channel GetPlatformReleaseChannel( - CastService* cast_servce) { - return ::metrics::SystemProfileProto::CHANNEL_STABLE; -} - -void PlatformSetClientID(CastService* cast_servce, - const std::string& client_id) { -} - -} // namespace metrics -} // namespace chromecast diff --git a/chromecast/chromecast.gyp b/chromecast/chromecast.gyp index c0ae948..39db0d4 100644 --- a/chromecast/chromecast.gyp +++ b/chromecast/chromecast.gyp @@ -345,7 +345,6 @@ 'browser/metrics/cast_metrics_service_client.h', 'browser/metrics/cast_stability_metrics_provider.cc', 'browser/metrics/cast_stability_metrics_provider.h', - 'browser/metrics/platform_metrics_providers.h', 'browser/pref_service_helper.cc', 'browser/pref_service_helper.h', 'browser/service/cast_service.cc', @@ -381,7 +380,6 @@ 'browser/cast_content_browser_client_simple.cc', 'browser/cast_network_delegate_simple.cc', 'browser/devtools/remote_debugging_server_simple.cc', - 'browser/metrics/platform_metrics_providers_simple.cc', 'browser/pref_service_helper_simple.cc', 'browser/service/cast_service_android.cc', 'browser/service/cast_service_android.h', @@ -415,6 +413,7 @@ ['OS=="android"', { 'dependencies': [ '../components/components.gyp:cdm_browser', + '../components/components.gyp:external_video_surface', 'cast_jni_headers', ], }], @@ -520,7 +519,6 @@ 'cast_version_header', '../base/base.gyp:base', '../components/components.gyp:breakpad_host', - '../components/components.gyp:external_video_surface', '../content/content.gyp:content', '../skia/skia.gyp:skia', '../ui/gfx/gfx.gyp:gfx', |