Add function to register a synthetic trial with the trial hash.

This will be used by Android Chrome to register external
experiments.

BUG=400357

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287695 0039d316-1c4b-4281-b951-d872f2087c98
parent 2940ea77
......@@ -8,6 +8,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/common/pref_names.h"
#include "components/metrics/metrics_service.h"
#include "components/variations/metrics_util.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/settings/cros_settings.h"
......@@ -49,9 +50,18 @@ bool ChromeMetricsServiceAccessor::IsCrashReportingEnabled() {
// static
bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
const std::string& trial, const std::string& group) {
const std::string& trial_name,
const std::string& group_name) {
return RegisterSyntheticFieldTrialWithNameHash(metrics::HashName(trial_name),
group_name);
}
// static
bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrialWithNameHash(
uint32_t trial_name_hash,
const std::string& group_name) {
return MetricsServiceAccessor::RegisterSyntheticFieldTrial(
g_browser_process->metrics_service(),
trial,
group);
trial_name_hash,
metrics::HashName(group_name));
}
......@@ -5,6 +5,9 @@
#ifndef CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_ACCESSOR_H_
#define CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_ACCESSOR_H_
#include <stdint.h>
#include <string>
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "chrome/browser/metrics/metrics_service_accessor.h"
......@@ -46,6 +49,7 @@ class ChromeMetricsServiceAccessor : public MetricsServiceAccessor {
friend class extensions::MetricsPrivateGetIsCrashReportingEnabledFunction;
friend class ::FlashDOMHandler;
friend class system_logs::ChromeInternalLogSource;
friend class UmaSessionStats;
FRIEND_TEST_ALL_PREFIXES(ChromeMetricsServiceAccessorTest,
MetricsReportingEnabled);
......@@ -70,8 +74,14 @@ class ChromeMetricsServiceAccessor : public MetricsServiceAccessor {
// registered at a time for a given trial name. Only the last group name that
// is registered for a given trial name will be recorded. The values passed
// in must not correspond to any real field trial in the code.
static bool RegisterSyntheticFieldTrial(const std::string& trial,
const std::string& group);
static bool RegisterSyntheticFieldTrial(const std::string& trial_name,
const std::string& group_name);
// Same as RegisterSyntheticFieldTrial above, but takes a hash for the trial
// name, rather than computing it from the string.
static bool RegisterSyntheticFieldTrialWithNameHash(
uint32_t trial_name_hash,
const std::string& group_name);
DISALLOW_IMPLICIT_CONSTRUCTORS(ChromeMetricsServiceAccessor);
};
......
......@@ -7,7 +7,6 @@
#include "chrome/browser/browser_process.h"
#include "components/metrics/metrics_service.h"
#include "components/metrics/metrics_service_observer.h"
#include "components/variations/metrics_util.h"
// static
void MetricsServiceAccessor::AddMetricsServiceObserver(
......@@ -27,13 +26,12 @@ void MetricsServiceAccessor::RemoveMetricsServiceObserver(
// static
bool MetricsServiceAccessor::RegisterSyntheticFieldTrial(
MetricsService* metrics_service,
const std::string& trial,
const std::string& group) {
uint32_t trial_name_hash,
uint32_t group_name_hash) {
if (!metrics_service)
return false;
SyntheticTrialGroup trial_group(metrics::HashName(trial),
metrics::HashName(group));
SyntheticTrialGroup trial_group(trial_name_hash, group_name_hash);
metrics_service->RegisterSyntheticFieldTrial(trial_group);
return true;
}
......@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_METRICS_METRICS_SERVICE_ACCESSOR_H_
#define CHROME_BROWSER_METRICS_METRICS_SERVICE_ACCESSOR_H_
#include <stdint.h>
#include <string>
#include "base/macros.h"
......@@ -26,16 +27,13 @@ class MetricsServiceAccessor {
static void AddMetricsServiceObserver(MetricsServiceObserver* observer);
static void RemoveMetricsServiceObserver(MetricsServiceObserver* observer);
// Registers a field trial name and group to be used to annotate a UMA report
// with a particular Chrome configuration state. A UMA report will be
// annotated with this trial group if and only if all events in the report
// were created after the trial is registered. Only one group name may be
// registered at a time for a given trial name. Only the last group name that
// is registered for a given trial name will be recorded. The values passed
// in must not correspond to any real field trial in the code.
// Registers the specified synthetic field trial (identified by a hash of the
// trial name and group name) with |metrics_service|, if the service is not
// NULL, returning true on success.
// See the comment on MetricsService::RegisterSyntheticFieldTrial for details.
static bool RegisterSyntheticFieldTrial(MetricsService* metrics_service,
const std::string& trial,
const std::string& group);
uint32_t trial_name_hash,
uint32_t group_name_hash);
private:
DISALLOW_COPY_AND_ASSIGN(MetricsServiceAccessor);
......
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