| Index: chrome/common/variations/child_process_field_trial_syncer.cc
|
| diff --git a/chrome/common/variations/child_process_field_trial_syncer.cc b/chrome/common/variations/child_process_field_trial_syncer.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9a0b309481e4e4656296b4c3184e328a0bdec03e
|
| --- /dev/null
|
| +++ b/chrome/common/variations/child_process_field_trial_syncer.cc
|
| @@ -0,0 +1,67 @@
|
| +// Copyright 2016 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/common/variations/child_process_field_trial_syncer.h"
|
| +
|
| +#include <set>
|
| +#include <utility>
|
| +
|
| +#include "base/base_switches.h"
|
| +#include "base/command_line.h"
|
| +#include "chrome/common/render_messages.h"
|
| +#include "components/variations/variations_util.h"
|
| +
|
| +namespace chrome_variations {
|
| +
|
| +ChildProcessFieldTrialSyncer::ChildProcessFieldTrialSyncer(
|
| + IPC::Sender* ipc_sender) : ipc_sender_(ipc_sender) {}
|
| +
|
| +ChildProcessFieldTrialSyncer::~ChildProcessFieldTrialSyncer() {}
|
| +
|
| +void ChildProcessFieldTrialSyncer::InitFieldTrialObserving(
|
| + const base::CommandLine& command_line) {
|
| + // Set up initial set of crash dump data for field trials in this process.
|
| + variations::SetVariationListCrashKeys();
|
| +
|
| + // Listen for field trial activations to report them to the browser.
|
| + base::FieldTrialList::AddObserver(this);
|
| +
|
| + // Some field trials may have been activated before this point. Notify the
|
| + // browser of these activations now. To detect these, take the set difference
|
| + // of currently active trials with the initially active trials.
|
| + base::FieldTrial::ActiveGroups initially_active_trials;
|
| + base::FieldTrialList::GetActiveFieldTrialGroupsFromString(
|
| + command_line.GetSwitchValueASCII(switches::kForceFieldTrials),
|
| + &initially_active_trials);
|
| + std::set<std::string> initially_active_trials_set;
|
| + for (const auto& entry : initially_active_trials) {
|
| + initially_active_trials_set.insert(std::move(entry.trial_name));
|
| + }
|
| +
|
| + base::FieldTrial::ActiveGroups current_active_trials;
|
| + base::FieldTrialList::GetActiveFieldTrialGroups(¤t_active_trials);
|
| + for (const auto& trial : current_active_trials) {
|
| + if (!ContainsKey(initially_active_trials_set, trial.trial_name))
|
| + OnFieldTrialGroupFinalized(trial.trial_name, trial.group_name);
|
| + }
|
| +}
|
| +
|
| +void ChildProcessFieldTrialSyncer::OnSetFieldTrialGroup(
|
| + const std::string& trial_name,
|
| + const std::string& group_name) {
|
| + base::FieldTrial* trial =
|
| + base::FieldTrialList::CreateFieldTrial(trial_name, group_name);
|
| + // Ensure the trial is marked as "used" by calling group() on it if it is
|
| + // marked as activated.
|
| + trial->group();
|
| + variations::SetVariationListCrashKeys();
|
| +}
|
| +
|
| +void ChildProcessFieldTrialSyncer::OnFieldTrialGroupFinalized(
|
| + const std::string& trial_name,
|
| + const std::string& group_name) {
|
| + ipc_sender_->Send(new ChromeViewHostMsg_FieldTrialActivated(trial_name));
|
| +}
|
| +
|
| +} // namespace chrome_variations
|
|
|