diff options
author | lwchkg <lwchkg@gmail.com> | 2016-02-23 06:06:52 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-23 14:08:23 +0000 |
commit | dc9dd38953b1cc32bb6d83b6562d8640f3365180 (patch) | |
tree | c89bdaa874e414aad45d6da03ee355c11370dbfe | |
parent | abf86fd83c48a4dfa3f059f2db732fbb11cb614d (diff) | |
download | chromium_src-dc9dd38953b1cc32bb6d83b6562d8640f3365180.zip chromium_src-dc9dd38953b1cc32bb6d83b6562d8640f3365180.tar.gz chromium_src-dc9dd38953b1cc32bb6d83b6562d8640f3365180.tar.bz2 |
Refactor ProfileInfoCache in c/b/signin and c/b/ui/webui/signin
ProfileInfoCache is being refactored into ProfileAttributesStorage and
ProfileAttributesEntry, which use profile paths instead of numerical
indices in the interface. See
https://codereview.chromium.org/1599013002/ for details.
BUG=305720
Review URL: https://codereview.chromium.org/1700213002
Cr-Commit-Position: refs/heads/master@{#376977}
-rw-r--r-- | chrome/browser/profiles/profile_manager.cc | 2 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_manager.h | 2 | ||||
-rw-r--r-- | chrome/browser/signin/chrome_signin_client.cc | 57 | ||||
-rw-r--r-- | chrome/browser/signin/chrome_signin_status_metrics_provider_delegate.cc | 1 | ||||
-rw-r--r-- | chrome/browser/signin/local_auth.cc | 66 | ||||
-rw-r--r-- | chrome/browser/signin/local_auth.h | 8 | ||||
-rw-r--r-- | chrome/browser/signin/local_auth_unittest.cc | 29 | ||||
-rw-r--r-- | chrome/browser/signin/signin_global_error_unittest.cc | 14 | ||||
-rw-r--r-- | chrome/browser/signin/signin_promo.cc | 1 | ||||
-rw-r--r-- | chrome/browser/ui/webui/signin/inline_login_handler_impl.cc | 26 | ||||
-rw-r--r-- | chrome/browser/ui/webui/signin/user_manager_screen_handler.cc | 110 | ||||
-rw-r--r-- | chrome/browser/ui/webui/signin/user_manager_screen_handler.h | 10 |
12 files changed, 160 insertions, 166 deletions
diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc index 55b1d61..913695e 100644 --- a/chrome/browser/profiles/profile_manager.cc +++ b/chrome/browser/profiles/profile_manager.cc @@ -472,7 +472,7 @@ void ProfileManager::CreateProfileAsync( } } -bool ProfileManager::IsValidProfile(void* profile) { +bool ProfileManager::IsValidProfile(const void* profile) { for (ProfilesInfoMap::iterator iter = profiles_info_.begin(); iter != profiles_info_.end(); ++iter) { if (iter->second->created) { diff --git a/chrome/browser/profiles/profile_manager.h b/chrome/browser/profiles/profile_manager.h index b8ce056..4f8b270 100644 --- a/chrome/browser/profiles/profile_manager.h +++ b/chrome/browser/profiles/profile_manager.h @@ -98,7 +98,7 @@ class ProfileManager : public base::NonThreadSafe, // Returns true if the profile pointer is known to point to an existing // profile. - bool IsValidProfile(void* profile); + bool IsValidProfile(const void* profile); // Returns the directory where the first created profile is stored, // relative to the user data directory currently in use. diff --git a/chrome/browser/signin/chrome_signin_client.cc b/chrome/browser/signin/chrome_signin_client.cc index 62d2212..d6f5b7b 100644 --- a/chrome/browser/signin/chrome_signin_client.cc +++ b/chrome/browser/signin/chrome_signin_client.cc @@ -13,7 +13,8 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/content_settings/cookie_settings_factory.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h" -#include "chrome/browser/profiles/profile_info_cache.h" +#include "chrome/browser/profiles/profile_attributes_entry.h" +#include "chrome/browser/profiles/profile_attributes_storage.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_metrics.h" #include "chrome/browser/profiles/profile_window.h" @@ -166,18 +167,19 @@ std::string ChromeSigninClient::GetSigninScopedDeviceId() { } void ChromeSigninClient::OnSignedOut() { - ProfileInfoCache& cache = - g_browser_process->profile_manager()->GetProfileInfoCache(); - size_t index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); + ProfileAttributesEntry* entry; + bool has_entry = g_browser_process->profile_manager()-> + GetProfileAttributesStorage(). + GetProfileAttributesWithPath(profile_->GetPath(), &entry); // If sign out occurs because Sync setup was in progress and the Profile got - // deleted, then the profile's no longer in the ProfileInfoCache. - if (index == std::string::npos) + // deleted, then the profile's no longer in the ProfileAttributesStorage. + if (!has_entry) return; - cache.SetLocalAuthCredentialsOfProfileAtIndex(index, std::string()); - cache.SetAuthInfoOfProfileAtIndex(index, std::string(), base::string16()); - cache.SetProfileSigninRequiredAtIndex(index, false); + entry->SetLocalAuthCredentials(std::string()); + entry->SetAuthInfo(std::string(), base::string16()); + entry->SetIsSigninRequired(false); } net::URLRequestContextGetter* ChromeSigninClient::GetURLRequestContext() { @@ -239,11 +241,10 @@ void ChromeSigninClient::OnSignedIn(const std::string& account_id, const std::string& username, const std::string& password) { ProfileManager* profile_manager = g_browser_process->profile_manager(); - ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); - size_t index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); - if (index != std::string::npos) { - cache.SetAuthInfoOfProfileAtIndex(index, gaia_id, - base::UTF8ToUTF16(username)); + ProfileAttributesEntry* entry; + if (profile_manager->GetProfileAttributesStorage(). + GetProfileAttributesWithPath(profile_->GetPath(), &entry)) { + entry->SetAuthInfo(gaia_id, base::UTF8ToUTF16(username)); ProfileMetrics::UpdateReportedProfilesStatistics(profile_manager); } } @@ -263,14 +264,14 @@ void ChromeSigninClient::OnErrorChanged() { if (g_browser_process->profile_manager() == nullptr) return; - ProfileInfoCache& cache = g_browser_process->profile_manager()-> - GetProfileInfoCache(); - size_t index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); - if (index == std::string::npos) + ProfileAttributesEntry* entry; + + if (!g_browser_process->profile_manager()->GetProfileAttributesStorage(). + GetProfileAttributesWithPath(profile_->GetPath(), &entry)) { return; + } - cache.SetProfileIsAuthErrorAtIndex(index, - signin_error_controller_->HasError()); + entry->SetIsAuthError(signin_error_controller_->HasError()); } void ChromeSigninClient::OnGetTokenInfoResponse( @@ -278,10 +279,12 @@ void ChromeSigninClient::OnGetTokenInfoResponse( if (!token_info->HasKey("error")) { std::string handle; if (token_info->GetString("token_handle", &handle)) { - ProfileInfoCache& info_cache = - g_browser_process->profile_manager()->GetProfileInfoCache(); - size_t index = info_cache.GetIndexOfProfileWithPath(profile_->GetPath()); - info_cache.SetPasswordChangeDetectionTokenAtIndex(index, handle); + ProfileAttributesEntry* entry = nullptr; + bool has_entry = g_browser_process->profile_manager()-> + GetProfileAttributesStorage(). + GetProfileAttributesWithPath(profile_->GetPath(), &entry); + DCHECK(has_entry); + entry->SetPasswordChangeDetectionToken(handle); } } oauth_request_.reset(); @@ -362,11 +365,11 @@ void ChromeSigninClient::MaybeFetchSigninTokenHandle() { // and thus distinguish between a password mismatch due to the password // being changed and the user simply mis-typing it. if (profiles::IsLockAvailable(profile_)) { - ProfileInfoCache& info_cache = - g_browser_process->profile_manager()->GetProfileInfoCache(); + ProfileAttributesStorage& storage = + g_browser_process->profile_manager()->GetProfileAttributesStorage(); ProfileAttributesEntry* entry; // If we don't have a token for detecting a password change, create one. - if (info_cache.GetProfileAttributesWithPath(profile_->GetPath(), &entry) && + if (storage.GetProfileAttributesWithPath(profile_->GetPath(), &entry) && entry->GetPasswordChangeDetectionToken().empty() && !oauth_request_) { std::string account_id = SigninManagerFactory::GetForProfile(profile_) ->GetAuthenticatedAccountId(); diff --git a/chrome/browser/signin/chrome_signin_status_metrics_provider_delegate.cc b/chrome/browser/signin/chrome_signin_status_metrics_provider_delegate.cc index 8d2c113..2960468 100644 --- a/chrome/browser/signin/chrome_signin_status_metrics_provider_delegate.cc +++ b/chrome/browser/signin/chrome_signin_status_metrics_provider_delegate.cc @@ -10,7 +10,6 @@ #include "build/build_config.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" diff --git a/chrome/browser/signin/local_auth.cc b/chrome/browser/signin/local_auth.cc index e4b09bd..5ddb1e6 100644 --- a/chrome/browser/signin/local_auth.cc +++ b/chrome/browser/signin/local_auth.cc @@ -5,12 +5,15 @@ #include "chrome/browser/signin/local_auth.h" #include "base/base64.h" +#include "base/files/file_path.h" #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/metrics/histogram.h" #include "base/strings/string_util.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_attributes_entry.h" +#include "chrome/browser/profiles/profile_attributes_storage.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/pref_names.h" #include "components/os_crypt/os_crypt.h" @@ -158,14 +161,6 @@ bool DecodePasswordHashRecord(const std::string& encoded, return OSCrypt::DecryptString(unbase64, decoded); } -size_t GetProfileInfoIndexOfProfile(const Profile* profile) { - DCHECK(profile); - - ProfileInfoCache& info = - g_browser_process->profile_manager()->GetProfileInfoCache(); - return info.GetIndexOfProfileWithPath(profile->GetPath()); -} - } // namespace std::string LocalAuth::TruncateStringByBits(const std::string& str, @@ -179,9 +174,10 @@ void LocalAuth::RegisterLocalAuthPrefs( std::string()); } -void LocalAuth::SetLocalAuthCredentialsWithEncoding(size_t info_index, - const std::string& password, - char encoding_version) { +void LocalAuth::SetLocalAuthCredentialsWithEncoding( + ProfileAttributesEntry* entry, + const std::string& password, + char encoding_version) { const HashEncoding& encoding = encodings[(encoding_version - '0') - 1]; // Salt should be random data, as long as the hash length, and different with @@ -201,42 +197,36 @@ void LocalAuth::SetLocalAuthCredentialsWithEncoding(size_t info_index, // Encode it and store it. std::string encoded = EncodePasswordHashRecord(record, encoding); - ProfileInfoCache& info = - g_browser_process->profile_manager()->GetProfileInfoCache(); - info.SetLocalAuthCredentialsOfProfileAtIndex(info_index, encoded); + entry->SetLocalAuthCredentials(encoded); } -void LocalAuth::SetLocalAuthCredentials(size_t info_index, +void LocalAuth::SetLocalAuthCredentials(ProfileAttributesEntry* entry, const std::string& password) { - if (info_index == std::string::npos) { - NOTREACHED(); - return; - } + DCHECK(entry); DCHECK(password.length()); SetLocalAuthCredentialsWithEncoding( - info_index, password, '0' + NUM_HASH_ENCODINGS); + entry, password, '0' + NUM_HASH_ENCODINGS); } void LocalAuth::SetLocalAuthCredentials(const Profile* profile, const std::string& password) { - SetLocalAuthCredentials(GetProfileInfoIndexOfProfile(profile), password); + DCHECK(g_browser_process->profile_manager()->IsValidProfile(profile)); + ProfileAttributesEntry* entry = nullptr; + bool has_entry = g_browser_process->profile_manager()-> + GetProfileAttributesStorage(). + GetProfileAttributesWithPath(profile->GetPath(), &entry); + DCHECK(has_entry); + SetLocalAuthCredentials(entry, password); } -bool LocalAuth::ValidateLocalAuthCredentials(size_t info_index, +bool LocalAuth::ValidateLocalAuthCredentials(ProfileAttributesEntry* entry, const std::string& password) { - if (info_index == std::string::npos) { - NOTREACHED(); - return false; - } + DCHECK(entry); std::string record; char encoding; - ProfileInfoCache& info = - g_browser_process->profile_manager()->GetProfileInfoCache(); - - std::string encodedhash = - info.GetLocalAuthCredentialsOfProfileAtIndex(info_index); + std::string encodedhash = entry->GetLocalAuthCredentials(); if (encodedhash.length() == 0 && password.length() == 0) return true; if (!DecodePasswordHashRecord(encodedhash, &record, &encoding)) @@ -266,12 +256,20 @@ bool LocalAuth::ValidateLocalAuthCredentials(size_t info_index, // Update the stored credentials to the latest encoding if necessary. if (passwords_match && (hash_encoding->version - '0') != NUM_HASH_ENCODINGS) - SetLocalAuthCredentials(info_index, password); + SetLocalAuthCredentials(entry, password); return passwords_match; } bool LocalAuth::ValidateLocalAuthCredentials(const Profile* profile, const std::string& password) { - return ValidateLocalAuthCredentials(GetProfileInfoIndexOfProfile(profile), - password); + DCHECK(g_browser_process->profile_manager()->IsValidProfile(profile)); + ProfileAttributesEntry* entry; + + if (!g_browser_process->profile_manager()->GetProfileAttributesStorage(). + GetProfileAttributesWithPath(profile->GetPath(), &entry)) { + NOTREACHED(); + return false; + } + + return ValidateLocalAuthCredentials(entry, password); } diff --git a/chrome/browser/signin/local_auth.h b/chrome/browser/signin/local_auth.h index 4d591f4..0e999f0 100644 --- a/chrome/browser/signin/local_auth.h +++ b/chrome/browser/signin/local_auth.h @@ -17,6 +17,7 @@ class LocalAuthTest; class Profile; +class ProfileAttributesEntry; namespace user_prefs { class PrefRegistrySyncable; @@ -27,14 +28,13 @@ class LocalAuth { static void RegisterLocalAuthPrefs( user_prefs::PrefRegistrySyncable* registry); - static void SetLocalAuthCredentials(size_t profile_info_index, + static void SetLocalAuthCredentials(ProfileAttributesEntry* entry, const std::string& password); - static void SetLocalAuthCredentials(const Profile* profile, const std::string& password); - static bool ValidateLocalAuthCredentials(size_t profile_info_index, + static bool ValidateLocalAuthCredentials(ProfileAttributesEntry* entry, const std::string& password); static bool ValidateLocalAuthCredentials(const Profile* profile, @@ -50,7 +50,7 @@ class LocalAuth { static std::string TruncateStringByBits(const std::string& str, const size_t len_bits); - static void SetLocalAuthCredentialsWithEncoding(size_t profile_info_index, + static void SetLocalAuthCredentialsWithEncoding(ProfileAttributesEntry* entry, const std::string& password, char encoding_version); }; diff --git a/chrome/browser/signin/local_auth_unittest.cc b/chrome/browser/signin/local_auth_unittest.cc index 9145099..8aa0ddd 100644 --- a/chrome/browser/signin/local_auth_unittest.cc +++ b/chrome/browser/signin/local_auth_unittest.cc @@ -8,7 +8,8 @@ #include "base/base64.h" #include "build/build_config.h" -#include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/profiles/profile_attributes_entry.h" +#include "chrome/browser/profiles/profile_attributes_storage.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile_manager.h" @@ -28,10 +29,10 @@ TEST_F(LocalAuthTest, SetAndCheckCredentials) { TestingBrowserProcess::GetGlobal()); ASSERT_TRUE(testing_profile_manager.SetUp()); Profile* prof = testing_profile_manager.CreateTestingProfile("p1"); - ProfileInfoCache& cache = - testing_profile_manager.profile_manager()->GetProfileInfoCache(); - EXPECT_EQ(1U, cache.GetNumberOfProfiles()); - EXPECT_EQ("", cache.GetLocalAuthCredentialsOfProfileAtIndex(0)); + ProfileAttributesEntry* entry; + ASSERT_TRUE(testing_profile_manager.profile_attributes_storage()-> + GetProfileAttributesWithPath(prof->GetPath(), &entry)); + EXPECT_EQ("", entry->GetLocalAuthCredentials()); #if defined(OS_MACOSX) OSCrypt::UseMockKeychain(true); @@ -41,7 +42,7 @@ TEST_F(LocalAuthTest, SetAndCheckCredentials) { EXPECT_FALSE(LocalAuth::ValidateLocalAuthCredentials(prof, password)); LocalAuth::SetLocalAuthCredentials(prof, password); - std::string passhash = cache.GetLocalAuthCredentialsOfProfileAtIndex(0); + std::string passhash = entry->GetLocalAuthCredentials(); // We perform basic validation on the written record to ensure bugs don't slip // in that cannot be seen from the API: @@ -60,7 +61,7 @@ TEST_F(LocalAuthTest, SetAndCheckCredentials) { EXPECT_FALSE(LocalAuth::ValidateLocalAuthCredentials(prof, password + "1")); LocalAuth::SetLocalAuthCredentials(prof, password); // makes different salt - EXPECT_NE(passhash, cache.GetLocalAuthCredentialsOfProfileAtIndex(0)); + EXPECT_NE(passhash, entry->GetLocalAuthCredentials()); } TEST_F(LocalAuthTest, SetUpgradeAndCheckCredentials) { @@ -68,28 +69,26 @@ TEST_F(LocalAuthTest, SetUpgradeAndCheckCredentials) { TestingBrowserProcess::GetGlobal()); ASSERT_TRUE(testing_profile_manager.SetUp()); Profile* prof = testing_profile_manager.CreateTestingProfile("p1"); - ProfileInfoCache& cache = - testing_profile_manager.profile_manager()->GetProfileInfoCache(); #if defined(OS_MACOSX) OSCrypt::UseMockKeychain(true); #endif std::string password("Some Password"); - size_t profile_index = cache.GetIndexOfProfileWithPath(prof->GetPath()); - LocalAuth::SetLocalAuthCredentialsWithEncoding(profile_index, password, '1'); + ProfileAttributesEntry* entry; + ASSERT_TRUE(testing_profile_manager.profile_attributes_storage()-> + GetProfileAttributesWithPath(prof->GetPath(), &entry)); + LocalAuth::SetLocalAuthCredentialsWithEncoding(entry, password, '1'); // Ensure we indeed persisted the correct encoding. - std::string oldpasshash = cache.GetLocalAuthCredentialsOfProfileAtIndex( - profile_index); + std::string oldpasshash = entry->GetLocalAuthCredentials(); EXPECT_EQ('1', oldpasshash[0]); // Validate, ensure we can validate against the old encoding. EXPECT_TRUE(LocalAuth::ValidateLocalAuthCredentials(prof, password)); // Ensure we updated the encoding. - std::string newpasshash = cache.GetLocalAuthCredentialsOfProfileAtIndex( - profile_index); + std::string newpasshash = entry->GetLocalAuthCredentials(); EXPECT_EQ('2', newpasshash[0]); // Encoding '2' writes fewer bytes than encoding '1'. EXPECT_LE(newpasshash.length(), oldpasshash.length()); diff --git a/chrome/browser/signin/signin_global_error_unittest.cc b/chrome/browser/signin/signin_global_error_unittest.cc index 2bbf760..ae4fc48 100644 --- a/chrome/browser/signin/signin_global_error_unittest.cc +++ b/chrome/browser/signin/signin_global_error_unittest.cc @@ -6,11 +6,14 @@ #include <stddef.h> +#include <string> + #include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/strings/utf_string_conversions.h" #include "base/test/histogram_tester.h" -#include "chrome/browser/profiles/profile_info_cache.h" +#include "chrome/browser/profiles/profile_attributes_entry.h" +#include "chrome/browser/profiles/profile_attributes_storage.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_metrics.h" #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" @@ -58,11 +61,10 @@ class SigninGlobalErrorTest : public testing::Test { SigninManagerFactory::GetForProfile(profile()) ->SetAuthenticatedAccountInfo(kTestAccountId, kTestUsername); - ProfileInfoCache& cache = - profile_manager_.profile_manager()->GetProfileInfoCache(); - cache.SetAuthInfoOfProfileAtIndex( - cache.GetIndexOfProfileWithPath(profile()->GetPath()), - kTestGaiaId, base::UTF8ToUTF16(kTestUsername)); + ProfileAttributesEntry* entry; + ASSERT_TRUE(profile_manager_.profile_attributes_storage()-> + GetProfileAttributesWithPath(profile()->GetPath(), &entry)); + entry->SetAuthInfo(kTestGaiaId, base::UTF8ToUTF16(kTestUsername)); global_error_ = SigninGlobalErrorFactory::GetForProfile(profile()); error_controller_ = SigninErrorControllerFactory::GetForProfile(profile()); diff --git a/chrome/browser/signin/signin_promo.cc b/chrome/browser/signin/signin_promo.cc index c9aec13..80315d4 100644 --- a/chrome/browser/signin/signin_promo.cc +++ b/chrome/browser/signin/signin_promo.cc @@ -16,7 +16,6 @@ #include "chrome/browser/first_run/first_run.h" #include "chrome/browser/google/google_brand.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/signin_error_controller_factory.h" diff --git a/chrome/browser/ui/webui/signin/inline_login_handler_impl.cc b/chrome/browser/ui/webui/signin/inline_login_handler_impl.cc index e6c5a20..3729203 100644 --- a/chrome/browser/ui/webui/signin/inline_login_handler_impl.cc +++ b/chrome/browser/ui/webui/signin/inline_login_handler_impl.cc @@ -7,6 +7,7 @@ #include <stddef.h> #include <string> +#include <vector> #include "base/bind.h" #include "base/callback_helpers.h" @@ -22,6 +23,8 @@ #include "base/values.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_attributes_entry.h" +#include "chrome/browser/profiles/profile_attributes_storage.h" #include "chrome/browser/profiles/profile_window.h" #include "chrome/browser/signin/about_signin_internals_factory.h" #include "chrome/browser/signin/account_tracker_service_factory.h" @@ -553,14 +556,17 @@ bool InlineLoginHandlerImpl::CanOffer(Profile* profile, if (g_browser_process && !same_email) { ProfileManager* profile_manager = g_browser_process->profile_manager(); if (profile_manager) { - ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); - for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { - // For backward compatibility, need to also check the username of the - // profile, since the GAIA ID may not have been set yet for the - // profile cache info. It will get set once the profile is opened. - std::string profile_gaia_id = cache.GetGAIAIdOfProfileAtIndex(i); - std::string profile_email = - base::UTF16ToUTF8(cache.GetUserNameOfProfileAtIndex(i)); + std::vector<ProfileAttributesEntry*> entries = + profile_manager->GetProfileAttributesStorage(). + GetAllProfilesAttributes(); + + for (const ProfileAttributesEntry* entry : entries) { + // For backward compatibility, need to check also the username of the + // profile, since the GAIA ID may not have been set yet in the + // ProfileAttributesStorage. It will be set once the profile + // is opened. + std::string profile_gaia_id = entry->GetGAIAId(); + std::string profile_email = base::UTF16ToUTF8(entry->GetUserName()); if (gaia_id == profile_gaia_id || gaia::AreEmailsSame(email, profile_email)) { if (error_message) { @@ -834,8 +840,8 @@ void InlineLoginHandlerImpl::FinishCompleteLogin( ProfileManager* profile_manager = g_browser_process->profile_manager(); if (profile_manager) { ProfileAttributesEntry* entry; - if (profile_manager->GetProfileInfoCache() - .GetProfileAttributesWithPath(params.profile_path, &entry)) { + if (profile_manager->GetProfileAttributesStorage() + .GetProfileAttributesWithPath(params.profile_path, &entry)) { entry->SetIsSigninRequired(false); } } diff --git a/chrome/browser/ui/webui/signin/user_manager_screen_handler.cc b/chrome/browser/ui/webui/signin/user_manager_screen_handler.cc index 0e88c61..41ce878 100644 --- a/chrome/browser/ui/webui/signin/user_manager_screen_handler.cc +++ b/chrome/browser/ui/webui/signin/user_manager_screen_handler.cc @@ -6,6 +6,7 @@ #include <stddef.h> #include <utility> +#include <vector> #include "base/bind.h" #include "base/location.h" @@ -111,16 +112,14 @@ void OpenNewWindowForProfile(Profile* profile, Profile::CreateStatus status) { chrome::startup::IS_FIRST_RUN, false); } -std::string GetAvatarImageAtIndex( - size_t index, ProfileInfoCache* info_cache) { - bool is_gaia_picture = - info_cache->IsUsingGAIAPictureOfProfileAtIndex(index) && - info_cache->GetGAIAPictureOfProfileAtIndex(index); +std::string GetAvatarImage(const ProfileAttributesEntry* entry) { + bool is_gaia_picture = entry->IsUsingGAIAPicture() && + entry->GetGAIAPicture() != nullptr; // If the avatar is too small (i.e. the old-style low resolution avatar), // it will be pixelated when displayed in the User Manager, so we should // return the placeholder avatar instead. - gfx::Image avatar_image = info_cache->GetAvatarIconOfProfileAtIndex(index); + gfx::Image avatar_image = entry->GetAvatarIcon(); if (avatar_image.Width() <= profiles::kAvatarIconWidth || avatar_image.Height() <= profiles::kAvatarIconHeight ) { avatar_image = ui::ResourceBundle::GetSharedInstance().GetImageNamed( @@ -224,7 +223,7 @@ void HandleLogRemoveUserWarningShown(const base::ListValue* args) { // ProfileUpdateObserver ------------------------------------------------------ class UserManagerScreenHandler::ProfileUpdateObserver - : public ProfileInfoCacheObserver { + : public ProfileAttributesStorage::Observer { public: ProfileUpdateObserver( ProfileManager* profile_manager, UserManagerScreenHandler* handler) @@ -232,16 +231,16 @@ class UserManagerScreenHandler::ProfileUpdateObserver user_manager_handler_(handler) { DCHECK(profile_manager_); DCHECK(user_manager_handler_); - profile_manager_->GetProfileInfoCache().AddObserver(this); + profile_manager_->GetProfileAttributesStorage().AddObserver(this); } ~ProfileUpdateObserver() override { DCHECK(profile_manager_); - profile_manager_->GetProfileInfoCache().RemoveObserver(this); + profile_manager_->GetProfileAttributesStorage().RemoveObserver(this); } private: - // ProfileInfoCacheObserver implementation: + // ProfileAttributesStorage::Observer implementation: // If any change has been made to a profile, propagate it to all the // visible user manager screens. void OnProfileAdded(const base::FilePath& profile_path) override { @@ -294,7 +293,7 @@ class UserManagerScreenHandler::ProfileUpdateObserver // UserManagerScreenHandler --------------------------------------------------- UserManagerScreenHandler::UserManagerScreenHandler() : weak_ptr_factory_(this) { - profileInfoCacheObserver_.reset( + profile_attributes_storage_observer_.reset( new UserManagerScreenHandler::ProfileUpdateObserver( g_browser_process->profile_manager(), this)); } @@ -410,12 +409,11 @@ void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) return; - ProfileInfoCache& info_cache = - g_browser_process->profile_manager()->GetProfileInfoCache(); - ProfileAttributesEntry* entry; - if (!info_cache.GetProfileAttributesWithPath(profile_path, &entry)) + if (!g_browser_process->profile_manager()->GetProfileAttributesStorage(). + GetProfileAttributesWithPath(profile_path, &entry)) { return; + } base::string16 email_address; if (!args->GetString(1, &email_address)) @@ -430,12 +428,8 @@ void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( // Only try to validate locally or check the password change detection // if we actually have a local credential saved. - size_t profile_index = info_cache.GetIndexOfProfileWithPath(profile_path); - const bool has_local_credential = - !info_cache.GetLocalAuthCredentialsOfProfileAtIndex(profile_index) - .empty(); - if (has_local_credential) { - if (LocalAuth::ValidateLocalAuthCredentials(profile_index, password)) { + if (!entry->GetLocalAuthCredentials().empty()) { + if (LocalAuth::ValidateLocalAuthCredentials(entry, password)) { ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL); return; } @@ -508,11 +502,9 @@ void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) return; - const ProfileInfoCache& info_cache = - g_browser_process->profile_manager()->GetProfileInfoCache(); - size_t profile_index = info_cache.GetIndexOfProfileWithPath(profile_path); - - if (profile_index == std::string::npos) { + ProfileAttributesEntry* entry; + if (!g_browser_process->profile_manager()->GetProfileAttributesStorage(). + GetProfileAttributesWithPath(profile_path, &entry)) { NOTREACHED(); return; } @@ -522,7 +514,7 @@ void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { // unauthenticated version of "launch" instead of the proper one. Thus, // we have to validate in (secure) C++ code that it really is a profile // not needing authentication. If it is, just ignore the "launch" request. - if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) + if (entry->IsSigninRequired()) return; ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); @@ -574,10 +566,11 @@ void UserManagerScreenHandler::HandleRemoveUserWarningLoadStats( if (!chrome::FindAnyBrowser(profile, true)) { // If no windows are open for that profile, the statistics in - // ProfileInfoCache are up to date. The statistics in ProfileInfoCache are - // returned because the copy in user_pod_row.js may be outdated. However, if - // some statistics are missing in ProfileInfoCache (i.e. |item.success| is - // false), then the actual statistics are queried instead. + // ProfileAttributesStorage are up to date. The statistics in + // ProfileAttributesStorage are returned because the copy in user_pod_row.js + // may be outdated. However, if some statistics are missing in + // ProfileAttributesStorage (i.e. |item.success| is false), then the actual + // statistics are queried instead. base::DictionaryValue return_value; profiles::ProfileCategoryStats stats = profiles::GetProfileStatisticsFromCache(profile_path); @@ -847,8 +840,9 @@ void UserManagerScreenHandler::GetLocalizedValues( void UserManagerScreenHandler::SendUserList() { base::ListValue users_list; - ProfileInfoCache* info_cache = - &g_browser_process->profile_manager()->GetProfileInfoCache(); + std::vector<ProfileAttributesEntry*> entries = + g_browser_process->profile_manager()->GetProfileAttributesStorage(). + GetAllProfilesAttributesSortedByName(); user_auth_type_map_.clear(); // Profile deletion is not allowed in Metro mode. @@ -857,39 +851,32 @@ void UserManagerScreenHandler::SendUserList() { can_remove = !ash::Shell::HasInstance(); #endif - for (size_t i = 0; i < info_cache->GetNumberOfProfiles(); ++i) { + for (const ProfileAttributesEntry* entry : entries) { // Don't show profiles still in the middle of being set up as new legacy // supervised users. - if (info_cache->IsOmittedProfileAtIndex(i)) + if (entry->IsOmitted()) continue; base::DictionaryValue* profile_value = new base::DictionaryValue(); - base::FilePath profile_path = info_cache->GetPathOfProfileAtIndex(i); - - profile_value->SetString( - kKeyUsername, info_cache->GetUserNameOfProfileAtIndex(i)); - profile_value->SetString( - kKeyEmailAddress, info_cache->GetUserNameOfProfileAtIndex(i)); - profile_value->SetString( - kKeyDisplayName, - profiles::GetAvatarNameForProfile(profile_path)); - profile_value->Set( - kKeyProfilePath, base::CreateFilePathValue(profile_path)); + base::FilePath profile_path = entry->GetPath(); + + profile_value->SetString(kKeyUsername, entry->GetUserName()); + profile_value->SetString(kKeyEmailAddress, entry->GetUserName()); + profile_value->SetString(kKeyDisplayName, + profiles::GetAvatarNameForProfile(profile_path)); + profile_value->Set(kKeyProfilePath, + base::CreateFilePathValue(profile_path)); profile_value->SetBoolean(kKeyPublicAccount, false); profile_value->SetBoolean(kKeyLegacySupervisedUser, - info_cache->ProfileIsLegacySupervisedAtIndex(i)); - profile_value->SetBoolean( - kKeyChildUser, info_cache->ProfileIsChildAtIndex(i)); - profile_value->SetBoolean( - kKeyNeedsSignin, info_cache->ProfileIsSigninRequiredAtIndex(i)); - profile_value->SetBoolean( - kKeyHasLocalCreds, - !info_cache->GetLocalAuthCredentialsOfProfileAtIndex(i).empty()); + entry->IsLegacySupervised()); + profile_value->SetBoolean(kKeyChildUser, entry->IsChild()); + profile_value->SetBoolean(kKeyNeedsSignin, entry->IsSigninRequired()); + profile_value->SetBoolean(kKeyHasLocalCreds, + !entry->GetLocalAuthCredentials().empty()); profile_value->SetBoolean(kKeyIsOwner, false); profile_value->SetBoolean(kKeyCanRemove, can_remove); profile_value->SetBoolean(kKeyIsDesktop, true); - profile_value->SetString( - kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); + profile_value->SetString(kKeyAvatarUrl, GetAvatarImage(entry)); profiles::ProfileCategoryStats stats = profiles::GetProfileStatisticsFromCache(profile_path); @@ -953,11 +940,12 @@ void UserManagerScreenHandler::OnBrowserWindowReady(Browser* browser) { // Unlock the profile after browser opens so startup can read the lock bit. // Any necessary authentication must have been successful to reach this point. if (!browser->profile()->IsGuestSession()) { - ProfileInfoCache& info_cache = - g_browser_process->profile_manager()->GetProfileInfoCache(); - size_t index = info_cache.GetIndexOfProfileWithPath( - browser->profile()->GetPath()); - info_cache.SetProfileSigninRequiredAtIndex(index, false); + ProfileAttributesEntry* entry = nullptr; + bool has_entry = g_browser_process->profile_manager()-> + GetProfileAttributesStorage(). + GetProfileAttributesWithPath(browser->profile()->GetPath(), &entry); + DCHECK(has_entry); + entry->SetIsSigninRequired(false); } if (!url_hash_.empty()) { diff --git a/chrome/browser/ui/webui/signin/user_manager_screen_handler.h b/chrome/browser/ui/webui/signin/user_manager_screen_handler.h index 72dc64d..b2fcb09 100644 --- a/chrome/browser/ui/webui/signin/user_manager_screen_handler.h +++ b/chrome/browser/ui/webui/signin/user_manager_screen_handler.h @@ -45,8 +45,8 @@ class UserManagerScreenHandler void GetLocalizedValues(base::DictionaryValue* localized_strings); private: - // An observer for any changes to Profiles in the ProfileInfoCache so that - // all the visible user manager screens can be updated. + // An observer for any changes to Profiles in the ProfileAttributesStorage so + // that all the visible user manager screens can be updated. class ProfileUpdateObserver; // WebUIMessageHandler implementation. @@ -112,9 +112,9 @@ class UserManagerScreenHandler void OnSwitchToProfileComplete(Profile* profile, Profile::CreateStatus profile_create_status); - // Observes the ProfileInfoCache and gets notified when a profile has been - // modified, so that the displayed user pods can be updated. - scoped_ptr<ProfileUpdateObserver> profileInfoCacheObserver_; + // Observes the ProfileAttributesStorage and gets notified when a profile has + // been modified, so that the displayed user pods can be updated. + scoped_ptr<ProfileUpdateObserver> profile_attributes_storage_observer_; // Authenticator used when local-auth fails. scoped_ptr<gaia::GaiaOAuthClient> oauth_client_; |