From 9e2fa21e45b5d7e635a8b3d57fcc4ca31883e1db Mon Sep 17 00:00:00 2001 From: "akalin@chromium.org" Date: Thu, 4 Feb 2010 07:59:58 +0000 Subject: Fixed notifications-related bug on network reconnections. Tied talk_mediator logged_in state to mediator_thread instead of auth_watcher. Added some extra logging. BUG=34117 TEST=see bug Review URL: http://codereview.chromium.org/566028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38087 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/sync/notifier/listener/talk_mediator_impl.cc | 13 ++++++++----- chrome/browser/sync/notifier/listener/talk_mediator_impl.h | 6 ++++-- .../sync/notifier/listener/talk_mediator_unittest.cc | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) (limited to 'chrome/browser/sync/notifier') diff --git a/chrome/browser/sync/notifier/listener/talk_mediator_impl.cc b/chrome/browser/sync/notifier/listener/talk_mediator_impl.cc index 2433c08..a147e66 100644 --- a/chrome/browser/sync/notifier/listener/talk_mediator_impl.cc +++ b/chrome/browser/sync/notifier/listener/talk_mediator_impl.cc @@ -93,9 +93,7 @@ void TalkMediatorImpl::AuthWatcherEventHandler( // insure this code path is stable. break; case AuthWatcherEvent::AUTH_SUCCEEDED: - if (!state_.logged_in) { - DoLogin(); - } + DoLogin(); break; default: // Do nothing. @@ -116,6 +114,7 @@ bool TalkMediatorImpl::Login() { } bool TalkMediatorImpl::DoLogin() { + mutex_.AssertAcquired(); // Connect to the mediator thread and start processing messages. if (!state_.connected) { mediator_thread_->SignalStateChange.connect( @@ -123,9 +122,9 @@ bool TalkMediatorImpl::DoLogin() { &TalkMediatorImpl::MediatorThreadMessageHandler); state_.connected = 1; } - if (state_.initialized && !state_.logged_in) { + if (state_.initialized && !state_.logging_in) { mediator_thread_->Login(xmpp_settings_); - state_.logged_in = 1; + state_.logging_in = 1; return true; } return false; @@ -141,6 +140,7 @@ bool TalkMediatorImpl::Logout() { if (state_.started) { mediator_thread_->Logout(); state_.started = 0; + state_.logging_in = 0; state_.logged_in = 0; state_.subscribed = 0; return true; @@ -213,6 +213,8 @@ void TalkMediatorImpl::MediatorThreadMessageHandler( void TalkMediatorImpl::OnLogin() { LOG(INFO) << "P2P: Logged in."; AutoLock lock(mutex_); + state_.logging_in = 0; + state_.logged_in = 1; // ListenForUpdates enables the ListenTask. This is done before // SubscribeForUpdates. mediator_thread_->ListenForUpdates(); @@ -225,6 +227,7 @@ void TalkMediatorImpl::OnLogout() { LOG(INFO) << "P2P: Logged off."; OnSubscriptionFailure(); AutoLock lock(mutex_); + state_.logging_in = 0; state_.logged_in = 0; TalkMediatorEvent event = { TalkMediatorEvent::LOGOUT_SUCCEEDED }; channel_->NotifyListeners(event); diff --git a/chrome/browser/sync/notifier/listener/talk_mediator_impl.h b/chrome/browser/sync/notifier/listener/talk_mediator_impl.h index 99bbb79..922624e 100644 --- a/chrome/browser/sync/notifier/listener/talk_mediator_impl.h +++ b/chrome/browser/sync/notifier/listener/talk_mediator_impl.h @@ -49,13 +49,15 @@ class TalkMediatorImpl private: struct TalkMediatorState { TalkMediatorState() - : started(0), connected(0), initialized(0), logged_in(0), - subscribed(0) { + : started(0), connected(0), initialized(0), logging_in(0), + logged_in(0), subscribed(0) { } unsigned int started : 1; // Background thread has started. unsigned int connected : 1; // Connected to the mediator thread signal. unsigned int initialized : 1; // Initialized with login information. + unsigned int logging_in : 1; // Logging in to the mediator's + // authenticator. unsigned int logged_in : 1; // Logged in the mediator's authenticator. unsigned int subscribed : 1; // Subscribed to the xmpp receiving channel. }; diff --git a/chrome/browser/sync/notifier/listener/talk_mediator_unittest.cc b/chrome/browser/sync/notifier/listener/talk_mediator_unittest.cc index fb5e9a9..280a8a9 100644 --- a/chrome/browser/sync/notifier/listener/talk_mediator_unittest.cc +++ b/chrome/browser/sync/notifier/listener/talk_mediator_unittest.cc @@ -111,6 +111,7 @@ TEST_F(TalkMediatorImplTest, SendNotification) { ASSERT_TRUE(talk1->SetAuthToken("chromium@gmail.com", "token") == true); ASSERT_TRUE(talk1->Login() == true); + talk1->OnLogin(); ASSERT_TRUE(mock->login_calls == 1); // Failure due to not being subscribed. -- cgit v1.1