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

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

Issue 2248353002: [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 if (!clear_required_) 240
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;
241 return; 260 return;
261 }
242 clear_required_ = false; 262 clear_required_ = false;
243 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( 263 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData(
244 cryptohome::Identification( 264 cryptohome::Identification(
245 multi_user_util::GetAccountIdFromProfile(profile_)), 265 multi_user_util::GetAccountIdFromProfile(profile_)),
246 chromeos::SessionManagerClient::ArcCallback()); 266 base::Bind(&ArcAuthService::OnArcDataRemoved,
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();
247 } 286 }
248 287
249 std::string ArcAuthService::GetAndResetAuthCode() { 288 std::string ArcAuthService::GetAndResetAuthCode() {
250 DCHECK(thread_checker.Get().CalledOnValidThread()); 289 DCHECK(thread_checker.Get().CalledOnValidThread());
251 std::string auth_code; 290 std::string auth_code;
252 auth_code_.swap(auth_code); 291 auth_code_.swap(auth_code);
253 return auth_code; 292 return auth_code;
254 } 293 }
255 294
256 void ArcAuthService::GetAuthCodeDeprecated( 295 void ArcAuthService::GetAuthCodeDeprecated(
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); 387 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false);
349 ShutdownBridgeAndShowUI(UIPage::ERROR, 388 ShutdownBridgeAndShowUI(UIPage::ERROR,
350 l10n_util::GetStringUTF16(error_message_id)); 389 l10n_util::GetStringUTF16(error_message_id));
351 return; 390 return;
352 } 391 }
353 392
354 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED || 393 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED ||
355 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT || 394 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT ||
356 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR || 395 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR ||
357 result == ProvisioningResult::UNKNOWN_ERROR) 396 result == ProvisioningResult::UNKNOWN_ERROR)
358 clear_required_ = true; 397 RemoveArcData();
359 398
360 // We'll delay shutting down the bridge in this case to allow people to send 399 // We'll delay shutting down the bridge in this case to allow people to send
361 // feedback. 400 // feedback.
362 ShowUI(UIPage::ERROR_WITH_FEEDBACK, 401 ShowUI(UIPage::ERROR_WITH_FEEDBACK,
363 l10n_util::GetStringUTF16(error_message_id)); 402 l10n_util::GetStringUTF16(error_message_id));
364 } 403 }
365 404
366 void ArcAuthService::GetIsAccountManaged( 405 void ArcAuthService::GetIsAccountManaged(
367 const GetIsAccountManagedCallback& callback) { 406 const GetIsAccountManagedCallback& callback) {
368 DCHECK(thread_checker.Get().CalledOnValidThread()); 407 DCHECK(thread_checker.Get().CalledOnValidThread());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 if (!disable_ui_for_testing || enable_check_android_management_for_testing) 450 if (!disable_ui_for_testing || enable_check_android_management_for_testing)
412 ArcAndroidManagementChecker::StartClient(); 451 ArcAndroidManagementChecker::StartClient();
413 pref_change_registrar_.Init(profile_->GetPrefs()); 452 pref_change_registrar_.Init(profile_->GetPrefs());
414 pref_change_registrar_.Add( 453 pref_change_registrar_.Add(
415 prefs::kArcEnabled, 454 prefs::kArcEnabled,
416 base::Bind(&ArcAuthService::OnOptInPreferenceChanged, 455 base::Bind(&ArcAuthService::OnOptInPreferenceChanged,
417 weak_ptr_factory_.GetWeakPtr())); 456 weak_ptr_factory_.GetWeakPtr()));
418 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { 457 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) {
419 OnOptInPreferenceChanged(); 458 OnOptInPreferenceChanged();
420 } else { 459 } else {
460 RemoveArcData();
421 UpdateEnabledStateUMA(false); 461 UpdateEnabledStateUMA(false);
422 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); 462 PrefServiceSyncableFromProfile(profile_)->AddObserver(this);
423 OnIsSyncingChanged(); 463 OnIsSyncingChanged();
424 } 464 }
425 } else { 465 } else {
426 auth_code_.clear(); 466 auth_code_.clear();
427 StartArc(); 467 StartArc();
428 } 468 }
429 } 469 }
430 470
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 DCHECK(profile_); 561 DCHECK(profile_);
522 562
523 // TODO(dspaid): Move code from OnSyncedPrefChanged into this method. 563 // TODO(dspaid): Move code from OnSyncedPrefChanged into this method.
524 OnSyncedPrefChanged(prefs::kArcEnabled, IsArcManaged()); 564 OnSyncedPrefChanged(prefs::kArcEnabled, IsArcManaged());
525 565
526 const bool arc_enabled = IsArcEnabled(); 566 const bool arc_enabled = IsArcEnabled();
527 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInEnabled(arc_enabled)); 567 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInEnabled(arc_enabled));
528 568
529 if (!arc_enabled) { 569 if (!arc_enabled) {
530 StopArc(); 570 StopArc();
571 RemoveArcData();
531 return; 572 return;
532 } 573 }
533 574
534 if (state_ == State::ACTIVE) 575 if (state_ == State::ACTIVE)
535 return; 576 return;
536 CloseUI(); 577 CloseUI();
537 auth_code_.clear(); 578 auth_code_.clear();
538 579
539 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { 580 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) {
540 // Need pre-fetch auth code and show OptIn UI if needed. 581 // Need pre-fetch auth code and show OptIn UI if needed.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 ArcAuthNotification::Hide(); 632 ArcAuthNotification::Hide();
592 } 633 }
593 634
594 void ArcAuthService::SetUIPage(UIPage page, const base::string16& status) { 635 void ArcAuthService::SetUIPage(UIPage page, const base::string16& status) {
595 ui_page_ = page; 636 ui_page_ = page;
596 ui_page_status_ = status; 637 ui_page_status_ = status;
597 FOR_EACH_OBSERVER(Observer, observer_list_, 638 FOR_EACH_OBSERVER(Observer, observer_list_,
598 OnOptInUIShowPage(ui_page_, ui_page_status_)); 639 OnOptInUIShowPage(ui_page_, ui_page_status_));
599 } 640 }
600 641
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
601 void ArcAuthService::StartArc() { 651 void ArcAuthService::StartArc() {
602 DCHECK(thread_checker.Get().CalledOnValidThread()); 652 DCHECK(thread_checker.Get().CalledOnValidThread());
603 arc_bridge_service()->HandleStartup(); 653 arc_bridge_service()->HandleStartup();
604 SetState(State::ACTIVE); 654 SetState(State::ACTIVE);
605 } 655 }
606 656
607 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) { 657 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) {
608 DCHECK(thread_checker.Get().CalledOnValidThread()); 658 DCHECK(thread_checker.Get().CalledOnValidThread());
609 DCHECK(!auth_code.empty()); 659 DCHECK(!auth_code.empty());
610 660
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 return os << kStateFetchingCode; 852 return os << kStateFetchingCode;
803 case ArcAuthService::State::ACTIVE: 853 case ArcAuthService::State::ACTIVE:
804 return os << kStateActive; 854 return os << kStateActive;
805 default: 855 default:
806 NOTREACHED(); 856 NOTREACHED();
807 return os; 857 return os;
808 } 858 }
809 } 859 }
810 860
811 } // namespace arc 861 } // 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