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

Unified Diff: chrome/browser/chromeos/arc/arc_session_manager.cc

Issue 2507073002: Split ArcSessionManager from ArcAuthService. (Closed)
Patch Set: Fix rebase mistake 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_session_manager.cc
diff --git a/chrome/browser/chromeos/arc/arc_auth_service.cc b/chrome/browser/chromeos/arc/arc_session_manager.cc
similarity index 64%
copy from chrome/browser/chromeos/arc/arc_auth_service.cc
copy to chrome/browser/chromeos/arc/arc_session_manager.cc
index a325ce282d0a29038df34535bb169dfd347b1698..21effca88e1741d7f087ae3c547c954e774f4945 100644
--- a/chrome/browser/chromeos/arc/arc_auth_service.cc
+++ b/chrome/browser/chromeos/arc/arc_session_manager.cc
@@ -1,8 +1,8 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/chromeos/arc/arc_auth_service.h"
+#include "chrome/browser/chromeos/arc/arc_session_manager.h"
#include <utility>
@@ -50,10 +50,8 @@ namespace arc {
namespace {
-constexpr size_t kMinVersionForOnAccountInfoReady = 5;
-
// Weak pointer. This class is owned by ArcServiceManager.
-ArcAuthService* g_arc_auth_service = nullptr;
+ArcSessionManager* g_arc_session_manager = nullptr;
// Skip creating UI in unit tests
bool g_disable_ui_for_testing = false;
@@ -80,134 +78,35 @@ ash::ShelfDelegate* GetShelfDelegate() {
return nullptr;
}
-ProvisioningResult ConvertArcSignInFailureReasonToProvisioningResult(
- mojom::ArcSignInFailureReason reason) {
- using ArcSignInFailureReason = mojom::ArcSignInFailureReason;
-
-#define MAP_PROVISIONING_RESULT(name) \
- case ArcSignInFailureReason::name: \
- return ProvisioningResult::name
-
- switch (reason) {
- MAP_PROVISIONING_RESULT(UNKNOWN_ERROR);
- MAP_PROVISIONING_RESULT(MOJO_VERSION_MISMATCH);
- MAP_PROVISIONING_RESULT(MOJO_CALL_TIMEOUT);
- MAP_PROVISIONING_RESULT(DEVICE_CHECK_IN_FAILED);
- MAP_PROVISIONING_RESULT(DEVICE_CHECK_IN_TIMEOUT);
- MAP_PROVISIONING_RESULT(DEVICE_CHECK_IN_INTERNAL_ERROR);
- MAP_PROVISIONING_RESULT(GMS_NETWORK_ERROR);
- MAP_PROVISIONING_RESULT(GMS_SERVICE_UNAVAILABLE);
- MAP_PROVISIONING_RESULT(GMS_BAD_AUTHENTICATION);
- MAP_PROVISIONING_RESULT(GMS_SIGN_IN_FAILED);
- MAP_PROVISIONING_RESULT(GMS_SIGN_IN_TIMEOUT);
- MAP_PROVISIONING_RESULT(GMS_SIGN_IN_INTERNAL_ERROR);
- MAP_PROVISIONING_RESULT(CLOUD_PROVISION_FLOW_FAILED);
- MAP_PROVISIONING_RESULT(CLOUD_PROVISION_FLOW_TIMEOUT);
- MAP_PROVISIONING_RESULT(CLOUD_PROVISION_FLOW_INTERNAL_ERROR);
- }
-#undef MAP_PROVISIONING_RESULT
-
- NOTREACHED() << "unknown reason: " << static_cast<int>(reason);
- return ProvisioningResult::UNKNOWN_ERROR;
-}
-
-bool IsArcKioskMode() {
- return user_manager::UserManager::Get()->IsLoggedInAsArcKioskApp();
-}
-
-mojom::ChromeAccountType GetAccountType() {
- if (IsArcKioskMode())
- return mojom::ChromeAccountType::ROBOT_ACCOUNT;
- return mojom::ChromeAccountType::USER_ACCOUNT;
-}
-
} // namespace
-// TODO(lhchavez): Get rid of this class once we can safely remove all the
-// deprecated interfaces and only need to care about one type of callback.
-class ArcAuthService::AccountInfoNotifier {
- public:
- explicit AccountInfoNotifier(
- const GetAuthCodeDeprecatedCallback& auth_callback)
- : callback_type_(CallbackType::AUTH_CODE),
- auth_callback_(auth_callback) {}
-
- explicit AccountInfoNotifier(
- const GetAuthCodeAndAccountTypeDeprecatedCallback& auth_account_callback)
- : callback_type_(CallbackType::AUTH_CODE_AND_ACCOUNT),
- auth_account_callback_(auth_account_callback) {}
-
- explicit AccountInfoNotifier(const AccountInfoCallback& account_info_callback)
- : callback_type_(CallbackType::ACCOUNT_INFO),
- account_info_callback_(account_info_callback) {}
-
- void Notify(bool is_enforced,
- const std::string& auth_code,
- mojom::ChromeAccountType account_type,
- bool is_managed) {
- switch (callback_type_) {
- case CallbackType::AUTH_CODE:
- DCHECK(!auth_callback_.is_null());
- auth_callback_.Run(auth_code, is_enforced);
- break;
- case CallbackType::AUTH_CODE_AND_ACCOUNT:
- DCHECK(!auth_account_callback_.is_null());
- auth_account_callback_.Run(auth_code, is_enforced, account_type);
- break;
- case CallbackType::ACCOUNT_INFO:
- DCHECK(!account_info_callback_.is_null());
- mojom::AccountInfoPtr account_info = mojom::AccountInfo::New();
- if (!is_enforced) {
- account_info->auth_code = base::nullopt;
- } else {
- account_info->auth_code = auth_code;
- }
- account_info->account_type = account_type;
- account_info->is_managed = is_managed;
- account_info_callback_.Run(std::move(account_info));
- break;
- }
- }
-
- private:
- enum class CallbackType { AUTH_CODE, AUTH_CODE_AND_ACCOUNT, ACCOUNT_INFO };
-
- const CallbackType callback_type_;
- const GetAuthCodeDeprecatedCallback auth_callback_;
- const GetAuthCodeAndAccountTypeDeprecatedCallback auth_account_callback_;
- const AccountInfoCallback account_info_callback_;
-};
-
-ArcAuthService::ArcAuthService(ArcBridgeService* bridge_service)
- : ArcService(bridge_service), binding_(this), weak_ptr_factory_(this) {
+ArcSessionManager::ArcSessionManager(ArcBridgeService* bridge_service)
+ : ArcService(bridge_service), weak_ptr_factory_(this) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- DCHECK(!g_arc_auth_service);
-
- g_arc_auth_service = this;
+ DCHECK(!g_arc_session_manager);
+ g_arc_session_manager = this;
arc_bridge_service()->AddObserver(this);
- arc_bridge_service()->auth()->AddObserver(this);
}
-ArcAuthService::~ArcAuthService() {
+ArcSessionManager::~ArcSessionManager() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- DCHECK_EQ(this, g_arc_auth_service);
Shutdown();
- arc_bridge_service()->auth()->RemoveObserver(this);
arc_bridge_service()->RemoveObserver(this);
- g_arc_auth_service = nullptr;
+ DCHECK_EQ(this, g_arc_session_manager);
+ g_arc_session_manager = nullptr;
}
// static
-ArcAuthService* ArcAuthService::Get() {
+ArcSessionManager* ArcSessionManager::Get() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- return g_arc_auth_service;
+ return g_arc_session_manager;
}
// static
-void ArcAuthService::RegisterProfilePrefs(
+void ArcSessionManager::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
// TODO(dspaid): Implement a mechanism to allow this to sync on first boot
// only.
@@ -219,29 +118,29 @@ void ArcAuthService::RegisterProfilePrefs(
}
// static
-void ArcAuthService::DisableUIForTesting() {
+void ArcSessionManager::DisableUIForTesting() {
g_disable_ui_for_testing = true;
}
// static
-void ArcAuthService::SetShelfDelegateForTesting(
+void ArcSessionManager::SetShelfDelegateForTesting(
ash::ShelfDelegate* shelf_delegate) {
g_shelf_delegate_for_testing = shelf_delegate;
}
// static
-bool ArcAuthService::IsOptInVerificationDisabled() {
+bool ArcSessionManager::IsOptInVerificationDisabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kDisableArcOptInVerification);
}
// static
-void ArcAuthService::EnableCheckAndroidManagementForTesting() {
+void ArcSessionManager::EnableCheckAndroidManagementForTesting() {
g_enable_check_android_management_for_testing = true;
}
// static
-bool ArcAuthService::IsAllowedForProfile(const Profile* profile) {
+bool ArcSessionManager::IsAllowedForProfile(const Profile* profile) {
if (!ArcBridgeService::GetEnabled(base::CommandLine::ForCurrentProcess())) {
VLOG(1) << "Arc is not enabled.";
return false;
@@ -278,13 +177,12 @@ bool ArcAuthService::IsAllowedForProfile(const Profile* profile) {
return true;
}
-void ArcAuthService::OnInstanceReady() {
- auto* instance = arc_bridge_service()->auth()->GetInstanceForMethod("Init");
- DCHECK(instance);
- instance->Init(binding_.CreateInterfacePtrAndBind());
+// static
+bool ArcSessionManager::IsArcKioskMode() {
+ return user_manager::UserManager::Get()->IsLoggedInAsArcKioskApp();
}
-void ArcAuthService::OnBridgeStopped(ArcBridgeService::StopReason reason) {
+void ArcSessionManager::OnBridgeStopped(ArcBridgeService::StopReason reason) {
// TODO(crbug.com/625923): Use |reason| to report more detailed errors.
if (arc_sign_in_timer_.IsRunning()) {
OnProvisioningFinished(ProvisioningResult::ARC_STOPPED);
@@ -301,12 +199,12 @@ void ArcAuthService::OnBridgeStopped(ArcBridgeService::StopReason reason) {
// done.
// TODO(hidehiko): Restructure the code. crbug.com/665316
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(&ArcAuthService::OnArcDataRemoved,
+ FROM_HERE, base::Bind(&ArcSessionManager::OnArcDataRemoved,
weak_ptr_factory_.GetWeakPtr(), true));
}
}
-void ArcAuthService::RemoveArcData() {
+void ArcSessionManager::RemoveArcData() {
if (!arc_bridge_service()->stopped()) {
// Just set a flag. On bridge stopped, this will be re-called,
// then session manager should remove the data.
@@ -317,11 +215,11 @@ void ArcAuthService::RemoveArcData() {
chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData(
cryptohome::Identification(
multi_user_util::GetAccountIdFromProfile(profile_)),
- base::Bind(&ArcAuthService::OnArcDataRemoved,
+ base::Bind(&ArcSessionManager::OnArcDataRemoved,
weak_ptr_factory_.GetWeakPtr()));
}
-void ArcAuthService::OnArcDataRemoved(bool success) {
+void ArcSessionManager::OnArcDataRemoved(bool success) {
LOG_IF(ERROR, !success) << "Required ARC user data wipe failed.";
// Here check if |reenable_arc_| is marked or not.
@@ -339,149 +237,7 @@ void ArcAuthService::OnArcDataRemoved(bool success) {
EnableArc();
}
-void ArcAuthService::GetAuthCodeDeprecated0(
- const GetAuthCodeDeprecated0Callback& callback) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- NOTREACHED() << "GetAuthCodeDeprecated0() should no longer be callable";
-}
-
-void ArcAuthService::GetAuthCodeDeprecated(
- const GetAuthCodeDeprecatedCallback& callback) {
- // For robot account we must use RequestAccountInfo because it allows
- // to specify account type.
- DCHECK(!IsArcKioskMode());
- RequestAccountInfoInternal(
- base::MakeUnique<ArcAuthService::AccountInfoNotifier>(callback));
-}
-
-void ArcAuthService::GetAuthCodeAndAccountTypeDeprecated(
- const GetAuthCodeAndAccountTypeDeprecatedCallback& callback) {
- RequestAccountInfoInternal(
- base::MakeUnique<ArcAuthService::AccountInfoNotifier>(callback));
-}
-
-void ArcAuthService::RequestAccountInfo() {
- RequestAccountInfoInternal(
- base::MakeUnique<ArcAuthService::AccountInfoNotifier>(
- base::Bind(&ArcAuthService::OnAccountInfoReady,
- weak_ptr_factory_.GetWeakPtr())));
-}
-
-void ArcAuthService::OnAccountInfoReady(mojom::AccountInfoPtr account_info) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- auto* instance = arc_bridge_service()->auth()->GetInstanceForMethod(
- "OnAccountInfoReady", kMinVersionForOnAccountInfoReady);
- DCHECK(instance);
- instance->OnAccountInfoReady(std::move(account_info));
-}
-
-void ArcAuthService::RequestAccountInfoInternal(
- std::unique_ptr<ArcAuthService::AccountInfoNotifier>
- account_info_notifier) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- // No other auth code-related operation may be in progress.
- DCHECK(!account_info_notifier_);
-
- if (IsOptInVerificationDisabled()) {
- account_info_notifier->Notify(false /* = is_enforced */, std::string(),
- GetAccountType(),
- policy_util::IsAccountManaged(profile_));
- return;
- }
-
- // Hereafter asynchronous operation. Remember the notifier.
- account_info_notifier_ = std::move(account_info_notifier);
-
- // In Kiosk mode, use Robot auth code fetching.
- if (IsArcKioskMode()) {
- arc_robot_auth_.reset(new ArcRobotAuth());
- arc_robot_auth_->FetchRobotAuthCode(
- base::Bind(&ArcAuthService::OnRobotAuthCodeFetched,
- weak_ptr_factory_.GetWeakPtr()));
- return;
- }
-
- // If endpoint is passed via command line flag, use automatic auth code
- // fetching.
- const base::CommandLine* command_line =
- base::CommandLine::ForCurrentProcess();
- if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) {
- std::string auth_endpoint = command_line->GetSwitchValueASCII(
- chromeos::switches::kArcUseAuthEndpoint);
- if (!auth_endpoint.empty()) {
- DCHECK(!auth_code_fetcher_);
- auth_code_fetcher_ = base::MakeUnique<ArcAuthCodeFetcher>(
- profile_, context_.get(), auth_endpoint);
- auth_code_fetcher_->Fetch(base::Bind(&ArcAuthService::OnAuthCodeFetched,
- weak_ptr_factory_.GetWeakPtr()));
- return;
- }
- }
-
- // Otherwise, show LSO page to user after HTTP context preparation, and let
- // them click "Sign in" button.
- DCHECK(context_);
- context_->Prepare(base::Bind(&ArcAuthService::OnContextPrepared,
- weak_ptr_factory_.GetWeakPtr()));
-}
-
-void ArcAuthService::OnContextPrepared(
- net::URLRequestContextGetter* request_context_getter) {
- if (!support_host_)
- return;
-
- if (request_context_getter) {
- support_host_->ShowLso();
- } else {
- support_host_->ShowError(ArcSupportHost::Error::SIGN_IN_NETWORK_ERROR,
- false);
- }
-}
-
-void ArcAuthService::OnRobotAuthCodeFetched(
- const std::string& robot_auth_code) {
- // We fetching robot auth code for ARC kiosk only.
- DCHECK(IsArcKioskMode());
-
- // Current instance of ArcRobotAuth became useless.
- arc_robot_auth_.reset();
-
- if (robot_auth_code.empty()) {
- VLOG(1) << "Robot account auth code fetching error";
- // Log out the user. All the cleanup will be done in Shutdown() method.
- // The callback is not called because auth code is empty.
- chrome::AttemptUserExit();
- return;
- }
-
- OnAuthCodeObtained(robot_auth_code);
-}
-
-void ArcAuthService::OnAuthCodeFetched(const std::string& auth_code) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- auth_code_fetcher_.reset();
-
- if (auth_code.empty()) {
- OnProvisioningFinished(
- ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR);
- return;
- }
-
- OnAuthCodeObtained(auth_code);
-}
-
-void ArcAuthService::OnSignInComplete() {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- DCHECK_EQ(state_, State::ACTIVE);
- OnProvisioningFinished(ProvisioningResult::SUCCESS);
-}
-
-void ArcAuthService::OnSignInFailed(mojom::ArcSignInFailureReason reason) {
- OnProvisioningFinished(
- ConvertArcSignInFailureReasonToProvisioningResult(reason));
-}
-
-void ArcAuthService::OnProvisioningFinished(ProvisioningResult result) {
+void ArcSessionManager::OnProvisioningFinished(ProvisioningResult result) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK_EQ(state_, State::ACTIVE);
@@ -580,23 +336,16 @@ void ArcAuthService::OnProvisioningFinished(ProvisioningResult result) {
support_host_->ShowError(error, true /* = show send feedback button */);
}
-void ArcAuthService::GetIsAccountManagedDeprecated(
- const GetIsAccountManagedDeprecatedCallback& callback) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
-
- callback.Run(policy_util::IsAccountManaged(profile_));
-}
-
-void ArcAuthService::SetState(State state) {
+void ArcSessionManager::SetState(State state) {
state_ = state;
}
-bool ArcAuthService::IsAllowed() const {
+bool ArcSessionManager::IsAllowed() const {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
return profile_ != nullptr;
}
-void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) {
+void ArcSessionManager::OnPrimaryUserProfilePrepared(Profile* profile) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(profile && profile != profile_);
@@ -649,8 +398,9 @@ void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) {
}
pref_change_registrar_.Init(profile_->GetPrefs());
pref_change_registrar_.Add(
- prefs::kArcEnabled, base::Bind(&ArcAuthService::OnOptInPreferenceChanged,
- weak_ptr_factory_.GetWeakPtr()));
+ prefs::kArcEnabled,
+ base::Bind(&ArcSessionManager::OnOptInPreferenceChanged,
+ weak_ptr_factory_.GetWeakPtr()));
if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) {
OnOptInPreferenceChanged();
} else {
@@ -660,7 +410,7 @@ void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) {
}
}
-void ArcAuthService::OnIsSyncingChanged() {
+void ArcSessionManager::OnIsSyncingChanged() {
sync_preferences::PrefServiceSyncable* const pref_service_syncable =
PrefServiceSyncableFromProfile(profile_);
if (!pref_service_syncable->IsSyncing())
@@ -672,7 +422,7 @@ void ArcAuthService::OnIsSyncingChanged() {
OnOptInPreferenceChanged();
}
-void ArcAuthService::Shutdown() {
+void ArcSessionManager::Shutdown() {
ShutdownBridge();
if (support_host_) {
support_host_->Close();
@@ -688,12 +438,11 @@ void ArcAuthService::Shutdown() {
pref_change_registrar_.RemoveAll();
context_.reset();
profile_ = nullptr;
- arc_robot_auth_.reset();
SetState(State::NOT_INITIALIZED);
}
-void ArcAuthService::OnSyncedPrefChanged(const std::string& path,
- bool from_sync) {
+void ArcSessionManager::OnSyncedPrefChanged(const std::string& path,
+ bool from_sync) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// Update UMA only for local changes
@@ -711,7 +460,7 @@ void ArcAuthService::OnSyncedPrefChanged(const std::string& path,
}
}
-void ArcAuthService::StopArc() {
+void ArcSessionManager::StopArc() {
if (state_ != State::STOPPED) {
profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false);
profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, false);
@@ -721,7 +470,7 @@ void ArcAuthService::StopArc() {
support_host_->Close();
}
-void ArcAuthService::OnOptInPreferenceChanged() {
+void ArcSessionManager::OnOptInPreferenceChanged() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(profile_);
@@ -778,18 +527,16 @@ void ArcAuthService::OnOptInPreferenceChanged() {
profile_, context_->token_service(), context_->account_id(),
true /* retry_on_error */));
android_management_checker_->StartCheck(
- base::Bind(&ArcAuthService::OnBackgroundAndroidManagementChecked,
+ base::Bind(&ArcSessionManager::OnBackgroundAndroidManagementChecked,
weak_ptr_factory_.GetWeakPtr()));
}
}
}
-void ArcAuthService::ShutdownBridge() {
+void ArcSessionManager::ShutdownBridge() {
arc_sign_in_timer_.Stop();
playstore_launcher_.reset();
- account_info_notifier_.reset();
android_management_checker_.reset();
- auth_code_fetcher_.reset();
arc_bridge_service()->RequestStop();
if (state_ != State::NOT_INITIALIZED)
SetState(State::STOPPED);
@@ -797,47 +544,37 @@ void ArcAuthService::ShutdownBridge() {
observer.OnShutdownBridge();
}
-void ArcAuthService::AddObserver(Observer* observer) {
+void ArcSessionManager::AddObserver(Observer* observer) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
observer_list_.AddObserver(observer);
}
-void ArcAuthService::RemoveObserver(Observer* observer) {
+void ArcSessionManager::RemoveObserver(Observer* observer) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
observer_list_.RemoveObserver(observer);
}
// This is the special method to support enterprise mojo API.
// TODO(hidehiko): Remove this.
-void ArcAuthService::StopAndEnableArc() {
+void ArcSessionManager::StopAndEnableArc() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(!arc_bridge_service()->stopped());
reenable_arc_ = true;
StopArc();
}
-void ArcAuthService::StartArc() {
+void ArcSessionManager::StartArc() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
arc_bridge_service()->RequestStart();
SetState(State::ACTIVE);
}
-void ArcAuthService::OnAuthCodeObtained(const std::string& auth_code) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- DCHECK(!auth_code.empty());
-
- account_info_notifier_->Notify(!IsOptInVerificationDisabled(), auth_code,
- GetAccountType(),
- policy_util::IsAccountManaged(profile_));
- account_info_notifier_.reset();
-}
-
-void ArcAuthService::OnArcSignInTimeout() {
+void ArcSessionManager::OnArcSignInTimeout() {
LOG(ERROR) << "Timed out waiting for first sign in.";
OnProvisioningFinished(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT);
}
-void ArcAuthService::CancelAuthCode() {
+void ArcSessionManager::CancelAuthCode() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (state_ == State::NOT_INITIALIZED) {
@@ -870,13 +607,13 @@ void ArcAuthService::CancelAuthCode() {
DisableArc();
}
-bool ArcAuthService::IsArcManaged() const {
+bool ArcSessionManager::IsArcManaged() const {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(profile_);
return profile_->GetPrefs()->IsManagedPreference(prefs::kArcEnabled);
}
-bool ArcAuthService::IsArcEnabled() const {
+bool ArcSessionManager::IsArcEnabled() const {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (!IsAllowed())
return false;
@@ -885,7 +622,7 @@ bool ArcAuthService::IsArcEnabled() const {
return profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled);
}
-void ArcAuthService::EnableArc() {
+void ArcSessionManager::EnableArc() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(profile_);
@@ -898,20 +635,20 @@ void ArcAuthService::EnableArc() {
profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
}
-void ArcAuthService::DisableArc() {
+void ArcSessionManager::DisableArc() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(profile_);
profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false);
}
-void ArcAuthService::RecordArcState() {
+void ArcSessionManager::RecordArcState() {
// Only record Enabled state if ARC is allowed in the first place, so we do
// not split the ARC population by devices that cannot run ARC.
if (IsAllowed())
UpdateEnabledStateUMA(IsArcEnabled());
}
-void ArcAuthService::StartUI() {
+void ArcSessionManager::StartUI() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (!arc_bridge_service()->stopped()) {
@@ -929,7 +666,7 @@ void ArcAuthService::StartUI() {
support_host_->ShowTermsOfService();
}
-void ArcAuthService::StartArcAndroidManagementCheck() {
+void ArcSessionManager::StartArcAndroidManagementCheck() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(arc_bridge_service()->stopped());
DCHECK(state_ == State::SHOWING_TERMS_OF_SERVICE ||
@@ -940,11 +677,11 @@ void ArcAuthService::StartArcAndroidManagementCheck() {
profile_, context_->token_service(), context_->account_id(),
false /* retry_on_error */));
android_management_checker_->StartCheck(
- base::Bind(&ArcAuthService::OnAndroidManagementChecked,
+ base::Bind(&ArcSessionManager::OnAndroidManagementChecked,
weak_ptr_factory_.GetWeakPtr()));
}
-void ArcAuthService::OnAndroidManagementChecked(
+void ArcSessionManager::OnAndroidManagementChecked(
policy::AndroidManagementClient::Result result) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK_EQ(state_, State::CHECKING_ANDROID_MANAGEMENT);
@@ -953,9 +690,10 @@ void ArcAuthService::OnAndroidManagementChecked(
case policy::AndroidManagementClient::Result::UNMANAGED:
VLOG(1) << "Starting ARC for first sign in.";
sign_in_time_ = base::Time::Now();
- arc_sign_in_timer_.Start(FROM_HERE, kArcSignInTimeout,
- base::Bind(&ArcAuthService::OnArcSignInTimeout,
- weak_ptr_factory_.GetWeakPtr()));
+ arc_sign_in_timer_.Start(
+ FROM_HERE, kArcSignInTimeout,
+ base::Bind(&ArcSessionManager::OnArcSignInTimeout,
+ weak_ptr_factory_.GetWeakPtr()));
StartArc();
break;
case policy::AndroidManagementClient::Result::MANAGED:
@@ -977,7 +715,7 @@ void ArcAuthService::OnAndroidManagementChecked(
}
}
-void ArcAuthService::OnBackgroundAndroidManagementChecked(
+void ArcSessionManager::OnBackgroundAndroidManagementChecked(
policy::AndroidManagementClient::Result result) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
switch (result) {
@@ -994,14 +732,14 @@ void ArcAuthService::OnBackgroundAndroidManagementChecked(
}
}
-void ArcAuthService::OnWindowClosed() {
+void ArcSessionManager::OnWindowClosed() {
DCHECK(support_host_);
CancelAuthCode();
}
-void ArcAuthService::OnTermsAgreed(bool is_metrics_enabled,
- bool is_backup_and_restore_enabled,
- bool is_location_service_enabled) {
+void ArcSessionManager::OnTermsAgreed(bool is_metrics_enabled,
+ bool is_backup_and_restore_enabled,
+ bool is_location_service_enabled) {
DCHECK(support_host_);
// Terms were accepted
@@ -1018,12 +756,7 @@ void ArcAuthService::OnTermsAgreed(bool is_metrics_enabled,
StartArcAndroidManagementCheck();
}
-void ArcAuthService::OnAuthSucceeded(const std::string& auth_code) {
- DCHECK(support_host_);
- OnAuthCodeObtained(auth_code);
-}
-
-void ArcAuthService::OnRetryClicked() {
+void ArcSessionManager::OnRetryClicked() {
DCHECK(support_host_);
UpdateOptInActionUMA(OptInActionType::RETRY);
@@ -1042,11 +775,8 @@ void ArcAuthService::OnRetryClicked() {
ShutdownBridge();
reenable_arc_ = true;
} else if (state_ == State::ACTIVE) {
- // This happens when ARC support Chrome app reports an error on "Sign in"
- // page.
- DCHECK(context_);
- context_->Prepare(base::Bind(&ArcAuthService::OnContextPrepared,
- weak_ptr_factory_.GetWeakPtr()));
+ // This case is handled in ArcAuthService.
+ // Do nothing.
} else {
// Otherwise, we restart ARC. Note: this is the first boot case.
// For second or later boot, either ERROR_WITH_FEEDBACK case or ACTIVE
@@ -1056,40 +786,43 @@ void ArcAuthService::OnRetryClicked() {
}
}
-void ArcAuthService::OnSendFeedbackClicked() {
+void ArcSessionManager::OnSendFeedbackClicked() {
DCHECK(support_host_);
chrome::OpenFeedbackDialog(nullptr);
}
-void ArcAuthService::OnMetricsModeChanged(bool enabled, bool managed) {
+void ArcSessionManager::OnMetricsModeChanged(bool enabled, bool managed) {
if (!support_host_)
return;
support_host_->SetMetricsPreferenceCheckbox(enabled, managed);
}
-void ArcAuthService::OnBackupAndRestoreModeChanged(bool enabled, bool managed) {
+void ArcSessionManager::OnBackupAndRestoreModeChanged(bool enabled,
+ bool managed) {
if (!support_host_)
return;
support_host_->SetBackupAndRestorePreferenceCheckbox(enabled, managed);
}
-void ArcAuthService::OnLocationServicesModeChanged(bool enabled, bool managed) {
+void ArcSessionManager::OnLocationServicesModeChanged(bool enabled,
+ bool managed) {
if (!support_host_)
return;
support_host_->SetLocationServicesPreferenceCheckbox(enabled, managed);
}
-std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) {
+std::ostream& operator<<(std::ostream& os,
+ const ArcSessionManager::State& state) {
switch (state) {
- case ArcAuthService::State::NOT_INITIALIZED:
+ case ArcSessionManager::State::NOT_INITIALIZED:
return os << "NOT_INITIALIZED";
- case ArcAuthService::State::STOPPED:
+ case ArcSessionManager::State::STOPPED:
return os << "STOPPED";
- case ArcAuthService::State::SHOWING_TERMS_OF_SERVICE:
+ case ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE:
return os << "SHOWING_TERMS_OF_SERVICE";
- case ArcAuthService::State::CHECKING_ANDROID_MANAGEMENT:
+ case ArcSessionManager::State::CHECKING_ANDROID_MANAGEMENT:
return os << "CHECKING_ANDROID_MANAGEMENT";
- case ArcAuthService::State::ACTIVE:
+ case ArcSessionManager::State::ACTIVE:
return os << "ACTIVE";
}
« no previous file with comments | « chrome/browser/chromeos/arc/arc_session_manager.h ('k') | chrome/browser/chromeos/arc/arc_session_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698