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

Unified Diff: services/authenticating_url_loader/authenticating_url_loader_impl.cc

Issue 1161603003: Have the authenticating_url_loader cache token per-origin. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 7 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
Index: services/authenticating_url_loader/authenticating_url_loader_impl.cc
diff --git a/services/authenticating_url_loader/authenticating_url_loader_impl.cc b/services/authenticating_url_loader/authenticating_url_loader_impl.cc
index 9d839afdca9c5b75fc50ef6174553e171cfbc641..e525d1a95e8af7cb4f3bfefbc9005af1988dbca1 100644
--- a/services/authenticating_url_loader/authenticating_url_loader_impl.cc
+++ b/services/authenticating_url_loader/authenticating_url_loader_impl.cc
@@ -14,13 +14,15 @@ AuthenticatingURLLoaderImpl::AuthenticatingURLLoaderImpl(
InterfaceRequest<AuthenticatingURLLoader> request,
authentication::AuthenticationService* authentication_service,
NetworkService* network_service,
+ std::map<GURL, std::string>* cached_tokens,
const Callback<void(AuthenticatingURLLoaderImpl*)>&
connection_error_callback)
: binding_(this, request.Pass()),
authentication_service_(authentication_service),
network_service_(network_service),
connection_error_callback_(connection_error_callback),
- request_authorization_state_(REQUEST_NOT_AUTHORIZED) {
+ request_authorization_state_(REQUEST_NOT_AUTHORIZED),
+ cached_tokens_(cached_tokens) {
binding_.set_error_handler(this);
}
@@ -38,11 +40,16 @@ void AuthenticatingURLLoaderImpl::Start(
callback.Run(nullptr);
return;
}
- url_ = request->url;
+ url_ = GURL(request->url);
auto_follow_redirects_ = request->auto_follow_redirects;
bypass_cache_ = request->bypass_cache;
headers_ = request->headers.Clone();
pending_start_callback_ = callback;
+ GURL url(request->url);
blundell 2015/05/27 15:43:44 nit: unneeded, just use |url_|.
qsr 2015/05/27 16:02:26 Missed one. Thanks.
+ if (cached_tokens_->find(url_.GetOrigin()) != cached_tokens_->end()) {
+ request->headers.push_back("Authorization: Bearer " +
+ (*cached_tokens_)[url.GetOrigin()]);
+ }
StartNetworkRequest(request.Pass());
}
@@ -117,6 +124,7 @@ void AuthenticatingURLLoaderImpl::OnOAuth2TokenReceived(String token,
}
DCHECK(token);
+ (*cached_tokens_)[url_.GetOrigin()] = token;
token_ = token;
mojo::Array<mojo::String> headers(0);
if (headers_)
@@ -124,7 +132,7 @@ void AuthenticatingURLLoaderImpl::OnOAuth2TokenReceived(String token,
headers.push_back("Authorization: Bearer " + token.get());
URLRequestPtr request(mojo::URLRequest::New());
- request->url = url_;
+ request->url = url_.spec();
request->auto_follow_redirects = auto_follow_redirects_;
request->bypass_cache = bypass_cache_;
request->headers = headers.Pass();

Powered by Google App Engine
This is Rietveld 408576698