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

Unified Diff: jingle/notifier/listener/talk_mediator_impl.cc

Issue 6794005: Move sync notifier contruction out of syncer thread. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Rebase 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « jingle/notifier/listener/talk_mediator_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..5bd70dcbc9b08eb5bbc7c4b5e2e758cb54f896f6 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());
+ CheckOrSetValidThread();
// 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());
+ CheckOrSetValidThread();
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());
+ CheckOrSetValidThread();
if (state_.logged_in && state_.subscribed) {
mediator_thread_->SendNotification(data);
return true;
@@ -65,15 +65,14 @@ 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());
-
+ CheckOrSetValidThread();
xmpp_settings_ =
MakeXmppClientSettings(notifier_options_, email, token, token_service);
@@ -87,7 +86,7 @@ void TalkMediatorImpl::SetAuthToken(const std::string& email,
}
void TalkMediatorImpl::AddSubscription(const Subscription& subscription) {
- DCHECK(non_thread_safe_.CalledOnValidThread());
+ CheckOrSetValidThread();
subscriptions_.push_back(subscription);
if (state_.logged_in) {
VLOG(1) << "Resubscribing for updates, a new service got added";
@@ -97,7 +96,7 @@ void TalkMediatorImpl::AddSubscription(const Subscription& subscription) {
void TalkMediatorImpl::OnConnectionStateChange(bool logged_in) {
- DCHECK(non_thread_safe_.CalledOnValidThread());
+ CheckOrSetValidThread();
// 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 +115,7 @@ void TalkMediatorImpl::OnConnectionStateChange(bool logged_in) {
}
void TalkMediatorImpl::OnSubscriptionStateChange(bool subscribed) {
- DCHECK(non_thread_safe_.CalledOnValidThread());
+ CheckOrSetValidThread();
state_.subscribed = subscribed;
VLOG(1) << "P2P: " << (subscribed ? "subscribed" : "unsubscribed");
if (delegate_)
@@ -125,18 +124,26 @@ void TalkMediatorImpl::OnSubscriptionStateChange(bool subscribed) {
void TalkMediatorImpl::OnIncomingNotification(
const Notification& notification) {
- DCHECK(non_thread_safe_.CalledOnValidThread());
+ CheckOrSetValidThread();
VLOG(1) << "P2P: Updates are available on the server.";
if (delegate_)
delegate_->OnIncomingNotification(notification);
}
void TalkMediatorImpl::OnOutgoingNotification() {
- DCHECK(non_thread_safe_.CalledOnValidThread());
+ CheckOrSetValidThread();
VLOG(1) << "P2P: Peers were notified that updates are available on the "
"server.";
if (delegate_)
delegate_->OnOutgoingNotification();
}
+void TalkMediatorImpl::CheckOrSetValidThread() {
+ if (method_message_loop_) {
+ DCHECK_EQ(MessageLoop::current(), method_message_loop_);
+ } else {
+ method_message_loop_ = MessageLoop::current();
+ }
+}
+
} // namespace notifier
« no previous file with comments | « jingle/notifier/listener/talk_mediator_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698