Chromium Code Reviews| 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 clear_required_ = false; | |
| 240 RemoveArcData(); | |
| 241 } else { | |
| 242 OnArcDataRemoved(true); | |
|
khmel
2016/08/04 23:23:29
nit: this used quite confusion for me. May we rena
hidehiko
2016/08/09 13:23:56
I agree that this may be confusing, but TBH, your
khmel
2016/08/09 15:23:11
sure, it was only nit :)
| |
| 243 } | |
| 244 } | |
| 245 | |
| 246 void ArcAuthService::RemoveArcData() { | |
| 247 if (!arc_bridge_service()->stopped()) { | |
| 248 // Just set a flag. On bridge stopped, this will be re-called, | |
| 249 // then session manager should remove the data. | |
| 250 clear_required_ = true; | |
| 238 return; | 251 return; |
| 252 } | |
| 239 clear_required_ = false; | 253 clear_required_ = false; |
| 240 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( | 254 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( |
| 241 cryptohome::Identification( | 255 cryptohome::Identification( |
| 242 multi_user_util::GetAccountIdFromProfile(profile_)), | 256 multi_user_util::GetAccountIdFromProfile(profile_)), |
| 243 chromeos::SessionManagerClient::ArcCallback()); | 257 base::Bind(&ArcAuthService::OnArcDataRemoved, |
| 258 weak_ptr_factory_.GetWeakPtr())); | |
| 259 } | |
| 260 | |
| 261 void ArcAuthService::OnArcDataRemoved(bool success) { | |
| 262 LOG_IF(ERROR, !success) << "Required ARC user data wipe failed."; | |
| 263 | |
| 264 if (!reenable_arc_) | |
| 265 return; | |
| 266 | |
| 267 // Restart ARC anyway. Let the enterprise reporting instance decide whether | |
| 268 // the ARC user data wipe is still required or not. | |
| 269 reenable_arc_ = false; | |
| 270 VLOG(1) << "Reenable ARC"; | |
| 271 EnableArc(); | |
| 244 } | 272 } |
| 245 | 273 |
| 246 std::string ArcAuthService::GetAndResetAuthCode() { | 274 std::string ArcAuthService::GetAndResetAuthCode() { |
| 247 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 275 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 248 std::string auth_code; | 276 std::string auth_code; |
| 249 auth_code_.swap(auth_code); | 277 auth_code_.swap(auth_code); |
| 250 return auth_code; | 278 return auth_code; |
| 251 } | 279 } |
| 252 | 280 |
| 253 void ArcAuthService::GetAuthCodeDeprecated( | 281 void ArcAuthService::GetAuthCodeDeprecated( |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); | 373 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); |
| 346 ShutdownBridgeAndShowUI(UIPage::ERROR, | 374 ShutdownBridgeAndShowUI(UIPage::ERROR, |
| 347 l10n_util::GetStringUTF16(error_message_id)); | 375 l10n_util::GetStringUTF16(error_message_id)); |
| 348 return; | 376 return; |
| 349 } | 377 } |
| 350 | 378 |
| 351 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED || | 379 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED || |
| 352 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT || | 380 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT || |
| 353 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR || | 381 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR || |
| 354 result == ProvisioningResult::UNKNOWN_ERROR) | 382 result == ProvisioningResult::UNKNOWN_ERROR) |
| 355 clear_required_ = true; | 383 RemoveArcData(); |
|
khmel
2016/08/04 23:23:29
nit: {}
hidehiko
2016/08/09 13:23:56
Let me keep this as is for consistency.
No {} for
khmel
2016/08/09 15:23:11
We have multi-line conditions. Based on my previou
| |
| 356 | 384 |
| 357 // We'll delay shutting down the bridge in this case to allow people to send | 385 // We'll delay shutting down the bridge in this case to allow people to send |
| 358 // feedback. | 386 // feedback. |
| 359 ShowUI(UIPage::ERROR_WITH_FEEDBACK, | 387 ShowUI(UIPage::ERROR_WITH_FEEDBACK, |
| 360 l10n_util::GetStringUTF16(error_message_id)); | 388 l10n_util::GetStringUTF16(error_message_id)); |
| 361 } | 389 } |
| 362 | 390 |
| 363 void ArcAuthService::GetIsAccountManaged( | 391 void ArcAuthService::GetIsAccountManaged( |
| 364 const GetIsAccountManagedCallback& callback) { | 392 const GetIsAccountManagedCallback& callback) { |
| 365 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 393 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 | 545 |
| 518 void ArcAuthService::OnOptInPreferenceChanged() { | 546 void ArcAuthService::OnOptInPreferenceChanged() { |
| 519 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 547 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 520 DCHECK(profile_); | 548 DCHECK(profile_); |
| 521 | 549 |
| 522 const bool arc_enabled = IsArcEnabled(); | 550 const bool arc_enabled = IsArcEnabled(); |
| 523 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInEnabled(arc_enabled)); | 551 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInEnabled(arc_enabled)); |
| 524 | 552 |
| 525 if (!arc_enabled) { | 553 if (!arc_enabled) { |
| 526 StopArc(); | 554 StopArc(); |
| 555 RemoveArcData(); | |
| 527 return; | 556 return; |
| 528 } | 557 } |
| 529 | 558 |
| 530 if (state_ == State::ACTIVE) | 559 if (state_ == State::ACTIVE) |
| 531 return; | 560 return; |
| 532 CloseUI(); | 561 CloseUI(); |
| 533 auth_code_.clear(); | 562 auth_code_.clear(); |
| 534 | 563 |
| 535 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { | 564 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { |
| 536 // Need pre-fetch auth code and show OptIn UI if needed. | 565 // Need pre-fetch auth code and show OptIn UI if needed. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 587 ArcAuthNotification::Hide(); | 616 ArcAuthNotification::Hide(); |
| 588 } | 617 } |
| 589 | 618 |
| 590 void ArcAuthService::SetUIPage(UIPage page, const base::string16& status) { | 619 void ArcAuthService::SetUIPage(UIPage page, const base::string16& status) { |
| 591 ui_page_ = page; | 620 ui_page_ = page; |
| 592 ui_page_status_ = status; | 621 ui_page_status_ = status; |
| 593 FOR_EACH_OBSERVER(Observer, observer_list_, | 622 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 594 OnOptInUIShowPage(ui_page_, ui_page_status_)); | 623 OnOptInUIShowPage(ui_page_, ui_page_status_)); |
| 595 } | 624 } |
| 596 | 625 |
| 626 // This is the special method to support enterprise mojo API. | |
| 627 // TODO(hidehiko): Remove this. | |
| 628 void ArcAuthService::ReenableArc() { | |
| 629 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 630 DCHECK(!arc_bridge_service()->stopped()); | |
| 631 reenable_arc_ = true; | |
| 632 StopArc(); | |
| 633 } | |
| 634 | |
| 597 void ArcAuthService::StartArc() { | 635 void ArcAuthService::StartArc() { |
| 598 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 636 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 599 arc_bridge_service()->HandleStartup(); | 637 arc_bridge_service()->HandleStartup(); |
| 600 SetState(State::ACTIVE); | 638 SetState(State::ACTIVE); |
| 601 } | 639 } |
| 602 | 640 |
| 603 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) { | 641 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) { |
| 604 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 642 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 605 DCHECK(!auth_code.empty()); | 643 DCHECK(!auth_code.empty()); |
| 606 | 644 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 806 return os << kStateFetchingCode; | 844 return os << kStateFetchingCode; |
| 807 case ArcAuthService::State::ACTIVE: | 845 case ArcAuthService::State::ACTIVE: |
| 808 return os << kStateActive; | 846 return os << kStateActive; |
| 809 default: | 847 default: |
| 810 NOTREACHED(); | 848 NOTREACHED(); |
| 811 return os; | 849 return os; |
| 812 } | 850 } |
| 813 } | 851 } |
| 814 | 852 |
| 815 } // namespace arc | 853 } // namespace arc |
| OLD | NEW |