Commit 33156fc8 authored by chcunningham's avatar chcunningham Committed by Commit Bot

Convert ChromeOS easy_unlock/ to use IdentityManager

Use new IdentityManager and utils. SignInManager is deprecated.
Also cleans up some stale includes.

Bug: 797952
Change-Id: I4ee9dc7f480319dff277ddf71e1776f081082ccb
Reviewed-on: https://chromium-review.googlesource.com/1131675
Commit-Queue: Chrome Cunningham (In Paris) <chcunningham@chromium.org>
Reviewed-by: default avatarJames Hawkins <jhawkins@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#574198}
parent 9aae24b9
......@@ -17,8 +17,7 @@
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_signin_chromeos.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chromeos/chromeos_features.h"
#include "chromeos/components/proximity_auth/logging/logging.h"
#include "chromeos/services/device_sync/public/cpp/device_sync_client.h"
......@@ -27,9 +26,8 @@
#include "components/cryptauth/cryptauth_enrollment_manager.h"
#include "components/cryptauth/local_device_data_provider.h"
#include "components/prefs/pref_service.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager_base.h"
#include "components/version_info/version_info.h"
#include "services/identity/public/cpp/identity_manager.h"
using proximity_auth::ScreenlockState;
......@@ -41,12 +39,12 @@ ChromeProximityAuthClient::ChromeProximityAuthClient(Profile* profile)
ChromeProximityAuthClient::~ChromeProximityAuthClient() {}
std::string ChromeProximityAuthClient::GetAuthenticatedUsername() const {
const SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfileIfExists(profile_);
// |profile_| has to be a signed-in profile with SigninManager already
const identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfileIfExists(profile_);
// |profile_| has to be a signed-in profile with IdentityManager already
// created. Otherwise, just crash to collect stack.
DCHECK(signin_manager);
return signin_manager->GetAuthenticatedAccountInfo().email;
DCHECK(identity_manager);
return identity_manager->GetPrimaryAccountInfo().email;
}
void ChromeProximityAuthClient::UpdateScreenlockState(ScreenlockState state) {
......
......@@ -31,8 +31,6 @@
#include "chrome/browser/chromeos/login/session/user_session_manager.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/pref_names.h"
......@@ -54,8 +52,6 @@
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/session_manager/core/session_manager.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/user_manager/user.h"
#include "components/version_info/version_info.h"
#include "device/bluetooth/bluetooth_adapter.h"
......
......@@ -55,8 +55,6 @@
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/translate/core/browser/translate_download_manager.h"
#include "components/user_manager/user_manager.h"
#include "components/version_info/version_info.h"
......
......@@ -22,6 +22,7 @@
#include "chrome/browser/chromeos/login/users/mock_user_manager.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_browser_process.h"
......@@ -31,12 +32,14 @@
#include "chromeos/dbus/power_manager/suspend.pb.h"
#include "chromeos/services/device_sync/public/cpp/fake_device_sync_client.h"
#include "components/account_id/account_id.h"
#include "components/signin/core/browser/signin_manager_base.h"
#include "components/signin/core/browser/account_info.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/user_manager/scoped_user_manager.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/test/mock_bluetooth_adapter.h"
#include "services/identity/public/cpp/identity_manager.h"
#include "services/identity/public/cpp/identity_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
using device::MockBluetoothAdapter;
......@@ -48,11 +51,9 @@ namespace chromeos {
namespace {
// IDs for fake users used in tests.
// Emails for fake users used in tests.
const char kTestUserPrimary[] = "primary_user@nowhere.com";
const char kPrimaryGaiaId[] = "1111111111";
const char kTestUserSecondary[] = "secondary_user@nowhere.com";
const char kSecondaryGaiaId[] = "2222222222";
class MockEasyUnlockNotificationController
: public EasyUnlockNotificationController {
......@@ -253,8 +254,7 @@ class EasyUnlockServiceTest : public testing::Test {
TestingBrowserProcess::GetGlobal()->SetLocalState(&local_pref_service_);
RegisterLocalState(local_pref_service_.registry());
SetUpProfile(&profile_, AccountId::FromUserEmailGaiaId(kTestUserPrimary,
kPrimaryGaiaId));
profile_ = SetUpProfile(kTestUserPrimary, &profile_gaia_id_);
}
void TearDown() override {
......@@ -302,37 +302,40 @@ class EasyUnlockServiceTest : public testing::Test {
app_manager->SetReady();
}
// Sets up a test profile with a user id.
void SetUpProfile(std::unique_ptr<TestingProfile>* profile,
const AccountId& account_id) {
ASSERT_TRUE(profile);
ASSERT_FALSE(profile->get());
// Sets up a test profile using the provided |email|. Will generate a unique
// gaia id and output to |gaia_id|. Returns the created TestingProfile.
std::unique_ptr<TestingProfile> SetUpProfile(const std::string& email,
std::string* gaia_id) {
TestingProfile::Builder builder;
builder.AddTestingFactory(EasyUnlockServiceFactory::GetInstance(),
&CreateEasyUnlockServiceForTest);
*profile = builder.Build();
std::unique_ptr<TestingProfile> profile = builder.Build();
AccountInfo account_info = identity::SetPrimaryAccount(
SigninManagerFactory::GetForProfile(profile.get()),
IdentityManagerFactory::GetForProfile(profile.get()), email);
*gaia_id = account_info.gaia;
mock_user_manager_->AddUser(account_id);
profile->get()->set_profile_name(account_id.GetUserEmail());
mock_user_manager_->AddUser(
AccountId::FromUserEmailGaiaId(email, *gaia_id));
profile.get()->set_profile_name(email);
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(profile->get());
signin_manager->SetAuthenticatedAccountInfo(account_id.GetGaiaId(),
account_id.GetUserEmail());
return profile;
}
void SetUpSecondaryProfile() {
SetUpProfile(
&secondary_profile_,
AccountId::FromUserEmailGaiaId(kTestUserSecondary, kSecondaryGaiaId));
secondary_profile_ =
SetUpProfile(kTestUserSecondary, &secondary_profile_gaia_id_);
}
// Must outlive TestingProfiles.
content::TestBrowserThreadBundle thread_bundle_;
std::unique_ptr<TestingProfile> profile_;
std::string profile_gaia_id_;
std::unique_ptr<TestingProfile> secondary_profile_;
std::string secondary_profile_gaia_id_;
MockUserManager* mock_user_manager_;
private:
......@@ -417,13 +420,13 @@ TEST_F(EasyUnlockServiceTest, NotAllowedForEphemeralAccounts) {
}
TEST_F(EasyUnlockServiceTest, GetAccountId) {
EXPECT_EQ(AccountId::FromUserEmailGaiaId(kTestUserPrimary, kPrimaryGaiaId),
EXPECT_EQ(AccountId::FromUserEmailGaiaId(kTestUserPrimary, profile_gaia_id_),
EasyUnlockService::Get(profile_.get())->GetAccountId());
SetUpSecondaryProfile();
EXPECT_EQ(
AccountId::FromUserEmailGaiaId(kTestUserSecondary, kSecondaryGaiaId),
EasyUnlockService::Get(secondary_profile_.get())->GetAccountId());
EXPECT_EQ(AccountId::FromUserEmailGaiaId(kTestUserSecondary,
secondary_profile_gaia_id_),
EasyUnlockService::Get(secondary_profile_.get())->GetAccountId());
}
} // namespace chromeos
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