Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3426)

Unified Diff: chrome/browser/profiles/profile_shortcut_manager_win.cc

Issue 1794353003: Refactor ProfileInfoCache in c/b/profiles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/profiles/profile_shortcut_manager_win.cc
diff --git a/chrome/browser/profiles/profile_shortcut_manager_win.cc b/chrome/browser/profiles/profile_shortcut_manager_win.cc
index df21756ed2e2f820a76bce143137c2c471c02a3a..eb2ae10f9d42543a16ba7d577ff7f96ffcd56049 100644
--- a/chrome/browser/profiles/profile_shortcut_manager_win.cc
+++ b/chrome/browser/profiles/profile_shortcut_manager_win.cc
@@ -24,8 +24,9 @@
#include "chrome/browser/app_icon_win.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.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_info_cache_observer.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/common/chrome_switches.h"
@@ -678,11 +679,11 @@ ProfileShortcutManagerWin::ProfileShortcutManagerWin(ProfileManager* manager)
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED,
content::NotificationService::AllSources());
- profile_manager_->GetProfileInfoCache().AddObserver(this);
+ profile_manager_->GetProfileAttributesStorage().AddObserver(this);
}
ProfileShortcutManagerWin::~ProfileShortcutManagerWin() {
- profile_manager_->GetProfileInfoCache().RemoveObserver(this);
+ profile_manager_->GetProfileAttributesStorage().RemoveObserver(this);
}
void ProfileShortcutManagerWin::CreateOrUpdateProfileIcon(
@@ -724,14 +725,16 @@ void ProfileShortcutManagerWin::GetShortcutProperties(
return;
}
- const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache();
- size_t profile_index = cache.GetIndexOfProfileWithPath(profile_path);
- DCHECK_LT(profile_index, cache.GetNumberOfProfiles());
+ ProfileAttributesStorage& storage =
+ profile_manager_->GetProfileAttributesStorage();
+ ProfileAttributesEntry* entry;
+ bool has_entry = storage.GetProfileAttributesWithPath(profile_path, &entry);
+ DCHECK(has_entry);
// The used profile name should be empty if there is only 1 profile.
base::string16 shortcut_profile_name;
- if (cache.GetNumberOfProfiles() > 1)
- shortcut_profile_name = cache.GetNameOfProfileAtIndex(profile_index);
+ if (storage.GetNumberOfProfiles() > 1u)
+ shortcut_profile_name = entry->GetName();
*name = base::FilePath(profiles::internal::GetShortcutFilenameForProfile(
shortcut_profile_name,
@@ -746,7 +749,8 @@ void ProfileShortcutManagerWin::GetShortcutProperties(
void ProfileShortcutManagerWin::OnProfileAdded(
const base::FilePath& profile_path) {
CreateOrUpdateProfileIcon(profile_path);
- if (profile_manager_->GetProfileInfoCache().GetNumberOfProfiles() == 2) {
+ if (profile_manager_->GetProfileAttributesStorage().GetNumberOfProfiles() ==
+ 2u) {
// When the second profile is added, make existing non-profile shortcuts
// point to the first profile and be badged/named appropriately.
CreateOrUpdateShortcutsForProfileAtPath(GetOtherProfilePath(profile_path),
@@ -758,15 +762,18 @@ void ProfileShortcutManagerWin::OnProfileAdded(
void ProfileShortcutManagerWin::OnProfileWasRemoved(
const base::FilePath& profile_path,
const base::string16& profile_name) {
- const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache();
+ ProfileAttributesStorage& storage =
+ profile_manager_->GetProfileAttributesStorage();
// If there is only one profile remaining, remove the badging information
// from an existing shortcut.
- const bool deleting_down_to_last_profile = (cache.GetNumberOfProfiles() == 1);
+ const bool deleting_down_to_last_profile =
+ (storage.GetNumberOfProfiles() == 1u);
if (deleting_down_to_last_profile) {
// This is needed to unbadge the icon.
- CreateOrUpdateShortcutsForProfileAtPath(cache.GetPathOfProfileAtIndex(0),
- UPDATE_EXISTING_ONLY,
- IGNORE_NON_PROFILE_SHORTCUTS);
+ CreateOrUpdateShortcutsForProfileAtPath(
+ storage.GetAllProfilesAttributes().front()->GetPath(),
+ UPDATE_EXISTING_ONLY,
+ IGNORE_NON_PROFILE_SHORTCUTS);
}
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
@@ -789,13 +796,21 @@ void ProfileShortcutManagerWin::OnProfileAvatarChanged(
base::FilePath ProfileShortcutManagerWin::GetOtherProfilePath(
const base::FilePath& profile_path) {
- const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache();
- DCHECK_EQ(2U, cache.GetNumberOfProfiles());
+ const ProfileAttributesStorage& storage =
+ profile_manager_->GetProfileAttributesStorage();
+ DCHECK_EQ(2u, storage.GetNumberOfProfiles());
// Get the index of the current profile, in order to find the index of the
// other profile.
- size_t current_profile_index = cache.GetIndexOfProfileWithPath(profile_path);
- size_t other_profile_index = (current_profile_index == 0) ? 1 : 0;
- return cache.GetPathOfProfileAtIndex(other_profile_index);
+ std::vector<ProfileAttributesEntry*> entries = g_browser_process->
+ profile_manager()->GetProfileAttributesStorage().
+ GetAllProfilesAttributes();
+ for (ProfileAttributesEntry* entry : entries) {
+ base::FilePath path = entry->GetPath();
+ if (path != profile_path)
+ return path;
+ }
+ NOTREACHED();
+ return base::FilePath();
}
void ProfileShortcutManagerWin::CreateOrUpdateShortcutsForProfileAtPath(
@@ -806,18 +821,20 @@ void ProfileShortcutManagerWin::CreateOrUpdateShortcutsForProfileAtPath(
BrowserThread::CurrentlyOn(BrowserThread::UI));
CreateOrUpdateShortcutsParams params(profile_path, create_mode, action);
- ProfileInfoCache* cache = &profile_manager_->GetProfileInfoCache();
- size_t profile_index = cache->GetIndexOfProfileWithPath(profile_path);
- if (profile_index == std::string::npos)
+ ProfileAttributesStorage& storage =
+ profile_manager_->GetProfileAttributesStorage();
+ ProfileAttributesEntry* entry;
+ bool has_entry = storage.GetProfileAttributesWithPath(profile_path, &entry);
+ if (!has_entry)
return;
- bool remove_badging = cache->GetNumberOfProfiles() == 1;
+ bool remove_badging = (storage.GetNumberOfProfiles() == 1u);
params.old_profile_name =
- cache->GetShortcutNameOfProfileAtIndex(profile_index);
+ entry->GetShortcutName();
// Exit early if the mode is to update existing profile shortcuts only and
// none were ever created for this profile, per the shortcut name not being
- // set in the profile info cache.
+ // set in the profile attributes storage.
if (params.old_profile_name.empty() &&
create_mode == UPDATE_EXISTING_ONLY &&
action == IGNORE_NON_PROFILE_SHORTCUTS) {
@@ -825,14 +842,13 @@ void ProfileShortcutManagerWin::CreateOrUpdateShortcutsForProfileAtPath(
}
if (!remove_badging) {
- params.profile_name = cache->GetNameOfProfileAtIndex(profile_index);
+ params.profile_name = entry->GetName();
// The profile might be using the Gaia avatar, which is not in the
// resources array.
bool has_gaia_image = false;
- if (cache->IsUsingGAIAPictureOfProfileAtIndex(profile_index)) {
- const gfx::Image* image =
- cache->GetGAIAPictureOfProfileAtIndex(profile_index);
+ if (entry->IsUsingGAIAPicture()) {
+ const gfx::Image* image = entry->GetGAIAPicture();
if (image) {
params.avatar_image_1x = GetSkBitmapCopy(*image);
// Gaia images are 256px, which makes them big enough to use in the
@@ -846,8 +862,7 @@ void ProfileShortcutManagerWin::CreateOrUpdateShortcutsForProfileAtPath(
// If the profile isn't using a Gaia image, or if the Gaia image did not
// exist, revert to the previously used avatar icon.
if (!has_gaia_image) {
- const size_t icon_index =
- cache->GetAvatarIconIndexOfProfileAtIndex(profile_index);
+ const size_t icon_index = entry->GetAvatarIconIndex();
const int resource_id_1x =
profiles::GetDefaultAvatarIconResourceIDAtIndex(icon_index);
const int resource_id_2x = kProfileAvatarIconResources2x[icon_index];
@@ -861,8 +876,7 @@ void ProfileShortcutManagerWin::CreateOrUpdateShortcutsForProfileAtPath(
BrowserThread::FILE, FROM_HERE,
base::Bind(&CreateOrUpdateDesktopShortcutsAndIconForProfile, params));
- cache->SetShortcutNameOfProfileAtIndex(profile_index,
- params.profile_name);
+ entry->SetShortcutName(params.profile_name);
}
void ProfileShortcutManagerWin::Observe(

Powered by Google App Engine
This is Rietveld 408576698