This source file includes following definitions.
- NotifyAllRenderers
- OnFieldTrialGroupFinalized
#include "chrome/browser/metrics/field_trial_synchronizer.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/threading/thread.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/metrics/variations/variations_util.h"
#include "chrome/common/render_messages.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
using content::BrowserThread;
namespace {
FieldTrialSynchronizer* g_field_trial_synchronizer = NULL;
}
FieldTrialSynchronizer::FieldTrialSynchronizer() {
DCHECK(g_field_trial_synchronizer == NULL);
g_field_trial_synchronizer = this;
base::FieldTrialList::AddObserver(this);
chrome_variations::SetChildProcessLoggingVariationList();
}
void FieldTrialSynchronizer::NotifyAllRenderers(
const std::string& field_trial_name,
const std::string& group_name) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
for (content::RenderProcessHost::iterator it(
content::RenderProcessHost::AllHostsIterator());
!it.IsAtEnd(); it.Advance()) {
it.GetCurrentValue()->Send(
new ChromeViewMsg_SetFieldTrialGroup(field_trial_name, group_name));
}
}
void FieldTrialSynchronizer::OnFieldTrialGroupFinalized(
const std::string& field_trial_name,
const std::string& group_name) {
CHECK(!field_trial_name.empty() && !group_name.empty());
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&FieldTrialSynchronizer::NotifyAllRenderers,
this,
field_trial_name,
group_name));
chrome_variations::SetChildProcessLoggingVariationList();
}
FieldTrialSynchronizer::~FieldTrialSynchronizer() {
base::FieldTrialList::RemoveObserver(this);
g_field_trial_synchronizer = NULL;
}