| OLD | NEW |
| 1 // Copyright 2015 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 #include "chrome/browser/chromeos/arc/arc_auth_service.h" | 5 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/common/shelf/shelf_delegate.h" | 9 #include "ash/common/shelf/shelf_delegate.h" |
| 10 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 43 #include "components/prefs/pref_service.h" | 43 #include "components/prefs/pref_service.h" |
| 44 #include "components/sync_preferences/pref_service_syncable.h" | 44 #include "components/sync_preferences/pref_service_syncable.h" |
| 45 #include "components/user_manager/user.h" | 45 #include "components/user_manager/user.h" |
| 46 #include "content/public/browser/browser_thread.h" | 46 #include "content/public/browser/browser_thread.h" |
| 47 #include "extensions/browser/extension_prefs.h" | 47 #include "extensions/browser/extension_prefs.h" |
| 48 | 48 |
| 49 namespace arc { | 49 namespace arc { |
| 50 | 50 |
| 51 namespace { | 51 namespace { |
| 52 | 52 |
| 53 constexpr size_t kMinVersionForOnAccountInfoReady = 5; | |
| 54 | |
| 55 // Weak pointer. This class is owned by ArcServiceManager. | 53 // Weak pointer. This class is owned by ArcServiceManager. |
| 56 ArcAuthService* g_arc_auth_service = nullptr; | 54 ArcSessionManager* g_arc_session_manager = nullptr; |
| 57 | 55 |
| 58 // Skip creating UI in unit tests | 56 // Skip creating UI in unit tests |
| 59 bool g_disable_ui_for_testing = false; | 57 bool g_disable_ui_for_testing = false; |
| 60 | 58 |
| 61 // Use specified ash::ShelfDelegate for unit tests. | 59 // Use specified ash::ShelfDelegate for unit tests. |
| 62 ash::ShelfDelegate* g_shelf_delegate_for_testing = nullptr; | 60 ash::ShelfDelegate* g_shelf_delegate_for_testing = nullptr; |
| 63 | 61 |
| 64 // The Android management check is disabled by default, it's used only for | 62 // The Android management check is disabled by default, it's used only for |
| 65 // testing. | 63 // testing. |
| 66 bool g_enable_check_android_management_for_testing = false; | 64 bool g_enable_check_android_management_for_testing = false; |
| 67 | 65 |
| 68 // Maximum amount of time we'll wait for ARC to finish booting up. Once this | 66 // Maximum amount of time we'll wait for ARC to finish booting up. Once this |
| 69 // timeout expires, keep ARC running in case the user wants to file feedback, | 67 // timeout expires, keep ARC running in case the user wants to file feedback, |
| 70 // but present the UI to try again. | 68 // but present the UI to try again. |
| 71 constexpr base::TimeDelta kArcSignInTimeout = base::TimeDelta::FromMinutes(5); | 69 constexpr base::TimeDelta kArcSignInTimeout = base::TimeDelta::FromMinutes(5); |
| 72 | 70 |
| 73 ash::ShelfDelegate* GetShelfDelegate() { | 71 ash::ShelfDelegate* GetShelfDelegate() { |
| 74 if (g_shelf_delegate_for_testing) | 72 if (g_shelf_delegate_for_testing) |
| 75 return g_shelf_delegate_for_testing; | 73 return g_shelf_delegate_for_testing; |
| 76 if (ash::WmShell::HasInstance()) { | 74 if (ash::WmShell::HasInstance()) { |
| 77 DCHECK(ash::WmShell::Get()->shelf_delegate()); | 75 DCHECK(ash::WmShell::Get()->shelf_delegate()); |
| 78 return ash::WmShell::Get()->shelf_delegate(); | 76 return ash::WmShell::Get()->shelf_delegate(); |
| 79 } | 77 } |
| 80 return nullptr; | 78 return nullptr; |
| 81 } | 79 } |
| 82 | 80 |
| 83 ProvisioningResult ConvertArcSignInFailureReasonToProvisioningResult( | |
| 84 mojom::ArcSignInFailureReason reason) { | |
| 85 using ArcSignInFailureReason = mojom::ArcSignInFailureReason; | |
| 86 | |
| 87 #define MAP_PROVISIONING_RESULT(name) \ | |
| 88 case ArcSignInFailureReason::name: \ | |
| 89 return ProvisioningResult::name | |
| 90 | |
| 91 switch (reason) { | |
| 92 MAP_PROVISIONING_RESULT(UNKNOWN_ERROR); | |
| 93 MAP_PROVISIONING_RESULT(MOJO_VERSION_MISMATCH); | |
| 94 MAP_PROVISIONING_RESULT(MOJO_CALL_TIMEOUT); | |
| 95 MAP_PROVISIONING_RESULT(DEVICE_CHECK_IN_FAILED); | |
| 96 MAP_PROVISIONING_RESULT(DEVICE_CHECK_IN_TIMEOUT); | |
| 97 MAP_PROVISIONING_RESULT(DEVICE_CHECK_IN_INTERNAL_ERROR); | |
| 98 MAP_PROVISIONING_RESULT(GMS_NETWORK_ERROR); | |
| 99 MAP_PROVISIONING_RESULT(GMS_SERVICE_UNAVAILABLE); | |
| 100 MAP_PROVISIONING_RESULT(GMS_BAD_AUTHENTICATION); | |
| 101 MAP_PROVISIONING_RESULT(GMS_SIGN_IN_FAILED); | |
| 102 MAP_PROVISIONING_RESULT(GMS_SIGN_IN_TIMEOUT); | |
| 103 MAP_PROVISIONING_RESULT(GMS_SIGN_IN_INTERNAL_ERROR); | |
| 104 MAP_PROVISIONING_RESULT(CLOUD_PROVISION_FLOW_FAILED); | |
| 105 MAP_PROVISIONING_RESULT(CLOUD_PROVISION_FLOW_TIMEOUT); | |
| 106 MAP_PROVISIONING_RESULT(CLOUD_PROVISION_FLOW_INTERNAL_ERROR); | |
| 107 } | |
| 108 #undef MAP_PROVISIONING_RESULT | |
| 109 | |
| 110 NOTREACHED() << "unknown reason: " << static_cast<int>(reason); | |
| 111 return ProvisioningResult::UNKNOWN_ERROR; | |
| 112 } | |
| 113 | |
| 114 bool IsArcKioskMode() { | |
| 115 return user_manager::UserManager::Get()->IsLoggedInAsArcKioskApp(); | |
| 116 } | |
| 117 | |
| 118 mojom::ChromeAccountType GetAccountType() { | |
| 119 if (IsArcKioskMode()) | |
| 120 return mojom::ChromeAccountType::ROBOT_ACCOUNT; | |
| 121 return mojom::ChromeAccountType::USER_ACCOUNT; | |
| 122 } | |
| 123 | |
| 124 } // namespace | 81 } // namespace |
| 125 | 82 |
| 126 // TODO(lhchavez): Get rid of this class once we can safely remove all the | 83 ArcSessionManager::ArcSessionManager(ArcBridgeService* bridge_service) |
| 127 // deprecated interfaces and only need to care about one type of callback. | 84 : ArcService(bridge_service), weak_ptr_factory_(this) { |
| 128 class ArcAuthService::AccountInfoNotifier { | |
| 129 public: | |
| 130 explicit AccountInfoNotifier( | |
| 131 const GetAuthCodeDeprecatedCallback& auth_callback) | |
| 132 : callback_type_(CallbackType::AUTH_CODE), | |
| 133 auth_callback_(auth_callback) {} | |
| 134 | |
| 135 explicit AccountInfoNotifier( | |
| 136 const GetAuthCodeAndAccountTypeDeprecatedCallback& auth_account_callback) | |
| 137 : callback_type_(CallbackType::AUTH_CODE_AND_ACCOUNT), | |
| 138 auth_account_callback_(auth_account_callback) {} | |
| 139 | |
| 140 explicit AccountInfoNotifier(const AccountInfoCallback& account_info_callback) | |
| 141 : callback_type_(CallbackType::ACCOUNT_INFO), | |
| 142 account_info_callback_(account_info_callback) {} | |
| 143 | |
| 144 void Notify(bool is_enforced, | |
| 145 const std::string& auth_code, | |
| 146 mojom::ChromeAccountType account_type, | |
| 147 bool is_managed) { | |
| 148 switch (callback_type_) { | |
| 149 case CallbackType::AUTH_CODE: | |
| 150 DCHECK(!auth_callback_.is_null()); | |
| 151 auth_callback_.Run(auth_code, is_enforced); | |
| 152 break; | |
| 153 case CallbackType::AUTH_CODE_AND_ACCOUNT: | |
| 154 DCHECK(!auth_account_callback_.is_null()); | |
| 155 auth_account_callback_.Run(auth_code, is_enforced, account_type); | |
| 156 break; | |
| 157 case CallbackType::ACCOUNT_INFO: | |
| 158 DCHECK(!account_info_callback_.is_null()); | |
| 159 mojom::AccountInfoPtr account_info = mojom::AccountInfo::New(); | |
| 160 if (!is_enforced) { | |
| 161 account_info->auth_code = base::nullopt; | |
| 162 } else { | |
| 163 account_info->auth_code = auth_code; | |
| 164 } | |
| 165 account_info->account_type = account_type; | |
| 166 account_info->is_managed = is_managed; | |
| 167 account_info_callback_.Run(std::move(account_info)); | |
| 168 break; | |
| 169 } | |
| 170 } | |
| 171 | |
| 172 private: | |
| 173 enum class CallbackType { AUTH_CODE, AUTH_CODE_AND_ACCOUNT, ACCOUNT_INFO }; | |
| 174 | |
| 175 const CallbackType callback_type_; | |
| 176 const GetAuthCodeDeprecatedCallback auth_callback_; | |
| 177 const GetAuthCodeAndAccountTypeDeprecatedCallback auth_account_callback_; | |
| 178 const AccountInfoCallback account_info_callback_; | |
| 179 }; | |
| 180 | |
| 181 ArcAuthService::ArcAuthService(ArcBridgeService* bridge_service) | |
| 182 : ArcService(bridge_service), binding_(this), weak_ptr_factory_(this) { | |
| 183 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 85 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 184 DCHECK(!g_arc_auth_service); | 86 DCHECK(!g_arc_session_manager); |
| 185 | 87 g_arc_session_manager = this; |
| 186 g_arc_auth_service = this; | |
| 187 | 88 |
| 188 arc_bridge_service()->AddObserver(this); | 89 arc_bridge_service()->AddObserver(this); |
| 189 arc_bridge_service()->auth()->AddObserver(this); | |
| 190 } | 90 } |
| 191 | 91 |
| 192 ArcAuthService::~ArcAuthService() { | 92 ArcSessionManager::~ArcSessionManager() { |
| 193 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 93 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 194 DCHECK_EQ(this, g_arc_auth_service); | |
| 195 | 94 |
| 196 Shutdown(); | 95 Shutdown(); |
| 197 arc_bridge_service()->auth()->RemoveObserver(this); | |
| 198 arc_bridge_service()->RemoveObserver(this); | 96 arc_bridge_service()->RemoveObserver(this); |
| 199 | 97 |
| 200 g_arc_auth_service = nullptr; | 98 DCHECK_EQ(this, g_arc_session_manager); |
| 99 g_arc_session_manager = nullptr; |
| 201 } | 100 } |
| 202 | 101 |
| 203 // static | 102 // static |
| 204 ArcAuthService* ArcAuthService::Get() { | 103 ArcSessionManager* ArcSessionManager::Get() { |
| 205 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 104 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 206 return g_arc_auth_service; | 105 return g_arc_session_manager; |
| 207 } | 106 } |
| 208 | 107 |
| 209 // static | 108 // static |
| 210 void ArcAuthService::RegisterProfilePrefs( | 109 void ArcSessionManager::RegisterProfilePrefs( |
| 211 user_prefs::PrefRegistrySyncable* registry) { | 110 user_prefs::PrefRegistrySyncable* registry) { |
| 212 // TODO(dspaid): Implement a mechanism to allow this to sync on first boot | 111 // TODO(dspaid): Implement a mechanism to allow this to sync on first boot |
| 213 // only. | 112 // only. |
| 214 registry->RegisterBooleanPref(prefs::kArcEnabled, false); | 113 registry->RegisterBooleanPref(prefs::kArcEnabled, false); |
| 215 registry->RegisterBooleanPref(prefs::kArcSignedIn, false); | 114 registry->RegisterBooleanPref(prefs::kArcSignedIn, false); |
| 216 registry->RegisterBooleanPref(prefs::kArcTermsAccepted, false); | 115 registry->RegisterBooleanPref(prefs::kArcTermsAccepted, false); |
| 217 registry->RegisterBooleanPref(prefs::kArcBackupRestoreEnabled, true); | 116 registry->RegisterBooleanPref(prefs::kArcBackupRestoreEnabled, true); |
| 218 registry->RegisterBooleanPref(prefs::kArcLocationServiceEnabled, true); | 117 registry->RegisterBooleanPref(prefs::kArcLocationServiceEnabled, true); |
| 219 } | 118 } |
| 220 | 119 |
| 221 // static | 120 // static |
| 222 void ArcAuthService::DisableUIForTesting() { | 121 void ArcSessionManager::DisableUIForTesting() { |
| 223 g_disable_ui_for_testing = true; | 122 g_disable_ui_for_testing = true; |
| 224 } | 123 } |
| 225 | 124 |
| 226 // static | 125 // static |
| 227 void ArcAuthService::SetShelfDelegateForTesting( | 126 void ArcSessionManager::SetShelfDelegateForTesting( |
| 228 ash::ShelfDelegate* shelf_delegate) { | 127 ash::ShelfDelegate* shelf_delegate) { |
| 229 g_shelf_delegate_for_testing = shelf_delegate; | 128 g_shelf_delegate_for_testing = shelf_delegate; |
| 230 } | 129 } |
| 231 | 130 |
| 232 // static | 131 // static |
| 233 bool ArcAuthService::IsOptInVerificationDisabled() { | 132 bool ArcSessionManager::IsOptInVerificationDisabled() { |
| 234 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 133 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 235 chromeos::switches::kDisableArcOptInVerification); | 134 chromeos::switches::kDisableArcOptInVerification); |
| 236 } | 135 } |
| 237 | 136 |
| 238 // static | 137 // static |
| 239 void ArcAuthService::EnableCheckAndroidManagementForTesting() { | 138 void ArcSessionManager::EnableCheckAndroidManagementForTesting() { |
| 240 g_enable_check_android_management_for_testing = true; | 139 g_enable_check_android_management_for_testing = true; |
| 241 } | 140 } |
| 242 | 141 |
| 243 // static | 142 // static |
| 244 bool ArcAuthService::IsAllowedForProfile(const Profile* profile) { | 143 bool ArcSessionManager::IsAllowedForProfile(const Profile* profile) { |
| 245 if (!ArcBridgeService::GetEnabled(base::CommandLine::ForCurrentProcess())) { | 144 if (!ArcBridgeService::GetEnabled(base::CommandLine::ForCurrentProcess())) { |
| 246 VLOG(1) << "Arc is not enabled."; | 145 VLOG(1) << "Arc is not enabled."; |
| 247 return false; | 146 return false; |
| 248 } | 147 } |
| 249 | 148 |
| 250 if (!profile) { | 149 if (!profile) { |
| 251 VLOG(1) << "ARC is not supported for systems without profile."; | 150 VLOG(1) << "ARC is not supported for systems without profile."; |
| 252 return false; | 151 return false; |
| 253 } | 152 } |
| 254 | 153 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 271 | 170 |
| 272 if (user_manager::UserManager::Get() | 171 if (user_manager::UserManager::Get() |
| 273 ->IsCurrentUserCryptohomeDataEphemeral()) { | 172 ->IsCurrentUserCryptohomeDataEphemeral()) { |
| 274 VLOG(2) << "Users with ephemeral data are not supported in Arc."; | 173 VLOG(2) << "Users with ephemeral data are not supported in Arc."; |
| 275 return false; | 174 return false; |
| 276 } | 175 } |
| 277 | 176 |
| 278 return true; | 177 return true; |
| 279 } | 178 } |
| 280 | 179 |
| 281 void ArcAuthService::OnInstanceReady() { | 180 // static |
| 282 auto* instance = arc_bridge_service()->auth()->GetInstanceForMethod("Init"); | 181 bool ArcSessionManager::IsArcKioskMode() { |
| 283 DCHECK(instance); | 182 return user_manager::UserManager::Get()->IsLoggedInAsArcKioskApp(); |
| 284 instance->Init(binding_.CreateInterfacePtrAndBind()); | |
| 285 } | 183 } |
| 286 | 184 |
| 287 void ArcAuthService::OnBridgeStopped(ArcBridgeService::StopReason reason) { | 185 void ArcSessionManager::OnBridgeStopped(ArcBridgeService::StopReason reason) { |
| 288 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. | 186 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. |
| 289 if (arc_sign_in_timer_.IsRunning()) { | 187 if (arc_sign_in_timer_.IsRunning()) { |
| 290 OnProvisioningFinished(ProvisioningResult::ARC_STOPPED); | 188 OnProvisioningFinished(ProvisioningResult::ARC_STOPPED); |
| 291 } | 189 } |
| 292 | 190 |
| 293 if (clear_required_) { | 191 if (clear_required_) { |
| 294 // This should be always true, but just in case as this is looked at | 192 // This should be always true, but just in case as this is looked at |
| 295 // inside RemoveArcData() at first. | 193 // inside RemoveArcData() at first. |
| 296 DCHECK(arc_bridge_service()->stopped()); | 194 DCHECK(arc_bridge_service()->stopped()); |
| 297 RemoveArcData(); | 195 RemoveArcData(); |
| 298 } else { | 196 } else { |
| 299 // To support special "Stop and enable ARC" procedure for enterprise, | 197 // To support special "Stop and enable ARC" procedure for enterprise, |
| 300 // here call OnArcDataRemoved(true) as if the data removal is successfully | 198 // here call OnArcDataRemoved(true) as if the data removal is successfully |
| 301 // done. | 199 // done. |
| 302 // TODO(hidehiko): Restructure the code. crbug.com/665316 | 200 // TODO(hidehiko): Restructure the code. crbug.com/665316 |
| 303 base::ThreadTaskRunnerHandle::Get()->PostTask( | 201 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 304 FROM_HERE, base::Bind(&ArcAuthService::OnArcDataRemoved, | 202 FROM_HERE, base::Bind(&ArcSessionManager::OnArcDataRemoved, |
| 305 weak_ptr_factory_.GetWeakPtr(), true)); | 203 weak_ptr_factory_.GetWeakPtr(), true)); |
| 306 } | 204 } |
| 307 } | 205 } |
| 308 | 206 |
| 309 void ArcAuthService::RemoveArcData() { | 207 void ArcSessionManager::RemoveArcData() { |
| 310 if (!arc_bridge_service()->stopped()) { | 208 if (!arc_bridge_service()->stopped()) { |
| 311 // Just set a flag. On bridge stopped, this will be re-called, | 209 // Just set a flag. On bridge stopped, this will be re-called, |
| 312 // then session manager should remove the data. | 210 // then session manager should remove the data. |
| 313 clear_required_ = true; | 211 clear_required_ = true; |
| 314 return; | 212 return; |
| 315 } | 213 } |
| 316 clear_required_ = false; | 214 clear_required_ = false; |
| 317 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( | 215 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( |
| 318 cryptohome::Identification( | 216 cryptohome::Identification( |
| 319 multi_user_util::GetAccountIdFromProfile(profile_)), | 217 multi_user_util::GetAccountIdFromProfile(profile_)), |
| 320 base::Bind(&ArcAuthService::OnArcDataRemoved, | 218 base::Bind(&ArcSessionManager::OnArcDataRemoved, |
| 321 weak_ptr_factory_.GetWeakPtr())); | 219 weak_ptr_factory_.GetWeakPtr())); |
| 322 } | 220 } |
| 323 | 221 |
| 324 void ArcAuthService::OnArcDataRemoved(bool success) { | 222 void ArcSessionManager::OnArcDataRemoved(bool success) { |
| 325 LOG_IF(ERROR, !success) << "Required ARC user data wipe failed."; | 223 LOG_IF(ERROR, !success) << "Required ARC user data wipe failed."; |
| 326 | 224 |
| 327 // Here check if |reenable_arc_| is marked or not. | 225 // Here check if |reenable_arc_| is marked or not. |
| 328 // The only case this happens should be in the special case for enterprise | 226 // The only case this happens should be in the special case for enterprise |
| 329 // "on managed lost" case. In that case, OnBridgeStopped() should trigger | 227 // "on managed lost" case. In that case, OnBridgeStopped() should trigger |
| 330 // the RemoveArcData(), then this. | 228 // the RemoveArcData(), then this. |
| 331 // TODO(hidehiko): Restructure the code. | 229 // TODO(hidehiko): Restructure the code. |
| 332 if (!reenable_arc_) | 230 if (!reenable_arc_) |
| 333 return; | 231 return; |
| 334 | 232 |
| 335 // Restart ARC anyway. Let the enterprise reporting instance decide whether | 233 // Restart ARC anyway. Let the enterprise reporting instance decide whether |
| 336 // the ARC user data wipe is still required or not. | 234 // the ARC user data wipe is still required or not. |
| 337 reenable_arc_ = false; | 235 reenable_arc_ = false; |
| 338 VLOG(1) << "Reenable ARC"; | 236 VLOG(1) << "Reenable ARC"; |
| 339 EnableArc(); | 237 EnableArc(); |
| 340 } | 238 } |
| 341 | 239 |
| 342 void ArcAuthService::GetAuthCodeDeprecated0( | 240 void ArcSessionManager::OnProvisioningFinished(ProvisioningResult result) { |
| 343 const GetAuthCodeDeprecated0Callback& callback) { | |
| 344 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 345 NOTREACHED() << "GetAuthCodeDeprecated0() should no longer be callable"; | |
| 346 } | |
| 347 | |
| 348 void ArcAuthService::GetAuthCodeDeprecated( | |
| 349 const GetAuthCodeDeprecatedCallback& callback) { | |
| 350 // For robot account we must use RequestAccountInfo because it allows | |
| 351 // to specify account type. | |
| 352 DCHECK(!IsArcKioskMode()); | |
| 353 RequestAccountInfoInternal( | |
| 354 base::MakeUnique<ArcAuthService::AccountInfoNotifier>(callback)); | |
| 355 } | |
| 356 | |
| 357 void ArcAuthService::GetAuthCodeAndAccountTypeDeprecated( | |
| 358 const GetAuthCodeAndAccountTypeDeprecatedCallback& callback) { | |
| 359 RequestAccountInfoInternal( | |
| 360 base::MakeUnique<ArcAuthService::AccountInfoNotifier>(callback)); | |
| 361 } | |
| 362 | |
| 363 void ArcAuthService::RequestAccountInfo() { | |
| 364 RequestAccountInfoInternal( | |
| 365 base::MakeUnique<ArcAuthService::AccountInfoNotifier>( | |
| 366 base::Bind(&ArcAuthService::OnAccountInfoReady, | |
| 367 weak_ptr_factory_.GetWeakPtr()))); | |
| 368 } | |
| 369 | |
| 370 void ArcAuthService::OnAccountInfoReady(mojom::AccountInfoPtr account_info) { | |
| 371 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 372 auto* instance = arc_bridge_service()->auth()->GetInstanceForMethod( | |
| 373 "OnAccountInfoReady", kMinVersionForOnAccountInfoReady); | |
| 374 DCHECK(instance); | |
| 375 instance->OnAccountInfoReady(std::move(account_info)); | |
| 376 } | |
| 377 | |
| 378 void ArcAuthService::RequestAccountInfoInternal( | |
| 379 std::unique_ptr<ArcAuthService::AccountInfoNotifier> | |
| 380 account_info_notifier) { | |
| 381 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 382 // No other auth code-related operation may be in progress. | |
| 383 DCHECK(!account_info_notifier_); | |
| 384 | |
| 385 if (IsOptInVerificationDisabled()) { | |
| 386 account_info_notifier->Notify(false /* = is_enforced */, std::string(), | |
| 387 GetAccountType(), | |
| 388 policy_util::IsAccountManaged(profile_)); | |
| 389 return; | |
| 390 } | |
| 391 | |
| 392 // Hereafter asynchronous operation. Remember the notifier. | |
| 393 account_info_notifier_ = std::move(account_info_notifier); | |
| 394 | |
| 395 // In Kiosk mode, use Robot auth code fetching. | |
| 396 if (IsArcKioskMode()) { | |
| 397 arc_robot_auth_.reset(new ArcRobotAuth()); | |
| 398 arc_robot_auth_->FetchRobotAuthCode( | |
| 399 base::Bind(&ArcAuthService::OnRobotAuthCodeFetched, | |
| 400 weak_ptr_factory_.GetWeakPtr())); | |
| 401 return; | |
| 402 } | |
| 403 | |
| 404 // If endpoint is passed via command line flag, use automatic auth code | |
| 405 // fetching. | |
| 406 const base::CommandLine* command_line = | |
| 407 base::CommandLine::ForCurrentProcess(); | |
| 408 if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) { | |
| 409 std::string auth_endpoint = command_line->GetSwitchValueASCII( | |
| 410 chromeos::switches::kArcUseAuthEndpoint); | |
| 411 if (!auth_endpoint.empty()) { | |
| 412 DCHECK(!auth_code_fetcher_); | |
| 413 auth_code_fetcher_ = base::MakeUnique<ArcAuthCodeFetcher>( | |
| 414 profile_, context_.get(), auth_endpoint); | |
| 415 auth_code_fetcher_->Fetch(base::Bind(&ArcAuthService::OnAuthCodeFetched, | |
| 416 weak_ptr_factory_.GetWeakPtr())); | |
| 417 return; | |
| 418 } | |
| 419 } | |
| 420 | |
| 421 // Otherwise, show LSO page to user, and let them click "Sign in" button. | |
| 422 if (support_host_) | |
| 423 support_host_->ShowLso(); | |
| 424 } | |
| 425 | |
| 426 void ArcAuthService::OnRobotAuthCodeFetched( | |
| 427 const std::string& robot_auth_code) { | |
| 428 // We fetching robot auth code for ARC kiosk only. | |
| 429 DCHECK(IsArcKioskMode()); | |
| 430 | |
| 431 // Current instance of ArcRobotAuth became useless. | |
| 432 arc_robot_auth_.reset(); | |
| 433 | |
| 434 if (robot_auth_code.empty()) { | |
| 435 VLOG(1) << "Robot account auth code fetching error"; | |
| 436 // Log out the user. All the cleanup will be done in Shutdown() method. | |
| 437 // The callback is not called because auth code is empty. | |
| 438 chrome::AttemptUserExit(); | |
| 439 return; | |
| 440 } | |
| 441 | |
| 442 OnAuthCodeObtained(robot_auth_code); | |
| 443 } | |
| 444 | |
| 445 void ArcAuthService::OnAuthCodeFetched(const std::string& auth_code) { | |
| 446 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 447 auth_code_fetcher_.reset(); | |
| 448 | |
| 449 if (auth_code.empty()) { | |
| 450 OnProvisioningFinished( | |
| 451 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); | |
| 452 return; | |
| 453 } | |
| 454 | |
| 455 OnAuthCodeObtained(auth_code); | |
| 456 } | |
| 457 | |
| 458 void ArcAuthService::OnSignInComplete() { | |
| 459 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 460 DCHECK_EQ(state_, State::ACTIVE); | |
| 461 OnProvisioningFinished(ProvisioningResult::SUCCESS); | |
| 462 } | |
| 463 | |
| 464 void ArcAuthService::OnSignInFailed(mojom::ArcSignInFailureReason reason) { | |
| 465 OnProvisioningFinished( | |
| 466 ConvertArcSignInFailureReasonToProvisioningResult(reason)); | |
| 467 } | |
| 468 | |
| 469 void ArcAuthService::OnProvisioningFinished(ProvisioningResult result) { | |
| 470 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 241 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 471 DCHECK_EQ(state_, State::ACTIVE); | 242 DCHECK_EQ(state_, State::ACTIVE); |
| 472 | 243 |
| 473 if (result == ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR) { | 244 if (result == ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR) { |
| 474 // For backword compatibility, use NETWORK_ERROR for | 245 // For backword compatibility, use NETWORK_ERROR for |
| 475 // CHROME_SERVER_COMMUNICATION_ERROR case. | 246 // CHROME_SERVER_COMMUNICATION_ERROR case. |
| 476 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 247 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 477 } else if (!sign_in_time_.is_null()) { | 248 } else if (!sign_in_time_.is_null()) { |
| 478 arc_sign_in_timer_.Stop(); | 249 arc_sign_in_timer_.Stop(); |
| 479 | 250 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 result == ProvisioningResult::UNKNOWN_ERROR) { | 328 result == ProvisioningResult::UNKNOWN_ERROR) { |
| 558 RemoveArcData(); | 329 RemoveArcData(); |
| 559 } | 330 } |
| 560 | 331 |
| 561 // We'll delay shutting down the bridge in this case to allow people to send | 332 // We'll delay shutting down the bridge in this case to allow people to send |
| 562 // feedback. | 333 // feedback. |
| 563 if (support_host_) | 334 if (support_host_) |
| 564 support_host_->ShowError(error, true /* = show send feedback button */); | 335 support_host_->ShowError(error, true /* = show send feedback button */); |
| 565 } | 336 } |
| 566 | 337 |
| 567 void ArcAuthService::GetIsAccountManagedDeprecated( | 338 void ArcSessionManager::SetState(State state) { |
| 568 const GetIsAccountManagedDeprecatedCallback& callback) { | |
| 569 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 570 | |
| 571 callback.Run(policy_util::IsAccountManaged(profile_)); | |
| 572 } | |
| 573 | |
| 574 void ArcAuthService::SetState(State state) { | |
| 575 state_ = state; | 339 state_ = state; |
| 576 } | 340 } |
| 577 | 341 |
| 578 bool ArcAuthService::IsAllowed() const { | 342 bool ArcSessionManager::IsAllowed() const { |
| 579 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 343 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 580 return profile_ != nullptr; | 344 return profile_ != nullptr; |
| 581 } | 345 } |
| 582 | 346 |
| 583 void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) { | 347 void ArcSessionManager::OnPrimaryUserProfilePrepared(Profile* profile) { |
| 584 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 348 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 585 DCHECK(profile && profile != profile_); | 349 DCHECK(profile && profile != profile_); |
| 586 | 350 |
| 587 Shutdown(); | 351 Shutdown(); |
| 588 | 352 |
| 589 if (!IsAllowedForProfile(profile)) | 353 if (!IsAllowedForProfile(profile)) |
| 590 return; | 354 return; |
| 591 | 355 |
| 592 // TODO(khmel): Move this to IsAllowedForProfile. | 356 // TODO(khmel): Move this to IsAllowedForProfile. |
| 593 if (policy_util::IsArcDisabledForEnterprise() && | 357 if (policy_util::IsArcDisabledForEnterprise() && |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 StartArc(); | 399 StartArc(); |
| 636 return; | 400 return; |
| 637 } | 401 } |
| 638 | 402 |
| 639 if (!g_disable_ui_for_testing || | 403 if (!g_disable_ui_for_testing || |
| 640 g_enable_check_android_management_for_testing) { | 404 g_enable_check_android_management_for_testing) { |
| 641 ArcAndroidManagementChecker::StartClient(); | 405 ArcAndroidManagementChecker::StartClient(); |
| 642 } | 406 } |
| 643 pref_change_registrar_.Init(profile_->GetPrefs()); | 407 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 644 pref_change_registrar_.Add( | 408 pref_change_registrar_.Add( |
| 645 prefs::kArcEnabled, base::Bind(&ArcAuthService::OnOptInPreferenceChanged, | 409 prefs::kArcEnabled, |
| 646 weak_ptr_factory_.GetWeakPtr())); | 410 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged, |
| 411 weak_ptr_factory_.GetWeakPtr())); |
| 647 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { | 412 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { |
| 648 OnOptInPreferenceChanged(); | 413 OnOptInPreferenceChanged(); |
| 649 } else { | 414 } else { |
| 650 RemoveArcData(); | 415 RemoveArcData(); |
| 651 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); | 416 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); |
| 652 OnIsSyncingChanged(); | 417 OnIsSyncingChanged(); |
| 653 } | 418 } |
| 654 } | 419 } |
| 655 | 420 |
| 656 void ArcAuthService::OnIsSyncingChanged() { | 421 void ArcSessionManager::OnIsSyncingChanged() { |
| 657 sync_preferences::PrefServiceSyncable* const pref_service_syncable = | 422 sync_preferences::PrefServiceSyncable* const pref_service_syncable = |
| 658 PrefServiceSyncableFromProfile(profile_); | 423 PrefServiceSyncableFromProfile(profile_); |
| 659 if (!pref_service_syncable->IsSyncing()) | 424 if (!pref_service_syncable->IsSyncing()) |
| 660 return; | 425 return; |
| 661 | 426 |
| 662 pref_service_syncable->RemoveObserver(this); | 427 pref_service_syncable->RemoveObserver(this); |
| 663 | 428 |
| 664 if (IsArcEnabled()) | 429 if (IsArcEnabled()) |
| 665 OnOptInPreferenceChanged(); | 430 OnOptInPreferenceChanged(); |
| 666 } | 431 } |
| 667 | 432 |
| 668 void ArcAuthService::Shutdown() { | 433 void ArcSessionManager::Shutdown() { |
| 669 ShutdownBridge(); | 434 ShutdownBridge(); |
| 670 if (support_host_) { | 435 if (support_host_) { |
| 671 support_host_->Close(); | 436 support_host_->Close(); |
| 672 support_host_->RemoveObserver(this); | 437 support_host_->RemoveObserver(this); |
| 673 support_host_.reset(); | 438 support_host_.reset(); |
| 674 } | 439 } |
| 675 if (profile_) { | 440 if (profile_) { |
| 676 sync_preferences::PrefServiceSyncable* pref_service_syncable = | 441 sync_preferences::PrefServiceSyncable* pref_service_syncable = |
| 677 PrefServiceSyncableFromProfile(profile_); | 442 PrefServiceSyncableFromProfile(profile_); |
| 678 pref_service_syncable->RemoveObserver(this); | 443 pref_service_syncable->RemoveObserver(this); |
| 679 pref_service_syncable->RemoveSyncedPrefObserver(prefs::kArcEnabled, this); | 444 pref_service_syncable->RemoveSyncedPrefObserver(prefs::kArcEnabled, this); |
| 680 } | 445 } |
| 681 pref_change_registrar_.RemoveAll(); | 446 pref_change_registrar_.RemoveAll(); |
| 682 context_.reset(); | 447 context_.reset(); |
| 683 profile_ = nullptr; | 448 profile_ = nullptr; |
| 684 arc_robot_auth_.reset(); | |
| 685 SetState(State::NOT_INITIALIZED); | 449 SetState(State::NOT_INITIALIZED); |
| 686 } | 450 } |
| 687 | 451 |
| 688 void ArcAuthService::OnSyncedPrefChanged(const std::string& path, | 452 void ArcSessionManager::OnSyncedPrefChanged(const std::string& path, |
| 689 bool from_sync) { | 453 bool from_sync) { |
| 690 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 454 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 691 | 455 |
| 692 // Update UMA only for local changes | 456 // Update UMA only for local changes |
| 693 if (!from_sync) { | 457 if (!from_sync) { |
| 694 const bool arc_enabled = | 458 const bool arc_enabled = |
| 695 profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); | 459 profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); |
| 696 UpdateOptInActionUMA(arc_enabled ? OptInActionType::OPTED_IN | 460 UpdateOptInActionUMA(arc_enabled ? OptInActionType::OPTED_IN |
| 697 : OptInActionType::OPTED_OUT); | 461 : OptInActionType::OPTED_OUT); |
| 698 | 462 |
| 699 if (!arc_enabled && !IsArcManaged()) { | 463 if (!arc_enabled && !IsArcManaged()) { |
| 700 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate(); | 464 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate(); |
| 701 if (shelf_delegate) | 465 if (shelf_delegate) |
| 702 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); | 466 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); |
| 703 } | 467 } |
| 704 } | 468 } |
| 705 } | 469 } |
| 706 | 470 |
| 707 void ArcAuthService::StopArc() { | 471 void ArcSessionManager::StopArc() { |
| 708 if (state_ != State::STOPPED) { | 472 if (state_ != State::STOPPED) { |
| 709 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); | 473 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); |
| 710 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, false); | 474 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, false); |
| 711 } | 475 } |
| 712 ShutdownBridge(); | 476 ShutdownBridge(); |
| 713 if (support_host_) | 477 if (support_host_) |
| 714 support_host_->Close(); | 478 support_host_->Close(); |
| 715 } | 479 } |
| 716 | 480 |
| 717 void ArcAuthService::OnOptInPreferenceChanged() { | 481 void ArcSessionManager::OnOptInPreferenceChanged() { |
| 718 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 482 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 719 DCHECK(profile_); | 483 DCHECK(profile_); |
| 720 | 484 |
| 721 // TODO(dspaid): Move code from OnSyncedPrefChanged into this method. | 485 // TODO(dspaid): Move code from OnSyncedPrefChanged into this method. |
| 722 OnSyncedPrefChanged(prefs::kArcEnabled, IsArcManaged()); | 486 OnSyncedPrefChanged(prefs::kArcEnabled, IsArcManaged()); |
| 723 | 487 |
| 724 const bool arc_enabled = IsArcEnabled(); | 488 const bool arc_enabled = IsArcEnabled(); |
| 725 for (auto& observer : observer_list_) | 489 for (auto& observer : observer_list_) |
| 726 observer.OnOptInEnabled(arc_enabled); | 490 observer.OnOptInEnabled(arc_enabled); |
| 727 | 491 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 750 // Note: Because the callback may be called in synchronous way (i.e. called | 514 // Note: Because the callback may be called in synchronous way (i.e. called |
| 751 // on the same stack), StartCheck() needs to be called *after* StartArc(). | 515 // on the same stack), StartCheck() needs to be called *after* StartArc(). |
| 752 // Otherwise, DisableArc() which may be called in | 516 // Otherwise, DisableArc() which may be called in |
| 753 // OnBackgroundAndroidManagementChecked() could be ignored. | 517 // OnBackgroundAndroidManagementChecked() could be ignored. |
| 754 if (!g_disable_ui_for_testing || | 518 if (!g_disable_ui_for_testing || |
| 755 g_enable_check_android_management_for_testing) { | 519 g_enable_check_android_management_for_testing) { |
| 756 android_management_checker_.reset(new ArcAndroidManagementChecker( | 520 android_management_checker_.reset(new ArcAndroidManagementChecker( |
| 757 profile_, context_->token_service(), context_->account_id(), | 521 profile_, context_->token_service(), context_->account_id(), |
| 758 true /* retry_on_error */)); | 522 true /* retry_on_error */)); |
| 759 android_management_checker_->StartCheck( | 523 android_management_checker_->StartCheck( |
| 760 base::Bind(&ArcAuthService::OnBackgroundAndroidManagementChecked, | 524 base::Bind(&ArcSessionManager::OnBackgroundAndroidManagementChecked, |
| 761 weak_ptr_factory_.GetWeakPtr())); | 525 weak_ptr_factory_.GetWeakPtr())); |
| 762 } | 526 } |
| 763 } | 527 } |
| 764 } | 528 } |
| 765 | 529 |
| 766 void ArcAuthService::ShutdownBridge() { | 530 void ArcSessionManager::ShutdownBridge() { |
| 767 arc_sign_in_timer_.Stop(); | 531 arc_sign_in_timer_.Stop(); |
| 768 playstore_launcher_.reset(); | 532 playstore_launcher_.reset(); |
| 769 account_info_notifier_.reset(); | |
| 770 android_management_checker_.reset(); | 533 android_management_checker_.reset(); |
| 771 auth_code_fetcher_.reset(); | |
| 772 arc_bridge_service()->RequestStop(); | 534 arc_bridge_service()->RequestStop(); |
| 773 if (state_ != State::NOT_INITIALIZED) | 535 if (state_ != State::NOT_INITIALIZED) |
| 774 SetState(State::STOPPED); | 536 SetState(State::STOPPED); |
| 775 for (auto& observer : observer_list_) | 537 for (auto& observer : observer_list_) |
| 776 observer.OnShutdownBridge(); | 538 observer.OnShutdownBridge(); |
| 777 } | 539 } |
| 778 | 540 |
| 779 void ArcAuthService::AddObserver(Observer* observer) { | 541 void ArcSessionManager::AddObserver(Observer* observer) { |
| 780 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 542 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 781 observer_list_.AddObserver(observer); | 543 observer_list_.AddObserver(observer); |
| 782 } | 544 } |
| 783 | 545 |
| 784 void ArcAuthService::RemoveObserver(Observer* observer) { | 546 void ArcSessionManager::RemoveObserver(Observer* observer) { |
| 785 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 547 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 786 observer_list_.RemoveObserver(observer); | 548 observer_list_.RemoveObserver(observer); |
| 787 } | 549 } |
| 788 | 550 |
| 789 // This is the special method to support enterprise mojo API. | 551 // This is the special method to support enterprise mojo API. |
| 790 // TODO(hidehiko): Remove this. | 552 // TODO(hidehiko): Remove this. |
| 791 void ArcAuthService::StopAndEnableArc() { | 553 void ArcSessionManager::StopAndEnableArc() { |
| 792 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 554 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 793 DCHECK(!arc_bridge_service()->stopped()); | 555 DCHECK(!arc_bridge_service()->stopped()); |
| 794 reenable_arc_ = true; | 556 reenable_arc_ = true; |
| 795 StopArc(); | 557 StopArc(); |
| 796 } | 558 } |
| 797 | 559 |
| 798 void ArcAuthService::StartArc() { | 560 void ArcSessionManager::StartArc() { |
| 799 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 561 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 800 arc_bridge_service()->RequestStart(); | 562 arc_bridge_service()->RequestStart(); |
| 801 SetState(State::ACTIVE); | 563 SetState(State::ACTIVE); |
| 802 } | 564 } |
| 803 | 565 |
| 804 void ArcAuthService::OnAuthCodeObtained(const std::string& auth_code) { | 566 void ArcSessionManager::OnArcSignInTimeout() { |
| 805 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 806 DCHECK(!auth_code.empty()); | |
| 807 | |
| 808 account_info_notifier_->Notify(!IsOptInVerificationDisabled(), auth_code, | |
| 809 GetAccountType(), | |
| 810 policy_util::IsAccountManaged(profile_)); | |
| 811 account_info_notifier_.reset(); | |
| 812 } | |
| 813 | |
| 814 void ArcAuthService::OnArcSignInTimeout() { | |
| 815 LOG(ERROR) << "Timed out waiting for first sign in."; | 567 LOG(ERROR) << "Timed out waiting for first sign in."; |
| 816 OnProvisioningFinished(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT); | 568 OnProvisioningFinished(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT); |
| 817 } | 569 } |
| 818 | 570 |
| 819 void ArcAuthService::CancelAuthCode() { | 571 void ArcSessionManager::CancelAuthCode() { |
| 820 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 572 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 821 | 573 |
| 822 if (state_ == State::NOT_INITIALIZED) { | 574 if (state_ == State::NOT_INITIALIZED) { |
| 823 NOTREACHED(); | 575 NOTREACHED(); |
| 824 return; | 576 return; |
| 825 } | 577 } |
| 826 | 578 |
| 827 // In case |state_| is ACTIVE, UI page can be ARC_LOADING (which means normal | 579 // In case |state_| is ACTIVE, UI page can be ARC_LOADING (which means normal |
| 828 // ARC booting) or ERROR (in case ARC can not be started). If ARC is booting | 580 // ARC booting) or ERROR (in case ARC can not be started). If ARC is booting |
| 829 // normally don't stop it on progress close. | 581 // normally don't stop it on progress close. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 842 } | 594 } |
| 843 | 595 |
| 844 StopArc(); | 596 StopArc(); |
| 845 | 597 |
| 846 if (IsArcManaged()) | 598 if (IsArcManaged()) |
| 847 return; | 599 return; |
| 848 | 600 |
| 849 DisableArc(); | 601 DisableArc(); |
| 850 } | 602 } |
| 851 | 603 |
| 852 bool ArcAuthService::IsArcManaged() const { | 604 bool ArcSessionManager::IsArcManaged() const { |
| 853 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 605 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 854 DCHECK(profile_); | 606 DCHECK(profile_); |
| 855 return profile_->GetPrefs()->IsManagedPreference(prefs::kArcEnabled); | 607 return profile_->GetPrefs()->IsManagedPreference(prefs::kArcEnabled); |
| 856 } | 608 } |
| 857 | 609 |
| 858 bool ArcAuthService::IsArcEnabled() const { | 610 bool ArcSessionManager::IsArcEnabled() const { |
| 859 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 611 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 860 if (!IsAllowed()) | 612 if (!IsAllowed()) |
| 861 return false; | 613 return false; |
| 862 | 614 |
| 863 DCHECK(profile_); | 615 DCHECK(profile_); |
| 864 return profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); | 616 return profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); |
| 865 } | 617 } |
| 866 | 618 |
| 867 void ArcAuthService::EnableArc() { | 619 void ArcSessionManager::EnableArc() { |
| 868 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 620 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 869 DCHECK(profile_); | 621 DCHECK(profile_); |
| 870 | 622 |
| 871 if (IsArcEnabled()) { | 623 if (IsArcEnabled()) { |
| 872 OnOptInPreferenceChanged(); | 624 OnOptInPreferenceChanged(); |
| 873 return; | 625 return; |
| 874 } | 626 } |
| 875 | 627 |
| 876 if (!IsArcManaged()) | 628 if (!IsArcManaged()) |
| 877 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 629 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| 878 } | 630 } |
| 879 | 631 |
| 880 void ArcAuthService::DisableArc() { | 632 void ArcSessionManager::DisableArc() { |
| 881 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 633 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 882 DCHECK(profile_); | 634 DCHECK(profile_); |
| 883 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); | 635 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); |
| 884 } | 636 } |
| 885 | 637 |
| 886 void ArcAuthService::RecordArcState() { | 638 void ArcSessionManager::RecordArcState() { |
| 887 // Only record Enabled state if ARC is allowed in the first place, so we do | 639 // Only record Enabled state if ARC is allowed in the first place, so we do |
| 888 // not split the ARC population by devices that cannot run ARC. | 640 // not split the ARC population by devices that cannot run ARC. |
| 889 if (IsAllowed()) | 641 if (IsAllowed()) |
| 890 UpdateEnabledStateUMA(IsArcEnabled()); | 642 UpdateEnabledStateUMA(IsArcEnabled()); |
| 891 } | 643 } |
| 892 | 644 |
| 893 void ArcAuthService::StartUI() { | 645 void ArcSessionManager::StartUI() { |
| 894 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 646 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 895 | 647 |
| 896 if (!arc_bridge_service()->stopped()) { | 648 if (!arc_bridge_service()->stopped()) { |
| 897 // If the user attempts to re-enable ARC while the bridge is still running | 649 // If the user attempts to re-enable ARC while the bridge is still running |
| 898 // the user should not be able to continue until the bridge has stopped. | 650 // the user should not be able to continue until the bridge has stopped. |
| 899 if (support_host_) { | 651 if (support_host_) { |
| 900 support_host_->ShowError( | 652 support_host_->ShowError( |
| 901 ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false); | 653 ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false); |
| 902 } | 654 } |
| 903 return; | 655 return; |
| 904 } | 656 } |
| 905 | 657 |
| 906 SetState(State::SHOWING_TERMS_OF_SERVICE); | 658 SetState(State::SHOWING_TERMS_OF_SERVICE); |
| 907 if (support_host_) | 659 if (support_host_) |
| 908 support_host_->ShowTermsOfService(); | 660 support_host_->ShowTermsOfService(); |
| 909 } | 661 } |
| 910 | 662 |
| 911 void ArcAuthService::StartArcAndroidManagementCheck() { | 663 void ArcSessionManager::StartArcAndroidManagementCheck() { |
| 912 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 664 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 913 DCHECK(arc_bridge_service()->stopped()); | 665 DCHECK(arc_bridge_service()->stopped()); |
| 914 DCHECK(state_ == State::SHOWING_TERMS_OF_SERVICE || | 666 DCHECK(state_ == State::SHOWING_TERMS_OF_SERVICE || |
| 915 state_ == State::CHECKING_ANDROID_MANAGEMENT); | 667 state_ == State::CHECKING_ANDROID_MANAGEMENT); |
| 916 SetState(State::CHECKING_ANDROID_MANAGEMENT); | 668 SetState(State::CHECKING_ANDROID_MANAGEMENT); |
| 917 | 669 |
| 918 android_management_checker_.reset(new ArcAndroidManagementChecker( | 670 android_management_checker_.reset(new ArcAndroidManagementChecker( |
| 919 profile_, context_->token_service(), context_->account_id(), | 671 profile_, context_->token_service(), context_->account_id(), |
| 920 false /* retry_on_error */)); | 672 false /* retry_on_error */)); |
| 921 android_management_checker_->StartCheck( | 673 android_management_checker_->StartCheck( |
| 922 base::Bind(&ArcAuthService::OnAndroidManagementChecked, | 674 base::Bind(&ArcSessionManager::OnAndroidManagementChecked, |
| 923 weak_ptr_factory_.GetWeakPtr())); | 675 weak_ptr_factory_.GetWeakPtr())); |
| 924 } | 676 } |
| 925 | 677 |
| 926 void ArcAuthService::OnAndroidManagementChecked( | 678 void ArcSessionManager::OnAndroidManagementChecked( |
| 927 policy::AndroidManagementClient::Result result) { | 679 policy::AndroidManagementClient::Result result) { |
| 928 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 680 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 929 DCHECK_EQ(state_, State::CHECKING_ANDROID_MANAGEMENT); | 681 DCHECK_EQ(state_, State::CHECKING_ANDROID_MANAGEMENT); |
| 930 | 682 |
| 931 switch (result) { | 683 switch (result) { |
| 932 case policy::AndroidManagementClient::Result::UNMANAGED: | 684 case policy::AndroidManagementClient::Result::UNMANAGED: |
| 933 VLOG(1) << "Starting ARC for first sign in."; | 685 VLOG(1) << "Starting ARC for first sign in."; |
| 934 sign_in_time_ = base::Time::Now(); | 686 sign_in_time_ = base::Time::Now(); |
| 935 arc_sign_in_timer_.Start(FROM_HERE, kArcSignInTimeout, | 687 arc_sign_in_timer_.Start( |
| 936 base::Bind(&ArcAuthService::OnArcSignInTimeout, | 688 FROM_HERE, kArcSignInTimeout, |
| 937 weak_ptr_factory_.GetWeakPtr())); | 689 base::Bind(&ArcSessionManager::OnArcSignInTimeout, |
| 690 weak_ptr_factory_.GetWeakPtr())); |
| 938 StartArc(); | 691 StartArc(); |
| 939 break; | 692 break; |
| 940 case policy::AndroidManagementClient::Result::MANAGED: | 693 case policy::AndroidManagementClient::Result::MANAGED: |
| 941 ShutdownBridge(); | 694 ShutdownBridge(); |
| 942 if (support_host_) { | 695 if (support_host_) { |
| 943 support_host_->ShowError( | 696 support_host_->ShowError( |
| 944 ArcSupportHost::Error::ANDROID_MANAGEMENT_REQUIRED_ERROR, false); | 697 ArcSupportHost::Error::ANDROID_MANAGEMENT_REQUIRED_ERROR, false); |
| 945 } | 698 } |
| 946 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); | 699 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); |
| 947 break; | 700 break; |
| 948 case policy::AndroidManagementClient::Result::ERROR: | 701 case policy::AndroidManagementClient::Result::ERROR: |
| 949 ShutdownBridge(); | 702 ShutdownBridge(); |
| 950 if (support_host_) { | 703 if (support_host_) { |
| 951 support_host_->ShowError( | 704 support_host_->ShowError( |
| 952 ArcSupportHost::Error::SERVER_COMMUNICATION_ERROR, false); | 705 ArcSupportHost::Error::SERVER_COMMUNICATION_ERROR, false); |
| 953 } | 706 } |
| 954 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 707 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 955 break; | 708 break; |
| 956 } | 709 } |
| 957 } | 710 } |
| 958 | 711 |
| 959 void ArcAuthService::OnBackgroundAndroidManagementChecked( | 712 void ArcSessionManager::OnBackgroundAndroidManagementChecked( |
| 960 policy::AndroidManagementClient::Result result) { | 713 policy::AndroidManagementClient::Result result) { |
| 961 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 714 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 962 switch (result) { | 715 switch (result) { |
| 963 case policy::AndroidManagementClient::Result::UNMANAGED: | 716 case policy::AndroidManagementClient::Result::UNMANAGED: |
| 964 // Do nothing. ARC should be started already. | 717 // Do nothing. ARC should be started already. |
| 965 break; | 718 break; |
| 966 case policy::AndroidManagementClient::Result::MANAGED: | 719 case policy::AndroidManagementClient::Result::MANAGED: |
| 967 DisableArc(); | 720 DisableArc(); |
| 968 break; | 721 break; |
| 969 case policy::AndroidManagementClient::Result::ERROR: | 722 case policy::AndroidManagementClient::Result::ERROR: |
| 970 // This code should not be reached. For background check, | 723 // This code should not be reached. For background check, |
| 971 // retry_on_error should be set. | 724 // retry_on_error should be set. |
| 972 NOTREACHED(); | 725 NOTREACHED(); |
| 973 } | 726 } |
| 974 } | 727 } |
| 975 | 728 |
| 976 void ArcAuthService::OnWindowClosed() { | 729 void ArcSessionManager::OnWindowClosed() { |
| 977 DCHECK(support_host_); | 730 DCHECK(support_host_); |
| 978 CancelAuthCode(); | 731 CancelAuthCode(); |
| 979 } | 732 } |
| 980 | 733 |
| 981 void ArcAuthService::OnTermsAgreed(bool is_metrics_enabled, | 734 void ArcSessionManager::OnTermsAgreed(bool is_metrics_enabled, |
| 982 bool is_backup_and_restore_enabled, | 735 bool is_backup_and_restore_enabled, |
| 983 bool is_location_service_enabled) { | 736 bool is_location_service_enabled) { |
| 984 DCHECK(support_host_); | 737 DCHECK(support_host_); |
| 985 | 738 |
| 986 // Terms were accepted | 739 // Terms were accepted |
| 987 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); | 740 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); |
| 988 | 741 |
| 989 // Since this is ARC support's UI event callback, preference_handler_ | 742 // Since this is ARC support's UI event callback, preference_handler_ |
| 990 // should be always created (see OnPrimaryUserProfilePrepared()). | 743 // should be always created (see OnPrimaryUserProfilePrepared()). |
| 991 // TODO(hidehiko): Simplify the logic with the code restructuring. | 744 // TODO(hidehiko): Simplify the logic with the code restructuring. |
| 992 DCHECK(preference_handler_); | 745 DCHECK(preference_handler_); |
| 993 preference_handler_->EnableMetrics(is_metrics_enabled); | 746 preference_handler_->EnableMetrics(is_metrics_enabled); |
| 994 preference_handler_->EnableBackupRestore(is_backup_and_restore_enabled); | 747 preference_handler_->EnableBackupRestore(is_backup_and_restore_enabled); |
| 995 preference_handler_->EnableLocationService(is_location_service_enabled); | 748 preference_handler_->EnableLocationService(is_location_service_enabled); |
| 996 support_host_->ShowArcLoading(); | 749 support_host_->ShowArcLoading(); |
| 997 StartArcAndroidManagementCheck(); | 750 StartArcAndroidManagementCheck(); |
| 998 } | 751 } |
| 999 | 752 |
| 1000 void ArcAuthService::OnAuthSucceeded(const std::string& auth_code) { | 753 void ArcSessionManager::OnRetryClicked() { |
| 1001 DCHECK(support_host_); | |
| 1002 OnAuthCodeObtained(auth_code); | |
| 1003 } | |
| 1004 | |
| 1005 void ArcAuthService::OnRetryClicked() { | |
| 1006 DCHECK(support_host_); | 754 DCHECK(support_host_); |
| 1007 | 755 |
| 1008 UpdateOptInActionUMA(OptInActionType::RETRY); | 756 UpdateOptInActionUMA(OptInActionType::RETRY); |
| 1009 | 757 |
| 1010 // TODO(hidehiko): Simplify the retry logic. | 758 // TODO(hidehiko): Simplify the retry logic. |
| 1011 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { | 759 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { |
| 1012 // If the user has not yet agreed on Terms of Service, then show it. | 760 // If the user has not yet agreed on Terms of Service, then show it. |
| 1013 support_host_->ShowTermsOfService(); | 761 support_host_->ShowTermsOfService(); |
| 1014 } else if (support_host_->ui_page() == ArcSupportHost::UIPage::ERROR && | 762 } else if (support_host_->ui_page() == ArcSupportHost::UIPage::ERROR && |
| 1015 !arc_bridge_service()->stopped()) { | 763 !arc_bridge_service()->stopped()) { |
| 1016 // ERROR_WITH_FEEDBACK is set in OnSignInFailed(). In the case, stopping | 764 // ERROR_WITH_FEEDBACK is set in OnSignInFailed(). In the case, stopping |
| 1017 // ARC was postponed to contain its internal state into the report. | 765 // ARC was postponed to contain its internal state into the report. |
| 1018 // Here, on retry, stop it, then restart. | 766 // Here, on retry, stop it, then restart. |
| 1019 DCHECK_EQ(State::ACTIVE, state_); | 767 DCHECK_EQ(State::ACTIVE, state_); |
| 1020 support_host_->ShowArcLoading(); | 768 support_host_->ShowArcLoading(); |
| 1021 ShutdownBridge(); | 769 ShutdownBridge(); |
| 1022 reenable_arc_ = true; | 770 reenable_arc_ = true; |
| 1023 } else if (state_ == State::ACTIVE) { | 771 } else if (state_ == State::ACTIVE) { |
| 1024 // This happens when ARC support Chrome app reports an error on "Sign in" | 772 // This case is handled in ArcAuthService. |
| 1025 // page. | 773 // Do nothing. |
| 1026 support_host_->ShowLso(); | |
| 1027 } else { | 774 } else { |
| 1028 // Otherwise, we restart ARC. Note: this is the first boot case. | 775 // Otherwise, we restart ARC. Note: this is the first boot case. |
| 1029 // For second or later boot, either ERROR_WITH_FEEDBACK case or ACTIVE | 776 // For second or later boot, either ERROR_WITH_FEEDBACK case or ACTIVE |
| 1030 // case must hit. | 777 // case must hit. |
| 1031 support_host_->ShowArcLoading(); | 778 support_host_->ShowArcLoading(); |
| 1032 StartArcAndroidManagementCheck(); | 779 StartArcAndroidManagementCheck(); |
| 1033 } | 780 } |
| 1034 } | 781 } |
| 1035 | 782 |
| 1036 void ArcAuthService::OnSendFeedbackClicked() { | 783 void ArcSessionManager::OnSendFeedbackClicked() { |
| 1037 DCHECK(support_host_); | 784 DCHECK(support_host_); |
| 1038 chrome::OpenFeedbackDialog(nullptr); | 785 chrome::OpenFeedbackDialog(nullptr); |
| 1039 } | 786 } |
| 1040 | 787 |
| 1041 void ArcAuthService::OnMetricsModeChanged(bool enabled, bool managed) { | 788 void ArcSessionManager::OnMetricsModeChanged(bool enabled, bool managed) { |
| 1042 if (!support_host_) | 789 if (!support_host_) |
| 1043 return; | 790 return; |
| 1044 support_host_->SetMetricsPreferenceCheckbox(enabled, managed); | 791 support_host_->SetMetricsPreferenceCheckbox(enabled, managed); |
| 1045 } | 792 } |
| 1046 | 793 |
| 1047 void ArcAuthService::OnBackupAndRestoreModeChanged(bool enabled, bool managed) { | 794 void ArcSessionManager::OnBackupAndRestoreModeChanged(bool enabled, |
| 795 bool managed) { |
| 1048 if (!support_host_) | 796 if (!support_host_) |
| 1049 return; | 797 return; |
| 1050 support_host_->SetBackupAndRestorePreferenceCheckbox(enabled, managed); | 798 support_host_->SetBackupAndRestorePreferenceCheckbox(enabled, managed); |
| 1051 } | 799 } |
| 1052 | 800 |
| 1053 void ArcAuthService::OnLocationServicesModeChanged(bool enabled, bool managed) { | 801 void ArcSessionManager::OnLocationServicesModeChanged(bool enabled, |
| 802 bool managed) { |
| 1054 if (!support_host_) | 803 if (!support_host_) |
| 1055 return; | 804 return; |
| 1056 support_host_->SetLocationServicesPreferenceCheckbox(enabled, managed); | 805 support_host_->SetLocationServicesPreferenceCheckbox(enabled, managed); |
| 1057 } | 806 } |
| 1058 | 807 |
| 1059 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { | 808 std::ostream& operator<<(std::ostream& os, |
| 809 const ArcSessionManager::State& state) { |
| 1060 switch (state) { | 810 switch (state) { |
| 1061 case ArcAuthService::State::NOT_INITIALIZED: | 811 case ArcSessionManager::State::NOT_INITIALIZED: |
| 1062 return os << "NOT_INITIALIZED"; | 812 return os << "NOT_INITIALIZED"; |
| 1063 case ArcAuthService::State::STOPPED: | 813 case ArcSessionManager::State::STOPPED: |
| 1064 return os << "STOPPED"; | 814 return os << "STOPPED"; |
| 1065 case ArcAuthService::State::SHOWING_TERMS_OF_SERVICE: | 815 case ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE: |
| 1066 return os << "SHOWING_TERMS_OF_SERVICE"; | 816 return os << "SHOWING_TERMS_OF_SERVICE"; |
| 1067 case ArcAuthService::State::CHECKING_ANDROID_MANAGEMENT: | 817 case ArcSessionManager::State::CHECKING_ANDROID_MANAGEMENT: |
| 1068 return os << "CHECKING_ANDROID_MANAGEMENT"; | 818 return os << "CHECKING_ANDROID_MANAGEMENT"; |
| 1069 case ArcAuthService::State::ACTIVE: | 819 case ArcSessionManager::State::ACTIVE: |
| 1070 return os << "ACTIVE"; | 820 return os << "ACTIVE"; |
| 1071 } | 821 } |
| 1072 | 822 |
| 1073 // Some compiler reports an error even if all values of an enum-class are | 823 // Some compiler reports an error even if all values of an enum-class are |
| 1074 // covered indivisually in a switch statement. | 824 // covered indivisually in a switch statement. |
| 1075 NOTREACHED(); | 825 NOTREACHED(); |
| 1076 return os; | 826 return os; |
| 1077 } | 827 } |
| 1078 | 828 |
| 1079 } // namespace arc | 829 } // namespace arc |
| OLD | NEW |