Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: chrome/browser/chromeos/arc/arc_auth_service.cc

Issue 2255673004: Revert of [M53 cherry-pick] Migrate ArcUserDataService into ArcAuthService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/shelf/shelf_delegate.h" 9 #include "ash/shelf/shelf_delegate.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 } 230 }
231 231
232 void ArcAuthService::OnBridgeStopped(ArcBridgeService::StopReason reason) { 232 void ArcAuthService::OnBridgeStopped(ArcBridgeService::StopReason reason) {
233 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. 233 // TODO(crbug.com/625923): Use |reason| to report more detailed errors.
234 if (waiting_for_reply_) { 234 if (waiting_for_reply_) {
235 // Using SERVICE_UNAVAILABLE instead of UNKNOWN_ERROR, since the latter 235 // Using SERVICE_UNAVAILABLE instead of UNKNOWN_ERROR, since the latter
236 // causes this code to not try to stop ARC, so it would retry without the 236 // causes this code to not try to stop ARC, so it would retry without the
237 // user noticing. 237 // user noticing.
238 OnSignInFailedInternal(ProvisioningResult::ARC_STOPPED); 238 OnSignInFailedInternal(ProvisioningResult::ARC_STOPPED);
239 } 239 }
240 240 if (!clear_required_)
241 if (clear_required_) {
242 // This should be always true, but just in case as this is looked at
243 // inside RemoveArcData() at first.
244 DCHECK(arc_bridge_service()->stopped());
245 RemoveArcData();
246 } else {
247 // To support special "Stop and enable ARC" procedure for enterprise,
248 // here call OnArcDataRemoved(true) as if the data removal is successfully
249 // done.
250 // TODO(hidehiko): Restructure the code.
251 OnArcDataRemoved(true);
252 }
253 }
254
255 void ArcAuthService::RemoveArcData() {
256 if (!arc_bridge_service()->stopped()) {
257 // Just set a flag. On bridge stopped, this will be re-called,
258 // then session manager should remove the data.
259 clear_required_ = true;
260 return; 241 return;
261 }
262 clear_required_ = false; 242 clear_required_ = false;
263 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( 243 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData(
264 cryptohome::Identification( 244 cryptohome::Identification(
265 multi_user_util::GetAccountIdFromProfile(profile_)), 245 multi_user_util::GetAccountIdFromProfile(profile_)),
266 base::Bind(&ArcAuthService::OnArcDataRemoved, 246 chromeos::SessionManagerClient::ArcCallback());
267 weak_ptr_factory_.GetWeakPtr()));
268 }
269
270 void ArcAuthService::OnArcDataRemoved(bool success) {
271 LOG_IF(ERROR, !success) << "Required ARC user data wipe failed.";
272
273 // Here check if |reenable_arc_| is marked or not.
274 // The only case this happens should be in the special case for enterprise
275 // "on managed lost" case. In that case, OnBridgeStopped() should trigger
276 // the RemoveArcData(), then this.
277 // TODO(hidehiko): Restructure the code.
278 if (!reenable_arc_)
279 return;
280
281 // Restart ARC anyway. Let the enterprise reporting instance decide whether
282 // the ARC user data wipe is still required or not.
283 reenable_arc_ = false;
284 VLOG(1) << "Reenable ARC";
285 EnableArc();
286 } 247 }
287 248
288 std::string ArcAuthService::GetAndResetAuthCode() { 249 std::string ArcAuthService::GetAndResetAuthCode() {
289 DCHECK(thread_checker.Get().CalledOnValidThread()); 250 DCHECK(thread_checker.Get().CalledOnValidThread());
290 std::string auth_code; 251 std::string auth_code;
291 auth_code_.swap(auth_code); 252 auth_code_.swap(auth_code);
292 return auth_code; 253 return auth_code;
293 } 254 }
294 255
295 void ArcAuthService::GetAuthCodeDeprecated( 256 void ArcAuthService::GetAuthCodeDeprecated(
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); 348 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false);
388 ShutdownBridgeAndShowUI(UIPage::ERROR, 349 ShutdownBridgeAndShowUI(UIPage::ERROR,
389 l10n_util::GetStringUTF16(error_message_id)); 350 l10n_util::GetStringUTF16(error_message_id));
390 return; 351 return;
391 } 352 }
392 353
393 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED || 354 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED ||
394 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT || 355 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT ||
395 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR || 356 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR ||
396 result == ProvisioningResult::UNKNOWN_ERROR) 357 result == ProvisioningResult::UNKNOWN_ERROR)
397 RemoveArcData(); 358 clear_required_ = true;
398 359
399 // We'll delay shutting down the bridge in this case to allow people to send 360 // We'll delay shutting down the bridge in this case to allow people to send
400 // feedback. 361 // feedback.
401 ShowUI(UIPage::ERROR_WITH_FEEDBACK, 362 ShowUI(UIPage::ERROR_WITH_FEEDBACK,
402 l10n_util::GetStringUTF16(error_message_id)); 363 l10n_util::GetStringUTF16(error_message_id));
403 } 364 }
404 365
405 void ArcAuthService::GetIsAccountManaged( 366 void ArcAuthService::GetIsAccountManaged(
406 const GetIsAccountManagedCallback& callback) { 367 const GetIsAccountManagedCallback& callback) {
407 DCHECK(thread_checker.Get().CalledOnValidThread()); 368 DCHECK(thread_checker.Get().CalledOnValidThread());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 if (!disable_ui_for_testing || enable_check_android_management_for_testing) 411 if (!disable_ui_for_testing || enable_check_android_management_for_testing)
451 ArcAndroidManagementChecker::StartClient(); 412 ArcAndroidManagementChecker::StartClient();
452 pref_change_registrar_.Init(profile_->GetPrefs()); 413 pref_change_registrar_.Init(profile_->GetPrefs());
453 pref_change_registrar_.Add( 414 pref_change_registrar_.Add(
454 prefs::kArcEnabled, 415 prefs::kArcEnabled,
455 base::Bind(&ArcAuthService::OnOptInPreferenceChanged, 416 base::Bind(&ArcAuthService::OnOptInPreferenceChanged,
456 weak_ptr_factory_.GetWeakPtr())); 417 weak_ptr_factory_.GetWeakPtr()));
457 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { 418 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) {
458 OnOptInPreferenceChanged(); 419 OnOptInPreferenceChanged();
459 } else { 420 } else {
460 RemoveArcData();
461 UpdateEnabledStateUMA(false); 421 UpdateEnabledStateUMA(false);
462 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); 422 PrefServiceSyncableFromProfile(profile_)->AddObserver(this);
463 OnIsSyncingChanged(); 423 OnIsSyncingChanged();
464 } 424 }
465 } else { 425 } else {
466 auth_code_.clear(); 426 auth_code_.clear();
467 StartArc(); 427 StartArc();
468 } 428 }
469 } 429 }
470 430
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 DCHECK(profile_); 521 DCHECK(profile_);
562 522
563 // TODO(dspaid): Move code from OnSyncedPrefChanged into this method. 523 // TODO(dspaid): Move code from OnSyncedPrefChanged into this method.
564 OnSyncedPrefChanged(prefs::kArcEnabled, IsArcManaged()); 524 OnSyncedPrefChanged(prefs::kArcEnabled, IsArcManaged());
565 525
566 const bool arc_enabled = IsArcEnabled(); 526 const bool arc_enabled = IsArcEnabled();
567 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInEnabled(arc_enabled)); 527 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInEnabled(arc_enabled));
568 528
569 if (!arc_enabled) { 529 if (!arc_enabled) {
570 StopArc(); 530 StopArc();
571 RemoveArcData();
572 return; 531 return;
573 } 532 }
574 533
575 if (state_ == State::ACTIVE) 534 if (state_ == State::ACTIVE)
576 return; 535 return;
577 CloseUI(); 536 CloseUI();
578 auth_code_.clear(); 537 auth_code_.clear();
579 538
580 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { 539 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) {
581 // Need pre-fetch auth code and show OptIn UI if needed. 540 // Need pre-fetch auth code and show OptIn UI if needed.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 ArcAuthNotification::Hide(); 591 ArcAuthNotification::Hide();
633 } 592 }
634 593
635 void ArcAuthService::SetUIPage(UIPage page, const base::string16& status) { 594 void ArcAuthService::SetUIPage(UIPage page, const base::string16& status) {
636 ui_page_ = page; 595 ui_page_ = page;
637 ui_page_status_ = status; 596 ui_page_status_ = status;
638 FOR_EACH_OBSERVER(Observer, observer_list_, 597 FOR_EACH_OBSERVER(Observer, observer_list_,
639 OnOptInUIShowPage(ui_page_, ui_page_status_)); 598 OnOptInUIShowPage(ui_page_, ui_page_status_));
640 } 599 }
641 600
642 // This is the special method to support enterprise mojo API.
643 // TODO(hidehiko): Remove this.
644 void ArcAuthService::StopAndEnableArc() {
645 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
646 DCHECK(!arc_bridge_service()->stopped());
647 reenable_arc_ = true;
648 StopArc();
649 }
650
651 void ArcAuthService::StartArc() { 601 void ArcAuthService::StartArc() {
652 DCHECK(thread_checker.Get().CalledOnValidThread()); 602 DCHECK(thread_checker.Get().CalledOnValidThread());
653 arc_bridge_service()->HandleStartup(); 603 arc_bridge_service()->HandleStartup();
654 SetState(State::ACTIVE); 604 SetState(State::ACTIVE);
655 } 605 }
656 606
657 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) { 607 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) {
658 DCHECK(thread_checker.Get().CalledOnValidThread()); 608 DCHECK(thread_checker.Get().CalledOnValidThread());
659 DCHECK(!auth_code.empty()); 609 DCHECK(!auth_code.empty());
660 610
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 return os << kStateFetchingCode; 802 return os << kStateFetchingCode;
853 case ArcAuthService::State::ACTIVE: 803 case ArcAuthService::State::ACTIVE:
854 return os << kStateActive; 804 return os << kStateActive;
855 default: 805 default:
856 NOTREACHED(); 806 NOTREACHED();
857 return os; 807 return os;
858 } 808 }
859 } 809 }
860 810
861 } // namespace arc 811 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_service.h ('k') | chrome/browser/chromeos/arc/arc_auth_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698