Chromium Code Reviews| Index: jingle/notifier/listener/talk_mediator_impl.cc |
| diff --git a/jingle/notifier/listener/talk_mediator_impl.cc b/jingle/notifier/listener/talk_mediator_impl.cc |
| index fa0fc4fc16316a9eb7547c67af333281cd05d291..14b0ced42aac80d81cff0057fde5f1bbfc31b12a 100644 |
| --- a/jingle/notifier/listener/talk_mediator_impl.cc |
| +++ b/jingle/notifier/listener/talk_mediator_impl.cc |
| @@ -5,6 +5,7 @@ |
| #include "jingle/notifier/listener/talk_mediator_impl.h" |
| #include "base/logging.h" |
| +#include "base/message_loop.h" |
| #include "jingle/notifier/base/notifier_options_util.h" |
| namespace notifier { |
| @@ -14,21 +15,20 @@ TalkMediatorImpl::TalkMediatorImpl( |
| const NotifierOptions& notifier_options) |
| : delegate_(NULL), |
| mediator_thread_(mediator_thread), |
| - notifier_options_(notifier_options) { |
| - DCHECK(non_thread_safe_.CalledOnValidThread()); |
| + notifier_options_(notifier_options), |
| + construction_message_loop_(MessageLoop::current()), |
| + method_message_loop_(NULL) { |
| mediator_thread_->Start(); |
| state_.started = 1; |
| } |
| TalkMediatorImpl::~TalkMediatorImpl() { |
| - DCHECK(non_thread_safe_.CalledOnValidThread()); |
| - if (state_.started) { |
| - Logout(); |
| - } |
| + DCHECK_EQ(MessageLoop::current(), construction_message_loop_); |
| + DCHECK(!state_.started); |
| } |
| bool TalkMediatorImpl::Login() { |
| - DCHECK(non_thread_safe_.CalledOnValidThread()); |
| + DCHECK_EQ(MessageLoop::current(), method_message_loop_); |
| // Connect to the mediator thread and start processing messages. |
| mediator_thread_->AddObserver(this); |
| if (state_.initialized && !state_.logging_in && !state_.logged_in) { |
| @@ -40,7 +40,7 @@ bool TalkMediatorImpl::Login() { |
| } |
| bool TalkMediatorImpl::Logout() { |
| - DCHECK(non_thread_safe_.CalledOnValidThread()); |
| + DCHECK_EQ(MessageLoop::current(), method_message_loop_); |
| if (state_.started) { |
| state_.started = 0; |
| state_.logging_in = 0; |
| @@ -56,7 +56,7 @@ bool TalkMediatorImpl::Logout() { |
| } |
| bool TalkMediatorImpl::SendNotification(const Notification& data) { |
| - DCHECK(non_thread_safe_.CalledOnValidThread()); |
| + DCHECK_EQ(MessageLoop::current(), method_message_loop_); |
| if (state_.logged_in && state_.subscribed) { |
| mediator_thread_->SendNotification(data); |
| return true; |
| @@ -65,14 +65,19 @@ bool TalkMediatorImpl::SendNotification(const Notification& data) { |
| } |
| void TalkMediatorImpl::SetDelegate(TalkMediator::Delegate* delegate) { |
| - DCHECK(non_thread_safe_.CalledOnValidThread()); |
| + DCHECK_EQ(MessageLoop::current(), construction_message_loop_); |
| delegate_ = delegate; |
| } |
| void TalkMediatorImpl::SetAuthToken(const std::string& email, |
| const std::string& token, |
| const std::string& token_service) { |
| - DCHECK(non_thread_safe_.CalledOnValidThread()); |
| + // Is the first method to be called. Assign method_message_loop_. |
|
akalin
2011/04/05 22:02:46
The requirement that SetAuthToken() be called firs
nilesh
2011/04/05 23:36:17
Done.
|
| + if (!method_message_loop_) { |
| + method_message_loop_ = MessageLoop::current(); |
| + } else { |
| + DCHECK_EQ(MessageLoop::current(), method_message_loop_); |
| + } |
| xmpp_settings_ = |
| MakeXmppClientSettings(notifier_options_, email, token, token_service); |
| @@ -87,7 +92,7 @@ void TalkMediatorImpl::SetAuthToken(const std::string& email, |
| } |
| void TalkMediatorImpl::AddSubscription(const Subscription& subscription) { |
| - DCHECK(non_thread_safe_.CalledOnValidThread()); |
| + DCHECK_EQ(MessageLoop::current(), method_message_loop_); |
| subscriptions_.push_back(subscription); |
| if (state_.logged_in) { |
| VLOG(1) << "Resubscribing for updates, a new service got added"; |
| @@ -97,7 +102,7 @@ void TalkMediatorImpl::AddSubscription(const Subscription& subscription) { |
| void TalkMediatorImpl::OnConnectionStateChange(bool logged_in) { |
| - DCHECK(non_thread_safe_.CalledOnValidThread()); |
| + DCHECK_EQ(MessageLoop::current(), method_message_loop_); |
| // If we just lost connection, then the MediatorThread implementation will |
| // try to log in again. We need to set state_.logging_in to true in that case. |
| state_.logging_in = !logged_in; |
| @@ -116,7 +121,7 @@ void TalkMediatorImpl::OnConnectionStateChange(bool logged_in) { |
| } |
| void TalkMediatorImpl::OnSubscriptionStateChange(bool subscribed) { |
| - DCHECK(non_thread_safe_.CalledOnValidThread()); |
| + DCHECK_EQ(MessageLoop::current(), method_message_loop_); |
| state_.subscribed = subscribed; |
| VLOG(1) << "P2P: " << (subscribed ? "subscribed" : "unsubscribed"); |
| if (delegate_) |
| @@ -125,14 +130,14 @@ void TalkMediatorImpl::OnSubscriptionStateChange(bool subscribed) { |
| void TalkMediatorImpl::OnIncomingNotification( |
| const Notification& notification) { |
| - DCHECK(non_thread_safe_.CalledOnValidThread()); |
| + DCHECK_EQ(MessageLoop::current(), method_message_loop_); |
| VLOG(1) << "P2P: Updates are available on the server."; |
| if (delegate_) |
| delegate_->OnIncomingNotification(notification); |
| } |
| void TalkMediatorImpl::OnOutgoingNotification() { |
| - DCHECK(non_thread_safe_.CalledOnValidThread()); |
| + DCHECK_EQ(MessageLoop::current(), method_message_loop_); |
| VLOG(1) << "P2P: Peers were notified that updates are available on the " |
| "server."; |
| if (delegate_) |