| 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_CONTEXT_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_CONTEXT_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_CONTEXT_H_ | 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_CONTEXT_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 13 #include "google_apis/gaia/ubertoken_fetcher.h" | 14 #include "google_apis/gaia/ubertoken_fetcher.h" |
| 14 | 15 |
| 15 class Profile; | 16 class Profile; |
| 16 class ProfileOAuth2TokenService; | 17 class ProfileOAuth2TokenService; |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 class StoragePartition; | 20 class StoragePartition; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace net { | 23 namespace net { |
| 23 class URLRequestContextGetter; | 24 class URLRequestContextGetter; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace arc { | 27 namespace arc { |
| 27 | 28 |
| 28 class ArcAuthContextDelegate; | |
| 29 | |
| 30 class ArcAuthContext : public UbertokenConsumer, | 29 class ArcAuthContext : public UbertokenConsumer, |
| 31 public GaiaAuthConsumer, | 30 public GaiaAuthConsumer, |
| 32 public OAuth2TokenService::Observer { | 31 public OAuth2TokenService::Observer { |
| 33 public: | 32 public: |
| 34 ArcAuthContext(ArcAuthContextDelegate* delegate, Profile* profile); | 33 explicit ArcAuthContext(Profile* profile); |
| 35 ~ArcAuthContext() override; | 34 ~ArcAuthContext() override; |
| 36 | 35 |
| 37 void PrepareContext(); | 36 ProfileOAuth2TokenService* token_service() { return token_service_; } |
| 37 const std::string& account_id() const { return account_id_; } |
| 38 | 38 |
| 39 // Returns the URL request context information associated with this context. | 39 // Prepares the context. Calling while an inflight operation exists will |
| 40 net::URLRequestContextGetter* GetURLRequestContext(); | 40 // cancel the inflight operation. |
| 41 // On completion, |context| is passed to the callback. On error, |context| |
| 42 // is nullptr. |
| 43 using PrepareCallback = |
| 44 base::Callback<void(net::URLRequestContextGetter* context)>; |
| 45 void Prepare(const PrepareCallback& callback); |
| 41 | 46 |
| 42 // OAuth2TokenService::Observer: | 47 // OAuth2TokenService::Observer: |
| 43 void OnRefreshTokenAvailable(const std::string& account_id) override; | 48 void OnRefreshTokenAvailable(const std::string& account_id) override; |
| 44 void OnRefreshTokensLoaded() override; | 49 void OnRefreshTokensLoaded() override; |
| 45 | 50 |
| 46 // UbertokenConsumer: | 51 // UbertokenConsumer: |
| 47 void OnUbertokenSuccess(const std::string& token) override; | 52 void OnUbertokenSuccess(const std::string& token) override; |
| 48 void OnUbertokenFailure(const GoogleServiceAuthError& error) override; | 53 void OnUbertokenFailure(const GoogleServiceAuthError& error) override; |
| 49 | 54 |
| 50 // GaiaAuthConsumer: | 55 // GaiaAuthConsumer: |
| 51 void OnMergeSessionSuccess(const std::string& data) override; | 56 void OnMergeSessionSuccess(const std::string& data) override; |
| 52 void OnMergeSessionFailure(const GoogleServiceAuthError& error) override; | 57 void OnMergeSessionFailure(const GoogleServiceAuthError& error) override; |
| 53 | 58 |
| 54 const std::string& account_id() const { return account_id_; } | 59 private: |
| 60 void OnRefreshTokenTimeout(); |
| 55 | 61 |
| 56 ProfileOAuth2TokenService* token_service() { return token_service_; } | |
| 57 | |
| 58 private: | |
| 59 void StartFetchers(); | 62 void StartFetchers(); |
| 60 void ResetFetchers(); | 63 void ResetFetchers(); |
| 61 void OnRefreshTokenTimeout(); | |
| 62 | 64 |
| 63 // Unowned pointers. | 65 // Unowned pointer. |
| 64 ArcAuthContextDelegate* const delegate_; | |
| 65 ProfileOAuth2TokenService* token_service_; | 66 ProfileOAuth2TokenService* token_service_; |
| 66 | 67 std::string account_id_; |
| 67 bool context_prepared_ = false; | |
| 68 | 68 |
| 69 // Owned by content::BrowserContent. Used to isolate cookies for auth server | 69 // Owned by content::BrowserContent. Used to isolate cookies for auth server |
| 70 // communication and shared with Arc OptIn UI platform app. | 70 // communication and shared with Arc OptIn UI platform app. |
| 71 content::StoragePartition* storage_partition_ = nullptr; | 71 content::StoragePartition* storage_partition_ = nullptr; |
| 72 | 72 |
| 73 std::string account_id_; | 73 PrepareCallback callback_; |
| 74 bool context_prepared_ = false; |
| 75 |
| 76 base::OneShotTimer refresh_token_timeout_; |
| 74 std::unique_ptr<GaiaAuthFetcher> merger_fetcher_; | 77 std::unique_ptr<GaiaAuthFetcher> merger_fetcher_; |
| 75 std::unique_ptr<UbertokenFetcher> ubertoken_fetcher_; | 78 std::unique_ptr<UbertokenFetcher> ubertoken_fetcher_; |
| 76 base::OneShotTimer refresh_token_timeout_; | |
| 77 | 79 |
| 78 DISALLOW_COPY_AND_ASSIGN(ArcAuthContext); | 80 DISALLOW_COPY_AND_ASSIGN(ArcAuthContext); |
| 79 }; | 81 }; |
| 80 | 82 |
| 81 } // namespace arc | 83 } // namespace arc |
| 82 | 84 |
| 83 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_CONTEXT_H_ | 85 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_CONTEXT_H_ |
| OLD | NEW |