Chromium Code Reviews| Index: chrome/browser/chromeos/arc/arc_auth_code_fetcher.h |
| diff --git a/chrome/browser/chromeos/arc/arc_auth_code_fetcher.h b/chrome/browser/chromeos/arc/arc_auth_code_fetcher.h |
| index c514602e32540424672c3683ad89c62d32e0827a..1c59d3fc3d45b856febba670edf0e552d5cc8f23 100644 |
| --- a/chrome/browser/chromeos/arc/arc_auth_code_fetcher.h |
| +++ b/chrome/browser/chromeos/arc/arc_auth_code_fetcher.h |
| @@ -8,7 +8,10 @@ |
| #include <memory> |
| #include <string> |
| +#include "base/callback.h" |
| #include "base/macros.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "chrome/browser/chromeos/arc/arc_auth_context.h" |
| #include "google_apis/gaia/oauth2_token_service.h" |
| #include "net/url_request/url_fetcher_delegate.h" |
| @@ -21,17 +24,21 @@ class URLRequestContextGetter; |
| namespace arc { |
| -class ArcAuthCodeFetcherDelegate; |
| - |
| +// The instance is not reusable, so for each Fetch(), the instance must be |
| +// re-created. Deleting the instance cancels inflight operation. |
| class ArcAuthCodeFetcher : public OAuth2TokenService::Consumer, |
| public net::URLFetcherDelegate { |
| public: |
| - ArcAuthCodeFetcher(ArcAuthCodeFetcherDelegate* delegate, |
| - net::URLRequestContextGetter* request_context_getter, |
| - Profile* profile, |
| + ArcAuthCodeFetcher(Profile* profile, |
| + ArcAuthContext* context, |
| const std::string& auth_endpoint); |
| ~ArcAuthCodeFetcher() override; |
| + // Starts to fetch the token. On success fetched |auth_token| is passed. |
| + // On error, auth_token is empty. |
| + using FetchCallback = base::Callback<void(const std::string& auth_token)>; |
| + void Fetch(const FetchCallback& callback); |
| + |
| // OAuth2TokenService::Consumer: |
| void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| const std::string& access_token, |
| @@ -44,18 +51,23 @@ class ArcAuthCodeFetcher : public OAuth2TokenService::Consumer, |
| private: |
| void ResetFetchers(); |
| + void OnPrepared(net::URLRequestContextGetter* request_context_getter); |
| // Unowned pointers. |
| - ArcAuthCodeFetcherDelegate* const delegate_; |
| - net::URLRequestContextGetter* const request_context_getter_; |
| Profile* const profile_; |
| + ArcAuthContext* context_; |
|
Luis Héctor Chávez
2016/11/15 23:27:37
nit: ArcAuthContext* const context_;
hidehiko
2016/11/16 01:00:34
Done.
|
| + net::URLRequestContextGetter* request_context_getter_ = nullptr; |
| // URL to request auth code. |
| const std::string auth_endpoint_; |
| + FetchCallback callback_; |
| + |
| std::unique_ptr<OAuth2TokenService::Request> login_token_request_; |
| std::unique_ptr<net::URLFetcher> auth_code_fetcher_; |
| + base::WeakPtrFactory<ArcAuthCodeFetcher> weak_ptr_factory_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(ArcAuthCodeFetcher); |
| }; |