File: child_process_field_trial_syncer.cc

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (66 lines) | stat: -rw-r--r-- 2,580 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// 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 "components/variations/child_process_field_trial_syncer.h"

#include <set>
#include <utility>

#include "base/base_switches.h"
#include "base/command_line.h"
#include "components/variations/variations_util.h"

namespace variations {

ChildProcessFieldTrialSyncer::ChildProcessFieldTrialSyncer(
    base::FieldTrialList::Observer* observer)
    : observer_(observer) {}

ChildProcessFieldTrialSyncer::~ChildProcessFieldTrialSyncer() {}

void ChildProcessFieldTrialSyncer::InitFieldTrialObserving(
    const base::CommandLine& command_line,
    const char* single_process_switch_name) {
  // In single-process mode, there is no need to synchronize trials to the
  // browser process (because it's the same process), so this class is a no-op.
  if (command_line.HasSwitch(single_process_switch_name))
    return;

  // Set up initial set of crash dump data for field trials in this process.
  SetVariationListCrashKeys();

  // Listen for field trial activations to report them to the browser.
  base::FieldTrialList::AddObserver(observer_);

  // 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::GetInitiallyActiveFieldTrials(command_line,
                                                      &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(&current_active_trials);
  for (const auto& trial : current_active_trials) {
    if (!base::ContainsKey(initially_active_trials_set, trial.trial_name))
      observer_->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();
  SetVariationListCrashKeys();
}

}  // namespace variations