| 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 "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" |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 } | 227 } |
| 228 | 228 |
| 229 void ArcAuthService::OnBridgeStopped(ArcBridgeService::StopReason reason) { | 229 void ArcAuthService::OnBridgeStopped(ArcBridgeService::StopReason reason) { |
| 230 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. | 230 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. |
| 231 if (waiting_for_reply_) { | 231 if (waiting_for_reply_) { |
| 232 // Using SERVICE_UNAVAILABLE instead of UNKNOWN_ERROR, since the latter | 232 // Using SERVICE_UNAVAILABLE instead of UNKNOWN_ERROR, since the latter |
| 233 // causes this code to not try to stop ARC, so it would retry without the | 233 // causes this code to not try to stop ARC, so it would retry without the |
| 234 // user noticing. | 234 // user noticing. |
| 235 OnSignInFailedInternal(ProvisioningResult::ARC_STOPPED); | 235 OnSignInFailedInternal(ProvisioningResult::ARC_STOPPED); |
| 236 } | 236 } |
| 237 if (!clear_required_) | 237 |
| 238 if (clear_required_) { |
| 239 // This should be always true, but just in case as this is looked at |
| 240 // inside RemoveArcData() at first. |
| 241 DCHECK(arc_bridge_service()->stopped()); |
| 242 RemoveArcData(); |
| 243 } else { |
| 244 // To support special "Stop and enable ARC" procedure for enterprise, |
| 245 // here call OnArcDataRemoved(true) as if the data removal is successfully |
| 246 // done. |
| 247 // TODO(hidehiko): Restructure the code. |
| 248 OnArcDataRemoved(true); |
| 249 } |
| 250 } |
| 251 |
| 252 void ArcAuthService::RemoveArcData() { |
| 253 if (!arc_bridge_service()->stopped()) { |
| 254 // Just set a flag. On bridge stopped, this will be re-called, |
| 255 // then session manager should remove the data. |
| 256 clear_required_ = true; |
| 238 return; | 257 return; |
| 258 } |
| 239 clear_required_ = false; | 259 clear_required_ = false; |
| 240 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( | 260 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( |
| 241 cryptohome::Identification( | 261 cryptohome::Identification( |
| 242 multi_user_util::GetAccountIdFromProfile(profile_)), | 262 multi_user_util::GetAccountIdFromProfile(profile_)), |
| 243 chromeos::SessionManagerClient::ArcCallback()); | 263 base::Bind(&ArcAuthService::OnArcDataRemoved, |
| 264 weak_ptr_factory_.GetWeakPtr())); |
| 265 } |
| 266 |
| 267 void ArcAuthService::OnArcDataRemoved(bool success) { |
| 268 LOG_IF(ERROR, !success) << "Required ARC user data wipe failed."; |
| 269 |
| 270 // Here check if |reenable_arc_| is marked or not. |
| 271 // The only case this happens should be in the special case for enterprise |
| 272 // "on managed lost" case. In that case, OnBridgeStopped() should trigger |
| 273 // the RemoveArcData(), then this. |
| 274 // TODO(hidehiko): Restructure the code. |
| 275 if (!reenable_arc_) |
| 276 return; |
| 277 |
| 278 // Restart ARC anyway. Let the enterprise reporting instance decide whether |
| 279 // the ARC user data wipe is still required or not. |
| 280 reenable_arc_ = false; |
| 281 VLOG(1) << "Reenable ARC"; |
| 282 EnableArc(); |
| 244 } | 283 } |
| 245 | 284 |
| 246 std::string ArcAuthService::GetAndResetAuthCode() { | 285 std::string ArcAuthService::GetAndResetAuthCode() { |
| 247 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 286 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 248 std::string auth_code; | 287 std::string auth_code; |
| 249 auth_code_.swap(auth_code); | 288 auth_code_.swap(auth_code); |
| 250 return auth_code; | 289 return auth_code; |
| 251 } | 290 } |
| 252 | 291 |
| 253 void ArcAuthService::GetAuthCodeDeprecated( | 292 void ArcAuthService::GetAuthCodeDeprecated( |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); | 384 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); |
| 346 ShutdownBridgeAndShowUI(UIPage::ERROR, | 385 ShutdownBridgeAndShowUI(UIPage::ERROR, |
| 347 l10n_util::GetStringUTF16(error_message_id)); | 386 l10n_util::GetStringUTF16(error_message_id)); |
| 348 return; | 387 return; |
| 349 } | 388 } |
| 350 | 389 |
| 351 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED || | 390 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED || |
| 352 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT || | 391 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT || |
| 353 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR || | 392 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR || |
| 354 result == ProvisioningResult::UNKNOWN_ERROR) | 393 result == ProvisioningResult::UNKNOWN_ERROR) |
| 355 clear_required_ = true; | 394 RemoveArcData(); |
| 356 | 395 |
| 357 // We'll delay shutting down the bridge in this case to allow people to send | 396 // We'll delay shutting down the bridge in this case to allow people to send |
| 358 // feedback. | 397 // feedback. |
| 359 ShowUI(UIPage::ERROR_WITH_FEEDBACK, | 398 ShowUI(UIPage::ERROR_WITH_FEEDBACK, |
| 360 l10n_util::GetStringUTF16(error_message_id)); | 399 l10n_util::GetStringUTF16(error_message_id)); |
| 361 } | 400 } |
| 362 | 401 |
| 363 void ArcAuthService::GetIsAccountManaged( | 402 void ArcAuthService::GetIsAccountManaged( |
| 364 const GetIsAccountManagedCallback& callback) { | 403 const GetIsAccountManagedCallback& callback) { |
| 365 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 404 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 g_enable_check_android_management_for_testing) { | 453 g_enable_check_android_management_for_testing) { |
| 415 ArcAndroidManagementChecker::StartClient(); | 454 ArcAndroidManagementChecker::StartClient(); |
| 416 } | 455 } |
| 417 pref_change_registrar_.Init(profile_->GetPrefs()); | 456 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 418 pref_change_registrar_.Add( | 457 pref_change_registrar_.Add( |
| 419 prefs::kArcEnabled, base::Bind(&ArcAuthService::OnOptInPreferenceChanged, | 458 prefs::kArcEnabled, base::Bind(&ArcAuthService::OnOptInPreferenceChanged, |
| 420 weak_ptr_factory_.GetWeakPtr())); | 459 weak_ptr_factory_.GetWeakPtr())); |
| 421 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { | 460 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { |
| 422 OnOptInPreferenceChanged(); | 461 OnOptInPreferenceChanged(); |
| 423 } else { | 462 } else { |
| 463 RemoveArcData(); |
| 424 UpdateEnabledStateUMA(false); | 464 UpdateEnabledStateUMA(false); |
| 425 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); | 465 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); |
| 426 OnIsSyncingChanged(); | 466 OnIsSyncingChanged(); |
| 427 } | 467 } |
| 428 } | 468 } |
| 429 | 469 |
| 430 void ArcAuthService::OnIsSyncingChanged() { | 470 void ArcAuthService::OnIsSyncingChanged() { |
| 431 syncable_prefs::PrefServiceSyncable* const pref_service_syncable = | 471 syncable_prefs::PrefServiceSyncable* const pref_service_syncable = |
| 432 PrefServiceSyncableFromProfile(profile_); | 472 PrefServiceSyncableFromProfile(profile_); |
| 433 if (!pref_service_syncable->IsSyncing()) | 473 if (!pref_service_syncable->IsSyncing()) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 DCHECK(profile_); | 560 DCHECK(profile_); |
| 521 | 561 |
| 522 // TODO(dspaid): Move code from OnSyncedPrefChanged into this method. | 562 // TODO(dspaid): Move code from OnSyncedPrefChanged into this method. |
| 523 OnSyncedPrefChanged(prefs::kArcEnabled, IsArcManaged()); | 563 OnSyncedPrefChanged(prefs::kArcEnabled, IsArcManaged()); |
| 524 | 564 |
| 525 const bool arc_enabled = IsArcEnabled(); | 565 const bool arc_enabled = IsArcEnabled(); |
| 526 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInEnabled(arc_enabled)); | 566 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInEnabled(arc_enabled)); |
| 527 | 567 |
| 528 if (!arc_enabled) { | 568 if (!arc_enabled) { |
| 529 StopArc(); | 569 StopArc(); |
| 570 RemoveArcData(); |
| 530 return; | 571 return; |
| 531 } | 572 } |
| 532 | 573 |
| 533 if (state_ == State::ACTIVE) | 574 if (state_ == State::ACTIVE) |
| 534 return; | 575 return; |
| 535 CloseUI(); | 576 CloseUI(); |
| 536 auth_code_.clear(); | 577 auth_code_.clear(); |
| 537 | 578 |
| 538 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { | 579 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { |
| 539 // Need pre-fetch auth code and show OptIn UI if needed. | 580 // Need pre-fetch auth code and show OptIn UI if needed. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 ArcAuthNotification::Hide(); | 631 ArcAuthNotification::Hide(); |
| 591 } | 632 } |
| 592 | 633 |
| 593 void ArcAuthService::SetUIPage(UIPage page, const base::string16& status) { | 634 void ArcAuthService::SetUIPage(UIPage page, const base::string16& status) { |
| 594 ui_page_ = page; | 635 ui_page_ = page; |
| 595 ui_page_status_ = status; | 636 ui_page_status_ = status; |
| 596 FOR_EACH_OBSERVER(Observer, observer_list_, | 637 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 597 OnOptInUIShowPage(ui_page_, ui_page_status_)); | 638 OnOptInUIShowPage(ui_page_, ui_page_status_)); |
| 598 } | 639 } |
| 599 | 640 |
| 641 // This is the special method to support enterprise mojo API. |
| 642 // TODO(hidehiko): Remove this. |
| 643 void ArcAuthService::StopAndEnableArc() { |
| 644 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 645 DCHECK(!arc_bridge_service()->stopped()); |
| 646 reenable_arc_ = true; |
| 647 StopArc(); |
| 648 } |
| 649 |
| 600 void ArcAuthService::StartArc() { | 650 void ArcAuthService::StartArc() { |
| 601 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 651 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 602 arc_bridge_service()->HandleStartup(); | 652 arc_bridge_service()->HandleStartup(); |
| 603 SetState(State::ACTIVE); | 653 SetState(State::ACTIVE); |
| 604 } | 654 } |
| 605 | 655 |
| 606 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) { | 656 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) { |
| 607 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 657 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 608 DCHECK(!auth_code.empty()); | 658 DCHECK(!auth_code.empty()); |
| 609 | 659 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 return os << kStateFetchingCode; | 859 return os << kStateFetchingCode; |
| 810 case ArcAuthService::State::ACTIVE: | 860 case ArcAuthService::State::ACTIVE: |
| 811 return os << kStateActive; | 861 return os << kStateActive; |
| 812 default: | 862 default: |
| 813 NOTREACHED(); | 863 NOTREACHED(); |
| 814 return os; | 864 return os; |
| 815 } | 865 } |
| 816 } | 866 } |
| 817 | 867 |
| 818 } // namespace arc | 868 } // namespace arc |
| OLD | NEW |