Index: services/authenticating_url_loader/authenticating_url_loader_interceptor_factory.cc |
diff --git a/services/authenticating_url_loader/authenticating_url_loader_factory_impl.cc b/services/authenticating_url_loader/authenticating_url_loader_interceptor_factory.cc |
similarity index 53% |
copy from services/authenticating_url_loader/authenticating_url_loader_factory_impl.cc |
copy to services/authenticating_url_loader/authenticating_url_loader_interceptor_factory.cc |
index 795ce0c49dcc31f0bb515d2d308b995930267295..5346ad91a0871bb4d24de5d839043ff7d58f5b1a 100644 |
--- a/services/authenticating_url_loader/authenticating_url_loader_factory_impl.cc |
+++ b/services/authenticating_url_loader/authenticating_url_loader_interceptor_factory.cc |
@@ -2,29 +2,35 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "services/authenticating_url_loader/authenticating_url_loader_factory_impl.h" |
+#include "services/authenticating_url_loader/authenticating_url_loader_interceptor_factory.h" |
#include "base/bind.h" |
#include "base/logging.h" |
#include "base/stl_util.h" |
#include "mojo/public/cpp/application/application_impl.h" |
-#include "mojo/services/authenticating_url_loader/public/interfaces/authenticating_url_loader.mojom.h" |
-#include "services/authenticating_url_loader/authenticating_url_loader_impl.h" |
+#include "services/authenticating_url_loader/authenticating_url_loader_interceptor.h" |
namespace mojo { |
-AuthenticatingURLLoaderFactoryImpl::AuthenticatingURLLoaderFactoryImpl( |
- mojo::InterfaceRequest<AuthenticatingURLLoaderFactory> request, |
- mojo::ApplicationImpl* app, |
- std::map<GURL, std::string>* cached_tokens) |
- : binding_(this, request.Pass()), app_(app), cached_tokens_(cached_tokens) { |
+AuthenticatingURLLoaderInterceptorFactory:: |
+ AuthenticatingURLLoaderInterceptorFactory( |
+ mojo::InterfaceRequest<URLLoaderInterceptorFactory> request, |
+ authentication::AuthenticationServicePtr authentication_service, |
+ mojo::ApplicationImpl* app, |
+ std::map<GURL, std::string>* cached_tokens) |
+ : binding_(this, request.Pass()), |
+ authentication_service_(authentication_service.Pass()), |
+ app_(app), |
+ cached_tokens_(cached_tokens) { |
app_->ConnectToService("mojo:network_service", &network_service_); |
+ authentication_service_.set_error_handler(this); |
} |
-AuthenticatingURLLoaderFactoryImpl::~AuthenticatingURLLoaderFactoryImpl() { |
+AuthenticatingURLLoaderInterceptorFactory:: |
+ ~AuthenticatingURLLoaderInterceptorFactory() { |
} |
-std::string AuthenticatingURLLoaderFactoryImpl::GetCachedToken( |
+std::string AuthenticatingURLLoaderInterceptorFactory::GetCachedToken( |
const GURL& url) { |
GURL origin = url.GetOrigin(); |
if (cached_tokens_->find(origin) != cached_tokens_->end()) { |
@@ -33,7 +39,7 @@ std::string AuthenticatingURLLoaderFactoryImpl::GetCachedToken( |
return ""; |
} |
-void AuthenticatingURLLoaderFactoryImpl::RetrieveToken( |
+void AuthenticatingURLLoaderInterceptorFactory::RetrieveToken( |
const GURL& url, |
const base::Callback<void(std::string)>& callback) { |
if (!authentication_service_) { |
@@ -53,50 +59,47 @@ void AuthenticatingURLLoaderFactoryImpl::RetrieveToken( |
return; |
} |
authentication_service_->SelectAccount( |
- true, base::Bind(&AuthenticatingURLLoaderFactoryImpl::OnAccountSelected, |
- base::Unretained(this), origin)); |
+ true, base::Bind( |
+ &AuthenticatingURLLoaderInterceptorFactory::OnAccountSelected, |
+ base::Unretained(this), origin)); |
} |
pendings_retrieve_token_[origin].push_back(callback); |
} |
-void AuthenticatingURLLoaderFactoryImpl::OnURLLoaderError( |
- AuthenticatingURLLoaderImpl* url_loader) { |
+void AuthenticatingURLLoaderInterceptorFactory::OnInterceptorError( |
+ AuthenticatingURLLoaderInterceptor* interceptor) { |
auto it = std::find_if( |
- url_loaders_.begin(), url_loaders_.end(), |
- [url_loader](const std::unique_ptr<AuthenticatingURLLoaderImpl>& p) { |
- return p.get() == url_loader; |
+ interceptors_.begin(), interceptors_.end(), |
+ [interceptor]( |
+ const std::unique_ptr<AuthenticatingURLLoaderInterceptor>& p) { |
+ return p.get() == interceptor; |
}); |
- DCHECK(it != url_loaders_.end()); |
- url_loaders_.erase(it); |
+ DCHECK(it != interceptors_.end()); |
+ interceptors_.erase(it); |
} |
-void AuthenticatingURLLoaderFactoryImpl::CreateAuthenticatingURLLoader( |
- mojo::InterfaceRequest<AuthenticatingURLLoader> loader_request) { |
- url_loaders_.push_back(std::unique_ptr<AuthenticatingURLLoaderImpl>( |
- new AuthenticatingURLLoaderImpl(loader_request.Pass(), this))); |
-} |
+void AuthenticatingURLLoaderInterceptorFactory::OnConnectionError() { |
+ authentication_service_ = nullptr; |
-void AuthenticatingURLLoaderFactoryImpl::SetAuthenticationService( |
- authentication::AuthenticationServicePtr authentication_service) { |
- // If the authentication service changes, all pending request needs to fail. |
+ // All pending requests need to fail. |
for (const auto& callbacks : pendings_retrieve_token_) { |
for (const auto& callback : callbacks.second) { |
callback.Run(""); |
} |
} |
pendings_retrieve_token_.clear(); |
- authentication_service_ = authentication_service.Pass(); |
- if (authentication_service_) |
- authentication_service_.set_error_handler(this); |
} |
-void AuthenticatingURLLoaderFactoryImpl::OnConnectionError() { |
- SetAuthenticationService(nullptr); |
+void AuthenticatingURLLoaderInterceptorFactory::Create( |
+ mojo::InterfaceRequest<URLLoaderInterceptor> interceptor) { |
+ interceptors_.push_back(std::unique_ptr<AuthenticatingURLLoaderInterceptor>( |
+ new AuthenticatingURLLoaderInterceptor(interceptor.Pass(), this))); |
} |
-void AuthenticatingURLLoaderFactoryImpl::OnAccountSelected(const GURL& origin, |
- mojo::String account, |
- mojo::String error) { |
+void AuthenticatingURLLoaderInterceptorFactory::OnAccountSelected( |
+ const GURL& origin, |
+ mojo::String account, |
+ mojo::String error) { |
DCHECK(authentication_service_); |
if (error) { |
LOG(WARNING) << "Error (" << error << ") while selecting account"; |
@@ -108,11 +111,12 @@ void AuthenticatingURLLoaderFactoryImpl::OnAccountSelected(const GURL& origin, |
scopes[0] = "https://www.googleapis.com/auth/userinfo.email"; |
authentication_service_->GetOAuth2Token( |
account, scopes.Pass(), |
- base::Bind(&AuthenticatingURLLoaderFactoryImpl::OnOAuth2TokenReceived, |
- base::Unretained(this), origin)); |
+ base::Bind( |
+ &AuthenticatingURLLoaderInterceptorFactory::OnOAuth2TokenReceived, |
+ base::Unretained(this), origin)); |
} |
-void AuthenticatingURLLoaderFactoryImpl::OnOAuth2TokenReceived( |
+void AuthenticatingURLLoaderInterceptorFactory::OnOAuth2TokenReceived( |
const GURL& origin, |
mojo::String token, |
mojo::String error) { |
@@ -126,7 +130,7 @@ void AuthenticatingURLLoaderFactoryImpl::OnOAuth2TokenReceived( |
ExecuteCallbacks(origin, string_token); |
} |
-void AuthenticatingURLLoaderFactoryImpl::ExecuteCallbacks( |
+void AuthenticatingURLLoaderInterceptorFactory::ExecuteCallbacks( |
const GURL& origin, |
const std::string& result) { |
for (auto& callback : pendings_retrieve_token_[origin]) { |