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

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

Issue 2472223002: WIP (Closed)
Patch Set: Created 4 years, 1 month 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/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/command_line.h" 12 #include "base/command_line.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "chrome/browser/chromeos/arc/arc_auth_code_fetcher.h" 16 #include "chrome/browser/chromeos/arc/arc_auth_code_fetcher.h"
17 #include "chrome/browser/chromeos/arc/arc_auth_context.h" 17 #include "chrome/browser/chromeos/arc/arc_auth_context.h"
18 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" 18 #include "chrome/browser/chromeos/arc/arc_auth_notification.h"
19 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" 19 #include "chrome/browser/chromeos/arc/arc_optin_uma.h"
20 #include "chrome/browser/chromeos/arc/arc_support_host.h" 20 #include "chrome/browser/chromeos/arc/arc_support_host.h"
21 #include "chrome/browser/chromeos/arc/optin/arc_optin_preference_handler.h"
21 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h" 22 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h"
22 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" 23 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h"
23 #include "chrome/browser/chromeos/profiles/profile_helper.h" 24 #include "chrome/browser/chromeos/profiles/profile_helper.h"
24 #include "chrome/browser/extensions/extension_util.h"
25 #include "chrome/browser/policy/profile_policy_connector.h" 25 #include "chrome/browser/policy/profile_policy_connector.h"
26 #include "chrome/browser/policy/profile_policy_connector_factory.h" 26 #include "chrome/browser/policy/profile_policy_connector_factory.h"
27 #include "chrome/browser/prefs/pref_service_syncable_util.h" 27 #include "chrome/browser/prefs/pref_service_syncable_util.h"
28 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" 29 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h"
30 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" 30 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
31 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 31 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
32 #include "chrome/browser/ui/extensions/app_launch_params.h" 32 #include "chrome/browser/ui/browser_commands.h"
33 #include "chrome/browser/ui/extensions/application_launch.h"
34 #include "chrome/common/pref_names.h" 33 #include "chrome/common/pref_names.h"
35 #include "chrome/grit/generated_resources.h" 34 #include "chrome/grit/generated_resources.h"
36 #include "chromeos/chromeos_switches.h" 35 #include "chromeos/chromeos_switches.h"
37 #include "chromeos/cryptohome/cryptohome_parameters.h" 36 #include "chromeos/cryptohome/cryptohome_parameters.h"
38 #include "chromeos/dbus/dbus_thread_manager.h" 37 #include "chromeos/dbus/dbus_thread_manager.h"
39 #include "chromeos/dbus/session_manager_client.h" 38 #include "chromeos/dbus/session_manager_client.h"
40 #include "components/arc/arc_bridge_service.h" 39 #include "components/arc/arc_bridge_service.h"
41 #include "components/pref_registry/pref_registry_syncable.h" 40 #include "components/pref_registry/pref_registry_syncable.h"
42 #include "components/prefs/pref_service.h" 41 #include "components/prefs/pref_service.h"
43 #include "components/sync_preferences/pref_service_syncable.h" 42 #include "components/sync_preferences/pref_service_syncable.h"
44 #include "components/user_manager/user.h" 43 #include "components/user_manager/user.h"
45 #include "content/public/browser/browser_thread.h" 44 #include "content/public/browser/browser_thread.h"
46 #include "extensions/browser/app_window/app_window_registry.h"
47 #include "extensions/browser/extension_prefs.h" 45 #include "extensions/browser/extension_prefs.h"
48 #include "extensions/browser/extension_registry.h"
49 #include "ui/base/l10n/l10n_util.h"
50 46
51 namespace arc { 47 namespace arc {
52 48
53 namespace { 49 namespace {
54 50
55 // Weak pointer. This class is owned by ArcServiceManager. 51 // Weak pointer. This class is owned by ArcServiceManager.
56 ArcAuthService* g_arc_auth_service = nullptr; 52 ArcAuthService* g_arc_auth_service = nullptr;
57 53
58 // Skip creating UI in unit tests 54 // Skip creating UI in unit tests
59 bool g_disable_ui_for_testing = false; 55 bool g_disable_ui_for_testing = false;
60 56
61 // Use specified ash::ShelfDelegate for unit tests. 57 // Use specified ash::ShelfDelegate for unit tests.
62 ash::ShelfDelegate* g_shelf_delegate_for_testing = nullptr; 58 ash::ShelfDelegate* g_shelf_delegate_for_testing = nullptr;
63 59
64 // The Android management check is disabled by default, it's used only for 60 // The Android management check is disabled by default, it's used only for
65 // testing. 61 // testing.
66 bool g_enable_check_android_management_for_testing = false; 62 bool g_enable_check_android_management_for_testing = false;
67 63
68 // Maximum amount of time we'll wait for ARC to finish booting up. Once this 64 // 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, 65 // timeout expires, keep ARC running in case the user wants to file feedback,
70 // but present the UI to try again. 66 // but present the UI to try again.
71 constexpr base::TimeDelta kArcSignInTimeout = base::TimeDelta::FromMinutes(5); 67 constexpr base::TimeDelta kArcSignInTimeout = base::TimeDelta::FromMinutes(5);
72 68
69 using ErrorType = ArcSupportHost::ErrorType;
70 using UIPage = ArcSupportHost::UIPage;
71
73 ash::ShelfDelegate* GetShelfDelegate() { 72 ash::ShelfDelegate* GetShelfDelegate() {
74 if (g_shelf_delegate_for_testing) 73 if (g_shelf_delegate_for_testing)
75 return g_shelf_delegate_for_testing; 74 return g_shelf_delegate_for_testing;
76 if (ash::WmShell::HasInstance()) { 75 if (ash::WmShell::HasInstance()) {
77 DCHECK(ash::WmShell::Get()->shelf_delegate()); 76 DCHECK(ash::WmShell::Get()->shelf_delegate());
78 return ash::WmShell::Get()->shelf_delegate(); 77 return ash::WmShell::Get()->shelf_delegate();
79 } 78 }
80 return nullptr; 79 return nullptr;
81 } 80 }
82 81
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 DCHECK_EQ(state_, State::ACTIVE); 369 DCHECK_EQ(state_, State::ACTIVE);
371 DCHECK(!sign_in_time_.is_null()); 370 DCHECK(!sign_in_time_.is_null());
372 371
373 arc_sign_in_timer_.Stop(); 372 arc_sign_in_timer_.Stop();
374 373
375 UpdateProvisioningTiming(base::Time::Now() - sign_in_time_, false, 374 UpdateProvisioningTiming(base::Time::Now() - sign_in_time_, false,
376 policy_util::IsAccountManaged(profile_)); 375 policy_util::IsAccountManaged(profile_));
377 UpdateOptInCancelUMA(OptInCancelReason::CLOUD_PROVISION_FLOW_FAIL); 376 UpdateOptInCancelUMA(OptInCancelReason::CLOUD_PROVISION_FLOW_FAIL);
378 UpdateProvisioningResultUMA(result, policy_util::IsAccountManaged(profile_)); 377 UpdateProvisioningResultUMA(result, policy_util::IsAccountManaged(profile_));
379 378
380 int error_message_id; 379 ErrorType error_type;
381 switch (result) { 380 switch (result) {
382 case ProvisioningResult::GMS_NETWORK_ERROR: 381 case ProvisioningResult::GMS_NETWORK_ERROR:
383 error_message_id = IDS_ARC_SIGN_IN_NETWORK_ERROR; 382 error_type = ErrorType::SIGN_IN_NETWORK_ERROR;
384 break; 383 break;
385 case ProvisioningResult::GMS_SERVICE_UNAVAILABLE: 384 case ProvisioningResult::GMS_SERVICE_UNAVAILABLE:
386 case ProvisioningResult::GMS_SIGN_IN_FAILED: 385 case ProvisioningResult::GMS_SIGN_IN_FAILED:
387 case ProvisioningResult::GMS_SIGN_IN_TIMEOUT: 386 case ProvisioningResult::GMS_SIGN_IN_TIMEOUT:
388 case ProvisioningResult::GMS_SIGN_IN_INTERNAL_ERROR: 387 case ProvisioningResult::GMS_SIGN_IN_INTERNAL_ERROR:
389 error_message_id = IDS_ARC_SIGN_IN_SERVICE_UNAVAILABLE_ERROR; 388 error_type = ErrorType::SIGN_IN_SERVICE_UNAVAILABLE_ERROR;
390 break; 389 break;
391 case ProvisioningResult::GMS_BAD_AUTHENTICATION: 390 case ProvisioningResult::GMS_BAD_AUTHENTICATION:
392 error_message_id = IDS_ARC_SIGN_IN_BAD_AUTHENTICATION_ERROR; 391 error_type = ErrorType::SIGN_IN_BAD_AUTHENTICATION_ERROR;
393 break; 392 break;
394 case ProvisioningResult::DEVICE_CHECK_IN_FAILED: 393 case ProvisioningResult::DEVICE_CHECK_IN_FAILED:
395 case ProvisioningResult::DEVICE_CHECK_IN_TIMEOUT: 394 case ProvisioningResult::DEVICE_CHECK_IN_TIMEOUT:
396 case ProvisioningResult::DEVICE_CHECK_IN_INTERNAL_ERROR: 395 case ProvisioningResult::DEVICE_CHECK_IN_INTERNAL_ERROR:
397 error_message_id = IDS_ARC_SIGN_IN_GMS_NOT_AVAILABLE_ERROR; 396 error_type = ErrorType::SIGN_IN_GMS_NOT_AVAILABLE_ERROR;
398 break; 397 break;
399 case ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED: 398 case ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED:
400 case ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT: 399 case ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT:
401 case ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR: 400 case ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR:
402 error_message_id = IDS_ARC_SIGN_IN_CLOUD_PROVISION_FLOW_FAIL_ERROR; 401 error_type = ErrorType::SIGN_IN_CLOUD_PROVISION_FLOW_FAIL_ERROR;
403 break; 402 break;
404 default: 403 default:
405 error_message_id = IDS_ARC_SIGN_IN_UNKNOWN_ERROR; 404 error_type = ErrorType::SIGN_IN_UNKNOWN_ERROR;
406 break; 405 break;
407 } 406 }
408 407
409 if (result == ProvisioningResult::ARC_STOPPED) { 408 if (result == ProvisioningResult::ARC_STOPPED) {
410 if (profile_->GetPrefs()->HasPrefPath(prefs::kArcSignedIn)) 409 if (profile_->GetPrefs()->HasPrefPath(prefs::kArcSignedIn))
411 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); 410 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false);
412 ShutdownBridgeAndShowUI(UIPage::ERROR, 411 ShutdownBridge();
413 l10n_util::GetStringUTF16(error_message_id)); 412 if (support_host_)
413 support_host_->ShowErrorPage(error_type, false);
414 return; 414 return;
415 } 415 }
416 416
417 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED || 417 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED ||
418 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT || 418 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT ||
419 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR || 419 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR ||
420 // OVERALL_SIGN_IN_TIMEOUT might be an indication that ARC believes it is 420 // OVERALL_SIGN_IN_TIMEOUT might be an indication that ARC believes it is
421 // fully setup, but Chrome does not. 421 // fully setup, but Chrome does not.
422 result == ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT || 422 result == ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT ||
423 // Just to be safe, remove data if we don't know the cause. 423 // Just to be safe, remove data if we don't know the cause.
424 result == ProvisioningResult::UNKNOWN_ERROR) { 424 result == ProvisioningResult::UNKNOWN_ERROR) {
425 RemoveArcData(); 425 RemoveArcData();
426 } 426 }
427 427
428 // We'll delay shutting down the bridge in this case to allow people to send 428 // We'll delay shutting down the bridge in this case to allow people to send
429 // feedback. 429 // feedback.
430 ShowUI(UIPage::ERROR_WITH_FEEDBACK, 430 if (support_host_)
431 l10n_util::GetStringUTF16(error_message_id)); 431 support_host_->ShowErrorPage(error_type, true /* show feedback button */);
432 } 432 }
433 433
434 void ArcAuthService::GetIsAccountManaged( 434 void ArcAuthService::GetIsAccountManaged(
435 const GetIsAccountManagedCallback& callback) { 435 const GetIsAccountManagedCallback& callback) {
436 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 436 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
437 437
438 callback.Run(policy_util::IsAccountManaged(profile_)); 438 callback.Run(policy_util::IsAccountManaged(profile_));
439 } 439 }
440 440
441 void ArcAuthService::SetState(State state) { 441 void ArcAuthService::SetState(State state) {
(...skipping 24 matching lines...) Expand all
466 policy_util::IsAccountManaged(profile)) { 466 policy_util::IsAccountManaged(profile)) {
467 VLOG(2) << "Enterprise users are not supported in ARC."; 467 VLOG(2) << "Enterprise users are not supported in ARC.";
468 return; 468 return;
469 } 469 }
470 470
471 profile_ = profile; 471 profile_ = profile;
472 // Create the support host at initialization. Note that, practically, 472 // Create the support host at initialization. Note that, practically,
473 // ARC support Chrome app is rarely used (only opt-in and re-auth flow). 473 // ARC support Chrome app is rarely used (only opt-in and re-auth flow).
474 // So, it may be better to initialize it lazily. 474 // So, it may be better to initialize it lazily.
475 // TODO(hidehiko): Revisit to think about lazy initialization. 475 // TODO(hidehiko): Revisit to think about lazy initialization.
476 support_host_.reset(new ArcSupportHost()); 476 if (!g_disable_ui_for_testing && !IsOptInVerificationDisabled()) {
477 LOG(ERROR) << "HOGEHOGE";
478 support_host_.reset(new ArcSupportHost(profile_));
479 support_host_->set_observer(this);
480 }
477 SetState(State::STOPPED); 481 SetState(State::STOPPED);
478 482
483 preference_handler_ = base::MakeUnique<arc::ArcOptInPreferenceHandler>(
484 this, profile_->GetPrefs());
485 // This automatically updates all preferences.
486 preference_handler_->Start();
487
479 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( 488 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver(
480 prefs::kArcEnabled, this); 489 prefs::kArcEnabled, this);
481 490
482 context_.reset(new ArcAuthContext(this, profile_)); 491 context_.reset(new ArcAuthContext(this, profile_));
483 492
484 // In case UI is disabled we assume that ARC is opted-in. 493 // In case UI is disabled we assume that ARC is opted-in.
485 if (IsOptInVerificationDisabled()) { 494 if (IsOptInVerificationDisabled()) {
486 auth_code_.clear(); 495 auth_code_.clear();
487 StartArc(); 496 StartArc();
488 return; 497 return;
(...skipping 28 matching lines...) Expand all
517 if (IsArcEnabled()) 526 if (IsArcEnabled())
518 OnOptInPreferenceChanged(); 527 OnOptInPreferenceChanged();
519 528
520 if (!g_disable_ui_for_testing && profile_->IsNewProfile() && 529 if (!g_disable_ui_for_testing && profile_->IsNewProfile() &&
521 !profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { 530 !profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) {
522 ArcAuthNotification::Show(profile_); 531 ArcAuthNotification::Show(profile_);
523 } 532 }
524 } 533 }
525 534
526 void ArcAuthService::Shutdown() { 535 void ArcAuthService::Shutdown() {
527 ShutdownBridgeAndCloseUI(); 536 ShutdownBridge();
537 CloseUI();
528 if (profile_) { 538 if (profile_) {
529 sync_preferences::PrefServiceSyncable* pref_service_syncable = 539 sync_preferences::PrefServiceSyncable* pref_service_syncable =
530 PrefServiceSyncableFromProfile(profile_); 540 PrefServiceSyncableFromProfile(profile_);
531 pref_service_syncable->RemoveObserver(this); 541 pref_service_syncable->RemoveObserver(this);
532 pref_service_syncable->RemoveSyncedPrefObserver(prefs::kArcEnabled, this); 542 pref_service_syncable->RemoveSyncedPrefObserver(prefs::kArcEnabled, this);
533 } 543 }
534 pref_change_registrar_.RemoveAll(); 544 pref_change_registrar_.RemoveAll();
535 context_.reset(); 545 context_.reset();
536 profile_ = nullptr; 546 profile_ = nullptr;
537 SetState(State::NOT_INITIALIZED); 547 SetState(State::NOT_INITIALIZED);
538 } 548 }
539 549
540 void ArcAuthService::ShowUI(UIPage page, const base::string16& status) {
541 if (g_disable_ui_for_testing || IsOptInVerificationDisabled())
542 return;
543
544 SetUIPage(page, status);
545 const extensions::AppWindowRegistry* const app_window_registry =
546 extensions::AppWindowRegistry::Get(profile_);
547 DCHECK(app_window_registry);
548 if (app_window_registry->GetCurrentAppWindowForApp(
549 ArcSupportHost::kHostAppId)) {
550 return;
551 }
552
553 const extensions::Extension* extension =
554 extensions::ExtensionRegistry::Get(profile_)->GetInstalledExtension(
555 ArcSupportHost::kHostAppId);
556 CHECK(extension && extensions::util::IsAppLaunchable(
557 ArcSupportHost::kHostAppId, profile_));
558 OpenApplication(CreateAppLaunchParamsUserContainer(
559 profile_, extension, WindowOpenDisposition::NEW_WINDOW,
560 extensions::SOURCE_CHROME_INTERNAL));
561 }
562
563 void ArcAuthService::OnContextReady() { 550 void ArcAuthService::OnContextReady() {
564 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 551 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
565 552
566 DCHECK(!initial_opt_in_); 553 DCHECK(!initial_opt_in_);
567 554
568 // TODO(hidehiko): The check is not necessary if this is a part of re-auth 555 // TODO(hidehiko): The check is not necessary if this is a part of re-auth
569 // flow. Remove this. 556 // flow. Remove this.
570 android_management_checker_.reset(new ArcAndroidManagementChecker( 557 android_management_checker_.reset(new ArcAndroidManagementChecker(
571 profile_, context_->token_service(), context_->account_id(), 558 profile_, context_->token_service(), context_->account_id(),
572 false /* retry_on_error */)); 559 false /* retry_on_error */));
(...skipping 19 matching lines...) Expand all
592 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); 579 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId);
593 } 580 }
594 } 581 }
595 } 582 }
596 583
597 void ArcAuthService::StopArc() { 584 void ArcAuthService::StopArc() {
598 if (state_ != State::STOPPED) { 585 if (state_ != State::STOPPED) {
599 UpdateEnabledStateUMA(false); 586 UpdateEnabledStateUMA(false);
600 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); 587 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false);
601 } 588 }
602 ShutdownBridgeAndCloseUI(); 589 ShutdownBridge();
590 CloseUI();
603 } 591 }
604 592
605 void ArcAuthService::OnOptInPreferenceChanged() { 593 void ArcAuthService::OnOptInPreferenceChanged() {
606 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 594 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
607 DCHECK(profile_); 595 DCHECK(profile_);
608 596
609 // TODO(dspaid): Move code from OnSyncedPrefChanged into this method. 597 // TODO(dspaid): Move code from OnSyncedPrefChanged into this method.
610 OnSyncedPrefChanged(prefs::kArcEnabled, IsArcManaged()); 598 OnSyncedPrefChanged(prefs::kArcEnabled, IsArcManaged());
611 599
612 const bool arc_enabled = IsArcEnabled(); 600 const bool arc_enabled = IsArcEnabled();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 auth_account_callback_.Reset(); 644 auth_account_callback_.Reset();
657 android_management_checker_.reset(); 645 android_management_checker_.reset();
658 auth_code_fetcher_.reset(); 646 auth_code_fetcher_.reset();
659 arc_bridge_service()->RequestStop(); 647 arc_bridge_service()->RequestStop();
660 if (state_ != State::NOT_INITIALIZED) 648 if (state_ != State::NOT_INITIALIZED)
661 SetState(State::STOPPED); 649 SetState(State::STOPPED);
662 for (auto& observer : observer_list_) 650 for (auto& observer : observer_list_)
663 observer.OnShutdownBridge(); 651 observer.OnShutdownBridge();
664 } 652 }
665 653
666 void ArcAuthService::ShutdownBridgeAndCloseUI() {
667 ShutdownBridge();
668 CloseUI();
669 }
670
671 void ArcAuthService::ShutdownBridgeAndShowUI(UIPage page,
672 const base::string16& status) {
673 ShutdownBridge();
674 ShowUI(page, status);
675 }
676
677 void ArcAuthService::AddObserver(Observer* observer) { 654 void ArcAuthService::AddObserver(Observer* observer) {
678 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 655 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
679 observer_list_.AddObserver(observer); 656 observer_list_.AddObserver(observer);
680 } 657 }
681 658
682 void ArcAuthService::RemoveObserver(Observer* observer) { 659 void ArcAuthService::RemoveObserver(Observer* observer) {
683 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 660 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
684 observer_list_.RemoveObserver(observer); 661 observer_list_.RemoveObserver(observer);
685 } 662 }
686 663
687 void ArcAuthService::CloseUI() { 664 void ArcAuthService::CloseUI() {
688 ui_page_ = UIPage::NO_PAGE;
689 ui_page_status_.clear();
690 if (support_host_) 665 if (support_host_)
691 support_host_->Close(); 666 support_host_->Close();
692 if (!g_disable_ui_for_testing) 667 if (!g_disable_ui_for_testing)
693 ArcAuthNotification::Hide(); 668 ArcAuthNotification::Hide();
694 } 669 }
695 670
696 void ArcAuthService::SetUIPage(UIPage page, const base::string16& status) {
697 ui_page_ = page;
698 ui_page_status_ = status;
699 if (support_host_)
700 support_host_->ShowPage(ui_page_, ui_page_status_);
701 }
702
703 // This is the special method to support enterprise mojo API. 671 // This is the special method to support enterprise mojo API.
704 // TODO(hidehiko): Remove this. 672 // TODO(hidehiko): Remove this.
705 void ArcAuthService::StopAndEnableArc() { 673 void ArcAuthService::StopAndEnableArc() {
706 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 674 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
707 DCHECK(!arc_bridge_service()->stopped()); 675 DCHECK(!arc_bridge_service()->stopped());
708 reenable_arc_ = true; 676 reenable_arc_ = true;
709 StopArc(); 677 StopArc();
710 } 678 }
711 679
712 void ArcAuthService::StartArc() { 680 void ArcAuthService::StartArc() {
(...skipping 15 matching lines...) Expand all
728 return; 696 return;
729 } else { 697 } else {
730 auth_account_callback_.Run(auth_code, !IsOptInVerificationDisabled(), 698 auth_account_callback_.Run(auth_code, !IsOptInVerificationDisabled(),
731 mojom::ChromeAccountType::USER_ACCOUNT); 699 mojom::ChromeAccountType::USER_ACCOUNT);
732 auth_account_callback_.Reset(); 700 auth_account_callback_.Reset();
733 return; 701 return;
734 } 702 }
735 } 703 }
736 704
737 if (state_ != State::FETCHING_CODE) { 705 if (state_ != State::FETCHING_CODE) {
738 ShutdownBridgeAndCloseUI(); 706 ShutdownBridge();
707 CloseUI();
739 return; 708 return;
740 } 709 }
741 710
742 sign_in_time_ = base::Time::Now(); 711 sign_in_time_ = base::Time::Now();
743 VLOG(1) << "Starting ARC for first sign in."; 712 VLOG(1) << "Starting ARC for first sign in.";
744 713
745 SetUIPage(UIPage::START_PROGRESS, base::string16()); 714 if (support_host_)
715 support_host_->ShowLoadingPage();
746 ShutdownBridge(); 716 ShutdownBridge();
747 auth_code_ = auth_code; 717 auth_code_ = auth_code;
748 arc_sign_in_timer_.Start(FROM_HERE, kArcSignInTimeout, 718 arc_sign_in_timer_.Start(FROM_HERE, kArcSignInTimeout,
749 base::Bind(&ArcAuthService::OnArcSignInTimeout, 719 base::Bind(&ArcAuthService::OnArcSignInTimeout,
750 weak_ptr_factory_.GetWeakPtr())); 720 weak_ptr_factory_.GetWeakPtr()));
751 StartArc(); 721 StartArc();
752 } 722 }
753 723
754 void ArcAuthService::OnArcSignInTimeout() { 724 void ArcAuthService::OnArcSignInTimeout() {
755 LOG(ERROR) << "Timed out waiting for first sign in."; 725 LOG(ERROR) << "Timed out waiting for first sign in.";
756 OnSignInFailedInternal(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT); 726 OnSignInFailedInternal(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT);
757 } 727 }
758 728
759 void ArcAuthService::StartLso() { 729 void ArcAuthService::StartLso() {
760 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 730 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
761 731
762 // Update UMA only if error (with or without feedback) is currently shown. 732 // Update UMA only if error (with or without feedback) is currently shown.
763 if (ui_page_ == UIPage::ERROR) { 733 if (support_host_ && support_host_->ui_page() == UIPage::ERROR) {
764 UpdateOptInActionUMA(OptInActionType::RETRY); 734 UpdateOptInActionUMA(OptInActionType::RETRY);
765 } else if (ui_page_ == UIPage::ERROR_WITH_FEEDBACK) { 735 if (support_host_->error_page_has_send_feedback_button()) {
766 UpdateOptInActionUMA(OptInActionType::RETRY); 736 ShutdownBridge();
767 ShutdownBridge(); 737 }
768 } 738 }
769 739
770 // TODO(khmel): Use PrepareContextForAuthCodeRequest for this case. 740 // TODO(khmel): Use PrepareContextForAuthCodeRequest for this case.
771 initial_opt_in_ = false; 741 initial_opt_in_ = false;
772 StartUI(); 742 StartUI();
773 } 743 }
774 744
775 void ArcAuthService::CancelAuthCode() { 745 void ArcAuthService::CancelAuthCode() {
776 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 746 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
777 747
778 if (state_ == State::NOT_INITIALIZED) { 748 if (state_ == State::NOT_INITIALIZED) {
779 NOTREACHED(); 749 NOTREACHED();
780 return; 750 return;
781 } 751 }
782 752
783 // In case |state_| is ACTIVE, |ui_page_| can be START_PROGRESS (which means 753 // In case |state_| is ACTIVE, |ui_page_| can be START_PROGRESS (which means
784 // normal Arc booting) or ERROR or ERROR_WITH_FEEDBACK (in case Arc can not 754 // normal Arc booting) or ERROR or ERROR_WITH_FEEDBACK (in case Arc can not
785 // be started). If Arc is booting normally dont't stop it on progress close. 755 // be started). If Arc is booting normally dont't stop it on progress close.
786 if (state_ != State::FETCHING_CODE && ui_page_ != UIPage::ERROR && 756 if (state_ != State::FETCHING_CODE &&
787 ui_page_ != UIPage::ERROR_WITH_FEEDBACK) { 757 (support_host_ && support_host_->ui_page() != UIPage::ERROR))
788 return; 758 return;
789 }
790 759
791 // Update UMA with user cancel only if error is not currently shown. 760 // Update UMA with user cancel only if error is not currently shown.
792 if (ui_page_ != UIPage::ERROR && ui_page_ == UIPage::ERROR_WITH_FEEDBACK && 761 if (support_host_ &&
793 ui_page_ != UIPage::NO_PAGE) { 762 support_host_->ui_page() != UIPage::ERROR &&
763 support_host_->ui_page() != UIPage::NO_PAGE)
794 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); 764 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL);
795 }
796 765
797 StopArc(); 766 StopArc();
798 767
799 if (IsArcManaged()) 768 if (IsArcManaged())
800 return; 769 return;
801 770
802 DisableArc(); 771 DisableArc();
803 } 772 }
804 773
805 bool ArcAuthService::IsArcManaged() const { 774 bool ArcAuthService::IsArcManaged() const {
(...skipping 29 matching lines...) Expand all
835 DCHECK(profile_); 804 DCHECK(profile_);
836 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); 805 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false);
837 } 806 }
838 807
839 void ArcAuthService::StartUI() { 808 void ArcAuthService::StartUI() {
840 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 809 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
841 810
842 if (!arc_bridge_service()->stopped()) { 811 if (!arc_bridge_service()->stopped()) {
843 // If the user attempts to re-enable ARC while the bridge is still running 812 // If the user attempts to re-enable ARC while the bridge is still running
844 // the user should not be able to continue until the bridge has stopped. 813 // the user should not be able to continue until the bridge has stopped.
845 ShowUI(UIPage::ERROR, l10n_util::GetStringUTF16( 814 if (support_host_)
846 IDS_ARC_SIGN_IN_SERVICE_UNAVAILABLE_ERROR)); 815 support_host_->ShowErrorPage(
816 ErrorType::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false);
847 return; 817 return;
848 } 818 }
849 819
850 SetState(State::FETCHING_CODE); 820 SetState(State::FETCHING_CODE);
851 821
852 if (initial_opt_in_) { 822 if (initial_opt_in_) {
853 initial_opt_in_ = false; 823 initial_opt_in_ = false;
854 ShowUI(UIPage::TERMS, base::string16()); 824 if (support_host_)
825 support_host_->ShowTermsOfServicePage();
855 } else { 826 } else {
856 context_->PrepareContext(); 827 context_->PrepareContext();
857 } 828 }
858 } 829 }
859 830
860 void ArcAuthService::OnPrepareContextFailed() { 831 void ArcAuthService::OnPrepareContextFailed() {
861 DCHECK_EQ(state_, State::FETCHING_CODE); 832 DCHECK_EQ(state_, State::FETCHING_CODE);
862 833 ShutdownBridge();
863 ShutdownBridgeAndShowUI( 834 if (support_host_)
864 UIPage::ERROR, 835 support_host_->ShowErrorPage(ErrorType::SERVER_COMMUNICATION_ERROR, false);
865 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR));
866 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); 836 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
867 } 837 }
868 838
869 void ArcAuthService::OnAuthCodeSuccess(const std::string& auth_code) { 839 void ArcAuthService::OnAuthCodeSuccess(const std::string& auth_code) {
870 SetAuthCodeAndStartArc(auth_code); 840 SetAuthCodeAndStartArc(auth_code);
871 } 841 }
872 842
873 void ArcAuthService::OnAuthCodeFailed() { 843 void ArcAuthService::OnAuthCodeFailed() {
874 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 844 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
875 DCHECK_EQ(state_, State::FETCHING_CODE); 845 DCHECK_EQ(state_, State::FETCHING_CODE);
876 ShutdownBridgeAndShowUI( 846 ShutdownBridge();
877 UIPage::ERROR, 847 if (support_host_)
878 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); 848 support_host_->ShowErrorPage(ErrorType::SERVER_COMMUNICATION_ERROR, false);
879 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); 849 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
880 } 850 }
881 851
882 void ArcAuthService::OnAndroidManagementChecked( 852 void ArcAuthService::OnAndroidManagementChecked(
883 policy::AndroidManagementClient::Result result) { 853 policy::AndroidManagementClient::Result result) {
884 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 854 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
885 switch (result) { 855 switch (result) {
886 case policy::AndroidManagementClient::Result::UNMANAGED: 856 case policy::AndroidManagementClient::Result::UNMANAGED:
887 OnAndroidManagementPassed(); 857 OnAndroidManagementPassed();
888 break; 858 break;
889 case policy::AndroidManagementClient::Result::MANAGED: 859 case policy::AndroidManagementClient::Result::MANAGED:
890 ShutdownBridgeAndShowUI( 860 ShutdownBridge();
891 UIPage::ERROR, 861 if (support_host_) {
892 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR)); 862 support_host_->ShowErrorPage(
863 ErrorType::ANDROID_MANAGEMENT_REQUIRED_ERROR, false);
864 }
893 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); 865 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED);
894 break; 866 break;
895 case policy::AndroidManagementClient::Result::ERROR: 867 case policy::AndroidManagementClient::Result::ERROR:
896 ShutdownBridgeAndShowUI( 868 ShutdownBridge();
897 UIPage::ERROR, 869 if (support_host_) {
898 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); 870 support_host_->ShowErrorPage(
871 ErrorType::SERVER_COMMUNICATION_ERROR, false);
872 }
899 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); 873 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
900 break; 874 break;
901 } 875 }
902 } 876 }
903 877
904 void ArcAuthService::OnBackgroundAndroidManagementChecked( 878 void ArcAuthService::OnBackgroundAndroidManagementChecked(
905 policy::AndroidManagementClient::Result result) { 879 policy::AndroidManagementClient::Result result) {
906 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 880 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
907 switch (result) { 881 switch (result) {
908 case policy::AndroidManagementClient::Result::UNMANAGED: 882 case policy::AndroidManagementClient::Result::UNMANAGED:
(...skipping 17 matching lines...) Expand all
926 std::string auth_endpoint; 900 std::string auth_endpoint;
927 if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) { 901 if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) {
928 auth_endpoint = command_line->GetSwitchValueASCII( 902 auth_endpoint = command_line->GetSwitchValueASCII(
929 chromeos::switches::kArcUseAuthEndpoint); 903 chromeos::switches::kArcUseAuthEndpoint);
930 } 904 }
931 905
932 if (!auth_endpoint.empty()) { 906 if (!auth_endpoint.empty()) {
933 auth_code_fetcher_.reset(new ArcAuthCodeFetcher( 907 auth_code_fetcher_.reset(new ArcAuthCodeFetcher(
934 this, context_->GetURLRequestContext(), profile_, auth_endpoint)); 908 this, context_->GetURLRequestContext(), profile_, auth_endpoint));
935 } else { 909 } else {
936 ShowUI(UIPage::LSO_PROGRESS, base::string16()); 910 if (support_host_)
911 support_host_->ShowLsoPage();
937 } 912 }
938 } 913 }
939 914
940 void ArcAuthService::OnAndroidManagementPassed() { 915 void ArcAuthService::OnAndroidManagementPassed() {
941 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 916 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
942 917
943 if (state_ == State::ACTIVE) { 918 if (state_ == State::ACTIVE) {
944 if (IsAuthCodeRequest()) 919 if (IsAuthCodeRequest())
945 FetchAuthCode(); 920 FetchAuthCode();
946 return; 921 return;
947 } 922 }
948 923
949 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) || 924 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) ||
950 IsOptInVerificationDisabled()) { 925 IsOptInVerificationDisabled()) {
951 StartArc(); 926 StartArc();
952 } else { 927 } else {
953 FetchAuthCode(); 928 FetchAuthCode();
954 } 929 }
955 } 930 }
956 931
932 void ArcAuthService::OnMetricsModeChanged(bool enabled, bool managed) {
933 if (support_host_)
934 support_host_->SetMetricsCheckbox(enabled, managed);
935 }
936
937 void ArcAuthService::OnBackupAndRestoreModeChanged(
938 bool enabled, bool managed) {
939 if (support_host_)
940 support_host_->SetBackupAndRestoreCheckbox(enabled, managed);
941 }
942
943 void ArcAuthService::OnLocationServicesModeChanged(
944 bool enabled, bool managed) {
945 if (support_host_)
946 support_host_->SetLocationServiceCheckbox(enabled, managed);
947 }
948
949 void ArcAuthService::OnWindowClosed() {
950 CancelAuthCode();
951 }
952
953 void ArcAuthService::OnTermsAgreed(bool is_metrics_enabled,
954 bool is_backup_and_restore_enabled,
955 bool is_location_service_enabled) {
956 preference_handler_->EnableMetrics(is_metrics_enabled);
957 preference_handler_->EnableBackupRestore(is_backup_and_restore_enabled);
958 preference_handler_->EnableLocationService(is_location_service_enabled);
959 StartLso();
960 }
961
962 void ArcAuthService::OnAuthSucceeded(const std::string& auth_code) {
963 SetAuthCodeAndStartArc(auth_code);
964 }
965
966 void ArcAuthService::OnSendFeedbackClicked() {
967 chrome::OpenFeedbackDialog(nullptr);
968 }
969
957 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { 970 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) {
958 switch (state) { 971 switch (state) {
959 case ArcAuthService::State::NOT_INITIALIZED: 972 case ArcAuthService::State::NOT_INITIALIZED:
960 return os << "NOT_INITIALIZED"; 973 return os << "NOT_INITIALIZED";
961 case ArcAuthService::State::STOPPED: 974 case ArcAuthService::State::STOPPED:
962 return os << "STOPPED"; 975 return os << "STOPPED";
963 case ArcAuthService::State::FETCHING_CODE: 976 case ArcAuthService::State::FETCHING_CODE:
964 return os << "FETCHING_CODE"; 977 return os << "FETCHING_CODE";
965 case ArcAuthService::State::ACTIVE: 978 case ArcAuthService::State::ACTIVE:
966 return os << "ACTIVE"; 979 return os << "ACTIVE";
967 default: 980 default:
968 NOTREACHED(); 981 NOTREACHED();
969 return os; 982 return os;
970 } 983 }
971 } 984 }
972 985
973 } // namespace arc 986 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698