Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: chrome/browser/metrics/field_trial_synchronizer.cc

Issue 10071036: RefCounted types should not have public destructors, chrome/browser/ part 6 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Implementation fixes Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/experiments_helper.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 {
19
20 // This singleton instance should be constructed during the single threaded
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
23 // all the other threads have gone away.
24 FieldTrialSynchronizer* g_field_trial_synchronizer = NULL;
25
26 } // namespace
27
18 FieldTrialSynchronizer::FieldTrialSynchronizer() { 28 FieldTrialSynchronizer::FieldTrialSynchronizer() {
19 DCHECK(field_trial_synchronizer_ == NULL); 29 DCHECK(g_field_trial_synchronizer == NULL);
20 field_trial_synchronizer_ = this; 30 g_field_trial_synchronizer = this;
21 base::FieldTrialList::AddObserver(this); 31 base::FieldTrialList::AddObserver(this);
22 32
23 experiments_helper::SetChildProcessLoggingExperimentList(); 33 experiments_helper::SetChildProcessLoggingExperimentList();
24 } 34 }
25 35
26 FieldTrialSynchronizer::~FieldTrialSynchronizer() {
27 base::FieldTrialList::RemoveObserver(this);
28 field_trial_synchronizer_ = NULL;
29 }
30
31 void FieldTrialSynchronizer::NotifyAllRenderers( 36 void FieldTrialSynchronizer::NotifyAllRenderers(
32 const std::string& field_trial_name, 37 const std::string& field_trial_name,
33 const std::string& group_name) { 38 const std::string& group_name) {
34 // 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
35 // need to be on the UI thread. 40 // need to be on the UI thread.
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
37 42
38 for (content::RenderProcessHost::iterator it( 43 for (content::RenderProcessHost::iterator it(
39 content::RenderProcessHost::AllHostsIterator()); 44 content::RenderProcessHost::AllHostsIterator());
40 !it.IsAtEnd(); it.Advance()) { 45 !it.IsAtEnd(); it.Advance()) {
41 it.GetCurrentValue()->Send( 46 it.GetCurrentValue()->Send(
42 new ChromeViewMsg_SetFieldTrialGroup(field_trial_name, group_name)); 47 new ChromeViewMsg_SetFieldTrialGroup(field_trial_name, group_name));
43 } 48 }
44 } 49 }
45 50
46 void FieldTrialSynchronizer::OnFieldTrialGroupFinalized( 51 void FieldTrialSynchronizer::OnFieldTrialGroupFinalized(
47 const std::string& field_trial_name, 52 const std::string& field_trial_name,
48 const std::string& group_name) { 53 const std::string& group_name) {
49 BrowserThread::PostTask( 54 BrowserThread::PostTask(
50 BrowserThread::UI, FROM_HERE, 55 BrowserThread::UI, FROM_HERE,
51 base::Bind(&FieldTrialSynchronizer::NotifyAllRenderers, 56 base::Bind(&FieldTrialSynchronizer::NotifyAllRenderers,
52 this, 57 this,
53 field_trial_name, 58 field_trial_name,
54 group_name)); 59 group_name));
55 experiments_helper::SetChildProcessLoggingExperimentList(); 60 experiments_helper::SetChildProcessLoggingExperimentList();
56 } 61 }
57 62
58 // static 63 FieldTrialSynchronizer::~FieldTrialSynchronizer() {
59 FieldTrialSynchronizer* 64 base::FieldTrialList::RemoveObserver(this);
60 FieldTrialSynchronizer::field_trial_synchronizer_ = NULL; 65 g_field_trial_synchronizer = NULL;
66 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/field_trial_synchronizer.h ('k') | chrome/browser/notifications/notification_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698