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

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

Issue 2446563002: Refactor ArcAndroidManagementChecker. (Closed)
Patch Set: 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 00f012152ec36e34680d35f90d32f3609b5b4f34..b914d3ea788065fae51540dde87e2f02e875d9a4 100644
--- a/chrome/browser/chromeos/arc/arc_auth_service.cc
+++ b/chrome/browser/chromeos/arc/arc_auth_service.cc
@@ -20,6 +20,7 @@
#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/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"
@@ -38,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"
@@ -76,11 +76,6 @@ const char kStateStopped[] = "STOPPED";
const char kStateFetchingCode[] = "FETCHING_CODE";
const char kStateActive[] = "ACTIVE";
-bool IsAccountManaged(Profile* profile) {
- return policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile)
- ->IsManaged();
-}
-
bool IsArcDisabledForEnterprise() {
Luis Héctor Chávez 2016/10/24 22:39:57 Can we also move this to arc_policy_util.h?
hidehiko 2016/10/25 07:22:42 Addressed in https://codereview.chromium.org/24480
return base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kEnterpriseDisableArc);
@@ -368,9 +363,9 @@ void ArcAuthService::OnSignInComplete() {
profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, true);
CloseUI();
UpdateProvisioningTiming(base::Time::Now() - sign_in_time_, true,
- IsAccountManaged(profile_));
+ policy_util::IsAccountManaged(profile_));
UpdateProvisioningResultUMA(ProvisioningResult::SUCCESS,
- IsAccountManaged(profile_));
+ policy_util::IsAccountManaged(profile_));
for (auto& observer : observer_list_)
observer.OnInitialStart();
@@ -389,9 +384,9 @@ void ArcAuthService::OnSignInFailedInternal(ProvisioningResult result) {
arc_sign_in_timer_.Stop();
UpdateProvisioningTiming(base::Time::Now() - sign_in_time_, false,
- IsAccountManaged(profile_));
+ policy_util::IsAccountManaged(profile_));
UpdateOptInCancelUMA(OptInCancelReason::CLOUD_PROVISION_FLOW_FAIL);
- UpdateProvisioningResultUMA(result, IsAccountManaged(profile_));
+ UpdateProvisioningResultUMA(result, policy_util::IsAccountManaged(profile_));
int error_message_id;
switch (result) {
@@ -451,7 +446,7 @@ void ArcAuthService::GetIsAccountManaged(
const GetIsAccountManagedCallback& callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- callback.Run(IsAccountManaged(profile_));
+ callback.Run(policy_util::IsAccountManaged(profile_));
}
void ArcAuthService::SetState(State state) {
@@ -478,7 +473,7 @@ void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) {
return;
// TODO(khmel): Move this to IsAllowedForProfile.
- if (IsArcDisabledForEnterprise() && IsAccountManaged(profile)) {
+ if (IsArcDisabledForEnterprise() && policy_util::IsAccountManaged(profile)) {
VLOG(2) << "Enterprise users are not supported in ARC.";
return;
}
@@ -575,7 +570,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,
@@ -632,12 +635,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();
Luis Héctor Chávez 2016/10/24 22:36:02 IIUC you are not calling FetchAuthCode(); in this
hidehiko 2016/10/25 07:22:42 FetchAuthCode was not called even in the original
Luis Héctor Chávez 2016/10/25 17:11:39 Oh, right (good thing we're cleaning up this code)
+ // 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(
Luis Héctor Chávez 2016/10/24 22:36:02 Seems like you need some state to track whether th
hidehiko 2016/10/25 07:22:42 Inflight check is canceled by reset above and/or (
+ base::Bind(&ArcAuthService::OnBackgroundAndroidManagementChecked,
+ weak_ptr_factory_.GetWeakPtr()));
}
}
@@ -875,38 +886,14 @@ void ArcAuthService::OnAuthCodeFailed() {
UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
}
-void ArcAuthService::CheckAndroidManagement(bool background_mode) {
- // Do not send requests for Chrome OS managed users.
- if (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));
@@ -923,6 +910,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. The ARC should be started already.
Luis Héctor Chávez 2016/10/24 22:36:02 nit: s/The ARC/ARC/.
hidehiko 2016/10/25 07:22:42 Done.
+ break;
+ case policy::AndroidManagementClient::Result::RESULT_MANAGED:
+ DisableArc();
Luis Héctor Chávez 2016/10/24 22:36:03 Is there a way to intentionally delay the receipt
hidehiko 2016/10/25 07:22:42 Maybe, I'm not understanding the goal to delay the
Luis Héctor Chávez 2016/10/25 17:11:39 The concern is about a malicious actor that wants
Luis Héctor Chávez 2016/10/25 17:47:58 As discussed offline, since this is *not* a regres
hidehiko 2016/10/26 12:46:05 Acknowledged. Let's discuss separately.
+ break;
+ case policy::AndroidManagementClient::Result::RESULT_ERROR:
+ // This code should not be reached. For background check,
+ // retry_on_error sould be set.
Luis Héctor Chávez 2016/10/24 22:36:03 nit: s/sould/should/
hidehiko 2016/10/25 07:22:42 Done.
+ NOTREACHED();
+ }
+}
+
void ArcAuthService::FetchAuthCode() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);

Powered by Google App Engine
This is Rietveld 408576698