QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / chrome / browser / metrics / field_trial_synchronizer.h
blob6c62d2772b9d7c1f72a026c9ca8b1ab4c54f6b7c
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_METRICS_FIELD_TRIAL_SYNCHRONIZER_H_
6 #define CHROME_BROWSER_METRICS_FIELD_TRIAL_SYNCHRONIZER_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/metrics/field_trial.h"
15 // This class is used by the browser process to communicate FieldTrial setting
16 // (field trial name and group) to any previously started renderers.
18 // This class registers itself as an observer of FieldTrialList. FieldTrialList
19 // notifies this class by calling it's OnFieldTrialGroupFinalized method when a
20 // group is selected (finalized) for a FieldTrial and OnFieldTrialGroupFinalized
21 // method sends the FieldTrial's name and the group to all renderer processes.
22 // Each renderer process creates the FieldTrial, and by using a 100% probability
23 // for the FieldTrial, forces the FieldTrial to have the same group string.
25 class FieldTrialSynchronizer
26 : public base::RefCountedThreadSafe<FieldTrialSynchronizer>,
27 public base::FieldTrialList::Observer {
28 public:
29 // Construction also sets up the global singleton instance. This instance is
30 // used to communicate between the UI and other threads, and is destroyed only
31 // as the main thread (browser_main) terminates, which means all other threads
32 // have completed, and will not need this instance any further. It adds itself
33 // as an observer of FieldTrialList so that it gets notified whenever a group
34 // is finalized in the browser process.
35 FieldTrialSynchronizer();
37 // Notify all renderer processes about the |group_name| that is finalized for
38 // the given field trail (|field_trial_name|). This is called on UI thread.
39 void NotifyAllRenderers(const std::string& field_trial_name,
40 const std::string& group_name);
42 // FieldTrialList::Observer methods:
44 // This method is called by the FieldTrialList singleton when a trial's group
45 // is finalized. This method contacts all renderers (by calling
46 // NotifyAllRenderers) to create a FieldTrial that carries the randomly
47 // selected state from the browser process into all the renderer processes.
48 void OnFieldTrialGroupFinalized(const std::string& name,
49 const std::string& group_name) override;
51 private:
52 friend class base::RefCountedThreadSafe<FieldTrialSynchronizer>;
53 ~FieldTrialSynchronizer() override;
55 DISALLOW_COPY_AND_ASSIGN(FieldTrialSynchronizer);
58 #endif // CHROME_BROWSER_METRICS_FIELD_TRIAL_SYNCHRONIZER_H_