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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/arc/arc_auth_service.cc
diff --git a/chrome/browser/chromeos/arc/arc_auth_service.cc b/chrome/browser/chromeos/arc/arc_auth_service.cc
index 672eb8a6006065bdecdc53a3c4b7fca868fe66e1..79ba679ea06420ad9986582b71f64c7559b1a894 100644
--- a/chrome/browser/chromeos/arc/arc_auth_service.cc
+++ b/chrome/browser/chromeos/arc/arc_auth_service.cc
@@ -18,10 +18,10 @@
#include "chrome/browser/chromeos/arc/arc_auth_notification.h"
#include "chrome/browser/chromeos/arc/arc_optin_uma.h"
#include "chrome/browser/chromeos/arc/arc_support_host.h"
+#include "chrome/browser/chromeos/arc/optin/arc_optin_preference_handler.h"
#include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h"
#include "chrome/browser/chromeos/arc/policy/arc_policy_util.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
-#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/policy/profile_policy_connector.h"
#include "chrome/browser/policy/profile_policy_connector_factory.h"
#include "chrome/browser/prefs/pref_service_syncable_util.h"
@@ -29,8 +29,7 @@
#include "chrome/browser/ui/app_list/arc/arc_app_launcher.h"
#include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
-#include "chrome/browser/ui/extensions/app_launch_params.h"
-#include "chrome/browser/ui/extensions/application_launch.h"
+#include "chrome/browser/ui/browser_commands.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/chromeos_switches.h"
@@ -43,10 +42,7 @@
#include "components/sync_preferences/pref_service_syncable.h"
#include "components/user_manager/user.h"
#include "content/public/browser/browser_thread.h"
-#include "extensions/browser/app_window/app_window_registry.h"
#include "extensions/browser/extension_prefs.h"
-#include "extensions/browser/extension_registry.h"
-#include "ui/base/l10n/l10n_util.h"
namespace arc {
@@ -70,6 +66,9 @@ bool g_enable_check_android_management_for_testing = false;
// but present the UI to try again.
constexpr base::TimeDelta kArcSignInTimeout = base::TimeDelta::FromMinutes(5);
+using ErrorType = ArcSupportHost::ErrorType;
+using UIPage = ArcSupportHost::UIPage;
+
ash::ShelfDelegate* GetShelfDelegate() {
if (g_shelf_delegate_for_testing)
return g_shelf_delegate_for_testing;
@@ -377,40 +376,41 @@ void ArcAuthService::OnSignInFailedInternal(ProvisioningResult result) {
UpdateOptInCancelUMA(OptInCancelReason::CLOUD_PROVISION_FLOW_FAIL);
UpdateProvisioningResultUMA(result, policy_util::IsAccountManaged(profile_));
- int error_message_id;
+ ErrorType error_type;
switch (result) {
case ProvisioningResult::GMS_NETWORK_ERROR:
- error_message_id = IDS_ARC_SIGN_IN_NETWORK_ERROR;
+ error_type = ErrorType::SIGN_IN_NETWORK_ERROR;
break;
case ProvisioningResult::GMS_SERVICE_UNAVAILABLE:
case ProvisioningResult::GMS_SIGN_IN_FAILED:
case ProvisioningResult::GMS_SIGN_IN_TIMEOUT:
case ProvisioningResult::GMS_SIGN_IN_INTERNAL_ERROR:
- error_message_id = IDS_ARC_SIGN_IN_SERVICE_UNAVAILABLE_ERROR;
+ error_type = ErrorType::SIGN_IN_SERVICE_UNAVAILABLE_ERROR;
break;
case ProvisioningResult::GMS_BAD_AUTHENTICATION:
- error_message_id = IDS_ARC_SIGN_IN_BAD_AUTHENTICATION_ERROR;
+ error_type = ErrorType::SIGN_IN_BAD_AUTHENTICATION_ERROR;
break;
case ProvisioningResult::DEVICE_CHECK_IN_FAILED:
case ProvisioningResult::DEVICE_CHECK_IN_TIMEOUT:
case ProvisioningResult::DEVICE_CHECK_IN_INTERNAL_ERROR:
- error_message_id = IDS_ARC_SIGN_IN_GMS_NOT_AVAILABLE_ERROR;
+ error_type = ErrorType::SIGN_IN_GMS_NOT_AVAILABLE_ERROR;
break;
case ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED:
case ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT:
case ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR:
- error_message_id = IDS_ARC_SIGN_IN_CLOUD_PROVISION_FLOW_FAIL_ERROR;
+ error_type = ErrorType::SIGN_IN_CLOUD_PROVISION_FLOW_FAIL_ERROR;
break;
default:
- error_message_id = IDS_ARC_SIGN_IN_UNKNOWN_ERROR;
+ error_type = ErrorType::SIGN_IN_UNKNOWN_ERROR;
break;
}
if (result == ProvisioningResult::ARC_STOPPED) {
if (profile_->GetPrefs()->HasPrefPath(prefs::kArcSignedIn))
profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false);
- ShutdownBridgeAndShowUI(UIPage::ERROR,
- l10n_util::GetStringUTF16(error_message_id));
+ ShutdownBridge();
+ if (support_host_)
+ support_host_->ShowErrorPage(error_type, false);
return;
}
@@ -427,8 +427,8 @@ void ArcAuthService::OnSignInFailedInternal(ProvisioningResult result) {
// We'll delay shutting down the bridge in this case to allow people to send
// feedback.
- ShowUI(UIPage::ERROR_WITH_FEEDBACK,
- l10n_util::GetStringUTF16(error_message_id));
+ if (support_host_)
+ support_host_->ShowErrorPage(error_type, true /* show feedback button */);
}
void ArcAuthService::GetIsAccountManaged(
@@ -473,9 +473,18 @@ void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) {
// ARC support Chrome app is rarely used (only opt-in and re-auth flow).
// So, it may be better to initialize it lazily.
// TODO(hidehiko): Revisit to think about lazy initialization.
- support_host_.reset(new ArcSupportHost());
+ if (!g_disable_ui_for_testing && !IsOptInVerificationDisabled()) {
+ LOG(ERROR) << "HOGEHOGE";
+ support_host_.reset(new ArcSupportHost(profile_));
+ support_host_->set_observer(this);
+ }
SetState(State::STOPPED);
+ preference_handler_ = base::MakeUnique<arc::ArcOptInPreferenceHandler>(
+ this, profile_->GetPrefs());
+ // This automatically updates all preferences.
+ preference_handler_->Start();
+
PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver(
prefs::kArcEnabled, this);
@@ -524,7 +533,8 @@ void ArcAuthService::OnIsSyncingChanged() {
}
void ArcAuthService::Shutdown() {
- ShutdownBridgeAndCloseUI();
+ ShutdownBridge();
+ CloseUI();
if (profile_) {
sync_preferences::PrefServiceSyncable* pref_service_syncable =
PrefServiceSyncableFromProfile(profile_);
@@ -537,29 +547,6 @@ void ArcAuthService::Shutdown() {
SetState(State::NOT_INITIALIZED);
}
-void ArcAuthService::ShowUI(UIPage page, const base::string16& status) {
- if (g_disable_ui_for_testing || IsOptInVerificationDisabled())
- return;
-
- SetUIPage(page, status);
- const extensions::AppWindowRegistry* const app_window_registry =
- extensions::AppWindowRegistry::Get(profile_);
- DCHECK(app_window_registry);
- if (app_window_registry->GetCurrentAppWindowForApp(
- ArcSupportHost::kHostAppId)) {
- return;
- }
-
- const extensions::Extension* extension =
- extensions::ExtensionRegistry::Get(profile_)->GetInstalledExtension(
- ArcSupportHost::kHostAppId);
- CHECK(extension && extensions::util::IsAppLaunchable(
- ArcSupportHost::kHostAppId, profile_));
- OpenApplication(CreateAppLaunchParamsUserContainer(
- profile_, extension, WindowOpenDisposition::NEW_WINDOW,
- extensions::SOURCE_CHROME_INTERNAL));
-}
-
void ArcAuthService::OnContextReady() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
@@ -599,7 +586,8 @@ void ArcAuthService::StopArc() {
UpdateEnabledStateUMA(false);
profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false);
}
- ShutdownBridgeAndCloseUI();
+ ShutdownBridge();
+ CloseUI();
}
void ArcAuthService::OnOptInPreferenceChanged() {
@@ -663,17 +651,6 @@ void ArcAuthService::ShutdownBridge() {
observer.OnShutdownBridge();
}
-void ArcAuthService::ShutdownBridgeAndCloseUI() {
- ShutdownBridge();
- CloseUI();
-}
-
-void ArcAuthService::ShutdownBridgeAndShowUI(UIPage page,
- const base::string16& status) {
- ShutdownBridge();
- ShowUI(page, status);
-}
-
void ArcAuthService::AddObserver(Observer* observer) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
observer_list_.AddObserver(observer);
@@ -685,21 +662,12 @@ void ArcAuthService::RemoveObserver(Observer* observer) {
}
void ArcAuthService::CloseUI() {
- ui_page_ = UIPage::NO_PAGE;
- ui_page_status_.clear();
if (support_host_)
support_host_->Close();
if (!g_disable_ui_for_testing)
ArcAuthNotification::Hide();
}
-void ArcAuthService::SetUIPage(UIPage page, const base::string16& status) {
- ui_page_ = page;
- ui_page_status_ = status;
- if (support_host_)
- support_host_->ShowPage(ui_page_, ui_page_status_);
-}
-
// This is the special method to support enterprise mojo API.
// TODO(hidehiko): Remove this.
void ArcAuthService::StopAndEnableArc() {
@@ -735,14 +703,16 @@ void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) {
}
if (state_ != State::FETCHING_CODE) {
- ShutdownBridgeAndCloseUI();
+ ShutdownBridge();
+ CloseUI();
return;
}
sign_in_time_ = base::Time::Now();
VLOG(1) << "Starting ARC for first sign in.";
- SetUIPage(UIPage::START_PROGRESS, base::string16());
+ if (support_host_)
+ support_host_->ShowLoadingPage();
ShutdownBridge();
auth_code_ = auth_code;
arc_sign_in_timer_.Start(FROM_HERE, kArcSignInTimeout,
@@ -760,11 +730,11 @@ void ArcAuthService::StartLso() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// Update UMA only if error (with or without feedback) is currently shown.
- if (ui_page_ == UIPage::ERROR) {
+ if (support_host_ && support_host_->ui_page() == UIPage::ERROR) {
UpdateOptInActionUMA(OptInActionType::RETRY);
- } else if (ui_page_ == UIPage::ERROR_WITH_FEEDBACK) {
- UpdateOptInActionUMA(OptInActionType::RETRY);
- ShutdownBridge();
+ if (support_host_->error_page_has_send_feedback_button()) {
+ ShutdownBridge();
+ }
}
// TODO(khmel): Use PrepareContextForAuthCodeRequest for this case.
@@ -783,16 +753,15 @@ void ArcAuthService::CancelAuthCode() {
// In case |state_| is ACTIVE, |ui_page_| can be START_PROGRESS (which means
// normal Arc booting) or ERROR or ERROR_WITH_FEEDBACK (in case Arc can not
// be started). If Arc is booting normally dont't stop it on progress close.
- if (state_ != State::FETCHING_CODE && ui_page_ != UIPage::ERROR &&
- ui_page_ != UIPage::ERROR_WITH_FEEDBACK) {
+ if (state_ != State::FETCHING_CODE &&
+ (support_host_ && support_host_->ui_page() != UIPage::ERROR))
return;
- }
// Update UMA with user cancel only if error is not currently shown.
- if (ui_page_ != UIPage::ERROR && ui_page_ == UIPage::ERROR_WITH_FEEDBACK &&
- ui_page_ != UIPage::NO_PAGE) {
+ if (support_host_ &&
+ support_host_->ui_page() != UIPage::ERROR &&
+ support_host_->ui_page() != UIPage::NO_PAGE)
UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL);
- }
StopArc();
@@ -842,8 +811,9 @@ void ArcAuthService::StartUI() {
if (!arc_bridge_service()->stopped()) {
// If the user attempts to re-enable ARC while the bridge is still running
// the user should not be able to continue until the bridge has stopped.
- ShowUI(UIPage::ERROR, l10n_util::GetStringUTF16(
- IDS_ARC_SIGN_IN_SERVICE_UNAVAILABLE_ERROR));
+ if (support_host_)
+ support_host_->ShowErrorPage(
+ ErrorType::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false);
return;
}
@@ -851,7 +821,8 @@ void ArcAuthService::StartUI() {
if (initial_opt_in_) {
initial_opt_in_ = false;
- ShowUI(UIPage::TERMS, base::string16());
+ if (support_host_)
+ support_host_->ShowTermsOfServicePage();
} else {
context_->PrepareContext();
}
@@ -859,10 +830,9 @@ void ArcAuthService::StartUI() {
void ArcAuthService::OnPrepareContextFailed() {
DCHECK_EQ(state_, State::FETCHING_CODE);
-
- ShutdownBridgeAndShowUI(
- UIPage::ERROR,
- l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR));
+ ShutdownBridge();
+ if (support_host_)
+ support_host_->ShowErrorPage(ErrorType::SERVER_COMMUNICATION_ERROR, false);
UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
}
@@ -873,9 +843,9 @@ void ArcAuthService::OnAuthCodeSuccess(const std::string& auth_code) {
void ArcAuthService::OnAuthCodeFailed() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK_EQ(state_, State::FETCHING_CODE);
- ShutdownBridgeAndShowUI(
- UIPage::ERROR,
- l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR));
+ ShutdownBridge();
+ if (support_host_)
+ support_host_->ShowErrorPage(ErrorType::SERVER_COMMUNICATION_ERROR, false);
UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
}
@@ -887,15 +857,19 @@ void ArcAuthService::OnAndroidManagementChecked(
OnAndroidManagementPassed();
break;
case policy::AndroidManagementClient::Result::MANAGED:
- ShutdownBridgeAndShowUI(
- UIPage::ERROR,
- l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR));
+ ShutdownBridge();
+ if (support_host_) {
+ support_host_->ShowErrorPage(
+ ErrorType::ANDROID_MANAGEMENT_REQUIRED_ERROR, false);
+ }
UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED);
break;
case policy::AndroidManagementClient::Result::ERROR:
- ShutdownBridgeAndShowUI(
- UIPage::ERROR,
- l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR));
+ ShutdownBridge();
+ if (support_host_) {
+ support_host_->ShowErrorPage(
+ ErrorType::SERVER_COMMUNICATION_ERROR, false);
+ }
UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
break;
}
@@ -933,7 +907,8 @@ void ArcAuthService::FetchAuthCode() {
auth_code_fetcher_.reset(new ArcAuthCodeFetcher(
this, context_->GetURLRequestContext(), profile_, auth_endpoint));
} else {
- ShowUI(UIPage::LSO_PROGRESS, base::string16());
+ if (support_host_)
+ support_host_->ShowLsoPage();
}
}
@@ -954,6 +929,44 @@ void ArcAuthService::OnAndroidManagementPassed() {
}
}
+void ArcAuthService::OnMetricsModeChanged(bool enabled, bool managed) {
+ if (support_host_)
+ support_host_->SetMetricsCheckbox(enabled, managed);
+}
+
+void ArcAuthService::OnBackupAndRestoreModeChanged(
+ bool enabled, bool managed) {
+ if (support_host_)
+ support_host_->SetBackupAndRestoreCheckbox(enabled, managed);
+}
+
+void ArcAuthService::OnLocationServicesModeChanged(
+ bool enabled, bool managed) {
+ if (support_host_)
+ support_host_->SetLocationServiceCheckbox(enabled, managed);
+}
+
+void ArcAuthService::OnWindowClosed() {
+ CancelAuthCode();
+}
+
+void ArcAuthService::OnTermsAgreed(bool is_metrics_enabled,
+ bool is_backup_and_restore_enabled,
+ bool is_location_service_enabled) {
+ preference_handler_->EnableMetrics(is_metrics_enabled);
+ preference_handler_->EnableBackupRestore(is_backup_and_restore_enabled);
+ preference_handler_->EnableLocationService(is_location_service_enabled);
+ StartLso();
+}
+
+void ArcAuthService::OnAuthSucceeded(const std::string& auth_code) {
+ SetAuthCodeAndStartArc(auth_code);
+}
+
+void ArcAuthService::OnSendFeedbackClicked() {
+ chrome::OpenFeedbackDialog(nullptr);
+}
+
std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) {
switch (state) {
case ArcAuthService::State::NOT_INITIALIZED:

Powered by Google App Engine
This is Rietveld 408576698