Commit 0ee038dd authored by gunsch's avatar gunsch Committed by Commit bot

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}
parent f7b1cb69
...@@ -41,6 +41,33 @@ ...@@ -41,6 +41,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', 'target_name': 'cast_service',
'type': '<(component)', 'type': '<(component)',
...@@ -128,16 +155,18 @@ ...@@ -128,16 +155,18 @@
'type': 'executable', 'type': 'executable',
'dependencies': [ 'dependencies': [
'cast_common', 'cast_common',
'cast_metrics',
'cast_service', 'cast_service',
'cast_shell_pak', 'cast_shell_pak',
'cast_shell_resources', 'cast_shell_resources',
'cast_version_header', 'cast_version_header',
'chromecast_locales.gyp:chromecast_locales_pak', 'chromecast_locales.gyp:chromecast_locales_pak',
'chromecast_locales.gyp:chromecast_settings', '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',
'../content/content.gyp:content_app_browser', '../content/content.gyp:content_app_browser',
'../skia/skia.gyp:skia', '../skia/skia.gyp:skia',
'../ui/aura/aura.gyp:aura_test_support',
], ],
'sources': [ 'sources': [
'net/network_change_notifier_cast.cc', 'net/network_change_notifier_cast.cc',
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "chromecast/common/cast_paths.h" #include "chromecast/common/cast_paths.h"
#include "chromecast/common/pref_names.h" #include "chromecast/common/pref_names.h"
#include "chromecast/metrics/cast_metrics_prefs.h"
namespace chromecast { namespace chromecast {
...@@ -74,6 +75,7 @@ bool ChromecastConfig::Load(PrefRegistrySimple* registry) { ...@@ -74,6 +75,7 @@ bool ChromecastConfig::Load(PrefRegistrySimple* registry) {
VLOG(1) << "Loading config from " << config_path_.value(); VLOG(1) << "Loading config from " << config_path_.value();
registry->RegisterIntegerPref(prefs::kRemoteDebuggingPort, 0); registry->RegisterIntegerPref(prefs::kRemoteDebuggingPort, 0);
metrics::RegisterPrefs(registry);
RegisterPlatformPrefs(registry); RegisterPlatformPrefs(registry);
PersistentPrefStore::PrefReadError prefs_read_error = PersistentPrefStore::PrefReadError prefs_read_error =
......
include_rules = [
"+components/metrics",
]
# components/metrics OWNERS for review of Chromecast metrics code
asvitkine@chromium.org
mpearson@chromium.org
jar@chromium.org
isherman@chromium.org
// 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
// 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_
// 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
// 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_
// 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_
// 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
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_registry_simple.h"
#include "chromecast/common/chromecast_config.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_cast.h"
#include "chromecast/net/network_change_notifier_factory_cast.h" #include "chromecast/net/network_change_notifier_factory_cast.h"
#include "chromecast/service/cast_service.h" #include "chromecast/service/cast_service.h"
...@@ -74,6 +75,9 @@ void CastBrowserMainParts::PreMainMessageLoopRun() { ...@@ -74,6 +75,9 @@ void CastBrowserMainParts::PreMainMessageLoopRun() {
url_request_context_factory_->InitializeOnUIThread(); url_request_context_factory_->InitializeOnUIThread();
browser_context_.reset(new CastBrowserContext(url_request_context_factory_)); 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()); dev_tools_.reset(new RemoteDebuggingServer());
InitializeWebUI(); InitializeWebUI();
...@@ -92,6 +96,7 @@ void CastBrowserMainParts::PostMainMessageLoopRun() { ...@@ -92,6 +96,7 @@ void CastBrowserMainParts::PostMainMessageLoopRun() {
cast_service_.reset(); cast_service_.reset();
dev_tools_.reset(); dev_tools_.reset();
metrics_service_client_.reset();
browser_context_.reset(); browser_context_.reset();
} }
......
...@@ -18,6 +18,10 @@ namespace chromecast { ...@@ -18,6 +18,10 @@ namespace chromecast {
class CastService; class CastService;
namespace metrics {
class CastMetricsServiceClient;
} // namespace metrics
namespace shell { namespace shell {
class CastBrowserContext; class CastBrowserContext;
...@@ -46,6 +50,7 @@ class CastBrowserMainParts : public content::BrowserMainParts { ...@@ -46,6 +50,7 @@ class CastBrowserMainParts : public content::BrowserMainParts {
private: private:
scoped_ptr<CastBrowserContext> browser_context_; scoped_ptr<CastBrowserContext> browser_context_;
scoped_ptr<CastService> cast_service_; scoped_ptr<CastService> cast_service_;
scoped_ptr<metrics::CastMetricsServiceClient> metrics_service_client_;
scoped_ptr<RemoteDebuggingServer> dev_tools_; scoped_ptr<RemoteDebuggingServer> dev_tools_;
URLRequestContextFactory* const url_request_context_factory_; URLRequestContextFactory* const url_request_context_factory_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment