diff options
author | rtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-29 05:42:22 +0000 |
---|---|---|
committer | rtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-29 05:42:22 +0000 |
commit | 63a8ba1e1fb71156beff23b4a26828dbc387c734 (patch) | |
tree | e69b6e1f24c5d7d1446bc6d5596518f44399bc67 /chrome/browser/metrics/field_trial_synchronizer.cc | |
parent | dbf00c96e956033c1ea9b7542fa0d9c5ab1e66ac (diff) | |
download | chromium_src-63a8ba1e1fb71156beff23b4a26828dbc387c734.zip chromium_src-63a8ba1e1fb71156beff23b4a26828dbc387c734.tar.gz chromium_src-63a8ba1e1fb71156beff23b4a26828dbc387c734.tar.bz2 |
Field trials are currently implemented (commonly) using a static variable that is set
once, the first time it is necessary to decide if there is an experiment by a given
name active.
With this change the field-test system can "push" a group that is selected for
the given field trial (field test) if/when an experiment does arrive.
This change implements a simple IPC notification of the result of a FieldTrial
setting being sent to any previously started renderers.
BUG=16494
TEST=field trial tests
R=jar
Review URL: http://codereview.chromium.org/6883029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83488 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/metrics/field_trial_synchronizer.cc')
-rw-r--r-- | chrome/browser/metrics/field_trial_synchronizer.cc | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/chrome/browser/metrics/field_trial_synchronizer.cc b/chrome/browser/metrics/field_trial_synchronizer.cc new file mode 100644 index 0000000..0e7484f --- /dev/null +++ b/chrome/browser/metrics/field_trial_synchronizer.cc @@ -0,0 +1,52 @@ +// Copyright (c) 2011 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 "chrome/browser/metrics/field_trial_synchronizer.h" + +#include "base/logging.h" +#include "base/threading/thread.h" +#include "chrome/common/chrome_constants.h" +#include "chrome/common/render_messages.h" +#include "content/browser/browser_thread.h" +#include "content/browser/renderer_host/render_process_host.h" + +FieldTrialSynchronizer::FieldTrialSynchronizer() { + DCHECK(field_trial_synchronizer_ == NULL); + field_trial_synchronizer_ = this; + base::FieldTrialList::AddObserver(this); +} + +FieldTrialSynchronizer::~FieldTrialSynchronizer() { + base::FieldTrialList::RemoveObserver(this); + field_trial_synchronizer_ = NULL; +} + +void FieldTrialSynchronizer::NotifyAllRenderers( + const std::string& field_trial_name, + const std::string& group_name) { + // To iterate over RenderProcessHosts, or to send messages to the hosts, we + // need to be on the UI thread. + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); + !it.IsAtEnd(); it.Advance()) { + it.GetCurrentValue()->Send( + new ViewMsg_SetFieldTrialGroup(field_trial_name, group_name)); + } +} + +void FieldTrialSynchronizer::OnFieldTrialGroupFinalized( + const std::string& field_trial_name, + const std::string& group_name) { + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + NewRunnableMethod(this, + &FieldTrialSynchronizer::NotifyAllRenderers, + field_trial_name, + group_name)); +} + +// static +FieldTrialSynchronizer* + FieldTrialSynchronizer::field_trial_synchronizer_ = NULL; |