File: field_trial_synchronizer.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (68 lines) | stat: -rw-r--r-- 2,769 bytes parent folder | download | duplicates (8)
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
67
68
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_FIELD_TRIAL_SYNCHRONIZER_H_
#define CONTENT_BROWSER_FIELD_TRIAL_SYNCHRONIZER_H_

#include <string>
#include <vector>

#include "base/metrics/field_trial.h"
#include "components/variations/variations_ids_provider.h"

namespace content {
class RenderProcessHost;

// This class is used by the browser process to communicate FieldTrial setting
// (field trial name and group) and Variation header to any previously started
// renderers.
//
// This class registers itself as an observer of FieldTrialList. FieldTrialList
// notifies this class by calling its OnFieldTrialGroupFinalized method when a
// group is selected (finalized) for a FieldTrial and OnFieldTrialGroupFinalized
// method sends the FieldTrial's name and the group to all renderer processes.
// Each renderer process creates the FieldTrial, and by using a 100% probability
// for the FieldTrial, forces the FieldTrial to have the same group string. This
// is mostly an optimization so that renderers don't send anything to the
// browser when they know that a trial is already active.
//
// This class also registers itself as a VariationsIdsProvider Observer and
// updates the renderers if the variations header changes.
class FieldTrialSynchronizer
    : public base::FieldTrialList::Observer,
      public variations::VariationsIdsProvider::Observer {
 public:
  // Creates the global FieldTrialSynchronizer instance for this process. After
  // this is invoked, renderers are notified whenever a field trial group is
  // finalized.
  static void CreateInstance();

  FieldTrialSynchronizer(const FieldTrialSynchronizer&) = delete;
  FieldTrialSynchronizer& operator=(const FieldTrialSynchronizer&) = delete;

  // FieldTrialList::Observer methods:

  // This method is called by the FieldTrialList singleton when a trial's group
  // is finalized. This method contacts all renderers (by calling
  // NotifyAllRenderers) to create a FieldTrial that carries the randomly
  // selected state from the browser process into all the renderer processes.
  void OnFieldTrialGroupFinalized(const base::FieldTrial& trial,
                                  const std::string& group_name) override;

  // VariationsIdsProvider::Observer methods:
  void VariationIdsHeaderUpdated() override;

  // Sends the current variations header to |host|'s renderer.
  static void UpdateRendererVariationsHeader(RenderProcessHost* host);

 private:
  FieldTrialSynchronizer();
  ~FieldTrialSynchronizer() override;

  static void NotifyAllRenderersOfVariationsHeader();
};

}  // namespace content

#endif  // CONTENT_BROWSER_FIELD_TRIAL_SYNCHRONIZER_H_