asvitkine | 23974972 | 2016-06-02 06:34:39 | [diff] [blame] | 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 | |
asvitkine | 92c1a93 | 2016-11-24 19:51:22 | [diff] [blame] | 5 | #ifndef COMPONENTS_VARIATIONS_FIELD_TRIAL_SYNCER_H_ |
| 6 | #define COMPONENTS_VARIATIONS_FIELD_TRIAL_SYNCER_H_ |
asvitkine | 23974972 | 2016-06-02 06:34:39 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/macros.h" |
| 11 | #include "base/metrics/field_trial.h" |
asvitkine | 23974972 | 2016-06-02 06:34:39 | [diff] [blame] | 12 | |
| 13 | namespace base { |
| 14 | class CommandLine; |
| 15 | } |
| 16 | |
asvitkine | 92c1a93 | 2016-11-24 19:51:22 | [diff] [blame] | 17 | namespace variations { |
asvitkine | 23974972 | 2016-06-02 06:34:39 | [diff] [blame] | 18 | |
| 19 | // ChildProcessFieldTrialSyncer is a utility class that's responsible for |
| 20 | // syncing the "activated" state of field trials between browser and child |
| 21 | // processes. Specifically, when a field trial is activated in the browser, it |
| 22 | // also activates it in the child process and when a field trial is activated |
| 23 | // in the child process, it notifies the browser process to activate it. |
asvitkine | 5dc812a | 2016-06-07 18:20:30 | [diff] [blame] | 24 | class ChildProcessFieldTrialSyncer { |
asvitkine | 23974972 | 2016-06-02 06:34:39 | [diff] [blame] | 25 | public: |
| 26 | // ChildProcessFieldTrialSyncer constructor taking an externally owned |
asvitkine | 5dc812a | 2016-06-07 18:20:30 | [diff] [blame] | 27 | // |observer| param that's responsible for sending IPCs to the browser process |
| 28 | // when a trial is activated. The |observer| must outlive this object. |
| 29 | explicit ChildProcessFieldTrialSyncer( |
| 30 | base::FieldTrialList::Observer* observer); |
| 31 | ~ChildProcessFieldTrialSyncer(); |
asvitkine | 23974972 | 2016-06-02 06:34:39 | [diff] [blame] | 32 | |
| 33 | // Initializes field trial state change observation and notifies the browser |
Lukasz Anforowicz | 5a02412 | 2017-07-19 21:31:57 | [diff] [blame] | 34 | // of any field trials that might have already been activated. |
| 35 | void InitFieldTrialObserving(const base::CommandLine& command_line); |
asvitkine | 23974972 | 2016-06-02 06:34:39 | [diff] [blame] | 36 | |
| 37 | // Handler for messages from the browser process notifying the child process |
| 38 | // that a field trial was activated. |
| 39 | void OnSetFieldTrialGroup(const std::string& trial_name, |
| 40 | const std::string& group_name); |
| 41 | |
| 42 | private: |
asvitkine | 5dc812a | 2016-06-07 18:20:30 | [diff] [blame] | 43 | base::FieldTrialList::Observer* const observer_; |
asvitkine | 23974972 | 2016-06-02 06:34:39 | [diff] [blame] | 44 | |
| 45 | DISALLOW_COPY_AND_ASSIGN(ChildProcessFieldTrialSyncer); |
| 46 | }; |
| 47 | |
asvitkine | 92c1a93 | 2016-11-24 19:51:22 | [diff] [blame] | 48 | } // namespace variations |
asvitkine | 23974972 | 2016-06-02 06:34:39 | [diff] [blame] | 49 | |
asvitkine | 92c1a93 | 2016-11-24 19:51:22 | [diff] [blame] | 50 | #endif // COMPONENTS_VARIATIONS_FIELD_TRIAL_SYNCER_H_ |