Commit 9df369c7 authored by Kush Sinha's avatar Kush Sinha Committed by Commit Bot

Remove usages of AccountMapperUtil in AccountManagerUIHandler

Bug: 925827
Change-Id: I9e0c1942eb60b39b251767d05549e4a136f8235f
Reviewed-on: https://chromium-review.googlesource.com/c/1483018Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Commit-Queue: Kush Sinha <sinhak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635964}
parent df68fd38
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "chrome/browser/ui/webui/signin/inline_login_handler_dialog_chromeos.h" #include "chrome/browser/ui/webui/signin/inline_login_handler_dialog_chromeos.h"
#include "chromeos/account_manager/account_manager.h" #include "chromeos/account_manager/account_manager.h"
#include "chromeos/account_manager/account_manager_factory.h" #include "chromeos/account_manager/account_manager_factory.h"
#include "components/signin/core/browser/account_tracker_service.h"
#include "components/user_manager/user.h" #include "components/user_manager/user.h"
#include "google_apis/gaia/google_service_auth_error.h" #include "google_apis/gaia/google_service_auth_error.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
...@@ -52,15 +51,27 @@ AccountManager::AccountKey GetAccountKeyFromJsCallback( ...@@ -52,15 +51,27 @@ AccountManager::AccountKey GetAccountKeyFromJsCallback(
return AccountManager::AccountKey{id, account_type}; return AccountManager::AccountKey{id, account_type};
} }
bool IsSameAccount(const AccountManager::AccountKey& account_key,
const AccountId& account_id) {
switch (account_key.account_type) {
case chromeos::account_manager::AccountType::ACCOUNT_TYPE_GAIA:
return (account_id.GetAccountType() == AccountType::GOOGLE) &&
(account_id.GetGaiaId() == account_key.id);
case chromeos::account_manager::AccountType::ACCOUNT_TYPE_ACTIVE_DIRECTORY:
return (account_id.GetAccountType() == AccountType::ACTIVE_DIRECTORY) &&
(account_id.GetObjGuid() == account_key.id);
case chromeos::account_manager::AccountType::ACCOUNT_TYPE_UNSPECIFIED:
return false;
}
}
} // namespace } // namespace
AccountManagerUIHandler::AccountManagerUIHandler( AccountManagerUIHandler::AccountManagerUIHandler(
AccountManager* account_manager, AccountManager* account_manager,
AccountTrackerService* account_tracker_service,
identity::IdentityManager* identity_manager) identity::IdentityManager* identity_manager)
: account_manager_(account_manager), : account_manager_(account_manager),
identity_manager_(identity_manager), identity_manager_(identity_manager),
account_mapper_util_(account_tracker_service),
account_manager_observer_(this), account_manager_observer_(this),
identity_manager_observer_(this), identity_manager_observer_(this),
weak_factory_(this) { weak_factory_(this) {
...@@ -129,20 +140,15 @@ void AccountManagerUIHandler::OnGetAccounts( ...@@ -129,20 +140,15 @@ void AccountManagerUIHandler::OnGetAccounts(
account.SetInteger("accountType", account_key.account_type); account.SetInteger("accountType", account_key.account_type);
account.SetBoolean("isDeviceAccount", false); account.SetBoolean("isDeviceAccount", false);
const std::string oauth_account_id =
account_mapper_util_.AccountKeyToOAuthAccountId(account_key);
account.SetBoolean(
"isSignedIn",
identity_manager_->HasAccountWithRefreshToken(oauth_account_id) &&
!identity_manager_
->HasAccountWithRefreshTokenInPersistentErrorState(
oauth_account_id));
base::Optional<AccountInfo> maybe_account_info = base::Optional<AccountInfo> maybe_account_info =
identity_manager_->FindAccountInfoForAccountWithRefreshTokenByGaiaId( identity_manager_->FindAccountInfoForAccountWithRefreshTokenByGaiaId(
account_key.id); account_key.id);
DCHECK(maybe_account_info.has_value()); DCHECK(maybe_account_info.has_value());
account.SetBoolean(
"isSignedIn",
!identity_manager_->HasAccountWithRefreshTokenInPersistentErrorState(
maybe_account_info->account_id));
account.SetString("fullName", maybe_account_info->full_name); account.SetString("fullName", maybe_account_info->full_name);
account.SetString("email", maybe_account_info->email); account.SetString("email", maybe_account_info->email);
if (!maybe_account_info->account_image.IsEmpty()) { if (!maybe_account_info->account_image.IsEmpty()) {
...@@ -158,7 +164,7 @@ void AccountManagerUIHandler::OnGetAccounts( ...@@ -158,7 +164,7 @@ void AccountManagerUIHandler::OnGetAccounts(
default_icon.GetRepresentation(1.0f).GetBitmap())); default_icon.GetRepresentation(1.0f).GetBitmap()));
} }
if (account_mapper_util_.IsEqual(account_key, device_account_id)) { if (IsSameAccount(account_key, device_account_id)) {
device_account = std::move(account); device_account = std::move(account);
} else { } else {
accounts.GetList().push_back(std::move(account)); accounts.GetList().push_back(std::move(account));
...@@ -203,7 +209,7 @@ void AccountManagerUIHandler::HandleRemoveAccount(const base::ListValue* args) { ...@@ -203,7 +209,7 @@ void AccountManagerUIHandler::HandleRemoveAccount(const base::ListValue* args) {
->GetAccountId(); ->GetAccountId();
const AccountManager::AccountKey account_key = const AccountManager::AccountKey account_key =
GetAccountKeyFromJsCallback(dictionary); GetAccountKeyFromJsCallback(dictionary);
if (account_mapper_util_.IsEqual(account_key, device_account_id)) { if (IsSameAccount(account_key, device_account_id)) {
// It should not be possible to remove a device account. // It should not be possible to remove a device account.
return; return;
} }
......
...@@ -11,13 +11,10 @@ ...@@ -11,13 +11,10 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "chrome/browser/chromeos/account_mapper_util.h"
#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h" #include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
#include "chromeos/account_manager/account_manager.h" #include "chromeos/account_manager/account_manager.h"
#include "services/identity/public/cpp/identity_manager.h" #include "services/identity/public/cpp/identity_manager.h"
class AccountTrackerService;
namespace chromeos { namespace chromeos {
namespace settings { namespace settings {
...@@ -28,7 +25,6 @@ class AccountManagerUIHandler : public ::settings::SettingsPageUIHandler, ...@@ -28,7 +25,6 @@ class AccountManagerUIHandler : public ::settings::SettingsPageUIHandler,
// Accepts non-owning pointers to |AccountManager|, |AccountTrackerService| // Accepts non-owning pointers to |AccountManager|, |AccountTrackerService|
// and |IdentityManager|. Both of these must outlive |this| instance. // and |IdentityManager|. Both of these must outlive |this| instance.
AccountManagerUIHandler(AccountManager* account_manager, AccountManagerUIHandler(AccountManager* account_manager,
AccountTrackerService* account_tracker_service,
identity::IdentityManager* identity_manager); identity::IdentityManager* identity_manager);
~AccountManagerUIHandler() override; ~AccountManagerUIHandler() override;
...@@ -76,8 +72,6 @@ class AccountManagerUIHandler : public ::settings::SettingsPageUIHandler, ...@@ -76,8 +72,6 @@ class AccountManagerUIHandler : public ::settings::SettingsPageUIHandler,
// A non-owning pointer to |IdentityManager|. // A non-owning pointer to |IdentityManager|.
identity::IdentityManager* const identity_manager_; identity::IdentityManager* const identity_manager_;
chromeos::AccountMapperUtil account_mapper_util_;
// An observer for |AccountManager|. Automatically deregisters when |this| is // An observer for |AccountManager|. Automatically deregisters when |this| is
// destructed. // destructed.
ScopedObserver<AccountManager, AccountManager::Observer> ScopedObserver<AccountManager, AccountManager::Observer>
......
...@@ -86,7 +86,6 @@ ...@@ -86,7 +86,6 @@
#include "chrome/browser/chromeos/login/demo_mode/demo_session.h" #include "chrome/browser/chromeos/login/demo_mode/demo_session.h"
#include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_utils.h" #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_utils.h"
#include "chrome/browser/chromeos/multidevice_setup/multidevice_setup_client_factory.h" #include "chrome/browser/chromeos/multidevice_setup/multidevice_setup_client_factory.h"
#include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/ui/webui/chromeos/smb_shares/smb_handler.h" #include "chrome/browser/ui/webui/chromeos/smb_shares/smb_handler.h"
#include "chrome/browser/ui/webui/settings/chromeos/accessibility_handler.h" #include "chrome/browser/ui/webui/settings/chromeos/accessibility_handler.h"
#include "chrome/browser/ui/webui/settings/chromeos/account_manager_handler.h" #include "chrome/browser/ui/webui/settings/chromeos/account_manager_handler.h"
...@@ -207,7 +206,6 @@ MdSettingsUI::MdSettingsUI(content::WebUI* web_ui) ...@@ -207,7 +206,6 @@ MdSettingsUI::MdSettingsUI(content::WebUI* web_ui)
AddSettingsPageUIHandler( AddSettingsPageUIHandler(
std::make_unique<chromeos::settings::AccountManagerUIHandler>( std::make_unique<chromeos::settings::AccountManagerUIHandler>(
account_manager, account_manager,
AccountTrackerServiceFactory::GetInstance()->GetForProfile(profile),
IdentityManagerFactory::GetForProfile(profile))); IdentityManagerFactory::GetForProfile(profile)));
} }
AddSettingsPageUIHandler( AddSettingsPageUIHandler(
......
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