| Index: android_webview/browser/aw_metrics_service_client.cc
|
| diff --git a/android_webview/browser/aw_metrics_service_client.cc b/android_webview/browser/aw_metrics_service_client.cc
|
| index 685cc33f88eb67db7ba1c6913ee35923be88ce7f..2bca66ace02dea2393133333c875cb0cabf0863a 100644
|
| --- a/android_webview/browser/aw_metrics_service_client.cc
|
| +++ b/android_webview/browser/aw_metrics_service_client.cc
|
| @@ -10,6 +10,7 @@
|
| #include "base/guid.h"
|
| #include "base/i18n/rtl.h"
|
| #include "components/metrics/call_stack_profile_metrics_provider.h"
|
| +#include "components/metrics/enabled_state_provider.h"
|
| #include "components/metrics/gpu/gpu_metrics_provider.h"
|
| #include "components/metrics/metrics_pref_names.h"
|
| #include "components/metrics/metrics_service.h"
|
| @@ -62,6 +63,24 @@ void GetOrCreateGUID(const base::FilePath guid_file_path, std::string* guid) {
|
|
|
| } // namespace
|
|
|
| +class AwMetricsServiceClient::AwEnabledStateProvider
|
| + : public metrics::EnabledStateProvider {
|
| + public:
|
| + AwEnabledStateProvider(AwMetricsServiceClient* metrics_service_client)
|
| + : metrics_service_client_(metrics_service_client) {}
|
| + ~AwEnabledStateProvider() override {}
|
| +
|
| + bool IsConsentGiven() override {
|
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| + return metrics_service_client_->is_enabled_;
|
| + }
|
| +
|
| + private:
|
| + AwMetricsServiceClient* metrics_service_client_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(AwEnabledStateProvider);
|
| +};
|
| +
|
| // static
|
| AwMetricsServiceClient* AwMetricsServiceClient::GetInstance() {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| @@ -78,6 +97,8 @@ void AwMetricsServiceClient::Initialize(
|
| pref_service_ = pref_service;
|
| request_context_ = request_context;
|
|
|
| + enabled_state_provider_.reset(new AwEnabledStateProvider(this));
|
| +
|
| std::string* guid = new std::string;
|
| // Initialization happens on the UI thread, but getting the GUID should happen
|
| // on the file I/O thread. So we start to initialize, then post to get the
|
| @@ -98,8 +119,7 @@ void AwMetricsServiceClient::InitializeWithGUID(std::string* guid) {
|
| pref_service_->SetString(metrics::prefs::kMetricsClientID, *guid);
|
|
|
| metrics_state_manager_ = metrics::MetricsStateManager::Create(
|
| - pref_service_, base::Bind(&AwMetricsServiceClient::is_reporting_enabled,
|
| - base::Unretained(this)),
|
| + pref_service_, enabled_state_provider_.get(),
|
| base::Bind(&StoreClientInfo), base::Bind(&LoadClientInfo));
|
|
|
| metrics_service_.reset(new ::metrics::MetricsService(
|
| @@ -130,7 +150,7 @@ void AwMetricsServiceClient::InitializeWithGUID(std::string* guid) {
|
|
|
| is_initialized_ = true;
|
|
|
| - if (is_reporting_enabled())
|
| + if (enabled_state_provider_->IsReportingEnabled())
|
| metrics_service_->Start();
|
| }
|
|
|
| @@ -218,13 +238,9 @@ AwMetricsServiceClient::AwMetricsServiceClient()
|
| : is_initialized_(false),
|
| is_enabled_(false),
|
| pref_service_(nullptr),
|
| - request_context_(nullptr) {}
|
| + request_context_(nullptr),
|
| + enabled_state_provider_(nullptr) {}
|
|
|
| AwMetricsServiceClient::~AwMetricsServiceClient() {}
|
|
|
| -bool AwMetricsServiceClient::is_reporting_enabled() {
|
| - DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| - return is_enabled_;
|
| -}
|
| -
|
| } // namespace android_webview
|
|
|