summaryrefslogtreecommitdiffstats
path: root/jingle/notifier
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-28 22:34:27 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-28 22:34:27 +0000
commitf9682409ab601aad49dc953ae7b41108af157175 (patch)
treec0404e5ee7a10c98df94ca6395860c34021b6c3e /jingle/notifier
parent5569c2d0bea4a8c73cf95ac2e44fab2ac91740de (diff)
downloadchromium_src-f9682409ab601aad49dc953ae7b41108af157175.zip
chromium_src-f9682409ab601aad49dc953ae7b41108af157175.tar.gz
chromium_src-f9682409ab601aad49dc953ae7b41108af157175.tar.bz2
[Sync] Simplify notifier code now that we have a single sync thread
Notifiers used to be created on the UI thread but used on the sync thread. This made the thread-verification code more complicated. Make notifiers be created and used on the sync thread only. Use const string refs instead of (dangerously) calling c_str(). BUG=79174 TEST= Review URL: http://codereview.chromium.org/7134103 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90855 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'jingle/notifier')
-rw-r--r--jingle/notifier/listener/mediator_thread_impl.cc33
-rw-r--r--jingle/notifier/listener/mediator_thread_impl.h4
-rw-r--r--jingle/notifier/listener/talk_mediator_impl.cc33
-rw-r--r--jingle/notifier/listener/talk_mediator_impl.h5
4 files changed, 26 insertions, 49 deletions
diff --git a/jingle/notifier/listener/mediator_thread_impl.cc b/jingle/notifier/listener/mediator_thread_impl.cc
index 6826e78..a9d7052 100644
--- a/jingle/notifier/listener/mediator_thread_impl.cc
+++ b/jingle/notifier/listener/mediator_thread_impl.cc
@@ -212,33 +212,33 @@ void MediatorThreadImpl::Core::OnDisconnect() {
MediatorThreadImpl::MediatorThreadImpl(const NotifierOptions& notifier_options)
: core_(new Core(notifier_options)),
- construction_message_loop_proxy_(
+ parent_message_loop_proxy_(
base::MessageLoopProxy::CreateForCurrentThread()),
io_message_loop_proxy_(
notifier_options.request_context_getter->GetIOMessageLoopProxy()) {
}
MediatorThreadImpl::~MediatorThreadImpl() {
- DCHECK(construction_message_loop_proxy_->BelongsToCurrentThread());
+ DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
LogoutImpl();
}
void MediatorThreadImpl::AddObserver(Observer* observer) {
- CheckOrSetValidThread();
+ DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
core_->AddObserver(observer);
}
void MediatorThreadImpl::RemoveObserver(Observer* observer) {
- CheckOrSetValidThread();
+ DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
core_->RemoveObserver(observer);
}
void MediatorThreadImpl::Start() {
- DCHECK(construction_message_loop_proxy_->BelongsToCurrentThread());
+ DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
}
void MediatorThreadImpl::Login(const buzz::XmppClientSettings& settings) {
- CheckOrSetValidThread();
+ DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
io_message_loop_proxy_->PostTask(
FROM_HERE,
NewRunnableMethod(core_.get(),
@@ -247,12 +247,12 @@ void MediatorThreadImpl::Login(const buzz::XmppClientSettings& settings) {
}
void MediatorThreadImpl::Logout() {
- CheckOrSetValidThread();
+ DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
LogoutImpl();
}
void MediatorThreadImpl::ListenForUpdates() {
- CheckOrSetValidThread();
+ DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
io_message_loop_proxy_->PostTask(
FROM_HERE,
NewRunnableMethod(core_.get(),
@@ -261,7 +261,7 @@ void MediatorThreadImpl::ListenForUpdates() {
void MediatorThreadImpl::SubscribeForUpdates(
const SubscriptionList& subscriptions) {
- CheckOrSetValidThread();
+ DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
io_message_loop_proxy_->PostTask(
FROM_HERE,
NewRunnableMethod(
@@ -272,7 +272,7 @@ void MediatorThreadImpl::SubscribeForUpdates(
void MediatorThreadImpl::SendNotification(
const Notification& data) {
- CheckOrSetValidThread();
+ DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
io_message_loop_proxy_->PostTask(
FROM_HERE,
NewRunnableMethod(core_.get(),
@@ -282,7 +282,7 @@ void MediatorThreadImpl::SendNotification(
void MediatorThreadImpl::UpdateXmppSettings(
const buzz::XmppClientSettings& settings) {
- CheckOrSetValidThread();
+ DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
io_message_loop_proxy_->PostTask(
FROM_HERE,
NewRunnableMethod(core_.get(),
@@ -292,7 +292,7 @@ void MediatorThreadImpl::UpdateXmppSettings(
void MediatorThreadImpl::TriggerOnConnectForTest(
base::WeakPtr<talk_base::Task> base_task) {
- CheckOrSetValidThread();
+ DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
io_message_loop_proxy_->PostTask(
FROM_HERE,
NewRunnableMethod(core_.get(),
@@ -307,13 +307,4 @@ void MediatorThreadImpl::LogoutImpl() {
&MediatorThreadImpl::Core::Disconnect));
}
-void MediatorThreadImpl::CheckOrSetValidThread() {
- if (method_message_loop_proxy_) {
- DCHECK(method_message_loop_proxy_->BelongsToCurrentThread());
- } else {
- method_message_loop_proxy_ =
- base::MessageLoopProxy::CreateForCurrentThread();
- }
-}
-
} // namespace notifier
diff --git a/jingle/notifier/listener/mediator_thread_impl.h b/jingle/notifier/listener/mediator_thread_impl.h
index 0656757..ab85ccd 100644
--- a/jingle/notifier/listener/mediator_thread_impl.h
+++ b/jingle/notifier/listener/mediator_thread_impl.h
@@ -70,7 +70,6 @@ class MediatorThreadImpl : public MediatorThread {
void TriggerOnConnectForTest(base::WeakPtr<talk_base::Task> base_task);
private:
- void CheckOrSetValidThread();
// The logic of Logout without the thread check so it can be called in the
// d'tor.
void LogoutImpl();
@@ -78,8 +77,7 @@ class MediatorThreadImpl : public MediatorThread {
// refcounted.
class Core;
scoped_refptr<Core> core_;
- scoped_refptr<base::MessageLoopProxy> construction_message_loop_proxy_;
- scoped_refptr<base::MessageLoopProxy> method_message_loop_proxy_;
+ scoped_refptr<base::MessageLoopProxy> parent_message_loop_proxy_;
scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
DISALLOW_COPY_AND_ASSIGN(MediatorThreadImpl);
};
diff --git a/jingle/notifier/listener/talk_mediator_impl.cc b/jingle/notifier/listener/talk_mediator_impl.cc
index 5b90663..7760261 100644
--- a/jingle/notifier/listener/talk_mediator_impl.cc
+++ b/jingle/notifier/listener/talk_mediator_impl.cc
@@ -16,19 +16,18 @@ TalkMediatorImpl::TalkMediatorImpl(
: delegate_(NULL),
mediator_thread_(mediator_thread),
notifier_options_(notifier_options),
- construction_message_loop_(MessageLoop::current()),
- method_message_loop_(NULL) {
+ parent_message_loop_(MessageLoop::current()) {
mediator_thread_->Start();
state_.started = 1;
}
TalkMediatorImpl::~TalkMediatorImpl() {
- DCHECK_EQ(MessageLoop::current(), construction_message_loop_);
+ DCHECK_EQ(MessageLoop::current(), parent_message_loop_);
DCHECK(!state_.started);
}
bool TalkMediatorImpl::Login() {
- CheckOrSetValidThread();
+ DCHECK_EQ(MessageLoop::current(), parent_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 +39,7 @@ bool TalkMediatorImpl::Login() {
}
bool TalkMediatorImpl::Logout() {
- CheckOrSetValidThread();
+ DCHECK_EQ(MessageLoop::current(), parent_message_loop_);
if (state_.started) {
state_.started = 0;
state_.logging_in = 0;
@@ -55,19 +54,19 @@ bool TalkMediatorImpl::Logout() {
}
void TalkMediatorImpl::SendNotification(const Notification& data) {
- CheckOrSetValidThread();
+ DCHECK_EQ(MessageLoop::current(), parent_message_loop_);
mediator_thread_->SendNotification(data);
}
void TalkMediatorImpl::SetDelegate(TalkMediator::Delegate* delegate) {
- DCHECK_EQ(MessageLoop::current(), construction_message_loop_);
+ DCHECK_EQ(MessageLoop::current(), parent_message_loop_);
delegate_ = delegate;
}
void TalkMediatorImpl::SetAuthToken(const std::string& email,
const std::string& token,
const std::string& token_service) {
- CheckOrSetValidThread();
+ DCHECK_EQ(MessageLoop::current(), parent_message_loop_);
xmpp_settings_ =
MakeXmppClientSettings(notifier_options_, email, token, token_service);
@@ -81,7 +80,7 @@ void TalkMediatorImpl::SetAuthToken(const std::string& email,
}
void TalkMediatorImpl::AddSubscription(const Subscription& subscription) {
- CheckOrSetValidThread();
+ DCHECK_EQ(MessageLoop::current(), parent_message_loop_);
subscriptions_.push_back(subscription);
if (state_.logged_in) {
VLOG(1) << "Resubscribing for updates, a new service got added";
@@ -91,7 +90,7 @@ void TalkMediatorImpl::AddSubscription(const Subscription& subscription) {
void TalkMediatorImpl::OnConnectionStateChange(bool logged_in) {
- CheckOrSetValidThread();
+ DCHECK_EQ(MessageLoop::current(), parent_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;
@@ -110,7 +109,7 @@ void TalkMediatorImpl::OnConnectionStateChange(bool logged_in) {
}
void TalkMediatorImpl::OnSubscriptionStateChange(bool subscribed) {
- CheckOrSetValidThread();
+ DCHECK_EQ(MessageLoop::current(), parent_message_loop_);
VLOG(1) << "P2P: " << (subscribed ? "subscribed" : "unsubscribed");
if (delegate_)
delegate_->OnNotificationStateChange(subscribed);
@@ -118,26 +117,18 @@ void TalkMediatorImpl::OnSubscriptionStateChange(bool subscribed) {
void TalkMediatorImpl::OnIncomingNotification(
const Notification& notification) {
- CheckOrSetValidThread();
+ DCHECK_EQ(MessageLoop::current(), parent_message_loop_);
VLOG(1) << "P2P: Updates are available on the server.";
if (delegate_)
delegate_->OnIncomingNotification(notification);
}
void TalkMediatorImpl::OnOutgoingNotification() {
- CheckOrSetValidThread();
+ DCHECK_EQ(MessageLoop::current(), parent_message_loop_);
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
diff --git a/jingle/notifier/listener/talk_mediator_impl.h b/jingle/notifier/listener/talk_mediator_impl.h
index 718bb89..93f122a 100644
--- a/jingle/notifier/listener/talk_mediator_impl.h
+++ b/jingle/notifier/listener/talk_mediator_impl.h
@@ -79,8 +79,6 @@ class TalkMediatorImpl
unsigned int logged_in : 1; // Logged in the mediator's authenticator.
};
- void CheckOrSetValidThread();
-
// Delegate, which we don't own. May be NULL.
TalkMediator::Delegate* delegate_;
@@ -97,8 +95,7 @@ class TalkMediatorImpl
SubscriptionList subscriptions_;
- MessageLoop* construction_message_loop_;
- MessageLoop* method_message_loop_;
+ MessageLoop* parent_message_loop_;
FRIEND_TEST_ALL_PREFIXES(TalkMediatorImplTest, SetAuthToken);
FRIEND_TEST_ALL_PREFIXES(TalkMediatorImplTest, SendNotification);