| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_CODE_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_CODE_FETCHER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_CODE_FETCHER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_CODE_FETCHER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 class URLRequestContextGetter; | 22 class URLRequestContextGetter; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace arc { | 25 namespace arc { |
| 26 | 26 |
| 27 // The instance is not reusable, so for each Fetch(), the instance must be | 27 // The instance is not reusable, so for each Fetch(), the instance must be |
| 28 // re-created. Deleting the instance cancels inflight operation. | 28 // re-created. Deleting the instance cancels inflight operation. |
| 29 class ArcAuthCodeFetcher : public OAuth2TokenService::Consumer, | 29 class ArcAuthCodeFetcher : public OAuth2TokenService::Consumer, |
| 30 public net::URLFetcherDelegate { | 30 public net::URLFetcherDelegate { |
| 31 public: | 31 public: |
| 32 ArcAuthCodeFetcher(Profile* profile, | 32 ArcAuthCodeFetcher(Profile* profile, ArcAuthContext* context); |
| 33 ArcAuthContext* context, | |
| 34 const std::string& auth_endpoint); | |
| 35 ~ArcAuthCodeFetcher() override; | 33 ~ArcAuthCodeFetcher() override; |
| 36 | 34 |
| 37 // Starts to fetch the token. On success fetched |auth_token| is passed. | 35 // Starts to fetch the token. On success fetched |auth_token| is passed. |
| 38 // On error, auth_token is empty. | 36 // On error, auth_token is empty. |
| 39 using FetchCallback = base::Callback<void(const std::string& auth_token)>; | 37 using FetchCallback = base::Callback<void(const std::string& auth_token)>; |
| 40 void Fetch(const FetchCallback& callback); | 38 void Fetch(const FetchCallback& callback); |
| 41 | 39 |
| 42 // OAuth2TokenService::Consumer: | 40 // OAuth2TokenService::Consumer: |
| 43 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 41 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 44 const std::string& access_token, | 42 const std::string& access_token, |
| 45 const base::Time& expiration_time) override; | 43 const base::Time& expiration_time) override; |
| 46 void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 44 void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 47 const GoogleServiceAuthError& error) override; | 45 const GoogleServiceAuthError& error) override; |
| 48 | 46 |
| 49 // net::URLFetcherDelegate: | 47 // net::URLFetcherDelegate: |
| 50 void OnURLFetchComplete(const net::URLFetcher* source) override; | 48 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 51 | 49 |
| 52 private: | 50 private: |
| 53 void ResetFetchers(); | 51 void ResetFetchers(); |
| 54 void OnPrepared(net::URLRequestContextGetter* request_context_getter); | 52 void OnPrepared(net::URLRequestContextGetter* request_context_getter); |
| 55 | 53 |
| 56 // Unowned pointers. | 54 // Unowned pointers. |
| 57 Profile* const profile_; | 55 Profile* const profile_; |
| 58 ArcAuthContext* const context_; | 56 ArcAuthContext* const context_; |
| 59 net::URLRequestContextGetter* request_context_getter_ = nullptr; | 57 net::URLRequestContextGetter* request_context_getter_ = nullptr; |
| 60 | 58 |
| 61 // URL to request auth code. | |
| 62 const std::string auth_endpoint_; | |
| 63 | |
| 64 FetchCallback callback_; | 59 FetchCallback callback_; |
| 65 | 60 |
| 66 std::unique_ptr<OAuth2TokenService::Request> login_token_request_; | 61 std::unique_ptr<OAuth2TokenService::Request> login_token_request_; |
| 67 std::unique_ptr<net::URLFetcher> auth_code_fetcher_; | 62 std::unique_ptr<net::URLFetcher> auth_code_fetcher_; |
| 68 | 63 |
| 69 base::WeakPtrFactory<ArcAuthCodeFetcher> weak_ptr_factory_; | 64 base::WeakPtrFactory<ArcAuthCodeFetcher> weak_ptr_factory_; |
| 70 | 65 |
| 71 DISALLOW_COPY_AND_ASSIGN(ArcAuthCodeFetcher); | 66 DISALLOW_COPY_AND_ASSIGN(ArcAuthCodeFetcher); |
| 72 }; | 67 }; |
| 73 | 68 |
| 74 } // namespace arc | 69 } // namespace arc |
| 75 | 70 |
| 76 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_CODE_FETCHER_H_ | 71 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_CODE_FETCHER_H_ |
| OLD | NEW |