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

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

Issue 2446563002: Refactor ArcAndroidManagementChecker. (Closed)
Patch Set: rebase Created 4 years, 2 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 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 cfed7e505fdf125f430c3e64374641718f4f093a..e04f0143202e0c76c44ba15678efa3521985037c 100644
--- a/chrome/browser/chromeos/arc/arc_auth_service.cc
+++ b/chrome/browser/chromeos/arc/arc_auth_service.cc
@@ -39,7 +39,6 @@
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/session_manager_client.h"
#include "components/arc/arc_bridge_service.h"
-#include "components/policy/core/browser/browser_policy_connector.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/syncable_prefs/pref_service_syncable.h"
@@ -566,7 +565,15 @@ void ArcAuthService::OnContextReady() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(!initial_opt_in_);
- CheckAndroidManagement(false);
+
+ // TODO(hidehiko): The check is not necessary if this is a part of re-auth
+ // flow. Remove this.
+ android_management_checker_.reset(new ArcAndroidManagementChecker(
+ profile_, context_->token_service(), context_->account_id(),
+ false /* retry_on_error */));
+ android_management_checker_->StartCheck(
+ base::Bind(&ArcAuthService::OnAndroidManagementChecked,
+ weak_ptr_factory_.GetWeakPtr()));
}
void ArcAuthService::OnSyncedPrefChanged(const std::string& path,
@@ -623,12 +630,20 @@ void ArcAuthService::OnOptInPreferenceChanged() {
initial_opt_in_ = true;
StartUI();
} else {
- // Ready to start Arc, but check Android management first.
+ // Ready to start Arc, but check Android management in parallel.
+ StartArc();
+ // Note: Because the callback may be called in synchronous way (i.e. called
+ // on the same stack), StartCheck() needs to be called *after* StartArc().
+ // Otherwise, DisableArc() which may be called in
+ // OnBackgroundAndroidManagementChecked() could be ignored.
if (!g_disable_ui_for_testing ||
g_enable_check_android_management_for_testing) {
- CheckAndroidManagement(true);
- } else {
- StartArc();
+ android_management_checker_.reset(new ArcAndroidManagementChecker(
+ profile_, context_->token_service(), context_->account_id(),
+ true /* retry_on_error */));
+ android_management_checker_->StartCheck(
+ base::Bind(&ArcAuthService::OnBackgroundAndroidManagementChecked,
+ weak_ptr_factory_.GetWeakPtr()));
}
}
@@ -866,38 +881,14 @@ void ArcAuthService::OnAuthCodeFailed() {
UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
}
-void ArcAuthService::CheckAndroidManagement(bool background_mode) {
- // Do not send requests for Chrome OS managed users.
- if (policy_util::IsAccountManaged(profile_)) {
- OnAndroidManagementPassed();
- return;
- }
-
- // Do not send requests for well-known consumer domains.
- if (policy::BrowserPolicyConnector::IsNonEnterpriseUser(
- profile_->GetProfileUserName())) {
- OnAndroidManagementPassed();
- return;
- }
-
- android_management_checker_.reset(
- new ArcAndroidManagementChecker(this, context_->token_service(),
- context_->account_id(), background_mode));
- if (background_mode)
- OnAndroidManagementPassed();
-}
-
void ArcAuthService::OnAndroidManagementChecked(
policy::AndroidManagementClient::Result result) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
switch (result) {
case policy::AndroidManagementClient::Result::RESULT_UNMANAGED:
OnAndroidManagementPassed();
break;
case policy::AndroidManagementClient::Result::RESULT_MANAGED:
- if (android_management_checker_->background_mode()) {
- DisableArc();
- return;
- }
ShutdownBridgeAndShowUI(
UIPage::ERROR,
l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR));
@@ -914,6 +905,23 @@ void ArcAuthService::OnAndroidManagementChecked(
}
}
+void ArcAuthService::OnBackgroundAndroidManagementChecked(
+ policy::AndroidManagementClient::Result result) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ switch (result) {
+ case policy::AndroidManagementClient::Result::RESULT_UNMANAGED:
+ // Do nothing. ARC should be started already.
+ break;
+ case policy::AndroidManagementClient::Result::RESULT_MANAGED:
+ DisableArc();
+ break;
+ case policy::AndroidManagementClient::Result::RESULT_ERROR:
+ // This code should not be reached. For background check,
+ // retry_on_error should be set.
+ NOTREACHED();
+ }
+}
+
void ArcAuthService::FetchAuthCode() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_service.h ('k') | chrome/browser/chromeos/arc/policy/arc_android_management_checker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698