Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Unified Diff: chromecast/metrics/cast_metrics_service_client.cc

Issue 482813004: Adds CastMetricsServiceClient to Chromecast shell. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: registers prefs Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromecast/metrics/cast_metrics_service_client.h ('k') | chromecast/metrics/platform_metrics_providers.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromecast/metrics/cast_metrics_service_client.cc
diff --git a/chromecast/metrics/cast_metrics_service_client.cc b/chromecast/metrics/cast_metrics_service_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0ab08a3b54d57573e5961c3a3f90fe8de4f53a94
--- /dev/null
+++ b/chromecast/metrics/cast_metrics_service_client.cc
@@ -0,0 +1,135 @@
+// 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(
+ net::URLRequestContextGetter* request_context) {
+ return new CastMetricsServiceClient(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) {
+ brand_code->clear();
+ return true;
Alexei Svitkine (slow) 2014/08/20 21:21:47 Why not just return false, so that a brand isn't s
gunsch 2014/08/22 16:42:20 Done.
+}
+
+::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) {
+ if (!metrics_service_->recording_active() ||
+ !metrics_service_->reporting_active()) {
Alexei Svitkine (slow) 2014/08/20 21:21:46 Doesn't MetricsService do these checks internally
gunsch 2014/08/22 16:42:20 Done.
+ metrics_service_->Start();
+ }
+ } else {
+ if (metrics_service_->recording_active() ||
+ metrics_service_->reporting_active()) {
+ metrics_service_->Stop();
+ }
+ }
+}
+
+CastMetricsServiceClient::CastMetricsServiceClient(
+ net::URLRequestContextGetter* request_context)
+ : metrics_state_manager_(::metrics::MetricsStateManager::Create(
+ ChromecastConfig::GetInstance()->pref_service(),
Alexei Svitkine (slow) 2014/08/20 21:21:46 Nit: I think it would be cleaner to pass this as a
gunsch 2014/08/22 16:42:20 Done.
+ 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()) {
Alexei Svitkine (slow) 2014/08/20 21:21:46 Nit: Chromium style usually prefers no {}'s on sin
gunsch 2014/08/22 16:42:20 Done.
+ metrics_service_->Start();
+ }
+}
+
+CastMetricsServiceClient::~CastMetricsServiceClient() {
+}
+
+bool CastMetricsServiceClient::IsReportingEnabled() {
+ return PlatformIsReportingEnabled();
+}
+
+} // namespace metrics
+} // namespace chromecast
« no previous file with comments | « chromecast/metrics/cast_metrics_service_client.h ('k') | chromecast/metrics/platform_metrics_providers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698