Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: chrome/common/variations/child_process_field_trial_syncer.cc

Issue 2020413002: Refactor out a new class for syncing field trials in child processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweak param names & comments. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/common/variations/child_process_field_trial_syncer.h"
6
7 #include "base/base_switches.h"
8 #include "base/command_line.h"
9 #include "chrome/common/render_messages.h"
10 #include "components/variations/variations_util.h"
11
12 namespace chrome_variations {
13
14 ChildProcessFieldTrialSyncer::ChildProcessFieldTrialSyncer(
15 IPC::Sender* ipc_sender) : ipc_sender_(ipc_sender) {}
16
17 ChildProcessFieldTrialSyncer::~ChildProcessFieldTrialSyncer() {}
18
19 void ChildProcessFieldTrialSyncer::InitFieldTrialObserving(
20 const base::CommandLine& command_line) {
21 // Set up initial set of crash dump data for field trials in this process.
22 variations::SetVariationListCrashKeys();
23
24 // Listen for field trial activations to report them to the browser.
25 base::FieldTrialList::AddObserver(this);
26
27 // Some field trials may have been activated before this point. Notify the
28 // browser of these activations now. To detect these, take the set difference
29 // of currently active trials with the initially active trials.
30 base::FieldTrial::ActiveGroups initially_active_trials;
31 base::FieldTrialList::GetActiveFieldTrialGroupsFromString(
32 command_line.GetSwitchValueASCII(switches::kForceFieldTrials),
33 &initially_active_trials);
34 std::set<std::string> initially_active_trials_set;
Lei Zhang 2016/06/01 20:52:51 IWYU: <set>
Alexei Svitkine (slow) 2016/06/01 21:00:39 Done.
35 for (const auto& entry : initially_active_trials) {
36 initially_active_trials_set.insert(std::move(entry.trial_name));
Lei Zhang 2016/06/01 20:52:51 IYWU: <utility>
Alexei Svitkine (slow) 2016/06/01 21:00:38 Done.
37 }
38
39 base::FieldTrial::ActiveGroups current_active_trials;
40 base::FieldTrialList::GetActiveFieldTrialGroups(&current_active_trials);
41 for (const auto& trial : current_active_trials) {
Lei Zhang 2016/06/01 20:52:51 Side question as this is just refactoring existing
Alexei Svitkine (slow) 2016/06/01 21:00:39 The initial set is actually sent on the command-li
42 if (!ContainsKey(initially_active_trials_set, trial.trial_name))
43 OnFieldTrialGroupFinalized(trial.trial_name, trial.group_name);
44 }
45 }
46
47 void ChildProcessFieldTrialSyncer::OnSetFieldTrialGroup(
48 const std::string& trial_name,
49 const std::string& group_name) {
50 base::FieldTrial* trial =
51 base::FieldTrialList::CreateFieldTrial(trial_name, group_name);
52 // Ensure the trial is marked as "used" by calling group() on it if it is
53 // marked as activated.
54 trial->group();
55 variations::SetVariationListCrashKeys();
56 }
57
58 void ChildProcessFieldTrialSyncer::OnFieldTrialGroupFinalized(
59 const std::string& trial_name,
60 const std::string& group_name) {
61 ipc_sender_->Send(new ChromeViewHostMsg_FieldTrialActivated(trial_name));
62 }
63
64 } // namespace chrome_variations
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698