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

Side by Side Diff: chrome/browser/sync/notifier/non_blocking_invalidation_notifier.cc

Issue 6794005: Move sync notifier contruction out of syncer thread. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Minor fix. Created 9 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) 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/sync/notifier/non_blocking_invalidation_notifier.h" 5 #include "chrome/browser/sync/notifier/non_blocking_invalidation_notifier.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 9
10 namespace sync_notifier { 10 namespace sync_notifier {
11 11
12 NonBlockingInvalidationNotifier::NonBlockingInvalidationNotifier( 12 NonBlockingInvalidationNotifier::NonBlockingInvalidationNotifier(
13 const notifier::NotifierOptions& notifier_options, 13 const notifier::NotifierOptions& notifier_options,
14 const std::string& client_info) 14 const std::string& client_info)
15 : parent_message_loop_(MessageLoop::current()), 15 : construction_message_loop_(MessageLoop::current()),
16 method_message_loop_(NULL),
16 observers_(new ObserverListThreadSafe<SyncNotifierObserver>()), 17 observers_(new ObserverListThreadSafe<SyncNotifierObserver>()),
17 worker_thread_("InvalidationNotifier worker thread"), 18 worker_thread_("InvalidationNotifier worker thread"),
18 worker_thread_vars_(NULL) { 19 worker_thread_vars_(NULL) {
19 DCHECK_EQ(notifier::NOTIFICATION_SERVER, 20 DCHECK_EQ(notifier::NOTIFICATION_SERVER,
20 notifier_options.notification_method); 21 notifier_options.notification_method);
21 const base::Thread::Options options(MessageLoop::TYPE_IO, 0); 22 const base::Thread::Options options(MessageLoop::TYPE_IO, 0);
22 CHECK(worker_thread_.StartWithOptions(options)); 23 CHECK(worker_thread_.StartWithOptions(options));
23 worker_message_loop()->PostTask( 24 worker_message_loop()->PostTask(
24 FROM_HERE, 25 FROM_HERE,
25 NewRunnableMethod( 26 NewRunnableMethod(
26 this, 27 this,
27 &NonBlockingInvalidationNotifier::CreateWorkerThreadVars, 28 &NonBlockingInvalidationNotifier::CreateWorkerThreadVars,
28 notifier_options, client_info)); 29 notifier_options, client_info));
29 } 30 }
30 31
31 NonBlockingInvalidationNotifier::~NonBlockingInvalidationNotifier() { 32 NonBlockingInvalidationNotifier::~NonBlockingInvalidationNotifier() {
32 DCHECK_EQ(MessageLoop::current(), parent_message_loop_); 33 DCHECK_EQ(MessageLoop::current(), construction_message_loop_);
33 worker_message_loop()->PostTask( 34 worker_message_loop()->PostTask(
34 FROM_HERE, 35 FROM_HERE,
35 NewRunnableMethod( 36 NewRunnableMethod(
36 this, 37 this,
37 &NonBlockingInvalidationNotifier::DestroyWorkerThreadVars)); 38 &NonBlockingInvalidationNotifier::DestroyWorkerThreadVars));
38 worker_thread_.Stop(); 39 worker_thread_.Stop();
39 CHECK(!worker_thread_vars_); 40 CHECK(!worker_thread_vars_);
40 } 41 }
41 42
42 void NonBlockingInvalidationNotifier::AddObserver( 43 void NonBlockingInvalidationNotifier::AddObserver(
43 SyncNotifierObserver* observer) { 44 SyncNotifierObserver* observer) {
44 DCHECK_EQ(MessageLoop::current(), parent_message_loop_); 45 if (!method_message_loop_) {
akalin 2011/04/05 22:02:46 Same thing as TalkMediatorImpl
nilesh 2011/04/05 23:36:17 Done.
46 method_message_loop_ = MessageLoop::current();
47 } else {
48 DCHECK_EQ(MessageLoop::current(), method_message_loop_);
49 }
45 observers_->AddObserver(observer); 50 observers_->AddObserver(observer);
46 } 51 }
47 52
48 void NonBlockingInvalidationNotifier::RemoveObserver( 53 void NonBlockingInvalidationNotifier::RemoveObserver(
49 SyncNotifierObserver* observer) { 54 SyncNotifierObserver* observer) {
50 DCHECK_EQ(MessageLoop::current(), parent_message_loop_); 55 DCHECK_EQ(MessageLoop::current(), method_message_loop_);
51 observers_->RemoveObserver(observer); 56 observers_->RemoveObserver(observer);
52 } 57 }
53 58
54 void NonBlockingInvalidationNotifier::SetState(const std::string& state) { 59 void NonBlockingInvalidationNotifier::SetState(const std::string& state) {
55 DCHECK_EQ(MessageLoop::current(), parent_message_loop_); 60 if (!method_message_loop_) {
61 method_message_loop_ = MessageLoop::current();
62 } else {
63 DCHECK_EQ(MessageLoop::current(), method_message_loop_);
64 }
56 worker_message_loop()->PostTask( 65 worker_message_loop()->PostTask(
57 FROM_HERE, 66 FROM_HERE,
58 NewRunnableMethod( 67 NewRunnableMethod(
59 this, 68 this,
60 &NonBlockingInvalidationNotifier::SetStateOnWorkerThread, 69 &NonBlockingInvalidationNotifier::SetStateOnWorkerThread,
61 state)); 70 state));
62 } 71 }
63 72
64 void NonBlockingInvalidationNotifier::UpdateCredentials( 73 void NonBlockingInvalidationNotifier::UpdateCredentials(
65 const std::string& email, const std::string& token) { 74 const std::string& email, const std::string& token) {
66 DCHECK_EQ(MessageLoop::current(), parent_message_loop_); 75 DCHECK_EQ(MessageLoop::current(), method_message_loop_);
67 worker_message_loop()->PostTask( 76 worker_message_loop()->PostTask(
68 FROM_HERE, 77 FROM_HERE,
69 NewRunnableMethod( 78 NewRunnableMethod(
70 this, 79 this,
71 &NonBlockingInvalidationNotifier::UpdateCredentialsOnWorkerThread, 80 &NonBlockingInvalidationNotifier::UpdateCredentialsOnWorkerThread,
72 email, token)); 81 email, token));
73 } 82 }
74 83
75 void NonBlockingInvalidationNotifier::UpdateEnabledTypes( 84 void NonBlockingInvalidationNotifier::UpdateEnabledTypes(
76 const syncable::ModelTypeSet& types) { 85 const syncable::ModelTypeSet& types) {
77 DCHECK_EQ(MessageLoop::current(), parent_message_loop_); 86 DCHECK_EQ(MessageLoop::current(), method_message_loop_);
78 worker_message_loop()->PostTask( 87 worker_message_loop()->PostTask(
79 FROM_HERE, 88 FROM_HERE,
80 NewRunnableMethod( 89 NewRunnableMethod(
81 this, 90 this,
82 &NonBlockingInvalidationNotifier::UpdateEnabledTypesOnWorkerThread, 91 &NonBlockingInvalidationNotifier::UpdateEnabledTypesOnWorkerThread,
83 types)); 92 types));
84 } 93 }
85 94
86 void NonBlockingInvalidationNotifier::SendNotification() { 95 void NonBlockingInvalidationNotifier::SendNotification() {
87 DCHECK_EQ(MessageLoop::current(), parent_message_loop_); 96 DCHECK_EQ(MessageLoop::current(), method_message_loop_);
88 // InvalidationClient doesn't implement SendNotification(), so no 97 // InvalidationClient doesn't implement SendNotification(), so no
89 // need to forward on the call. 98 // need to forward on the call.
90 } 99 }
91 100
92 MessageLoop* NonBlockingInvalidationNotifier::worker_message_loop() { 101 MessageLoop* NonBlockingInvalidationNotifier::worker_message_loop() {
93 MessageLoop* current_message_loop = MessageLoop::current(); 102 MessageLoop* current_message_loop = MessageLoop::current();
94 DCHECK(current_message_loop); 103 DCHECK(current_message_loop);
95 MessageLoop* worker_message_loop = worker_thread_.message_loop(); 104 MessageLoop* worker_message_loop = worker_thread_.message_loop();
96 DCHECK(worker_message_loop); 105 DCHECK(worker_message_loop);
97 DCHECK(current_message_loop == parent_message_loop_ || 106 DCHECK(current_message_loop == construction_message_loop_ ||
107 current_message_loop == method_message_loop_ ||
98 current_message_loop == worker_message_loop); 108 current_message_loop == worker_message_loop);
99 return worker_message_loop; 109 return worker_message_loop;
100 } 110 }
101 111
102 void NonBlockingInvalidationNotifier::CreateWorkerThreadVars( 112 void NonBlockingInvalidationNotifier::CreateWorkerThreadVars(
103 const notifier::NotifierOptions& notifier_options, 113 const notifier::NotifierOptions& notifier_options,
104 const std::string& client_info) { 114 const std::string& client_info) {
105 DCHECK_EQ(MessageLoop::current(), worker_message_loop()); 115 DCHECK_EQ(MessageLoop::current(), worker_message_loop());
106 worker_thread_vars_ = 116 worker_thread_vars_ =
107 new WorkerThreadVars(notifier_options, client_info, observers_); 117 new WorkerThreadVars(notifier_options, client_info, observers_);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 &cert_verifier_, client_info), 178 &cert_verifier_, client_info),
169 observer_router_(observers) { 179 observer_router_(observers) {
170 invalidation_notifier.AddObserver(&observer_router_); 180 invalidation_notifier.AddObserver(&observer_router_);
171 } 181 }
172 182
173 NonBlockingInvalidationNotifier::WorkerThreadVars::~WorkerThreadVars() { 183 NonBlockingInvalidationNotifier::WorkerThreadVars::~WorkerThreadVars() {
174 invalidation_notifier.RemoveObserver(&observer_router_); 184 invalidation_notifier.RemoveObserver(&observer_router_);
175 } 185 }
176 186
177 } // namespace sync_notifier 187 } // namespace sync_notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698