Chromium Code Reviews| 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/render_messages.h" | 10 #include "chrome/common/field_trial.mojom.h" |
| 11 #include "components/variations/variations_util.h" | 11 #include "components/variations/variations_util.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
| 14 | 14 |
| 15 using content::BrowserThread; | 15 using content::BrowserThread; |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // This singleton instance should be constructed during the single threaded | 19 // This singleton instance should be constructed during the single threaded |
| 20 // portion of main(). It initializes globals to provide support for all future | 20 // portion of main(). It initializes globals to provide support for all future |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 35 void FieldTrialSynchronizer::NotifyAllRenderers( | 35 void FieldTrialSynchronizer::NotifyAllRenderers( |
| 36 const std::string& field_trial_name, | 36 const std::string& field_trial_name, |
| 37 const std::string& group_name) { | 37 const std::string& group_name) { |
| 38 // To iterate over RenderProcessHosts, or to send messages to the hosts, we | 38 // To iterate over RenderProcessHosts, or to send messages to the hosts, we |
| 39 // need to be on the UI thread. | 39 // need to be on the UI thread. |
| 40 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 40 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 41 | 41 |
| 42 for (content::RenderProcessHost::iterator it( | 42 for (content::RenderProcessHost::iterator it( |
| 43 content::RenderProcessHost::AllHostsIterator()); | 43 content::RenderProcessHost::AllHostsIterator()); |
| 44 !it.IsAtEnd(); it.Advance()) { | 44 !it.IsAtEnd(); it.Advance()) { |
| 45 it.GetCurrentValue()->Send(new ChromeViewMsg_SetFieldTrialGroup( | 45 IPC::ChannelProxy* channel = it.GetCurrentValue()->GetChannel(); |
| 46 field_trial_name, group_name)); | 46 // channel might be NULL in tests. |
|
sky
2017/01/20 17:12:59
optional: NULL -> null
| |
| 47 if (channel) { | |
| 48 chrome::mojom::FieldTrialGroupSetterAssociatedPtr | |
| 49 field_trial_group_setter; | |
| 50 channel->GetRemoteAssociatedInterface(&field_trial_group_setter); | |
|
sky
2017/01/20 17:12:59
It seems weird to me to configure something via an
nigeltao1
2017/01/20 22:40:58
Yeah, I did say
"But let me know if I should look
| |
| 51 field_trial_group_setter->SetFieldTrialGroup(field_trial_name, | |
| 52 group_name); | |
| 53 } | |
| 47 } | 54 } |
| 48 } | 55 } |
| 49 | 56 |
| 50 void FieldTrialSynchronizer::OnFieldTrialGroupFinalized( | 57 void FieldTrialSynchronizer::OnFieldTrialGroupFinalized( |
| 51 const std::string& field_trial_name, | 58 const std::string& field_trial_name, |
| 52 const std::string& group_name) { | 59 const std::string& group_name) { |
| 53 BrowserThread::PostTask( | 60 BrowserThread::PostTask( |
| 54 BrowserThread::UI, FROM_HERE, | 61 BrowserThread::UI, FROM_HERE, |
| 55 base::Bind(&FieldTrialSynchronizer::NotifyAllRenderers, | 62 base::Bind(&FieldTrialSynchronizer::NotifyAllRenderers, |
| 56 this, | 63 this, |
| 57 field_trial_name, | 64 field_trial_name, |
| 58 group_name)); | 65 group_name)); |
| 59 variations::SetVariationListCrashKeys(); | 66 variations::SetVariationListCrashKeys(); |
| 60 } | 67 } |
| 61 | 68 |
| 62 FieldTrialSynchronizer::~FieldTrialSynchronizer() { | 69 FieldTrialSynchronizer::~FieldTrialSynchronizer() { |
| 63 base::FieldTrialList::RemoveObserver(this); | 70 base::FieldTrialList::RemoveObserver(this); |
| 64 g_field_trial_synchronizer = NULL; | 71 g_field_trial_synchronizer = NULL; |
| 65 } | 72 } |
| OLD | NEW |