| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SERVICES_AUTHENTICATING_URL_LOADER_AUTHENTICATING_URL_LOADER_FACTORY_IMP
L_H_ | 5 #ifndef SERVICES_AUTHENTICATING_URL_LOADER_AUTHENTICATING_URL_LOADER_INTERCEPTOR
_FACTORY_H_ |
| 6 #define SERVICES_AUTHENTICATING_URL_LOADER_AUTHENTICATING_URL_LOADER_FACTORY_IMP
L_H_ | 6 #define SERVICES_AUTHENTICATING_URL_LOADER_AUTHENTICATING_URL_LOADER_INTERCEPTOR
_FACTORY_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "mojo/public/cpp/bindings/error_handler.h" | 11 #include "mojo/public/cpp/bindings/error_handler.h" |
| 12 #include "mojo/public/cpp/bindings/interface_request.h" | 12 #include "mojo/public/cpp/bindings/interface_request.h" |
| 13 #include "mojo/public/cpp/bindings/strong_binding.h" | 13 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 14 #include "mojo/services/authenticating_url_loader/public/interfaces/authenticati
ng_url_loader_factory.mojom.h" | |
| 15 #include "mojo/services/authentication/public/interfaces/authentication.mojom.h" | 14 #include "mojo/services/authentication/public/interfaces/authentication.mojom.h" |
| 16 #include "mojo/services/network/public/interfaces/network_service.mojom.h" | 15 #include "mojo/services/network/public/interfaces/network_service.mojom.h" |
| 17 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 18 | 17 |
| 19 namespace mojo { | 18 namespace mojo { |
| 20 | 19 |
| 21 class ApplicationImpl; | 20 class ApplicationImpl; |
| 22 | 21 |
| 23 class AuthenticatingURLLoaderImpl; | 22 class AuthenticatingURLLoaderInterceptor; |
| 24 | 23 |
| 25 class AuthenticatingURLLoaderFactoryImpl | 24 class AuthenticatingURLLoaderInterceptorFactory |
| 26 : public AuthenticatingURLLoaderFactory, | 25 : public URLLoaderInterceptorFactory, |
| 27 public ErrorHandler { | 26 public ErrorHandler { |
| 28 public: | 27 public: |
| 29 AuthenticatingURLLoaderFactoryImpl( | 28 AuthenticatingURLLoaderInterceptorFactory( |
| 30 mojo::InterfaceRequest<AuthenticatingURLLoaderFactory> request, | 29 mojo::InterfaceRequest<URLLoaderInterceptorFactory> request, |
| 30 authentication::AuthenticationServicePtr authentication_service, |
| 31 mojo::ApplicationImpl* app, | 31 mojo::ApplicationImpl* app, |
| 32 std::map<GURL, std::string>* cached_tokens); | 32 std::map<GURL, std::string>* cached_tokens); |
| 33 ~AuthenticatingURLLoaderFactoryImpl() override; | 33 ~AuthenticatingURLLoaderInterceptorFactory() override; |
| 34 | 34 |
| 35 NetworkService* network_service() { return network_service_.get(); } | 35 NetworkService* network_service() { return network_service_.get(); } |
| 36 | 36 |
| 37 // Returns a cached token for the given url (only considers the origin). Will | 37 // Returns a cached token for the given url (only considers the origin). Will |
| 38 // returns an empty string if no token is cached. | 38 // returns an empty string if no token is cached. |
| 39 std::string GetCachedToken(const GURL& url); | 39 std::string GetCachedToken(const GURL& url); |
| 40 | 40 |
| 41 void RetrieveToken(const GURL& url, | 41 void RetrieveToken(const GURL& url, |
| 42 const base::Callback<void(std::string)>& callback); | 42 const base::Callback<void(std::string)>& callback); |
| 43 | 43 |
| 44 void OnURLLoaderError(AuthenticatingURLLoaderImpl* url_loader); | 44 void OnInterceptorError(AuthenticatingURLLoaderInterceptor* interceptor); |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 // AuthenticatingURLLoaderFactory: | 47 // URLLoaderInterceptorFactory: |
| 48 void CreateAuthenticatingURLLoader( | 48 void Create( |
| 49 mojo::InterfaceRequest<AuthenticatingURLLoader> loader_request) override; | 49 mojo::InterfaceRequest<URLLoaderInterceptor> interceptor) override; |
| 50 void SetAuthenticationService( | |
| 51 authentication::AuthenticationServicePtr authentication_service) override; | |
| 52 | 50 |
| 53 // ErrorHandler: | 51 // ErrorHandler: |
| 54 void OnConnectionError() override; | 52 void OnConnectionError() override; |
| 55 | 53 |
| 56 void OnAccountSelected(const GURL& origin, | 54 void OnAccountSelected(const GURL& origin, |
| 57 mojo::String account, | 55 mojo::String account, |
| 58 mojo::String error); | 56 mojo::String error); |
| 59 | 57 |
| 60 void OnOAuth2TokenReceived(const GURL& origin, | 58 void OnOAuth2TokenReceived(const GURL& origin, |
| 61 mojo::String token, | 59 mojo::String token, |
| 62 mojo::String error); | 60 mojo::String error); |
| 63 | 61 |
| 64 void ExecuteCallbacks(const GURL& origin, const std::string& result); | 62 void ExecuteCallbacks(const GURL& origin, const std::string& result); |
| 65 | 63 |
| 66 StrongBinding<AuthenticatingURLLoaderFactory> binding_; | 64 StrongBinding<URLLoaderInterceptorFactory> binding_; |
| 65 authentication::AuthenticationServicePtr authentication_service_; |
| 67 ApplicationImpl* app_; | 66 ApplicationImpl* app_; |
| 68 std::map<GURL, std::string>* cached_tokens_; | 67 std::map<GURL, std::string>* cached_tokens_; |
| 69 std::map<GURL, std::string> cached_accounts_; | 68 std::map<GURL, std::string> cached_accounts_; |
| 70 authentication::AuthenticationServicePtr authentication_service_; | |
| 71 NetworkServicePtr network_service_; | 69 NetworkServicePtr network_service_; |
| 72 std::vector<std::unique_ptr<AuthenticatingURLLoaderImpl>> url_loaders_; | 70 std::vector<std::unique_ptr<AuthenticatingURLLoaderInterceptor>> |
| 71 interceptors_; |
| 73 std::map<GURL, std::vector<base::Callback<void(std::string)>>> | 72 std::map<GURL, std::vector<base::Callback<void(std::string)>>> |
| 74 pendings_retrieve_token_; | 73 pendings_retrieve_token_; |
| 75 }; | 74 }; |
| 76 | 75 |
| 77 } // namespace mojo | 76 } // namespace mojo |
| 78 | 77 |
| 79 #endif // SERVICES_AUTHENTICATING_URL_LOADER_AUTHENTICATING_URL_LOADER_FACTORY_
IMPL_H_ | 78 #endif // SERVICES_AUTHENTICATING_URL_LOADER_AUTHENTICATING_URL_LOADER_INTERCEP
TOR_FACTORY_H_ |
| OLD | NEW |