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