OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/metrics/field_trial_synchronizer.h" | 5 #include "chrome/browser/metrics/field_trial_synchronizer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
9 #include "chrome/common/chrome_constants.h" | 9 #include "chrome/common/chrome_constants.h" |
10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
11 #include "content/browser/renderer_host/render_process_host.h" | |
12 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/render_process_host.h" |
13 | 13 |
14 using content::BrowserThread; | 14 using content::BrowserThread; |
15 | 15 |
16 FieldTrialSynchronizer::FieldTrialSynchronizer() { | 16 FieldTrialSynchronizer::FieldTrialSynchronizer() { |
17 DCHECK(field_trial_synchronizer_ == NULL); | 17 DCHECK(field_trial_synchronizer_ == NULL); |
18 field_trial_synchronizer_ = this; | 18 field_trial_synchronizer_ = this; |
19 base::FieldTrialList::AddObserver(this); | 19 base::FieldTrialList::AddObserver(this); |
20 } | 20 } |
21 | 21 |
22 FieldTrialSynchronizer::~FieldTrialSynchronizer() { | 22 FieldTrialSynchronizer::~FieldTrialSynchronizer() { |
23 base::FieldTrialList::RemoveObserver(this); | 23 base::FieldTrialList::RemoveObserver(this); |
24 field_trial_synchronizer_ = NULL; | 24 field_trial_synchronizer_ = NULL; |
25 } | 25 } |
26 | 26 |
27 void FieldTrialSynchronizer::NotifyAllRenderers( | 27 void FieldTrialSynchronizer::NotifyAllRenderers( |
28 const std::string& field_trial_name, | 28 const std::string& field_trial_name, |
29 const std::string& group_name) { | 29 const std::string& group_name) { |
30 // To iterate over RenderProcessHosts, or to send messages to the hosts, we | 30 // To iterate over RenderProcessHosts, or to send messages to the hosts, we |
31 // need to be on the UI thread. | 31 // need to be on the UI thread. |
32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
33 | 33 |
34 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); | 34 for (content::RenderProcessHost::iterator it( |
| 35 content::RenderProcessHost::AllHostsIterator()); |
35 !it.IsAtEnd(); it.Advance()) { | 36 !it.IsAtEnd(); it.Advance()) { |
36 it.GetCurrentValue()->Send( | 37 it.GetCurrentValue()->Send( |
37 new ChromeViewMsg_SetFieldTrialGroup(field_trial_name, group_name)); | 38 new ChromeViewMsg_SetFieldTrialGroup(field_trial_name, group_name)); |
38 } | 39 } |
39 } | 40 } |
40 | 41 |
41 void FieldTrialSynchronizer::OnFieldTrialGroupFinalized( | 42 void FieldTrialSynchronizer::OnFieldTrialGroupFinalized( |
42 const std::string& field_trial_name, | 43 const std::string& field_trial_name, |
43 const std::string& group_name) { | 44 const std::string& group_name) { |
44 BrowserThread::PostTask( | 45 BrowserThread::PostTask( |
45 BrowserThread::UI, FROM_HERE, | 46 BrowserThread::UI, FROM_HERE, |
46 NewRunnableMethod(this, | 47 NewRunnableMethod(this, |
47 &FieldTrialSynchronizer::NotifyAllRenderers, | 48 &FieldTrialSynchronizer::NotifyAllRenderers, |
48 field_trial_name, | 49 field_trial_name, |
49 group_name)); | 50 group_name)); |
50 } | 51 } |
51 | 52 |
52 // static | 53 // static |
53 FieldTrialSynchronizer* | 54 FieldTrialSynchronizer* |
54 FieldTrialSynchronizer::field_trial_synchronizer_ = NULL; | 55 FieldTrialSynchronizer::field_trial_synchronizer_ = NULL; |
OLD | NEW |