| 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_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "chrome/browser/chromeos/arc/arc_support_host.h" | |
| 14 #include "components/arc/arc_service.h" | 13 #include "components/arc/arc_service.h" |
| 15 #include "components/arc/common/auth.mojom.h" | 14 #include "components/arc/common/auth.mojom.h" |
| 16 #include "components/arc/instance_holder.h" | 15 #include "components/arc/instance_holder.h" |
| 17 #include "mojo/public/cpp/bindings/binding.h" | 16 #include "mojo/public/cpp/bindings/binding.h" |
| 18 | 17 |
| 19 namespace net { | |
| 20 class URLRequestContextGetter; | |
| 21 } | |
| 22 | |
| 23 namespace arc { | 18 namespace arc { |
| 24 | 19 |
| 25 class ArcAuthCodeFetcher; | 20 class ArcAuthCodeFetcher; |
| 26 class ArcRobotAuth; | |
| 27 | 21 |
| 28 // Implementation of ARC authorization. | 22 // Implementation of ARC authorization. |
| 29 // TODO(hidehiko): Move to c/b/c/arc/auth with adding tests. | 23 // TODO(hidehiko): Move to c/b/c/arc/auth with adding tests. |
| 30 class ArcAuthService : public ArcService, | 24 class ArcAuthService : public ArcService, |
| 31 public mojom::AuthHost, | 25 public mojom::AuthHost, |
| 32 public InstanceHolder<mojom::AuthInstance>::Observer, | 26 public InstanceHolder<mojom::AuthInstance>::Observer { |
| 33 public ArcSupportHost::Observer { | |
| 34 public: | 27 public: |
| 35 explicit ArcAuthService(ArcBridgeService* bridge_service); | 28 explicit ArcAuthService(ArcBridgeService* bridge_service); |
| 36 ~ArcAuthService() override; | 29 ~ArcAuthService() override; |
| 37 | 30 |
| 38 // This is introduced to work with existing tests. | 31 // This is introduced to work with existing tests. |
| 39 // TODO(crbug.com/664095): Clean up the test and remove this method. | 32 // TODO(crbug.com/664095): Clean up the test and remove this method. |
| 40 static ArcAuthService* GetForTest(); | 33 static ArcAuthService* GetForTest(); |
| 41 | 34 |
| 42 // InstanceHolder<mojom::AuthInstance>::Observer: | 35 // InstanceHolder<mojom::AuthInstance>::Observer: |
| 43 void OnInstanceReady() override; | 36 void OnInstanceReady() override; |
| 44 void OnInstanceClosed() override; | 37 void OnInstanceClosed() override; |
| 45 | 38 |
| 46 // mojom::AuthHost: | 39 // mojom::AuthHost: |
| 47 void OnSignInComplete() override; | 40 void OnSignInComplete() override; |
| 48 void OnSignInFailed(mojom::ArcSignInFailureReason reason) override; | 41 void OnSignInFailed(mojom::ArcSignInFailureReason reason) override; |
| 49 void RequestAccountInfo() override; | 42 void RequestAccountInfo() override; |
| 50 | 43 |
| 51 // Deprecated methods: | 44 // Deprecated methods: |
| 52 // For security reason this code can be used only once and exists for specific | 45 // For security reason this code can be used only once and exists for specific |
| 53 // period of time. | 46 // period of time. |
| 54 void GetAuthCodeDeprecated0( | 47 void GetAuthCodeDeprecated0( |
| 55 const GetAuthCodeDeprecated0Callback& callback) override; | 48 const GetAuthCodeDeprecated0Callback& callback) override; |
| 56 void GetAuthCodeDeprecated( | 49 void GetAuthCodeDeprecated( |
| 57 const GetAuthCodeDeprecatedCallback& callback) override; | 50 const GetAuthCodeDeprecatedCallback& callback) override; |
| 58 void GetAuthCodeAndAccountTypeDeprecated( | 51 void GetAuthCodeAndAccountTypeDeprecated( |
| 59 const GetAuthCodeAndAccountTypeDeprecatedCallback& callback) override; | 52 const GetAuthCodeAndAccountTypeDeprecatedCallback& callback) override; |
| 60 void GetIsAccountManagedDeprecated( | 53 void GetIsAccountManagedDeprecated( |
| 61 const GetIsAccountManagedDeprecatedCallback& callback) override; | 54 const GetIsAccountManagedDeprecatedCallback& callback) override; |
| 62 | 55 |
| 63 // ArcSupportHost::Observer: | |
| 64 void OnAuthSucceeded(const std::string& auth_code) override; | |
| 65 void OnRetryClicked() override; | |
| 66 | |
| 67 private: | 56 private: |
| 68 using AccountInfoCallback = base::Callback<void(mojom::AccountInfoPtr)>; | 57 using AccountInfoCallback = base::Callback<void(mojom::AccountInfoPtr)>; |
| 69 class AccountInfoNotifier; | 58 class AccountInfoNotifier; |
| 70 | 59 |
| 71 // Starts to request account info. | 60 // Starts to request account info. |
| 72 void RequestAccountInfoInternal( | 61 void RequestAccountInfoInternal( |
| 73 std::unique_ptr<AccountInfoNotifier> account_info_notifier); | 62 std::unique_ptr<AccountInfoNotifier> account_info_notifier); |
| 74 | 63 |
| 75 // Called when HTTP context is prepared. | 64 // Callback on auth_code fetched. |
| 76 void OnContextPrepared(net::URLRequestContextGetter* request_context_getter); | |
| 77 | |
| 78 void OnAccountInfoReady(mojom::AccountInfoPtr account_info); | |
| 79 | |
| 80 // Callback for Robot auth in Kiosk mode. | |
| 81 void OnRobotAuthCodeFetched(const std::string& auth_code); | |
| 82 | |
| 83 // Callback for automatic auth code fetching when --arc-user-auth-endpoint | |
| 84 // flag is set. | |
| 85 void OnAuthCodeFetched(const std::string& auth_code); | 65 void OnAuthCodeFetched(const std::string& auth_code); |
| 86 | 66 |
| 87 // Common procedure across LSO auth code fetching, automatic auth code | 67 // Called to let ARC container know the account info. |
| 88 // fetching, and Robot auth. | 68 void OnAccountInfoReady(mojom::AccountInfoPtr account_info); |
| 89 void OnAuthCodeObtained(const std::string& auth_code); | |
| 90 | 69 |
| 91 mojo::Binding<mojom::AuthHost> binding_; | 70 mojo::Binding<mojom::AuthHost> binding_; |
| 92 | 71 |
| 93 std::unique_ptr<ArcAuthCodeFetcher> auth_code_fetcher_; | |
| 94 std::unique_ptr<ArcRobotAuth> arc_robot_auth_; | |
| 95 | |
| 96 std::unique_ptr<AccountInfoNotifier> notifier_; | 72 std::unique_ptr<AccountInfoNotifier> notifier_; |
| 73 std::unique_ptr<ArcAuthCodeFetcher> fetcher_; |
| 97 | 74 |
| 98 base::WeakPtrFactory<ArcAuthService> weak_ptr_factory_; | 75 base::WeakPtrFactory<ArcAuthService> weak_ptr_factory_; |
| 99 | 76 |
| 100 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); | 77 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); |
| 101 }; | 78 }; |
| 102 | 79 |
| 103 } // namespace arc | 80 } // namespace arc |
| 104 | 81 |
| 105 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ | 82 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ |
| OLD | NEW |