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

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

Issue 1242793005: Refactor most c/b/profiles calls to ProfileInfoCache. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Windows unit test and ChromeOS build Created 5 years, 5 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 9db08f1a2081df10cf51e98b8e2ac5f9c8e47005..14d64cc80418ae54cfd53303287bacb979b5f0e9 100644
--- a/chrome/browser/profiles/profile_shortcut_manager_win.cc
+++ b/chrome/browser/profiles/profile_shortcut_manager_win.cc
@@ -23,6 +23,8 @@
#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"
@@ -664,11 +666,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(
@@ -710,14 +712,18 @@ 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;
+ if (!storage.GetProfileAttributesWithPath(profile_path, &entry)) {
Mike Lerman 2015/08/06 16:06:20 Isn't this equivalent to DCHECK(storage.GetProfile
+ NOTREACHED();
+ return;
+ }
// 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() > 1)
+ shortcut_profile_name = entry->GetName();
*name = base::FilePath(profiles::internal::GetShortcutFilenameForProfile(
shortcut_profile_name,
@@ -732,7 +738,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() == 2) {
// 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),
@@ -744,13 +751,19 @@ 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() == 1;
+
if (deleting_down_to_last_profile) {
+ // The remaining profile should be the last one still in |storage|.
+ std::vector<ProfileAttributesEntry*> entries =
+ storage.GetAllProfilesAttributes();
+ DCHECK_EQ(1U, entries.size());
Mike Lerman 2015/08/06 16:06:20 We're only in this condition if NumberOfProfiles()
// This is needed to unbadge the icon.
- CreateOrUpdateShortcutsForProfileAtPath(cache.GetPathOfProfileAtIndex(0),
+ CreateOrUpdateShortcutsForProfileAtPath(entries[0]->GetPath(),
UPDATE_EXISTING_ONLY,
IGNORE_NON_PROFILE_SHORTCUTS);
}
@@ -775,13 +788,24 @@ void ProfileShortcutManagerWin::OnProfileAvatarChanged(
base::FilePath ProfileShortcutManagerWin::GetOtherProfilePath(
const base::FilePath& profile_path) {
- const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache();
- DCHECK_EQ(2U, cache.GetNumberOfProfiles());
+ 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);
+ ProfileAttributesEntry* current_entry;
Mike Lerman 2015/08/06 16:06:20 I don't think you need all the extra checks. I thi
+ if (!storage.GetProfileAttributesWithPath(profile_path, &current_entry)) {
+ NOTREACHED();
+ return base::FilePath();
+ }
+
+ std::vector<ProfileAttributesEntry*> entries =
+ storage.GetAllProfilesAttributes();
+ DCHECK_EQ(2U, entries.size());
Mike Lerman 2015/08/06 16:06:20 you checked number of profiles == 2 at line 793, d
+ ProfileAttributesEntry* other_entry =
+ entries[0]->GetPath() == current_entry->GetPath() ?
+ entries[1] : entries[0];
+ return other_entry->GetPath();
}
void ProfileShortcutManagerWin::CreateOrUpdateShortcutsForProfileAtPath(
@@ -792,14 +816,15 @@ 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;
+ if (!storage.GetProfileAttributesWithPath(profile_path, &entry)) {
Mike Lerman 2015/08/06 16:06:20 { curlies }?
return;
- bool remove_badging = cache->GetNumberOfProfiles() == 1;
+ }
+ bool remove_badging = storage.GetNumberOfProfiles() == 1;
- params.old_profile_name =
- cache->GetShortcutNameOfProfileAtIndex(profile_index);
+ params.old_profile_name = 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
@@ -811,14 +836,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
@@ -832,8 +856,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];
@@ -847,8 +870,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