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/renderer_configuration.mojom.h" | 10 #include "chrome/common/renderer_configuration.mojom.h" |
| 11 #include "components/metrics/persistent_system_profile.h" |
11 #include "components/variations/variations_util.h" | 12 #include "components/variations/variations_util.h" |
12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
14 | 15 |
15 using content::BrowserThread; | 16 using content::BrowserThread; |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // This singleton instance should be constructed during the single threaded | 20 // This singleton instance should be constructed during the single threaded |
20 // 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 |
(...skipping 11 matching lines...) Expand all Loading... |
32 variations::SetVariationListCrashKeys(); | 33 variations::SetVariationListCrashKeys(); |
33 } | 34 } |
34 | 35 |
35 void FieldTrialSynchronizer::NotifyAllRenderers( | 36 void FieldTrialSynchronizer::NotifyAllRenderers( |
36 const std::string& field_trial_name, | 37 const std::string& field_trial_name, |
37 const std::string& group_name) { | 38 const std::string& group_name) { |
38 // 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 |
39 // need to be on the UI thread. | 40 // need to be on the UI thread. |
40 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 41 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
41 | 42 |
| 43 // Note this in the persistent profile as it will take a while for a new |
| 44 // "complete" profile to be genereated. |
| 45 metrics::GlobalPersistentSystemProfile::GetInstance()->AddFieldTrial( |
| 46 field_trial_name, group_name); |
| 47 |
42 for (content::RenderProcessHost::iterator it( | 48 for (content::RenderProcessHost::iterator it( |
43 content::RenderProcessHost::AllHostsIterator()); | 49 content::RenderProcessHost::AllHostsIterator()); |
44 !it.IsAtEnd(); it.Advance()) { | 50 !it.IsAtEnd(); it.Advance()) { |
45 IPC::ChannelProxy* channel = it.GetCurrentValue()->GetChannel(); | 51 IPC::ChannelProxy* channel = it.GetCurrentValue()->GetChannel(); |
46 // channel might be null in tests. | 52 // channel might be null in tests. |
47 if (channel) { | 53 if (channel) { |
48 chrome::mojom::RendererConfigurationAssociatedPtr renderer_configuration; | 54 chrome::mojom::RendererConfigurationAssociatedPtr renderer_configuration; |
49 channel->GetRemoteAssociatedInterface(&renderer_configuration); | 55 channel->GetRemoteAssociatedInterface(&renderer_configuration); |
50 renderer_configuration->SetFieldTrialGroup(field_trial_name, group_name); | 56 renderer_configuration->SetFieldTrialGroup(field_trial_name, group_name); |
51 } | 57 } |
52 } | 58 } |
53 } | 59 } |
54 | 60 |
55 void FieldTrialSynchronizer::OnFieldTrialGroupFinalized( | 61 void FieldTrialSynchronizer::OnFieldTrialGroupFinalized( |
56 const std::string& field_trial_name, | 62 const std::string& field_trial_name, |
57 const std::string& group_name) { | 63 const std::string& group_name) { |
58 BrowserThread::PostTask( | 64 BrowserThread::PostTask( |
59 BrowserThread::UI, FROM_HERE, | 65 BrowserThread::UI, FROM_HERE, |
60 base::BindOnce(&FieldTrialSynchronizer::NotifyAllRenderers, this, | 66 base::BindOnce(&FieldTrialSynchronizer::NotifyAllRenderers, this, |
61 field_trial_name, group_name)); | 67 field_trial_name, group_name)); |
62 variations::SetVariationListCrashKeys(); | 68 variations::SetVariationListCrashKeys(); |
63 } | 69 } |
64 | 70 |
65 FieldTrialSynchronizer::~FieldTrialSynchronizer() { | 71 FieldTrialSynchronizer::~FieldTrialSynchronizer() { |
66 base::FieldTrialList::RemoveObserver(this); | 72 base::FieldTrialList::RemoveObserver(this); |
67 g_field_trial_synchronizer = NULL; | 73 g_field_trial_synchronizer = NULL; |
68 } | 74 } |
OLD | NEW |