summaryrefslogtreecommitdiffstats
path: root/jingle
diff options
context:
space:
mode:
authorsanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-17 21:34:27 +0000
committersanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-17 21:34:27 +0000
commit8633e0b9a706ebfdd93e7ad848369a5a7ce87d13 (patch)
tree1c8e5853f5179d3b7128fce1f1320f7cea92f99b /jingle
parent90b1a7a5fc8d2939ab40be1081fdbc55c6461bf2 (diff)
downloadchromium_src-8633e0b9a706ebfdd93e7ad848369a5a7ce87d13.zip
chromium_src-8633e0b9a706ebfdd93e7ad848369a5a7ce87d13.tar.gz
chromium_src-8633e0b9a706ebfdd93e7ad848369a5a7ce87d13.tar.bz2
Modified the jingle library to be able to able to update the auth token after login has happened. This will allow refreshed OAuth2 access tokens to be passed in.
BUG=None TEST=Test Cloud Print notifications with OAuth2 tokens (not live yet) Review URL: http://codereview.chromium.org/6708005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78605 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'jingle')
-rw-r--r--jingle/notifier/communicator/login.cc4
-rw-r--r--jingle/notifier/communicator/login.h3
-rw-r--r--jingle/notifier/listener/mediator_thread.h7
-rw-r--r--jingle/notifier/listener/mediator_thread_impl.cc26
-rw-r--r--jingle/notifier/listener/mediator_thread_impl.h2
-rw-r--r--jingle/notifier/listener/mediator_thread_mock.cc6
-rw-r--r--jingle/notifier/listener/mediator_thread_mock.h3
-rw-r--r--jingle/notifier/listener/talk_mediator_impl.cc10
-rw-r--r--jingle/notifier/listener/talk_mediator_unittest.cc7
9 files changed, 66 insertions, 2 deletions
diff --git a/jingle/notifier/communicator/login.cc b/jingle/notifier/communicator/login.cc
index 6b1119b..98d644b 100644
--- a/jingle/notifier/communicator/login.cc
+++ b/jingle/notifier/communicator/login.cc
@@ -75,6 +75,10 @@ void Login::StartConnection() {
single_attempt_.reset(new SingleLoginAttempt(login_settings_.get(), this));
}
+void Login::UpdateXmppSettings(const buzz::XmppClientSettings& user_settings) {
+ *(login_settings_->modifiable_user_settings()) = user_settings;
+}
+
void Login::OnConnect(base::WeakPtr<talk_base::Task> base_task) {
ResetReconnectState();
delegate_->OnConnect(base_task);
diff --git a/jingle/notifier/communicator/login.h b/jingle/notifier/communicator/login.h
index 0d3e430..7652bf1 100644
--- a/jingle/notifier/communicator/login.h
+++ b/jingle/notifier/communicator/login.h
@@ -69,6 +69,9 @@ class Login : public net::NetworkChangeNotifier::IPAddressObserver,
virtual ~Login();
void StartConnection();
+ // The updated settings only take effect the next time StartConnection
+ // is called.
+ void UpdateXmppSettings(const buzz::XmppClientSettings& user_settings);
// net::NetworkChangeNotifier::IPAddressObserver implementation.
virtual void OnIPAddressChanged();
diff --git a/jingle/notifier/listener/mediator_thread.h b/jingle/notifier/listener/mediator_thread.h
index 74b4838d..157639e 100644
--- a/jingle/notifier/listener/mediator_thread.h
+++ b/jingle/notifier/listener/mediator_thread.h
@@ -49,6 +49,13 @@ class MediatorThread {
virtual void SubscribeForUpdates(const SubscriptionList& subscriptions) = 0;
virtual void ListenForUpdates() = 0;
virtual void SendNotification(const Notification& data) = 0;
+ // UpdateXmppSettings is used to update the user information (typically the
+ // auth token) AFTER a call to Login and BEFORE a call to Logout(). This will
+ // not cause an immediate reconnect. The updated settings will be used the
+ // next time we attempt a reconnect because of a broken connection.
+ // The typical use-case for this is to update OAuth2 access tokens which
+ // expire every hour.
+ virtual void UpdateXmppSettings(const buzz::XmppClientSettings& settings) = 0;
};
} // namespace notifier
diff --git a/jingle/notifier/listener/mediator_thread_impl.cc b/jingle/notifier/listener/mediator_thread_impl.cc
index 72a4707..5d0f7b3 100644
--- a/jingle/notifier/listener/mediator_thread_impl.cc
+++ b/jingle/notifier/listener/mediator_thread_impl.cc
@@ -69,7 +69,8 @@ void MediatorThreadImpl::Logout() {
NewRunnableMethod(this, &MediatorThreadImpl::DoDisconnect));
// TODO(akalin): Decomp this into a separate stop method.
worker_thread_.Stop();
- // worker_thread_ should have cleaned this up.
+ // worker_thread_ should have cleaned this up. It is OK to check this
+ // variable in this thread because worker_thread_ is gone by now.
CHECK(!login_.get());
}
@@ -101,6 +102,16 @@ void MediatorThreadImpl::SendNotification(
data));
}
+void MediatorThreadImpl::UpdateXmppSettings(
+ const buzz::XmppClientSettings& settings) {
+ DCHECK_EQ(MessageLoop::current(), parent_message_loop_);
+ worker_message_loop()->PostTask(
+ FROM_HERE,
+ NewRunnableMethod(this,
+ &MediatorThreadImpl::DoUpdateXmppSettings,
+ settings));
+}
+
MessageLoop* MediatorThreadImpl::worker_message_loop() {
MessageLoop* current_message_loop = MessageLoop::current();
DCHECK(current_message_loop);
@@ -220,6 +231,19 @@ void MediatorThreadImpl::DoSendNotification(
observers_->Notify(&Observer::OnOutgoingNotification);
}
+void MediatorThreadImpl::DoUpdateXmppSettings(
+ const buzz::XmppClientSettings& settings) {
+ DCHECK_EQ(MessageLoop::current(), worker_message_loop());
+ VLOG(1) << "P2P: Thread Updating login settings.";
+ // The caller should only call UpdateXmppSettings after a Login call.
+ if (login_.get())
+ login_->UpdateXmppSettings(settings);
+ else
+ NOTREACHED() <<
+ "P2P: Thread UpdateXmppSettings called when login_ was NULL";
+}
+
+
void MediatorThreadImpl::OnIncomingNotification(
const Notification& notification) {
DCHECK_EQ(MessageLoop::current(), worker_message_loop());
diff --git a/jingle/notifier/listener/mediator_thread_impl.h b/jingle/notifier/listener/mediator_thread_impl.h
index aeacb32..4ac582e 100644
--- a/jingle/notifier/listener/mediator_thread_impl.h
+++ b/jingle/notifier/listener/mediator_thread_impl.h
@@ -72,6 +72,7 @@ class MediatorThreadImpl : public MediatorThread, public LoginDelegate,
virtual void ListenForUpdates();
virtual void SubscribeForUpdates(const SubscriptionList& subscriptions);
virtual void SendNotification(const Notification& data);
+ virtual void UpdateXmppSettings(const buzz::XmppClientSettings& settings);
// Login::Delegate implementation.
virtual void OnConnect(base::WeakPtr<talk_base::Task> base_task);
@@ -110,6 +111,7 @@ class MediatorThreadImpl : public MediatorThread, public LoginDelegate,
void DoSendNotification(
const Notification& data);
+ void DoUpdateXmppSettings(const buzz::XmppClientSettings& settings);
const NotifierOptions notifier_options_;
diff --git a/jingle/notifier/listener/mediator_thread_mock.cc b/jingle/notifier/listener/mediator_thread_mock.cc
index e161986..980f81a2 100644
--- a/jingle/notifier/listener/mediator_thread_mock.cc
+++ b/jingle/notifier/listener/mediator_thread_mock.cc
@@ -21,6 +21,7 @@ void MockMediatorThread::Reset() {
subscribe_calls = 0;
listen_calls = 0;
send_calls = 0;
+ update_settings_calls = 0;
}
void MockMediatorThread::AddObserver(Observer* observer) {
@@ -76,4 +77,9 @@ void MockMediatorThread::ReceiveNotification(
}
}
+void MockMediatorThread::UpdateXmppSettings(
+ const buzz::XmppClientSettings& settings) {
+ update_settings_calls++;
+}
+
} // namespace notifier
diff --git a/jingle/notifier/listener/mediator_thread_mock.h b/jingle/notifier/listener/mediator_thread_mock.h
index 1f4ae76..12718a7 100644
--- a/jingle/notifier/listener/mediator_thread_mock.h
+++ b/jingle/notifier/listener/mediator_thread_mock.h
@@ -44,6 +44,8 @@ class MockMediatorThread : public MediatorThread {
virtual void ListenForUpdates();
virtual void SendNotification(const Notification &);
+ virtual void UpdateXmppSettings(const buzz::XmppClientSettings& settings);
+
void ReceiveNotification(const Notification& data);
@@ -55,6 +57,7 @@ class MockMediatorThread : public MediatorThread {
int subscribe_calls;
int listen_calls;
int send_calls;
+ int update_settings_calls;
};
} // namespace notifier
diff --git a/jingle/notifier/listener/talk_mediator_impl.cc b/jingle/notifier/listener/talk_mediator_impl.cc
index 5e7320b..1bf3d28 100644
--- a/jingle/notifier/listener/talk_mediator_impl.cc
+++ b/jingle/notifier/listener/talk_mediator_impl.cc
@@ -97,6 +97,12 @@ bool TalkMediatorImpl::SetAuthToken(const std::string& email,
xmpp_settings_.set_use_tls(false);
}
+ // The auth token got updated and we are already in the logging_in or
+ // logged_in state. Update the token.
+ if (state_.logging_in || state_.logged_in) {
+ mediator_thread_->UpdateXmppSettings(xmpp_settings_);
+ }
+
state_.initialized = 1;
return true;
}
@@ -113,7 +119,9 @@ void TalkMediatorImpl::AddSubscription(const Subscription& subscription) {
void TalkMediatorImpl::OnConnectionStateChange(bool logged_in) {
DCHECK(non_thread_safe_.CalledOnValidThread());
- state_.logging_in = 0;
+ // 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;
state_.logged_in = logged_in;
if (logged_in) {
VLOG(1) << "P2P: Logged in.";
diff --git a/jingle/notifier/listener/talk_mediator_unittest.cc b/jingle/notifier/listener/talk_mediator_unittest.cc
index 4c983ae1..2697e89 100644
--- a/jingle/notifier/listener/talk_mediator_unittest.cc
+++ b/jingle/notifier/listener/talk_mediator_unittest.cc
@@ -104,9 +104,16 @@ TEST_F(TalkMediatorImplTest, LoginWiring) {
EXPECT_TRUE(talk1->SetAuthToken("chromium@gmail.com", "token",
"fake_service"));
+ EXPECT_EQ(0, mock->update_settings_calls);
+
EXPECT_TRUE(talk1->Login());
EXPECT_EQ(1, mock->login_calls);
+ // We call SetAuthToken again to update the settings after an update.
+ EXPECT_TRUE(talk1->SetAuthToken("chromium@gmail.com", "token",
+ "fake_service"));
+ EXPECT_EQ(1, mock->update_settings_calls);
+
// Successive calls to login will fail. One needs to create a new talk
// mediator object.
EXPECT_FALSE(talk1->Login());