| 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 #include "chrome/browser/chromeos/arc/arc_auth_service.h" | 5 #include "chrome/browser/chromeos/arc/arc_auth_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "components/arc/arc_bridge_service.h" | 22 #include "components/arc/arc_bridge_service.h" |
| 23 #include "components/arc/arc_features.h" | 23 #include "components/arc/arc_features.h" |
| 24 #include "components/arc/arc_util.h" | 24 #include "components/arc/arc_util.h" |
| 25 #include "components/prefs/pref_service.h" | 25 #include "components/prefs/pref_service.h" |
| 26 #include "components/user_manager/user_manager.h" | 26 #include "components/user_manager/user_manager.h" |
| 27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 28 | 28 |
| 29 namespace arc { | 29 namespace arc { |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 ArcAuthService* g_arc_auth_service = nullptr; | |
| 33 | |
| 34 // Convers mojom::ArcSignInFailureReason into ProvisiningResult. | 32 // Convers mojom::ArcSignInFailureReason into ProvisiningResult. |
| 35 ProvisioningResult ConvertArcSignInFailureReasonToProvisioningResult( | 33 ProvisioningResult ConvertArcSignInFailureReasonToProvisioningResult( |
| 36 mojom::ArcSignInFailureReason reason) { | 34 mojom::ArcSignInFailureReason reason) { |
| 37 using ArcSignInFailureReason = mojom::ArcSignInFailureReason; | 35 using ArcSignInFailureReason = mojom::ArcSignInFailureReason; |
| 38 | 36 |
| 39 #define MAP_PROVISIONING_RESULT(name) \ | 37 #define MAP_PROVISIONING_RESULT(name) \ |
| 40 case ArcSignInFailureReason::name: \ | 38 case ArcSignInFailureReason::name: \ |
| 41 return ProvisioningResult::name | 39 return ProvisioningResult::name |
| 42 | 40 |
| 43 switch (reason) { | 41 switch (reason) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 64 return ProvisioningResult::UNKNOWN_ERROR; | 62 return ProvisioningResult::UNKNOWN_ERROR; |
| 65 } | 63 } |
| 66 | 64 |
| 67 mojom::ChromeAccountType GetAccountType() { | 65 mojom::ChromeAccountType GetAccountType() { |
| 68 return IsArcKioskMode() ? mojom::ChromeAccountType::ROBOT_ACCOUNT | 66 return IsArcKioskMode() ? mojom::ChromeAccountType::ROBOT_ACCOUNT |
| 69 : mojom::ChromeAccountType::USER_ACCOUNT; | 67 : mojom::ChromeAccountType::USER_ACCOUNT; |
| 70 } | 68 } |
| 71 | 69 |
| 72 } // namespace | 70 } // namespace |
| 73 | 71 |
| 72 // static |
| 73 const char ArcAuthService::kArcServiceName[] = "arc::ArcAuthService"; |
| 74 |
| 74 // TODO(lhchavez): Get rid of this class once we can safely remove all the | 75 // TODO(lhchavez): Get rid of this class once we can safely remove all the |
| 75 // deprecated interfaces and only need to care about one type of callback. | 76 // deprecated interfaces and only need to care about one type of callback. |
| 76 class ArcAuthService::AccountInfoNotifier { | 77 class ArcAuthService::AccountInfoNotifier { |
| 77 public: | 78 public: |
| 78 explicit AccountInfoNotifier( | 79 explicit AccountInfoNotifier( |
| 79 const GetAuthCodeDeprecatedCallback& auth_callback) | 80 const GetAuthCodeDeprecatedCallback& auth_callback) |
| 80 : callback_type_(CallbackType::AUTH_CODE), | 81 : callback_type_(CallbackType::AUTH_CODE), |
| 81 auth_callback_(auth_callback) {} | 82 auth_callback_(auth_callback) {} |
| 82 | 83 |
| 83 explicit AccountInfoNotifier( | 84 explicit AccountInfoNotifier( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 enum class CallbackType { AUTH_CODE, AUTH_CODE_AND_ACCOUNT, ACCOUNT_INFO }; | 128 enum class CallbackType { AUTH_CODE, AUTH_CODE_AND_ACCOUNT, ACCOUNT_INFO }; |
| 128 | 129 |
| 129 const CallbackType callback_type_; | 130 const CallbackType callback_type_; |
| 130 const GetAuthCodeDeprecatedCallback auth_callback_; | 131 const GetAuthCodeDeprecatedCallback auth_callback_; |
| 131 const GetAuthCodeAndAccountTypeDeprecatedCallback auth_account_callback_; | 132 const GetAuthCodeAndAccountTypeDeprecatedCallback auth_account_callback_; |
| 132 const AccountInfoCallback account_info_callback_; | 133 const AccountInfoCallback account_info_callback_; |
| 133 }; | 134 }; |
| 134 | 135 |
| 135 ArcAuthService::ArcAuthService(ArcBridgeService* bridge_service) | 136 ArcAuthService::ArcAuthService(ArcBridgeService* bridge_service) |
| 136 : ArcService(bridge_service), binding_(this), weak_ptr_factory_(this) { | 137 : ArcService(bridge_service), binding_(this), weak_ptr_factory_(this) { |
| 137 DCHECK(!g_arc_auth_service); | |
| 138 g_arc_auth_service = this; | |
| 139 arc_bridge_service()->auth()->AddObserver(this); | 138 arc_bridge_service()->auth()->AddObserver(this); |
| 140 } | 139 } |
| 141 | 140 |
| 142 ArcAuthService::~ArcAuthService() { | 141 ArcAuthService::~ArcAuthService() { |
| 143 arc_bridge_service()->auth()->RemoveObserver(this); | 142 arc_bridge_service()->auth()->RemoveObserver(this); |
| 144 | |
| 145 DCHECK_EQ(g_arc_auth_service, this); | |
| 146 g_arc_auth_service = nullptr; | |
| 147 } | |
| 148 | |
| 149 // static | |
| 150 ArcAuthService* ArcAuthService::GetForTest() { | |
| 151 DCHECK(g_arc_auth_service); | |
| 152 return g_arc_auth_service; | |
| 153 } | 143 } |
| 154 | 144 |
| 155 void ArcAuthService::OnInstanceReady() { | 145 void ArcAuthService::OnInstanceReady() { |
| 156 auto* instance = | 146 auto* instance = |
| 157 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->auth(), Init); | 147 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->auth(), Init); |
| 158 DCHECK(instance); | 148 DCHECK(instance); |
| 159 instance->Init(binding_.CreateInterfacePtrAndBind()); | 149 instance->Init(binding_.CreateInterfacePtrAndBind()); |
| 160 } | 150 } |
| 161 | 151 |
| 162 void ArcAuthService::OnInstanceClosed() { | 152 void ArcAuthService::OnInstanceClosed() { |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 349 |
| 360 notifier_->Notify( | 350 notifier_->Notify( |
| 361 !IsArcOptInVerificationDisabled(), auth_code, | 351 !IsArcOptInVerificationDisabled(), auth_code, |
| 362 ArcSessionManager::Get()->auth_context()->full_account_id(), | 352 ArcSessionManager::Get()->auth_context()->full_account_id(), |
| 363 GetAccountType(), | 353 GetAccountType(), |
| 364 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile())); | 354 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile())); |
| 365 notifier_.reset(); | 355 notifier_.reset(); |
| 366 } | 356 } |
| 367 | 357 |
| 368 } // namespace arc | 358 } // namespace arc |
| OLD | NEW |