Skip to content

Commit

Permalink
Componentize guts of ChromeMetricsServiceAccessor field trial functions
Browse files Browse the repository at this point in the history
This CL turns ChromeMetricsServiceAccessor's field trials-related functions
into just thin wrappers around MetricsServiceAccessor functions in preparation
for decoupling the iOS port from ChromeMetricsServiceAccessor.

BUG=508014

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

Cr-Commit-Position: refs/heads/master@{#351308}
  • Loading branch information
colinblundell authored and Commit bot committed Sep 29, 2015
1 parent e725862 commit dcd73e5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 20 deletions.
12 changes: 5 additions & 7 deletions chrome/browser/metrics/chrome_metrics_service_accessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "chrome/common/chrome_switches.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"
Expand Down Expand Up @@ -52,16 +51,15 @@ bool ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled() {
bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
const std::string& trial_name,
const std::string& group_name) {
return RegisterSyntheticFieldTrialWithNameHash(metrics::HashName(trial_name),
group_name);
return metrics::MetricsServiceAccessor::RegisterSyntheticFieldTrial(
g_browser_process->metrics_service(), trial_name, group_name);
}

// static
bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrialWithNameHash(
uint32_t trial_name_hash,
const std::string& group_name) {
return metrics::MetricsServiceAccessor::RegisterSyntheticFieldTrial(
g_browser_process->metrics_service(),
trial_name_hash,
metrics::HashName(group_name));
return metrics::MetricsServiceAccessor::
RegisterSyntheticFieldTrialWithNameHash(
g_browser_process->metrics_service(), trial_name_hash, group_name);
}
16 changes: 7 additions & 9 deletions chrome/browser/metrics/chrome_metrics_service_accessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,16 @@ class ChromeMetricsServiceAccessor : public metrics::MetricsServiceAccessor {
// http://crbug.com/362192, http://crbug.com/532084
static bool IsMetricsAndCrashReportingEnabled();

// 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.
// Calls metrics::MetricsServiceAccessor::RegisterSyntheticFieldTrial() with
// g_browser_process->metrics_service(). See that function's declaration for
// details.
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.
// Calls
// metrics::MetricsServiceAccessor::RegisterSyntheticFieldTrialWithNameHash()
// with g_browser_process->metrics_service(). See that function's declaration
// for details.
static bool RegisterSyntheticFieldTrialWithNameHash(
uint32_t trial_name_hash,
const std::string& group_name);
Expand Down
19 changes: 19 additions & 0 deletions components/metrics/metrics_service_accessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,30 @@
#include "components/metrics/metrics_service_accessor.h"

#include "components/metrics/metrics_service.h"
#include "components/variations/metrics_util.h"

namespace metrics {

// static
bool MetricsServiceAccessor::RegisterSyntheticFieldTrial(
MetricsService* metrics_service,
const std::string& trial_name,
const std::string& group_name) {
return RegisterSyntheticFieldTrialWithNameAndGroupHash(
metrics_service, HashName(trial_name), HashName(group_name));
}

// static
bool MetricsServiceAccessor::RegisterSyntheticFieldTrialWithNameHash(
MetricsService* metrics_service,
uint32_t trial_name_hash,
const std::string& group_name) {
return RegisterSyntheticFieldTrialWithNameAndGroupHash(
metrics_service, trial_name_hash, HashName(group_name));
}

// static
bool MetricsServiceAccessor::RegisterSyntheticFieldTrialWithNameAndGroupHash(
MetricsService* metrics_service,
uint32_t trial_name_hash,
uint32_t group_name_hash) {
Expand Down
27 changes: 23 additions & 4 deletions components/metrics/metrics_service_accessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define COMPONENTS_METRICS_METRICS_SERVICE_ACCESSOR_H_

#include <stdint.h>
#include <string>

#include "base/macros.h"

Expand All @@ -22,11 +23,29 @@ class MetricsServiceAccessor {
// disallow instantiation.
MetricsServiceAccessor() {}

// 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.
// Registers a field trial name and group with |metrics_service| (if not
// null), to be used to annotate a UMA report with a particular 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. Returns true on success.
// See the comment on MetricsService::RegisterSyntheticFieldTrial for details.
static bool RegisterSyntheticFieldTrial(
static bool RegisterSyntheticFieldTrial(MetricsService* metrics_service,
const std::string& trial_name,
const std::string& group_name);

// Same as RegisterSyntheticFieldTrial above, but takes in the trial name as a
// hash rather than computing the hash from the string.
static bool RegisterSyntheticFieldTrialWithNameHash(
MetricsService* metrics_service,
uint32_t trial_name_hash,
const std::string& group_name);

// Same as RegisterSyntheticFieldTrial above, but takes in the trial and group
// names as hashes rather than computing those hashes from the strings.
static bool RegisterSyntheticFieldTrialWithNameAndGroupHash(
MetricsService* metrics_service,
uint32_t trial_name_hash,
uint32_t group_name_hash);
Expand Down

0 comments on commit dcd73e5

Please sign in to comment.