Introduce MetricsServiceClient and ChromeMetricsServiceClient.

In a later CL, MetricsService ctor will take an instance of
MetricsServiceClient.

BUG=374238

Review URL: https://codereview.chromium.org/292693003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271380 0039d316-1c4b-4281-b951-d872f2087c98
parent c429c2e7
// 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 "chrome/browser/metrics/chrome_metrics_service_client.h"
#include "base/logging.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/ui/browser_otr_state.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/crash_keys.h"
namespace {
metrics::SystemProfileProto::Channel AsProtobufChannel(
chrome::VersionInfo::Channel channel) {
switch (channel) {
case chrome::VersionInfo::CHANNEL_UNKNOWN:
return metrics::SystemProfileProto::CHANNEL_UNKNOWN;
case chrome::VersionInfo::CHANNEL_CANARY:
return metrics::SystemProfileProto::CHANNEL_CANARY;
case chrome::VersionInfo::CHANNEL_DEV:
return metrics::SystemProfileProto::CHANNEL_DEV;
case chrome::VersionInfo::CHANNEL_BETA:
return metrics::SystemProfileProto::CHANNEL_BETA;
case chrome::VersionInfo::CHANNEL_STABLE:
return metrics::SystemProfileProto::CHANNEL_STABLE;
}
NOTREACHED();
return metrics::SystemProfileProto::CHANNEL_UNKNOWN;
}
} // namespace
ChromeMetricsServiceClient::ChromeMetricsServiceClient()
: MetricsServiceClient() {
}
ChromeMetricsServiceClient::~ChromeMetricsServiceClient() {
}
void ChromeMetricsServiceClient::SetClientID(const std::string& client_id) {
crash_keys::SetClientID(client_id);
}
bool ChromeMetricsServiceClient::IsOffTheRecordSessionActive() {
return !chrome::IsOffTheRecordSessionActive();
}
std::string ChromeMetricsServiceClient::GetApplicationLocale() {
return g_browser_process->GetApplicationLocale();
}
bool ChromeMetricsServiceClient::GetBrand(std::string* brand_code) {
return google_util::GetBrand(brand_code);
}
metrics::SystemProfileProto::Channel ChromeMetricsServiceClient::GetChannel() {
return AsProtobufChannel(chrome::VersionInfo::GetChannel());
}
std::string ChromeMetricsServiceClient::GetVersionString() {
// TODO(asvitkine): Move over from metrics_log.cc
return std::string();
}
// 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 CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_
#define CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_
#include <string>
#include "base/basictypes.h"
#include "components/metrics/metrics_service_client.h"
// ChromeMetricsServiceClient provides an implementation of MetricsServiceClient
// that depends on chrome/.
class ChromeMetricsServiceClient : metrics::MetricsServiceClient {
public:
ChromeMetricsServiceClient();
virtual ~ChromeMetricsServiceClient();
// metrics::MetricsServiceClient:
virtual void SetClientID(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;
private:
DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceClient);
};
#endif // CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_
......@@ -1177,6 +1177,8 @@
'browser/metrics/chrome_browser_main_extra_parts_metrics.h',
'browser/metrics/cloned_install_detector.cc',
'browser/metrics/cloned_install_detector.h',
'browser/metrics/chrome_metrics_service_client.cc',
'browser/metrics/chrome_metrics_service_client.h',
'browser/metrics/compression_utils.cc',
'browser/metrics/compression_utils.h',
'browser/metrics/extension_metrics.cc',
......
......@@ -23,6 +23,7 @@
'metrics/metrics_log_manager.h',
'metrics/metrics_pref_names.cc',
'metrics/metrics_pref_names.h',
'metrics/metrics_service_client.h',
'metrics/persisted_logs.cc',
'metrics/persisted_logs.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 COMPONENTS_METRICS_METRICS_SERVICE_CLIENT_H_
#define COMPONENTS_METRICS_METRICS_SERVICE_CLIENT_H_
#include <string>
#include "base/basictypes.h"
#include "components/metrics/proto/system_profile.pb.h"
namespace metrics {
// An abstraction of operations that depend on the embedder's (e.g. Chrome)
// environment.
class MetricsServiceClient {
public:
virtual ~MetricsServiceClient() {}
// Register the client id with other services (e.g. crash reporting), called
// when metrics recording gets enabled.
virtual void SetClientID(const std::string& client_id) = 0;
// Whether there's an "off the record" (aka "Incognito") session active.
virtual bool IsOffTheRecordSessionActive() = 0;
// Returns the current application locale (e.g. "en-US").
virtual std::string GetApplicationLocale() = 0;
// Retrieves the brand code string associated with the install, returning
// false if no brand code is available.
virtual bool GetBrand(std::string* brand_code) = 0;
// Returns the release channel (e.g. stable, beta, etc) of the application.
virtual SystemProfileProto::Channel GetChannel() = 0;
// Returns the version of the application as a string.
virtual std::string GetVersionString() = 0;
};
} // namespace metrics
#endif // COMPONENTS_METRICS_METRICS_SERVICE_CLIENT_H_
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