| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
| 10 #include "chrome/common/chrome_constants.h" | 10 #include "chrome/common/chrome_constants.h" |
| 11 #include "chrome/common/metrics/experiments_helper.h" | 11 #include "chrome/common/metrics/variations_util.h" |
| 12 #include "chrome/common/render_messages.h" | 12 #include "chrome/common/render_messages.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
| 15 | 15 |
| 16 using content::BrowserThread; | 16 using content::BrowserThread; |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // This singleton instance should be constructed during the single threaded | 20 // This singleton instance should be constructed during the single threaded |
| 21 // portion of main(). It initializes globals to provide support for all future | 21 // portion of main(). It initializes globals to provide support for all future |
| 22 // calls. This object is created on the UI thread, and it is destroyed after | 22 // calls. This object is created on the UI thread, and it is destroyed after |
| 23 // all the other threads have gone away. | 23 // all the other threads have gone away. |
| 24 FieldTrialSynchronizer* g_field_trial_synchronizer = NULL; | 24 FieldTrialSynchronizer* g_field_trial_synchronizer = NULL; |
| 25 | 25 |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 FieldTrialSynchronizer::FieldTrialSynchronizer() { | 28 FieldTrialSynchronizer::FieldTrialSynchronizer() { |
| 29 DCHECK(g_field_trial_synchronizer == NULL); | 29 DCHECK(g_field_trial_synchronizer == NULL); |
| 30 g_field_trial_synchronizer = this; | 30 g_field_trial_synchronizer = this; |
| 31 base::FieldTrialList::AddObserver(this); | 31 base::FieldTrialList::AddObserver(this); |
| 32 | 32 |
| 33 experiments_helper::SetChildProcessLoggingExperimentList(); | 33 chrome_variations::SetChildProcessLoggingVariationList(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void FieldTrialSynchronizer::NotifyAllRenderers( | 36 void FieldTrialSynchronizer::NotifyAllRenderers( |
| 37 const std::string& field_trial_name, | 37 const std::string& field_trial_name, |
| 38 const std::string& group_name) { | 38 const std::string& group_name) { |
| 39 // To iterate over RenderProcessHosts, or to send messages to the hosts, we | 39 // To iterate over RenderProcessHosts, or to send messages to the hosts, we |
| 40 // need to be on the UI thread. | 40 // need to be on the UI thread. |
| 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 42 | 42 |
| 43 for (content::RenderProcessHost::iterator it( | 43 for (content::RenderProcessHost::iterator it( |
| 44 content::RenderProcessHost::AllHostsIterator()); | 44 content::RenderProcessHost::AllHostsIterator()); |
| 45 !it.IsAtEnd(); it.Advance()) { | 45 !it.IsAtEnd(); it.Advance()) { |
| 46 it.GetCurrentValue()->Send( | 46 it.GetCurrentValue()->Send( |
| 47 new ChromeViewMsg_SetFieldTrialGroup(field_trial_name, group_name)); | 47 new ChromeViewMsg_SetFieldTrialGroup(field_trial_name, group_name)); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 void FieldTrialSynchronizer::OnFieldTrialGroupFinalized( | 51 void FieldTrialSynchronizer::OnFieldTrialGroupFinalized( |
| 52 const std::string& field_trial_name, | 52 const std::string& field_trial_name, |
| 53 const std::string& group_name) { | 53 const std::string& group_name) { |
| 54 BrowserThread::PostTask( | 54 BrowserThread::PostTask( |
| 55 BrowserThread::UI, FROM_HERE, | 55 BrowserThread::UI, FROM_HERE, |
| 56 base::Bind(&FieldTrialSynchronizer::NotifyAllRenderers, | 56 base::Bind(&FieldTrialSynchronizer::NotifyAllRenderers, |
| 57 this, | 57 this, |
| 58 field_trial_name, | 58 field_trial_name, |
| 59 group_name)); | 59 group_name)); |
| 60 experiments_helper::SetChildProcessLoggingExperimentList(); | 60 chrome_variations::SetChildProcessLoggingVariationList(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 FieldTrialSynchronizer::~FieldTrialSynchronizer() { | 63 FieldTrialSynchronizer::~FieldTrialSynchronizer() { |
| 64 base::FieldTrialList::RemoveObserver(this); | 64 base::FieldTrialList::RemoveObserver(this); |
| 65 g_field_trial_synchronizer = NULL; | 65 g_field_trial_synchronizer = NULL; |
| 66 } | 66 } |
| OLD | NEW |