Chromium Code Reviews| Index: blimp/engine/app/blimp_metrics_service_client.cc |
| diff --git a/blimp/engine/app/blimp_metrics_service_client.cc b/blimp/engine/app/blimp_metrics_service_client.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..757ba98e8e68fc84e8814c43d7cf86b8ec82a6d3 |
| --- /dev/null |
| +++ b/blimp/engine/app/blimp_metrics_service_client.cc |
| @@ -0,0 +1,182 @@ |
| +// Copyright 2016 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 "blimp/engine/app/blimp_metrics_service_client.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/i18n/rtl.h" |
| +#include "base/memory/ptr_util.h" |
| +#include "components/metrics/call_stack_profile_metrics_provider.h" |
| +#include "components/metrics/gpu/gpu_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" |
| +#include "components/metrics/profiler/profiler_metrics_provider.h" |
| +#include "components/metrics/ui/screen_info_metrics_provider.h" |
| +#include "components/metrics/url_constants.h" |
| +#include "components/prefs/pref_service.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +namespace blimp { |
| +namespace engine { |
| + |
| +base::LazyInstance<BlimpMetricsServiceClient>::Leaky g_lazy_instance_; |
|
Wez
2016/04/26 01:38:17
This needs to be in the anonymous namespace, surel
Jess
2016/04/26 21:24:10
Done.
|
| + |
| +namespace { |
| + |
| +// Standard interval between log uploads, in minutes |
|
Wez
2016/04/26 01:38:18
Can you reword this to explain what the "standard
Jess
2016/04/26 21:24:10
Done.
|
| +const int kStandardUploadIntervalMinutes = 30; // Thirty minutes. |
|
Wez
2016/04/26 01:38:18
nit: Trailing comment adds nothing ;)
Jess
2016/04/26 21:24:10
Removed.
|
| + |
| +bool IsReportingEnabled() { |
|
Wez
2016/04/26 01:38:18
nit: Suggest providing a one-line comment explaini
Jess
2016/04/26 21:24:10
Done.
|
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
|
Wez
2016/04/26 01:38:17
Why this thread-check here but nowhere else?
Jess
2016/04/26 21:24:10
Usually this call makes use of features the requir
|
| + return true; |
| +} |
| + |
| +// Callbacks for metrics::MetricsStateManager::Create. Store/LoadClientInfo |
| +// allows Windows Chrome to back up ClientInfo. They're no-ops for Blimp. |
|
Wez
2016/04/26 01:38:18
IsReportingEnabled also seems to be a callback for
Jess
2016/04/26 21:24:10
See comment above.
|
| +void StoreClientInfo(const metrics::ClientInfo& client_info) {} |
| + |
| +std::unique_ptr<metrics::ClientInfo> LoadClientInfo() { |
| + return nullptr; |
| +} |
| + |
| +} // namespace |
| + |
| +// static |
| +BlimpMetricsServiceClient* BlimpMetricsServiceClient::GetInstance() { |
| + return g_lazy_instance_.Pointer(); |
| +} |
| + |
| +// static |
| +void BlimpMetricsServiceClient::Initialize( |
| + PrefService* pref_service, |
| + net::URLRequestContextGetter* request_context) { |
| + DCHECK(!is_initialized_); |
| + pref_service_ = pref_service; |
| + request_context_ = request_context; |
| + |
| + metrics_state_manager_ = metrics::MetricsStateManager::Create( |
| + pref_service_, |
| + base::Bind(&IsReportingEnabled), |
| + base::Bind(&StoreClientInfo), base::Bind(&LoadClientInfo)); |
|
Wez
2016/04/26 01:38:18
nit: Is this the format "git cl format" gives? See
Jess
2016/04/26 21:24:10
Ran git cl format.
|
| + |
| + metrics_service_.reset(new ::metrics::MetricsService( |
|
Wez
2016/04/26 01:38:18
nit: Do we need the leading ::?
Jess
2016/04/26 21:24:10
No. Removed.
|
| + metrics_state_manager_.get(), this, pref_service_)); |
| + |
| + metrics_service_->RegisterMetricsProvider( |
| + base::WrapUnique<metrics::MetricsProvider>( |
| + new metrics::NetworkMetricsProvider( |
| + content::BrowserThread::GetBlockingPool()))); |
|
Wez
2016/04/26 01:38:18
We should be very careful about using content::Bro
Jess
2016/04/26 21:24:10
Honestly I am not quite sure here. Perhaps remova
|
| + |
| + metrics_service_->RegisterMetricsProvider( |
| + base::WrapUnique<metrics::MetricsProvider>( |
| + new metrics::GPUMetricsProvider)); |
|
Wez
2016/04/26 01:38:18
nit: Why are these two registrations grouped toget
Jess
2016/04/26 21:24:10
Separated.
|
| + metrics_service_->RegisterMetricsProvider( |
| + base::WrapUnique<metrics::MetricsProvider>( |
| + new metrics::ScreenInfoMetricsProvider)); |
| + |
| + metrics_service_->RegisterMetricsProvider( |
| + base::WrapUnique<metrics::MetricsProvider>( |
| + new metrics::ProfilerMetricsProvider())); |
| + |
| + metrics_service_->RegisterMetricsProvider( |
| + base::WrapUnique<metrics::MetricsProvider>( |
| + new metrics::CallStackProfileMetricsProvider)); |
| + |
| + metrics_service_->InitializeMetricsRecordingState(); |
| + |
| + is_initialized_ = true; |
| + |
| + if (IsReportingEnabled()) { |
| + metrics_service_->Start(); |
| + } |
| +} |
| + |
| +void BlimpMetricsServiceClient::Finalize() { |
| + DCHECK(is_initialized_); |
| + metrics_service_->Stop(); |
| +} |
| + |
| +metrics::MetricsService* BlimpMetricsServiceClient::GetMetricsService() { |
| + return metrics_service_.get(); |
| +} |
| + |
| +// In Chrome, UMA and Breakpad are enabled/disabled together by the same |
| +// checkbox and they share the same client ID (a.k.a. GUID). SetMetricsClientId |
| +// and OnRecordingDisabled are intended to provide the ID to Breakpad. |
| +// This is not used on required by Blimp, so these are no-ops. |
|
Wez
2016/04/26 01:38:18
typo: on -> or
I think it's reasonable to just sa
Jess
2016/04/26 21:24:10
Based on Marcin's work I think we actually do use
|
| +void BlimpMetricsServiceClient::SetMetricsClientId( |
| + const std::string& client_id) {} |
| + |
| +void BlimpMetricsServiceClient::OnRecordingDisabled() {} |
| + |
| +bool BlimpMetricsServiceClient::IsOffTheRecordSessionActive() { |
| + // Blimp does not have incognito mode. |
| + return false; |
| +} |
| + |
| +int32_t BlimpMetricsServiceClient::GetProduct() { |
| + // Indicates product family, not reported platform. |
|
Wez
2016/04/26 01:38:17
Not sure what this comment means by "reported plat
Jess
2016/04/26 21:24:10
Added exampled to help clarify. This Product is n
|
| + return metrics::ChromeUserMetricsExtension::CHROME; |
| +} |
| + |
| +std::string BlimpMetricsServiceClient::GetApplicationLocale() { |
| + return base::i18n::GetConfiguredLocale(); |
| +} |
| + |
| +bool BlimpMetricsServiceClient::GetBrand(std::string* brand_code) { |
| + // Blimp doesn't use brand codes. |
|
Wez
2016/04/26 01:38:18
Not clear from this comment what a brand-code even
Jess
2016/04/26 21:24:10
Acknowledged.
|
| + return false; |
| +} |
| + |
| +metrics::SystemProfileProto::Channel BlimpMetricsServiceClient::GetChannel() { |
| + // Blimp engine does not have channel info yet. |
| + return metrics::SystemProfileProto::CHANNEL_UNKNOWN; |
|
Wez
2016/04/26 01:38:18
nit: Hmmm, tricky; channel is used elsewhere to de
Jess
2016/04/26 21:24:10
Do we have the concept of a channel within the eng
|
| +} |
| + |
| +std::string BlimpMetricsServiceClient::GetVersionString() { |
| + // TODO(jessicag): Add in a meaningful version string. |
|
Wez
2016/04/26 01:38:17
Excitingly I'm working on a CL that will add such
Jess
2016/04/26 21:24:10
Acknowledged.
|
| + return std::string(); |
| +} |
| + |
| +void BlimpMetricsServiceClient::OnLogUploadComplete() {} |
| + |
| +void BlimpMetricsServiceClient::InitializeSystemProfileMetrics( |
| + const base::Closure& done_callback) { |
| + done_callback.Run(); |
|
Wez
2016/04/26 01:38:18
Add one-line comment to clarify why it's OK to cal
Jess
2016/04/26 21:24:10
Done.
|
| +} |
| + |
| +void BlimpMetricsServiceClient::CollectFinalMetricsForLog( |
| + const base::Closure& done_callback) { |
| + done_callback.Run(); |
| +} |
| + |
| +std::unique_ptr<metrics::MetricsLogUploader> |
| +BlimpMetricsServiceClient::CreateUploader( |
| + const base::Callback<void(int)>& on_upload_complete) { |
| + return base::WrapUnique<metrics::MetricsLogUploader>( |
| + new metrics::NetMetricsLogUploader( |
| + // URLRequestContextGetter* that remains valid for class lifetime |
| + // In place of g_browser_process->system_request_context() |
| + // In engine use subclass BlimpURLRequestContextGetter. |
| + // Member of g/e/common/blimp_browser_context. |
|
Wez
2016/04/26 01:38:18
This comment is already present in the class decla
Jess
2016/04/26 21:24:10
Cleaned up.
|
| + request_context_, |
| + metrics::kDefaultMetricsServerUrl, |
| + metrics::kDefaultMetricsMimeType, |
| + on_upload_complete)); |
| +} |
| + |
| +base::TimeDelta BlimpMetricsServiceClient::GetStandardUploadInterval() { |
| + return base::TimeDelta::FromMinutes(kStandardUploadIntervalMinutes); |
| +} |
| + |
| +BlimpMetricsServiceClient::BlimpMetricsServiceClient() |
| + : is_initialized_(false), |
| + pref_service_(nullptr), |
| + request_context_(nullptr) {} |
| + |
| +BlimpMetricsServiceClient::~BlimpMetricsServiceClient() {} |
| + |
| +} // namespace engine |
| +} // namespace blimp |