summaryrefslogtreecommitdiffstats
path: root/remoting/host
diff options
context:
space:
mode:
authorrmsousa@chromium.org <rmsousa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-21 01:39:47 +0000
committerrmsousa@chromium.org <rmsousa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-21 01:39:47 +0000
commitc9d1c67468a724ec6eeee9f27c67779988edbc11 (patch)
tree8d620e9f524e2dc050aaa9be4cdaf896c1687d2b /remoting/host
parentd9dcbd69eafecff0c5a225df0e814021b947c99b (diff)
downloadchromium_src-c9d1c67468a724ec6eeee9f27c67779988edbc11.zip
chromium_src-c9d1c67468a724ec6eeee9f27c67779988edbc11.tar.gz
chromium_src-c9d1c67468a724ec6eeee9f27c67779988edbc11.tar.bz2
Add auto-refresh support to OAuthTokenGetter (disabled for now).
Some fixes to GetUserInfo flow to avoid superfluous GetUserInfo calls. BUG= Review URL: https://codereview.chromium.org/294813002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271795 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host')
-rw-r--r--remoting/host/oauth_token_getter.cc37
-rw-r--r--remoting/host/oauth_token_getter.h7
-rw-r--r--remoting/host/remoting_me2me_host.cc3
3 files changed, 39 insertions, 8 deletions
diff --git a/remoting/host/oauth_token_getter.cc b/remoting/host/oauth_token_getter.cc
index bf92e95..7ac01c5 100644
--- a/remoting/host/oauth_token_getter.cc
+++ b/remoting/host/oauth_token_getter.cc
@@ -34,12 +34,16 @@ OAuthTokenGetter::OAuthCredentials::OAuthCredentials(
OAuthTokenGetter::OAuthTokenGetter(
scoped_ptr<OAuthCredentials> oauth_credentials,
- scoped_refptr<net::URLRequestContextGetter> url_request_context_getter)
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
+ bool auto_refresh)
: oauth_credentials_(oauth_credentials.Pass()),
gaia_oauth_client_(
new gaia::GaiaOAuthClient(url_request_context_getter)),
url_request_context_getter_(url_request_context_getter),
refreshing_oauth_token_(false) {
+ if (auto_refresh) {
+ refresh_timer_.reset(new base::OneShotTimer<OAuthTokenGetter>());
+ }
}
OAuthTokenGetter::~OAuthTokenGetter() {}
@@ -58,11 +62,24 @@ void OAuthTokenGetter::OnRefreshTokenResponse(
HOST_LOG << "Received OAuth token.";
oauth_access_token_ = access_token;
- auth_token_expiry_time_ = base::Time::Now() +
+ base::TimeDelta token_expiration =
base::TimeDelta::FromSeconds(expires_seconds) -
base::TimeDelta::FromSeconds(kTokenUpdateTimeBeforeExpirySeconds);
+ auth_token_expiry_time_ = base::Time::Now() + token_expiration;
+
+ if (refresh_timer_) {
+ refresh_timer_->Stop();
+ refresh_timer_->Start(FROM_HERE, token_expiration, this,
+ &OAuthTokenGetter::RefreshOAuthToken);
+ }
- gaia_oauth_client_->GetUserEmail(access_token, kMaxRetries, this);
+ if (verified_email_.empty()) {
+ gaia_oauth_client_->GetUserEmail(access_token, kMaxRetries, this);
+ } else {
+ refreshing_oauth_token_ = false;
+ NotifyCallbacks(
+ OAuthTokenGetter::SUCCESS, verified_email_, oauth_access_token_);
+ }
}
void OAuthTokenGetter::OnGetUserEmailResponse(const std::string& user_email) {
@@ -77,6 +94,7 @@ void OAuthTokenGetter::OnGetUserEmailResponse(const std::string& user_email) {
return;
}
+ verified_email_ = user_email;
refreshing_oauth_token_ = false;
// Now that we've refreshed the token and verified that it's for the correct
@@ -100,6 +118,12 @@ void OAuthTokenGetter::OnOAuthError() {
DCHECK(CalledOnValidThread());
LOG(ERROR) << "OAuth: invalid credentials.";
refreshing_oauth_token_ = false;
+
+ // Throw away invalid credentials and force a refresh.
+ oauth_access_token_.clear();
+ auth_token_expiry_time_ = base::Time();
+ verified_email_.clear();
+
NotifyCallbacks(OAuthTokenGetter::AUTH_ERROR, std::string(), std::string());
}
@@ -114,9 +138,10 @@ void OAuthTokenGetter::OnNetworkError(int response_code) {
void OAuthTokenGetter::CallWithToken(const TokenCallback& on_access_token) {
DCHECK(CalledOnValidThread());
- bool need_new_auth_token = oauth_credentials_.get() &&
- (auth_token_expiry_time_.is_null() ||
- base::Time::Now() >= auth_token_expiry_time_);
+ bool need_new_auth_token = auth_token_expiry_time_.is_null() ||
+ base::Time::Now() >= auth_token_expiry_time_ ||
+ verified_email_.empty();
+
if (need_new_auth_token) {
pending_callbacks_.push(on_access_token);
if (!refreshing_oauth_token_)
diff --git a/remoting/host/oauth_token_getter.h b/remoting/host/oauth_token_getter.h
index 4b48a4e..a47a3f8 100644
--- a/remoting/host/oauth_token_getter.h
+++ b/remoting/host/oauth_token_getter.h
@@ -10,6 +10,8 @@
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/threading/non_thread_safe.h"
+#include "base/time/time.h"
+#include "base/timer/timer.h"
#include "google_apis/gaia/gaia_oauth_client.h"
namespace net {
@@ -56,7 +58,8 @@ class OAuthTokenGetter :
OAuthTokenGetter(
scoped_ptr<OAuthCredentials> oauth_credentials,
- scoped_refptr<net::URLRequestContextGetter> url_request_context_getter);
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
+ bool auto_refresh);
virtual ~OAuthTokenGetter();
// Call |on_access_token| with an access token, or the failure status.
@@ -84,8 +87,10 @@ class OAuthTokenGetter :
bool refreshing_oauth_token_;
std::string oauth_access_token_;
+ std::string verified_email_;
base::Time auth_token_expiry_time_;
std::queue<OAuthTokenGetter::TokenCallback> pending_callbacks_;
+ scoped_ptr<base::OneShotTimer<OAuthTokenGetter> > refresh_timer_;
DISALLOW_COPY_AND_ASSIGN(OAuthTokenGetter);
};
diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc
index 5d33b02..c651be4 100644
--- a/remoting/host/remoting_me2me_host.cc
+++ b/remoting/host/remoting_me2me_host.cc
@@ -1144,7 +1144,8 @@ void HostProcess::StartHost() {
use_service_account_));
oauth_token_getter_.reset(new OAuthTokenGetter(
- oauth_credentials.Pass(), context_->url_request_context_getter()));
+ oauth_credentials.Pass(), context_->url_request_context_getter(),
+ false));
signaling_connector_->EnableOAuth(oauth_token_getter_.get());
}