Commit 86ecac87 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

[s13n] Convert ArcAndroidManagementChecker to IdentityManager

IdentityManager API provides a replacement to objects including SigninManager
and PO2TS. Since its implementation wraps both objects,
no functionality change is expected.

Note: This CL can not eliminate the uses of PO2TS completely from
ArcAndroidManagementChecker because it is still needed for creating
another object, AndroidManagementClient. This object will be
migrated on its own CL.

BUG=905279

Change-Id: I57096d6ff829afdfb3f4d882e390b87e9391ab12
Reviewed-on: https://chromium-review.googlesource.com/c/1335908
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608600}
parent 053bcc17
......@@ -15,12 +15,11 @@
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/core/common/cloud/device_management_service.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager_base.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace arc {
......@@ -39,10 +38,10 @@ policy::DeviceManagementService* GetDeviceManagementService() {
// Returns the Device Account Id. Assumes that |profile| is the only Profile
// on Chrome OS.
std::string GetDeviceAccountId(Profile* profile) {
const SigninManagerBase* const signin_manager =
SigninManagerFactory::GetForProfile(profile);
const auto* const identity_manager =
IdentityManagerFactory::GetForProfile(profile);
return signin_manager->GetAuthenticatedAccountId();
return identity_manager->GetPrimaryAccountId();
}
} // namespace
......@@ -50,7 +49,7 @@ std::string GetDeviceAccountId(Profile* profile) {
ArcAndroidManagementChecker::ArcAndroidManagementChecker(Profile* profile,
bool retry_on_error)
: profile_(profile),
token_service_(ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)),
identity_manager_(IdentityManagerFactory::GetForProfile(profile_)),
device_account_id_(GetDeviceAccountId(profile_)),
retry_on_error_(retry_on_error),
retry_delay_(kRetryDelayMin),
......@@ -59,11 +58,11 @@ ArcAndroidManagementChecker::ArcAndroidManagementChecker(Profile* profile,
g_browser_process->system_network_context_manager()
->GetSharedURLLoaderFactory(),
device_account_id_,
token_service_),
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)),
weak_ptr_factory_(this) {}
ArcAndroidManagementChecker::~ArcAndroidManagementChecker() {
token_service_->RemoveObserver(this);
identity_manager_->RemoveObserver(this);
}
// static
......@@ -88,7 +87,7 @@ void ArcAndroidManagementChecker::StartCheck(const CheckCallback& callback) {
}
void ArcAndroidManagementChecker::EnsureRefreshTokenLoaded() {
if (token_service_->RefreshTokenIsAvailable(device_account_id_)) {
if (identity_manager_->HasAccountWithRefreshToken(device_account_id_)) {
// If the refresh token is already available, just start the management
// check immediately.
StartCheckInternal();
......@@ -97,25 +96,26 @@ void ArcAndroidManagementChecker::EnsureRefreshTokenLoaded() {
// Set the observer to the token service so the callback will be called
// when the token is loaded.
token_service_->AddObserver(this);
identity_manager_->AddObserver(this);
}
void ArcAndroidManagementChecker::OnRefreshTokenAvailable(
const std::string& account_id) {
if (account_id != device_account_id_)
void ArcAndroidManagementChecker::OnRefreshTokenUpdatedForAccount(
const AccountInfo& account_info,
bool is_valid) {
if (account_info.account_id != device_account_id_)
return;
OnRefreshTokensLoaded();
}
void ArcAndroidManagementChecker::OnRefreshTokensLoaded() {
token_service_->RemoveObserver(this);
identity_manager_->RemoveObserver(this);
StartCheckInternal();
}
void ArcAndroidManagementChecker::StartCheckInternal() {
DCHECK(!callback_.is_null());
if (!token_service_->RefreshTokenIsAvailable(device_account_id_)) {
if (!identity_manager_->HasAccountWithRefreshToken(device_account_id_)) {
VLOG(2) << "No refresh token is available for android management check.";
std::move(callback_).Run(policy::AndroidManagementClient::Result::ERROR);
return;
......
......@@ -12,14 +12,13 @@
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "chrome/browser/chromeos/policy/android_management_client.h"
#include "google_apis/gaia/oauth2_token_service.h"
#include "services/identity/public/cpp/identity_manager.h"
class Profile;
class ProfileOAuth2TokenService;
namespace arc {
class ArcAndroidManagementChecker : public OAuth2TokenService::Observer {
class ArcAndroidManagementChecker : public identity::IdentityManager::Observer {
public:
ArcAndroidManagementChecker(Profile* profile, bool retry_on_error);
~ArcAndroidManagementChecker() override;
......@@ -40,16 +39,17 @@ class ArcAndroidManagementChecker : public OAuth2TokenService::Observer {
policy::AndroidManagementClient::Result result);
void ScheduleRetry();
// Ensures the refresh token is loaded in the |token_service|.
// Ensures the refresh token is loaded in the |identity_manager|.
void EnsureRefreshTokenLoaded();
// OAuth2TokenService::Observer:
void OnRefreshTokenAvailable(const std::string& account_id) override;
// identity::IdentityManager::Observer:
void OnRefreshTokenUpdatedForAccount(const AccountInfo& account_info,
bool is_valid) override;
void OnRefreshTokensLoaded() override;
// Unowned pointers.
Profile* profile_;
ProfileOAuth2TokenService* const token_service_;
identity::IdentityManager* const identity_manager_;
const std::string device_account_id_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment