diff options
author | lwchkg <lwchkg@gmail.com> | 2016-02-19 22:12:25 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-20 06:13:47 +0000 |
commit | c4d18c875a4fac73b210446b5693a7196a2a7178 (patch) | |
tree | ac1179b808cb2a5d443ab2b5d835d426bb4e551f | |
parent | 90c72beb055c1ada3576a1b58993fd3ace96f431 (diff) | |
download | chromium_src-c4d18c875a4fac73b210446b5693a7196a2a7178.zip chromium_src-c4d18c875a4fac73b210446b5693a7196a2a7178.tar.gz chromium_src-c4d18c875a4fac73b210446b5693a7196a2a7178.tar.bz2 |
Refactor ProfileInfoCache in c/b/ui/webui/options
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/1695683003
Cr-Commit-Position: refs/heads/master@{#376633}
13 files changed, 140 insertions, 127 deletions
diff --git a/chrome/browser/profiles/profile_attributes_storage.h b/chrome/browser/profiles/profile_attributes_storage.h index 0036813..cb55bf0 100644 --- a/chrome/browser/profiles/profile_attributes_storage.h +++ b/chrome/browser/profiles/profile_attributes_storage.h @@ -58,6 +58,14 @@ class ProfileAttributesStorage { // Returns the count of known profiles. virtual size_t GetNumberOfProfiles() const = 0; + // Returns a unique name that can be assigned to a newly created profile. + virtual base::string16 ChooseNameForNewProfile(size_t icon_index) const = 0; + + // Returns an avatar icon index that can be assigned to a newly created + // profile. Note that the icon may not be unique since there are a limited + // set of default icons. + virtual size_t ChooseAvatarIconIndexForNewProfile() const = 0; + virtual void AddObserver(ProfileAttributesStorage::Observer* observer) = 0; virtual void RemoveObserver(ProfileAttributesStorage::Observer* observer) = 0; diff --git a/chrome/browser/profiles/profile_info_cache.h b/chrome/browser/profiles/profile_info_cache.h index c54edc5..17c996f 100644 --- a/chrome/browser/profiles/profile_info_cache.h +++ b/chrome/browser/profiles/profile_info_cache.h @@ -151,12 +151,12 @@ class ProfileInfoCache : public ProfileInfoInterface, bool IsDefaultProfileName(const base::string16& name) const; // Returns unique name that can be assigned to a newly created profile. - base::string16 ChooseNameForNewProfile(size_t icon_index) const; + base::string16 ChooseNameForNewProfile(size_t icon_index) const override; // Returns an avatar icon index that can be assigned to a newly created // profile. Note that the icon may not be unique since there are a limited // set of default icons. - size_t ChooseAvatarIconIndexForNewProfile() const; + size_t ChooseAvatarIconIndexForNewProfile() const override; // Statistics void SetStatsBrowsingHistoryOfProfileAtIndex(size_t index, int value); diff --git a/chrome/browser/ui/webui/options/browser_options_handler.cc b/chrome/browser/ui/webui/options/browser_options_handler.cc index b904f74..04d0fae 100644 --- a/chrome/browser/ui/webui/options/browser_options_handler.cc +++ b/chrome/browser/ui/webui/options/browser_options_handler.cc @@ -37,8 +37,8 @@ #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_attributes_entry.h" #include "chrome/browser/profiles/profile_avatar_icon_util.h" -#include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_metrics.h" #include "chrome/browser/profiles/profile_shortcut_manager.h" @@ -837,7 +837,7 @@ void BrowserOptionsHandler::RegisterMessages() { void BrowserOptionsHandler::Uninitialize() { registrar_.RemoveAll(); g_browser_process->profile_manager()-> - GetProfileInfoCache().RemoveObserver(this); + GetProfileAttributesStorage().RemoveObserver(this); #if defined(OS_WIN) ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->RemoveObserver(this); #endif @@ -888,7 +888,8 @@ void BrowserOptionsHandler::InitializeHandler() { g_browser_process->policy_service()->AddObserver( policy::POLICY_DOMAIN_CHROME, this); - g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); + g_browser_process->profile_manager()-> + GetProfileAttributesStorage().AddObserver(this); ProfileSyncService* sync_service( ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile)); @@ -1294,37 +1295,33 @@ void BrowserOptionsHandler::OnProfileAvatarChanged( } scoped_ptr<base::ListValue> BrowserOptionsHandler::GetProfilesInfoList() { - ProfileInfoCache& cache = - g_browser_process->profile_manager()->GetProfileInfoCache(); + std::vector<ProfileAttributesEntry*> entries = + g_browser_process->profile_manager()-> + GetProfileAttributesStorage().GetAllProfilesAttributesSortedByName(); scoped_ptr<base::ListValue> profile_info_list(new base::ListValue); base::FilePath current_profile_path = web_ui()->GetWebContents()->GetBrowserContext()->GetPath(); - for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) { + for (const ProfileAttributesEntry* entry : entries) { // The items in |profile_value| are also described in // chrome/browser/resources/options/browser_options.js in a @typedef for // Profile. Please update it whenever you add or remove any keys here. - base::DictionaryValue* profile_value = new base::DictionaryValue(); - profile_value->SetString("name", cache.GetNameOfProfileAtIndex(i)); - base::FilePath profile_path = cache.GetPathOfProfileAtIndex(i); + profile_value->SetString("name", entry->GetName()); + base::FilePath profile_path = entry->GetPath(); profile_value->Set("filePath", base::CreateFilePathValue(profile_path)); profile_value->SetBoolean("isCurrentProfile", profile_path == current_profile_path); - profile_value->SetBoolean("isSupervised", - cache.ProfileIsSupervisedAtIndex(i)); - profile_value->SetBoolean("isChild", cache.ProfileIsChildAtIndex(i)); - - bool is_gaia_picture = - cache.IsUsingGAIAPictureOfProfileAtIndex(i) && - cache.GetGAIAPictureOfProfileAtIndex(i); - if (is_gaia_picture) { - gfx::Image icon = profiles::GetAvatarIconForWebUI( - cache.GetAvatarIconOfProfileAtIndex(i), true); + profile_value->SetBoolean("isSupervised", entry->IsSupervised()); + profile_value->SetBoolean("isChild", entry->IsChild()); + + if (entry->IsUsingGAIAPicture() && entry->GetGAIAPicture()) { + gfx::Image icon = profiles::GetAvatarIconForWebUI(entry->GetAvatarIcon(), + true); profile_value->SetString("iconURL", - webui::GetBitmapDataUrl(icon.AsBitmap())); + webui::GetBitmapDataUrl(icon.AsBitmap())); } else { - size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(i); + size_t icon_index = entry->GetAvatarIconIndex(); profile_value->SetString("iconURL", profiles::GetDefaultAvatarIconUrl(icon_index)); } diff --git a/chrome/browser/ui/webui/options/browser_options_handler.h b/chrome/browser/ui/webui/options/browser_options_handler.h index f3eeaad..2cbedb3 100644 --- a/chrome/browser/ui/webui/options/browser_options_handler.h +++ b/chrome/browser/ui/webui/options/browser_options_handler.h @@ -15,7 +15,7 @@ #include "base/scoped_observer.h" #include "build/build_config.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_info_cache_observer.h" +#include "chrome/browser/profiles/profile_attributes_storage.h" #include "chrome/browser/shell_integration.h" #include "chrome/browser/ui/host_desktop.h" #include "chrome/browser/ui/webui/options/options_ui.h" @@ -56,7 +56,7 @@ namespace options { // Chrome browser options page UI handler. class BrowserOptionsHandler : public OptionsPageUIHandler, - public ProfileInfoCacheObserver, + public ProfileAttributesStorage::Observer, public sync_driver::SyncServiceObserver, public SigninManagerBase::Observer, public ui::SelectFileDialog::Listener, @@ -116,13 +116,13 @@ class BrowserOptionsHandler const content::NotificationSource& source, const content::NotificationDetails& details) override; - // ProfileInfoCacheObserver implementation. - void OnProfileAdded(const base::FilePath& profile_path) override; - void OnProfileWasRemoved(const base::FilePath& profile_path, - const base::string16& profile_name) override; - void OnProfileNameChanged(const base::FilePath& profile_path, - const base::string16& old_profile_name) override; - void OnProfileAvatarChanged(const base::FilePath& profile_path) override; + // ProfileAttributesStorage::Observer implementation. + void OnProfileAdded(const base::FilePath& profile_path) override; + void OnProfileWasRemoved(const base::FilePath& profile_path, + const base::string16& profile_name) override; + void OnProfileNameChanged(const base::FilePath& profile_path, + const base::string16& old_profile_name) override; + void OnProfileAvatarChanged(const base::FilePath& profile_path) override; #if defined(ENABLE_PRINT_PREVIEW) && !defined(OS_CHROMEOS) void OnCloudPrintPrefsChanged(); diff --git a/chrome/browser/ui/webui/options/create_profile_handler.cc b/chrome/browser/ui/webui/options/create_profile_handler.cc index 7f87381..6036836 100644 --- a/chrome/browser/ui/webui/options/create_profile_handler.cc +++ b/chrome/browser/ui/webui/options/create_profile_handler.cc @@ -6,6 +6,8 @@ #include <stddef.h> +#include <vector> + #include "base/bind.h" #include "base/files/file_path.h" #include "base/metrics/histogram.h" @@ -13,6 +15,8 @@ #include "base/value_conversions.h" #include "base/values.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/profiles/profile_attributes_entry.h" +#include "chrome/browser/profiles/profile_attributes_storage.h" #include "chrome/browser/profiles/profile_avatar_icon_util.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_metrics.h" @@ -460,11 +464,11 @@ bool CreateProfileHandler::IsValidExistingSupervisedUserId( return false; // Check if this supervised user already exists on this machine. - const ProfileInfoCache& cache = - g_browser_process->profile_manager()->GetProfileInfoCache(); - for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { - if (existing_supervised_user_id == - cache.GetSupervisedUserIdOfProfileAtIndex(i)) + std::vector<ProfileAttributesEntry*> entries = + g_browser_process->profile_manager()-> + GetProfileAttributesStorage().GetAllProfilesAttributes(); + for (const ProfileAttributesEntry* entry : entries) { + if (existing_supervised_user_id == entry->GetSupervisedUserId()) return false; } return true; diff --git a/chrome/browser/ui/webui/options/create_profile_handler.h b/chrome/browser/ui/webui/options/create_profile_handler.h index dafcd91b..867f456 100644 --- a/chrome/browser/ui/webui/options/create_profile_handler.h +++ b/chrome/browser/ui/webui/options/create_profile_handler.h @@ -5,6 +5,8 @@ #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_ #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_ +#include <string> + #include "base/macros.h" #include "base/memory/weak_ptr.h" #include "base/time/time.h" diff --git a/chrome/browser/ui/webui/options/manage_profile_handler.cc b/chrome/browser/ui/webui/options/manage_profile_handler.cc index 74e04d6..b678f1c 100644 --- a/chrome/browser/ui/webui/options/manage_profile_handler.cc +++ b/chrome/browser/ui/webui/options/manage_profile_handler.cc @@ -6,6 +6,8 @@ #include <stddef.h> +#include <vector> + #include "base/bind.h" #include "base/bind_helpers.h" #include "base/macros.h" @@ -19,8 +21,8 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/profiles/gaia_info_update_service.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_attributes_entry.h" #include "chrome/browser/profiles/profile_avatar_icon_util.h" -#include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_metrics.h" #include "chrome/browser/profiles/profile_shortcut_manager.h" @@ -144,7 +146,8 @@ void ManageProfileHandler::GetLocalizedValues( } void ManageProfileHandler::InitializeHandler() { - g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); + g_browser_process->profile_manager()-> + GetProfileAttributesStorage().AddObserver(this); Profile* profile = Profile::FromWebUI(web_ui()); pref_change_registrar_.Init(profile->GetPrefs()); @@ -207,7 +210,7 @@ void ManageProfileHandler::RegisterMessages() { void ManageProfileHandler::Uninitialize() { g_browser_process->profile_manager()-> - GetProfileInfoCache().RemoveObserver(this); + GetProfileAttributesStorage().RemoveObserver(this); } void ManageProfileHandler::OnProfileAdded(const base::FilePath& profile_path) { @@ -285,12 +288,12 @@ void ManageProfileHandler::RequestDefaultProfileIcons( void ManageProfileHandler::RequestNewProfileDefaults( const base::ListValue* args) { - const ProfileInfoCache& cache = - g_browser_process->profile_manager()->GetProfileInfoCache(); - const size_t icon_index = cache.ChooseAvatarIconIndexForNewProfile(); + const ProfileAttributesStorage& storage = + g_browser_process->profile_manager()->GetProfileAttributesStorage(); + const size_t icon_index = storage.ChooseAvatarIconIndexForNewProfile(); base::DictionaryValue profile_info; - profile_info.SetString("name", cache.ChooseNameForNewProfile(icon_index)); + profile_info.SetString("name", storage.ChooseNameForNewProfile(icon_index)); profile_info.SetString("iconURL", profiles::GetDefaultAvatarIconUrl(icon_index)); @@ -303,23 +306,23 @@ void ManageProfileHandler::SendProfileIconsAndNames( base::ListValue image_url_list; base::ListValue default_name_list; - const ProfileInfoCache& cache = - g_browser_process->profile_manager()->GetProfileInfoCache(); + ProfileAttributesStorage& storage = + g_browser_process->profile_manager()->GetProfileAttributesStorage(); // In manage mode, first add the GAIA picture if it is available. No GAIA // picture in create mode. if (mode.GetString() == kManageProfileIdentifier) { Profile* profile = Profile::FromWebUI(web_ui()); - size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); - if (profile_index != std::string::npos) { - const gfx::Image* icon = - cache.GetGAIAPictureOfProfileAtIndex(profile_index); - if (icon) { - gfx::Image icon2 = profiles::GetAvatarIconForWebUI(*icon, true); - gaia_picture_url_ = webui::GetBitmapDataUrl(icon2.AsBitmap()); - image_url_list.AppendString(gaia_picture_url_); - default_name_list.AppendString(std::string()); - } + ProfileAttributesEntry* entry = nullptr; + bool success = storage.GetProfileAttributesWithPath(profile->GetPath(), + &entry); + DCHECK(success); + const gfx::Image* icon = entry->GetGAIAPicture(); + if (icon) { + gfx::Image icon2 = profiles::GetAvatarIconForWebUI(*icon, true); + gaia_picture_url_ = webui::GetBitmapDataUrl(icon2.AsBitmap()); + image_url_list.AppendString(gaia_picture_url_); + default_name_list.AppendString(std::string()); } } @@ -327,7 +330,7 @@ void ManageProfileHandler::SendProfileIconsAndNames( for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount(); i++) { std::string url = profiles::GetDefaultAvatarIconUrl(i); image_url_list.AppendString(url); - default_name_list.AppendString(cache.ChooseNameForNewProfile(i)); + default_name_list.AppendString(storage.ChooseNameForNewProfile(i)); } web_ui()->CallJavascriptFunction( @@ -336,13 +339,12 @@ void ManageProfileHandler::SendProfileIconsAndNames( } void ManageProfileHandler::SendExistingProfileNames() { - const ProfileInfoCache& cache = - g_browser_process->profile_manager()->GetProfileInfoCache(); + std::vector<ProfileAttributesEntry*> entries = + g_browser_process->profile_manager()-> + GetProfileAttributesStorage().GetAllProfilesAttributes(); base::DictionaryValue profile_name_dict; - for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) { - profile_name_dict.SetBoolean( - base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(i)), true); - } + for (const ProfileAttributesEntry* entry : entries) + profile_name_dict.SetBoolean(base::UTF16ToUTF8(entry->GetName()), true); web_ui()->CallJavascriptFunction( "ManageProfileOverlay.receiveExistingProfileNames", profile_name_dict); @@ -454,12 +456,11 @@ void ManageProfileHandler::ProfileIconSelectionChanged( // If the selection is the GAIA picture then also show the profile name in the // text field. This will display either the GAIA given name, if available, // or the first name. - ProfileInfoCache& cache = - g_browser_process->profile_manager()->GetProfileInfoCache(); - size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); - if (profile_index == std::string::npos) + ProfileAttributesEntry* entry = nullptr; + if (!g_browser_process->profile_manager()->GetProfileAttributesStorage(). + GetProfileAttributesWithPath(profile_file_path, &entry)) return; - base::string16 gaia_name = cache.GetNameOfProfileAtIndex(profile_index); + base::string16 gaia_name = entry->GetName(); if (gaia_name.empty()) return; @@ -478,23 +479,21 @@ void ManageProfileHandler::RequestHasProfileShortcuts( if (!GetProfilePathFromArgs(args, &profile_file_path)) return; - const ProfileInfoCache& cache = - g_browser_process->profile_manager()->GetProfileInfoCache(); - size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); - if (profile_index == std::string::npos) + ProfileAttributesStorage& storage = + g_browser_process->profile_manager()->GetProfileAttributesStorage(); + ProfileAttributesEntry* entry; + if (!storage.GetProfileAttributesWithPath(profile_file_path, &entry)) return; // Don't show the add/remove desktop shortcut button in the single user case. - if (cache.GetNumberOfProfiles() <= 1) + if (storage.GetNumberOfProfiles() <= 1u) return; - const base::FilePath profile_path = - cache.GetPathOfProfileAtIndex(profile_index); ProfileShortcutManager* shortcut_manager = g_browser_process->profile_manager()->profile_shortcut_manager(); shortcut_manager->HasProfileShortcuts( - profile_path, base::Bind(&ManageProfileHandler::OnHasProfileShortcuts, - weak_factory_.GetWeakPtr())); + entry->GetPath(), base::Bind(&ManageProfileHandler::OnHasProfileShortcuts, + weak_factory_.GetWeakPtr())); } void ManageProfileHandler::RequestCreateProfileUpdate( diff --git a/chrome/browser/ui/webui/options/manage_profile_handler.h b/chrome/browser/ui/webui/options/manage_profile_handler.h index 698368d..4407c92 100644 --- a/chrome/browser/ui/webui/options/manage_profile_handler.h +++ b/chrome/browser/ui/webui/options/manage_profile_handler.h @@ -9,7 +9,7 @@ #include "base/macros.h" #include "base/memory/weak_ptr.h" -#include "chrome/browser/profiles/profile_info_cache_observer.h" +#include "chrome/browser/profiles/profile_attributes_storage.h" #include "chrome/browser/ui/webui/options/options_ui.h" #include "components/prefs/pref_change_registrar.h" #include "components/sync_driver/sync_service_observer.h" @@ -22,7 +22,7 @@ namespace options { // Chrome personal stuff profiles manage overlay UI handler. class ManageProfileHandler : public OptionsPageUIHandler, - public ProfileInfoCacheObserver, + public ProfileAttributesStorage::Observer, public sync_driver::SyncServiceObserver { public: ManageProfileHandler(); @@ -37,7 +37,7 @@ class ManageProfileHandler : public OptionsPageUIHandler, // WebUIMessageHandler: void RegisterMessages() override; - // ProfileInfoCacheObserver: + // ProfileAttributesStorage::Observer: void OnProfileAdded(const base::FilePath& profile_path) override; void OnProfileWasRemoved(const base::FilePath& profile_path, const base::string16& profile_name) override; diff --git a/chrome/browser/ui/webui/options/options_ui_browsertest.cc b/chrome/browser/ui/webui/options/options_ui_browsertest.cc index e5d7a97..c03aaa8 100644 --- a/chrome/browser/ui/webui/options/options_ui_browsertest.cc +++ b/chrome/browser/ui/webui/options/options_ui_browsertest.cc @@ -39,6 +39,7 @@ #include "base/run_loop.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_attributes_storage.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/ui/browser_commands.h" #include "content/public/test/test_navigation_observer.h" @@ -225,12 +226,12 @@ IN_PROC_BROWSER_TEST_F(OptionsUIBrowserTest, MAYBE_VerifyManagedSignout) { EXPECT_TRUE(result); base::FilePath profile_dir = browser()->profile()->GetPath(); - ProfileInfoCache& profile_info_cache = - g_browser_process->profile_manager()->GetProfileInfoCache(); + ProfileAttributesStorage& storage = + g_browser_process->profile_manager()->GetProfileAttributesStorage(); + ProfileAttributesEntry* entry; EXPECT_TRUE(DirectoryExists(profile_dir)); - EXPECT_TRUE(profile_info_cache.GetIndexOfProfileWithPath(profile_dir) != - std::string::npos); + EXPECT_TRUE(storage.GetProfileAttributesWithPath(profile_dir, &entry)); // TODO(kaliamoorthi): Get the macos problem fixed and remove this code. // Deleting the Profile also destroys all browser windows of that Profile. @@ -244,8 +245,7 @@ IN_PROC_BROWSER_TEST_F(OptionsUIBrowserTest, MAYBE_VerifyManagedSignout) { browser()->tab_strip_model()->GetActiveWebContents(), "$('disconnect-managed-profile-ok').click();")); - EXPECT_TRUE(profile_info_cache.GetIndexOfProfileWithPath(profile_dir) == - std::string::npos); + EXPECT_TRUE(storage.GetProfileAttributesWithPath(profile_dir, &entry)); wait_for_browser_closed.Wait(); } diff --git a/chrome/browser/ui/webui/options/supervised_user_create_confirm_handler.cc b/chrome/browser/ui/webui/options/supervised_user_create_confirm_handler.cc index 2b169e0..cbc7922 100644 --- a/chrome/browser/ui/webui/options/supervised_user_create_confirm_handler.cc +++ b/chrome/browser/ui/webui/options/supervised_user_create_confirm_handler.cc @@ -6,6 +6,8 @@ #include <stddef.h> +#include <string> + #include "base/bind.h" #include "base/files/file_path.h" #include "base/macros.h" @@ -15,8 +17,8 @@ #include "base/values.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_info_cache_observer.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_window.h" #include "chrome/browser/signin/signin_manager_factory.h" @@ -35,20 +37,20 @@ namespace options { // ProfileUpdateObserver------------------------------------------------------ class SupervisedUserCreateConfirmHandler::ProfileUpdateObserver - : public ProfileInfoCacheObserver { + : public ProfileAttributesStorage::Observer { public: - ProfileUpdateObserver(ProfileInfoCache* profile_info_cache, + ProfileUpdateObserver(ProfileAttributesStorage* profile_attributes_storage, SupervisedUserCreateConfirmHandler* handler) - : profile_info_cache_(profile_info_cache), + : profile_attributes_storage_(profile_attributes_storage), create_confirm_handler_(handler), scoped_observer_(this) { - DCHECK(profile_info_cache_); + DCHECK(profile_attributes_storage_); DCHECK(create_confirm_handler_); - scoped_observer_.Add(profile_info_cache_); + scoped_observer_.Add(profile_attributes_storage_); } private: - // ProfileInfoCacheObserver implementation: + // ProfileAttributesStorage::Observer implementation: // Forward possibly relevant changes to the dialog, which will check the // affected profile and update or close as needed. void OnProfileWasRemoved(const base::FilePath& profile_path, @@ -62,12 +64,11 @@ class SupervisedUserCreateConfirmHandler::ProfileUpdateObserver void OnProfileNameChanged(const base::FilePath& profile_path, const base::string16& old_profile_name) override { - size_t profile_index = - profile_info_cache_->GetIndexOfProfileWithPath(profile_path); - if (profile_index == std::string::npos) + ProfileAttributesEntry* entry; + if (!profile_attributes_storage_-> + GetProfileAttributesWithPath(profile_path, &entry)) return; - base::string16 new_profile_name = - profile_info_cache_->GetNameOfProfileAtIndex(profile_index); + base::string16 new_profile_name = entry->GetName(); scoped_ptr<base::StringValue> profile_path_value( base::CreateFilePathValue(profile_path)); create_confirm_handler_->web_ui()->CallJavascriptFunction( @@ -77,14 +78,15 @@ class SupervisedUserCreateConfirmHandler::ProfileUpdateObserver } // Weak. - ProfileInfoCache* profile_info_cache_; + ProfileAttributesStorage* profile_attributes_storage_; // Weak; owns us. SupervisedUserCreateConfirmHandler* create_confirm_handler_; // Manages any sources we're observing, ensuring that they're all removed // on destruction. - ScopedObserver<ProfileInfoCache, ProfileUpdateObserver> scoped_observer_; + ScopedObserver<ProfileAttributesStorage, ProfileUpdateObserver> + scoped_observer_; DISALLOW_COPY_AND_ASSIGN(ProfileUpdateObserver); }; @@ -93,9 +95,10 @@ class SupervisedUserCreateConfirmHandler::ProfileUpdateObserver // SupervisedUserCreateConfirmHandler----------------------------------------- SupervisedUserCreateConfirmHandler::SupervisedUserCreateConfirmHandler() { - profile_info_cache_observer_.reset( + profile_update_observer_.reset( new SupervisedUserCreateConfirmHandler::ProfileUpdateObserver( - &g_browser_process->profile_manager()->GetProfileInfoCache(), this)); + &g_browser_process->profile_manager()->GetProfileAttributesStorage(), + this)); } SupervisedUserCreateConfirmHandler::~SupervisedUserCreateConfirmHandler() { diff --git a/chrome/browser/ui/webui/options/supervised_user_create_confirm_handler.h b/chrome/browser/ui/webui/options/supervised_user_create_confirm_handler.h index 980728c..a2593fd 100644 --- a/chrome/browser/ui/webui/options/supervised_user_create_confirm_handler.h +++ b/chrome/browser/ui/webui/options/supervised_user_create_confirm_handler.h @@ -28,8 +28,8 @@ class SupervisedUserCreateConfirmHandler : public OptionsPageUIHandler { void RegisterMessages() override; private: - // An observer for any changes to Profiles in the ProfileInfoCache so that - // this dialog can be updated or closed. + // An observer for any changes to Profiles in the ProfileAttributesStorage so + // that this dialog can be updated or closed. class ProfileUpdateObserver; // Callback for the "switchToProfile" message. @@ -37,9 +37,9 @@ class SupervisedUserCreateConfirmHandler : public OptionsPageUIHandler { // |args| is of the form [ {string} profileFilePath ] void SwitchToProfile(const base::ListValue* args); - // Observes the ProfileInfoCache and gets notified when a profile has been - // modified, so that the dialog can be updated or closed. - scoped_ptr<ProfileUpdateObserver> profile_info_cache_observer_; + // Observes the ProfileAttributesStorage and gets notified when a profile has + // been modified, so that the dialog can be updated or closed. + scoped_ptr<ProfileUpdateObserver> profile_update_observer_; DISALLOW_COPY_AND_ASSIGN(SupervisedUserCreateConfirmHandler); }; diff --git a/chrome/browser/ui/webui/options/supervised_user_import_handler.cc b/chrome/browser/ui/webui/options/supervised_user_import_handler.cc index 89a3360..4c81acc 100644 --- a/chrome/browser/ui/webui/options/supervised_user_import_handler.cc +++ b/chrome/browser/ui/webui/options/supervised_user_import_handler.cc @@ -7,14 +7,15 @@ #include <stddef.h> #include <set> +#include <vector> #include "base/bind.h" #include "base/macros.h" #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_avatar_icon_util.h" -#include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/signin/signin_error_controller_factory.h" #include "chrome/browser/signin/signin_manager_factory.h" @@ -44,12 +45,11 @@ scoped_ptr<base::ListValue> GetAvatarIcons() { } bool ProfileIsLegacySupervised(const base::FilePath& profile_path) { - const ProfileInfoCache& cache = - g_browser_process->profile_manager()->GetProfileInfoCache(); - size_t index = cache.GetIndexOfProfileWithPath(profile_path); - if (index == std::string::npos) - return false; - return cache.ProfileIsLegacySupervisedAtIndex(index); + ProfileAttributesEntry* entry; + + return g_browser_process->profile_manager()->GetProfileAttributesStorage(). + GetProfileAttributesWithPath(profile_path, &entry) && + entry->IsLegacySupervised(); } } // namespace @@ -101,7 +101,7 @@ void SupervisedUserImportHandler::InitializeHandler() { Profile* profile = Profile::FromWebUI(web_ui()); if (!profile->IsSupervised()) { profile_observer_.Add( - &g_browser_process->profile_manager()->GetProfileInfoCache()); + &g_browser_process->profile_manager()->GetProfileAttributesStorage()); SupervisedUserSyncService* sync_service = SupervisedUserSyncServiceFactory::GetForProfile(profile); if (sync_service) { @@ -194,17 +194,17 @@ void SupervisedUserImportHandler::RequestSupervisedUserImportUpdate( void SupervisedUserImportHandler::SendExistingSupervisedUsers( const base::DictionaryValue* dict) { DCHECK(dict); - const ProfileInfoCache& cache = - g_browser_process->profile_manager()->GetProfileInfoCache(); + std::vector<ProfileAttributesEntry*> entries = + g_browser_process->profile_manager()-> + GetProfileAttributesStorage().GetAllProfilesAttributes(); // Collect the ids of local supervised user profiles. std::set<std::string> supervised_user_ids; - for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { + for (const ProfileAttributesEntry* entry : entries) { // Filter out omitted profiles. These are currently being imported, and // shouldn't show up as "already on this device" just yet. - if (cache.ProfileIsLegacySupervisedAtIndex(i) && - !cache.IsOmittedProfileAtIndex(i)) { - supervised_user_ids.insert(cache.GetSupervisedUserIdOfProfileAtIndex(i)); + if (entry->IsLegacySupervised() && !entry->IsOmitted()) { + supervised_user_ids.insert(entry->GetSupervisedUserId()); } } diff --git a/chrome/browser/ui/webui/options/supervised_user_import_handler.h b/chrome/browser/ui/webui/options/supervised_user_import_handler.h index 0a5ff83..ee576bd 100644 --- a/chrome/browser/ui/webui/options/supervised_user_import_handler.h +++ b/chrome/browser/ui/webui/options/supervised_user_import_handler.h @@ -12,7 +12,7 @@ #include "base/memory/weak_ptr.h" #include "base/scoped_observer.h" #include "base/strings/string16.h" -#include "chrome/browser/profiles/profile_info_cache_observer.h" +#include "chrome/browser/profiles/profile_attributes_storage.h" #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_observer.h" #include "chrome/browser/ui/webui/options/options_ui.h" #include "components/signin/core/browser/signin_error_controller.h" @@ -22,14 +22,14 @@ class DictionaryValue; class ListValue; } -class ProfileInfoCache; +class ProfileAttributesStorage; class SupervisedUserSyncService; namespace options { // Handler for the 'import existing supervised user' dialog. class SupervisedUserImportHandler : public OptionsPageUIHandler, - public ProfileInfoCacheObserver, + public ProfileAttributesStorage::Observer, public SupervisedUserSyncServiceObserver, public SigninErrorController::Observer { public: @@ -47,7 +47,7 @@ class SupervisedUserImportHandler : public OptionsPageUIHandler, // WebUIMessageHandler implementation. void RegisterMessages() override; - // ProfileInfoCacheObserver implementation. + // ProfileAttributesStorage::Observer implementation. void OnProfileAdded(const base::FilePath& profile_path) override; void OnProfileWillBeRemoved(const base::FilePath& profile_path) override; void OnProfileWasRemoved(const base::FilePath& profile_path, @@ -99,7 +99,7 @@ class SupervisedUserImportHandler : public OptionsPageUIHandler, scoped_ptr<CallbackList::Subscription> subscription_; - ScopedObserver<ProfileInfoCache, SupervisedUserImportHandler> + ScopedObserver<ProfileAttributesStorage, SupervisedUserImportHandler> profile_observer_; ScopedObserver<SigninErrorController, SupervisedUserImportHandler> signin_error_observer_; |