summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-20 22:23:45 +0000
committersail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-20 22:23:45 +0000
commit5b0cafeaf2a1b5448667844838f6147779f39255 (patch)
tree9079d8a0bbca7fa5e6aca280a6fb04d44aa2c4cc
parentf5e3b5b9026ed752b2d6e8f7a6d1ac4a1d2b26d5 (diff)
downloadchromium_src-5b0cafeaf2a1b5448667844838f6147779f39255.zip
chromium_src-5b0cafeaf2a1b5448667844838f6147779f39255.tar.gz
chromium_src-5b0cafeaf2a1b5448667844838f6147779f39255.tar.bz2
Merge 115621 - Refactor ProfileInfoCacheObserver interface and usage thereof.
We want to simplify OnProfileAdded and OnProfileAvatarChanged so decouple the Observer interface a bit away from ProfileShortcutManagerWin. Instead, classes that implement the interface should fetch the global cache object and retrieve any additional information it needs from there when they are notified. BUG=109447 TEST=Ensure that ProfileInfoCacheTest and BackgroundModeManagerTest unit tests all pass. Review URL: http://codereview.chromium.org/9020013 TBR=stevet@chromium.org Review URL: https://chromiumcodereview.appspot.com/9271018 git-svn-id: svn://svn.chromium.org/chrome/branches/963/src@118526 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/background/background_mode_manager.cc33
-rw-r--r--chrome/browser/background/background_mode_manager.h19
-rw-r--r--chrome/browser/background/background_mode_manager_unittest.cc21
-rw-r--r--chrome/browser/profiles/profile_info_cache.cc50
-rw-r--r--chrome/browser/profiles/profile_info_cache_observer.h24
-rw-r--r--chrome/browser/profiles/profile_info_cache_unittest.cc37
-rw-r--r--chrome/browser/profiles/profile_info_cache_unittest.h22
-rw-r--r--chrome/browser/profiles/profile_shortcut_manager_win.cc59
-rw-r--r--chrome/browser/profiles/profile_shortcut_manager_win.h17
9 files changed, 131 insertions, 151 deletions
diff --git a/chrome/browser/background/background_mode_manager.cc b/chrome/browser/background/background_mode_manager.cc
index b2b4aba..217f7b8 100644
--- a/chrome/browser/background/background_mode_manager.cc
+++ b/chrome/browser/background/background_mode_manager.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/extensions/extension_service.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/status_icons/status_icon.h"
#include "chrome/browser/status_icons/status_tray.h"
#include "chrome/browser/ui/browser_list.h"
@@ -384,10 +385,11 @@ void BackgroundModeManager::OnApplicationListChanged(Profile* profile) {
///////////////////////////////////////////////////////////////////////////////
// BackgroundModeManager, ProfileInfoCacheObserver overrides
-void BackgroundModeManager::OnProfileAdded(const string16& profile_name,
- const string16& profile_base_dir,
- const FilePath& profile_path,
- const gfx::Image* avatar_image) {
+void BackgroundModeManager::OnProfileAdded(const FilePath& profile_path) {
+ ProfileInfoCache& cache =
+ g_browser_process->profile_manager()->GetProfileInfoCache();
+ string16 profile_name = cache.GetNameOfProfileAtIndex(
+ cache.GetIndexOfProfileWithPath(profile_path));
// At this point, the profile should be registered with the background mode
// manager, but when it's actually added to the cache is when its name is
// set so we need up to update that with the background_mode_data.
@@ -404,7 +406,11 @@ void BackgroundModeManager::OnProfileAdded(const string16& profile_name,
}
void BackgroundModeManager::OnProfileWillBeRemoved(
- const string16& profile_name) {
+ const FilePath& profile_path) {
+ ProfileInfoCache& cache =
+ g_browser_process->profile_manager()->GetProfileInfoCache();
+ string16 profile_name = cache.GetNameOfProfileAtIndex(
+ cache.GetIndexOfProfileWithPath(profile_path));
// Remove the profile from our map of profiles.
BackgroundModeInfoMap::iterator it =
GetBackgroundModeIterator(profile_name);
@@ -415,12 +421,18 @@ void BackgroundModeManager::OnProfileWillBeRemoved(
}
}
-void BackgroundModeManager::OnProfileWasRemoved(const string16& profile_name) {
+void BackgroundModeManager::OnProfileWasRemoved(
+ const FilePath& profile_path,
+ const string16& profile_name) {
}
void BackgroundModeManager::OnProfileNameChanged(
- const string16& old_profile_name,
- const string16& new_profile_name) {
+ const FilePath& profile_path,
+ const string16& old_profile_name) {
+ ProfileInfoCache& cache =
+ g_browser_process->profile_manager()->GetProfileInfoCache();
+ string16 new_profile_name = cache.GetNameOfProfileAtIndex(
+ cache.GetIndexOfProfileWithPath(profile_path));
BackgroundModeInfoMap::const_iterator it =
GetBackgroundModeIterator(old_profile_name);
// We check that the returned iterator is valid due to unittests, but really
@@ -433,10 +445,7 @@ void BackgroundModeManager::OnProfileNameChanged(
}
void BackgroundModeManager::OnProfileAvatarChanged(
- const string16& profile_name,
- const string16& profile_base_dir,
- const FilePath& profile_path,
- const gfx::Image* avatar_image) {
+ const FilePath& profile_path) {
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/background/background_mode_manager.h b/chrome/browser/background/background_mode_manager.h
index dc21d52..590898d 100644
--- a/chrome/browser/background/background_mode_manager.h
+++ b/chrome/browser/background/background_mode_manager.h
@@ -163,18 +163,13 @@ class BackgroundModeManager
virtual void OnApplicationListChanged(Profile* profile) OVERRIDE;
// Overrides from ProfileInfoCacheObserver
- virtual void OnProfileAdded(const string16& profile_name,
- const string16& profile_base_dir,
- const FilePath& profile_path,
- const gfx::Image* avatar_image) OVERRIDE;
- virtual void OnProfileWillBeRemoved(const string16& profile_name) OVERRIDE;
- virtual void OnProfileWasRemoved(const string16& profile_name) OVERRIDE;
- virtual void OnProfileNameChanged(const string16& old_profile_name,
- const string16& new_profile_name) OVERRIDE;
- virtual void OnProfileAvatarChanged(const string16& profile_name,
- const string16& profile_base_dir,
- const FilePath& profile_path,
- const gfx::Image* avatar_image) OVERRIDE;
+ virtual void OnProfileAdded(const FilePath& profile_path) OVERRIDE;
+ virtual void OnProfileWillBeRemoved(const FilePath& profile_path) OVERRIDE;
+ virtual void OnProfileWasRemoved(const FilePath& profile_path,
+ const string16& profile_name) OVERRIDE;
+ virtual void OnProfileNameChanged(const FilePath& profile_path,
+ const string16& old_profile_name) OVERRIDE;
+ virtual void OnProfileAvatarChanged(const FilePath& profile_path) OVERRIDE;
// Overrides from SimpleMenuModel::Delegate implementation.
virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
diff --git a/chrome/browser/background/background_mode_manager_unittest.cc b/chrome/browser/background/background_mode_manager_unittest.cc
index 6c3aeb9..619fa6d 100644
--- a/chrome/browser/background/background_mode_manager_unittest.cc
+++ b/chrome/browser/background/background_mode_manager_unittest.cc
@@ -258,36 +258,31 @@ TEST_F(BackgroundModeManagerTest, ProfileInfoCacheObserver) {
manager.RegisterProfile(profile1);
EXPECT_FALSE(BrowserList::WillKeepAlive());
- ProfileInfoCache* cache = profile_manager_.profile_info_cache();
-
// Install app, should show status tray icon.
manager.OnBackgroundAppInstalled(NULL);
manager.SetBackgroundAppCount(1);
manager.SetBackgroundAppCountForProfile(1);
manager.OnApplicationListChanged(profile1);
- string16 p1name = cache->GetNameOfProfileAtIndex(0);
- manager.OnProfileNameChanged(p1name, UTF8ToUTF16("p1new"));
+ manager.OnProfileNameChanged(
+ profile1->GetPath(),
+ manager.GetBackgroundModeData(profile1)->name());
- EXPECT_EQ(UTF8ToUTF16("p1new"),
+ EXPECT_EQ(UTF8ToUTF16("p1"),
manager.GetBackgroundModeData(profile1)->name());
TestingProfile* profile2 = profile_manager_.CreateTestingProfile("p2");
manager.RegisterProfile(profile2);
EXPECT_EQ(2, manager.NumberOfBackgroundModeData());
- gfx::Image gaia_image(gfx::test::CreateImage());
- manager.OnProfileAdded(UTF8ToUTF16("p2new"),
- profile2->GetPath().BaseName().LossyDisplayName(),
- profile2->GetPath(),
- &gaia_image);
- EXPECT_EQ(UTF8ToUTF16("p2new"),
+ manager.OnProfileAdded(profile2->GetPath());
+ EXPECT_EQ(UTF8ToUTF16("p2"),
manager.GetBackgroundModeData(profile2)->name());
- manager.OnProfileWillBeRemoved(UTF8ToUTF16("p2new"));
+ manager.OnProfileWillBeRemoved(profile2->GetPath());
EXPECT_EQ(1, manager.NumberOfBackgroundModeData());
// Check that the background mode data we think is in the map actually is.
- EXPECT_EQ(UTF8ToUTF16("p1new"),
+ EXPECT_EQ(UTF8ToUTF16("p1"),
manager.GetBackgroundModeData(profile1)->name());
}
diff --git a/chrome/browser/profiles/profile_info_cache.cc b/chrome/browser/profiles/profile_info_cache.cc
index fa5bf2c..ee81d35 100644
--- a/chrome/browser/profiles/profile_info_cache.cc
+++ b/chrome/browser/profiles/profile_info_cache.cc
@@ -205,14 +205,9 @@ void ProfileInfoCache::AddProfileToCache(const FilePath& profile_path,
sorted_keys_.insert(FindPositionForProfile(key, name), key);
- gfx::Image& avatar_img =
- ResourceBundle::GetSharedInstance().GetNativeImageNamed(
- GetDefaultAvatarIconResourceIDAtIndex(icon_index));
-
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_,
- OnProfileAdded(name, UTF8ToUTF16(key),
- profile_path, &avatar_img));
+ OnProfileAdded(profile_path));
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
@@ -234,7 +229,7 @@ void ProfileInfoCache::DeleteProfileFromCache(const FilePath& profile_path) {
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_,
- OnProfileWillBeRemoved(name));
+ OnProfileWillBeRemoved(profile_path));
DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache);
DictionaryValue* cache = update.Get();
@@ -244,7 +239,7 @@ void ProfileInfoCache::DeleteProfileFromCache(const FilePath& profile_path) {
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_,
- OnProfileWasRemoved(name));
+ OnProfileWasRemoved(profile_path, name));
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
@@ -412,12 +407,13 @@ void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index,
// This takes ownership of |info|.
SetInfoForProfileAtIndex(index, info.release());
string16 new_display_name = GetNameOfProfileAtIndex(index);
+ FilePath profile_path = GetPathOfProfileAtIndex(index);
UpdateSortForProfileIndex(index);
if (old_display_name != new_display_name) {
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_,
- OnProfileNameChanged(old_display_name, new_display_name));
+ OnProfileNameChanged(profile_path, old_display_name));
}
}
@@ -439,17 +435,10 @@ void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index,
// This takes ownership of |info|.
SetInfoForProfileAtIndex(index, info.release());
- string16 name = GetNameOfProfileAtIndex(index);
FilePath profile_path = GetPathOfProfileAtIndex(index);
- std::string key = CacheKeyFromProfilePath(profile_path);
- gfx::Image& avatar_img =
- ResourceBundle::GetSharedInstance().GetNativeImageNamed(
- GetDefaultAvatarIconResourceIDAtIndex(icon_index));
-
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_,
- OnProfileAvatarChanged(name, UTF8ToUTF16(key),
- profile_path, &avatar_img));
+ OnProfileAvatarChanged(profile_path));
}
void ProfileInfoCache::SetBackgroundStatusOfProfileAtIndex(
@@ -474,12 +463,13 @@ void ProfileInfoCache::SetGAIANameOfProfileAtIndex(size_t index,
// This takes ownership of |info|.
SetInfoForProfileAtIndex(index, info.release());
string16 new_display_name = GetNameOfProfileAtIndex(index);
+ FilePath profile_path = GetPathOfProfileAtIndex(index);
UpdateSortForProfileIndex(index);
if (old_display_name != new_display_name) {
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_,
- OnProfileNameChanged(old_display_name, new_display_name));
+ OnProfileNameChanged(profile_path, old_display_name));
}
}
@@ -494,12 +484,13 @@ void ProfileInfoCache::SetIsUsingGAIANameOfProfileAtIndex(size_t index,
// This takes ownership of |info|.
SetInfoForProfileAtIndex(index, info.release());
string16 new_display_name = GetNameOfProfileAtIndex(index);
+ FilePath profile_path = GetPathOfProfileAtIndex(index);
UpdateSortForProfileIndex(index);
if (old_display_name != new_display_name) {
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_,
- OnProfileNameChanged(old_display_name, new_display_name));
+ OnProfileNameChanged(profile_path, old_display_name));
}
}
@@ -550,34 +541,23 @@ void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index,
// This takes ownership of |info|.
SetInfoForProfileAtIndex(index, info.release());
- string16 name = GetNameOfProfileAtIndex(index);
- const gfx::Image& avatar_image = GetAvatarIconOfProfileAtIndex(index);
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_,
- OnProfileAvatarChanged(name, UTF8ToUTF16(key),
- path, &avatar_image));
+ OnProfileAvatarChanged(path));
}
void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index,
bool value) {
scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
- string16 name = GetNameOfProfileAtIndex(index);
info->SetBoolean(kUseGAIAPictureKey, value);
// This takes ownership of |info|.
SetInfoForProfileAtIndex(index, info.release());
// Retrieve some info to update observers who care about avatar changes.
- if (value) {
- FilePath profile_path = GetPathOfProfileAtIndex(index);
- std::string key = CacheKeyFromProfilePath(profile_path);
- if (gaia_pictures_.find(key) != gaia_pictures_.end()) {
- FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
- observer_list_,
- OnProfileAvatarChanged(name, UTF8ToUTF16(key),
- profile_path,
- gaia_pictures_[key]));
- }
- }
+ FilePath profile_path = GetPathOfProfileAtIndex(index);
+ FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
+ observer_list_,
+ OnProfileAvatarChanged(profile_path));
}
string16 ProfileInfoCache::ChooseNameForNewProfile(size_t icon_index) {
diff --git a/chrome/browser/profiles/profile_info_cache_observer.h b/chrome/browser/profiles/profile_info_cache_observer.h
index 4d1a6b3e..3657a9ad 100644
--- a/chrome/browser/profiles/profile_info_cache_observer.h
+++ b/chrome/browser/profiles/profile_info_cache_observer.h
@@ -16,23 +16,13 @@ class ProfileInfoCacheObserver {
public:
virtual ~ProfileInfoCacheObserver() {}
- virtual void OnProfileAdded(
- const string16& profile_name,
- const string16& profile_base_dir,
- const FilePath& profile_path,
- const gfx::Image* avatar_image) = 0;
- virtual void OnProfileWillBeRemoved(
- const string16& profile_name) = 0;
- virtual void OnProfileWasRemoved(
- const string16& profile_name) = 0;
- virtual void OnProfileNameChanged(
- const string16& old_profile_name,
- const string16& new_profile_name) = 0;
- virtual void OnProfileAvatarChanged(
- const string16& profile_name,
- const string16& profile_base_dir,
- const FilePath& profile_path,
- const gfx::Image* avatar_image) = 0;
+ virtual void OnProfileAdded(const FilePath& profile_path) = 0;
+ virtual void OnProfileWillBeRemoved(const FilePath& profile_path) = 0;
+ virtual void OnProfileWasRemoved(const FilePath& profile_path,
+ const string16& profile_name) = 0;
+ virtual void OnProfileNameChanged(const FilePath& profile_path,
+ const string16& old_profile_name) = 0;
+ virtual void OnProfileAvatarChanged(const FilePath& profile_path) = 0;
protected:
ProfileInfoCacheObserver() {}
diff --git a/chrome/browser/profiles/profile_info_cache_unittest.cc b/chrome/browser/profiles/profile_info_cache_unittest.cc
index 743ef4f..46ac014 100644
--- a/chrome/browser/profiles/profile_info_cache_unittest.cc
+++ b/chrome/browser/profiles/profile_info_cache_unittest.cc
@@ -22,35 +22,42 @@
using content::BrowserThread;
-ProfileNameVerifierObserver::ProfileNameVerifierObserver() {
+ProfileNameVerifierObserver::ProfileNameVerifierObserver(
+ TestingProfileManager* testing_profile_manager)
+ : testing_profile_manager_(testing_profile_manager) {
+ DCHECK(testing_profile_manager_);
}
ProfileNameVerifierObserver::~ProfileNameVerifierObserver() {
}
void ProfileNameVerifierObserver::OnProfileAdded(
- const string16& profile_name,
- const string16& profile_base_dir,
- const FilePath& profile_path,
- const gfx::Image* avatar_image) {
+ const FilePath& profile_path) {
+ string16 profile_name = GetCache()->GetNameOfProfileAtIndex(
+ GetCache()->GetIndexOfProfileWithPath(profile_path));
EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end());
profile_names_.insert(profile_name);
}
void ProfileNameVerifierObserver::OnProfileWillBeRemoved(
- const string16& profile_name) {
+ const FilePath& profile_path) {
+ string16 profile_name = GetCache()->GetNameOfProfileAtIndex(
+ GetCache()->GetIndexOfProfileWithPath(profile_path));
EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end());
profile_names_.erase(profile_name);
}
void ProfileNameVerifierObserver::OnProfileWasRemoved(
+ const FilePath& profile_path,
const string16& profile_name) {
EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end());
}
void ProfileNameVerifierObserver::OnProfileNameChanged(
- const string16& old_profile_name,
- const string16& new_profile_name) {
+ const FilePath& profile_path,
+ const string16& old_profile_name) {
+ string16 new_profile_name = GetCache()->GetNameOfProfileAtIndex(
+ GetCache()->GetIndexOfProfileWithPath(profile_path));
EXPECT_TRUE(profile_names_.find(old_profile_name) != profile_names_.end());
EXPECT_TRUE(profile_names_.find(new_profile_name) == profile_names_.end());
profile_names_.erase(old_profile_name);
@@ -58,18 +65,22 @@ void ProfileNameVerifierObserver::OnProfileNameChanged(
}
void ProfileNameVerifierObserver::OnProfileAvatarChanged(
- const string16& profile_name,
- const string16& profile_base_dir,
- const FilePath& profile_path,
- const gfx::Image* avatar_image) {
+ const FilePath& profile_path) {
+ string16 profile_name = GetCache()->GetNameOfProfileAtIndex(
+ GetCache()->GetIndexOfProfileWithPath(profile_path));
EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end());
}
+ProfileInfoCache* ProfileNameVerifierObserver::GetCache() {
+ return testing_profile_manager_->profile_info_cache();
+}
+
ProfileInfoCacheTest::ProfileInfoCacheTest()
: testing_profile_manager_(
static_cast<TestingBrowserProcess*>(g_browser_process)),
ui_thread_(BrowserThread::UI, &ui_loop_),
- file_thread_(BrowserThread::FILE, &ui_loop_) {
+ file_thread_(BrowserThread::FILE, &ui_loop_),
+ name_observer_(&testing_profile_manager_) {
}
ProfileInfoCacheTest::~ProfileInfoCacheTest() {
diff --git a/chrome/browser/profiles/profile_info_cache_unittest.h b/chrome/browser/profiles/profile_info_cache_unittest.h
index 25816d7..463da6f 100644
--- a/chrome/browser/profiles/profile_info_cache_unittest.h
+++ b/chrome/browser/profiles/profile_info_cache_unittest.h
@@ -21,30 +21,26 @@ class ProfileInfoCache;
// unexpected profile names.
class ProfileNameVerifierObserver : public ProfileInfoCacheObserver {
public:
- ProfileNameVerifierObserver();
+ explicit ProfileNameVerifierObserver(
+ TestingProfileManager* testing_profile_manager);
virtual ~ProfileNameVerifierObserver();
// ProfileInfoCacheObserver overrides:
- virtual void OnProfileAdded(
- const string16& profile_name,
- const string16& profile_base_dir,
- const FilePath& profile_path,
- const gfx::Image* avatar_image) OVERRIDE;
+ virtual void OnProfileAdded(const FilePath& profile_path) OVERRIDE;
virtual void OnProfileWillBeRemoved(
- const string16& profile_name) OVERRIDE;
+ const FilePath& profile_path) OVERRIDE;
virtual void OnProfileWasRemoved(
+ const FilePath& profile_path,
const string16& profile_name) OVERRIDE;
virtual void OnProfileNameChanged(
- const string16& old_profile_name,
- const string16& new_profile_name) OVERRIDE;
- virtual void OnProfileAvatarChanged(
- const string16& profile_name,
- const string16& profile_base_dir,
const FilePath& profile_path,
- const gfx::Image* avatar_image) OVERRIDE;
+ const string16& old_profile_name) OVERRIDE;
+ virtual void OnProfileAvatarChanged(const FilePath& profile_path) OVERRIDE;
private:
+ ProfileInfoCache* GetCache();
std::set<string16> profile_names_;
+ TestingProfileManager* testing_profile_manager_;
DISALLOW_COPY_AND_ASSIGN(ProfileNameVerifierObserver);
};
diff --git a/chrome/browser/profiles/profile_shortcut_manager_win.cc b/chrome/browser/profiles/profile_shortcut_manager_win.cc
index 1969139..ad62cea 100644
--- a/chrome/browser/profiles/profile_shortcut_manager_win.cc
+++ b/chrome/browser/profiles/profile_shortcut_manager_win.cc
@@ -215,10 +215,11 @@ ProfileShortcutManagerWin::~ProfileShortcutManagerWin() {
}
void ProfileShortcutManagerWin::OnProfileAdded(
- const string16& profile_name,
- const string16& profile_base_dir,
- const FilePath& profile_path,
- const gfx::Image* avatar_image) {
+ const FilePath& profile_path) {
+ ProfileInfoCache& cache =
+ g_browser_process->profile_manager()->GetProfileInfoCache();
+ size_t index = cache.GetIndexOfProfileWithPath(profile_path);
+
// Launch task to add shortcut to desktop on Windows. If this is the very
// first profile created, don't add the user name to the shortcut.
// TODO(mirandac): respect master_preferences choice to create no shortcuts
@@ -227,8 +228,10 @@ void ProfileShortcutManagerWin::OnProfileAdded(
{
// We make a copy of the Image to ensure that the underlying image data is
// AddRef'd, in case the original copy gets deleted.
- gfx::Image* avatar_copy = avatar_image ?
- new gfx::Image(*avatar_image) : NULL;
+ gfx::Image* avatar_copy =
+ new gfx::Image(cache.GetAvatarIconOfProfileAtIndex(index));
+ string16 profile_name = cache.GetNameOfProfileAtIndex(index);
+ string16 profile_base_dir = profile_path.BaseName().value();
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
base::Bind(&CreateChromeDesktopShortcutForProfile,
profile_name, profile_base_dir, profile_path,
@@ -238,8 +241,6 @@ void ProfileShortcutManagerWin::OnProfileAdded(
// If this is the second existing multi-user account created, change the
// original shortcut use the first profile's details (name, badge,
// argument).
- ProfileInfoCache& cache =
- g_browser_process->profile_manager()->GetProfileInfoCache();
if (cache.GetNumberOfProfiles() == 2) {
// Get the index of the first profile, based on the index of the second
// profile. It's either 0 or 1, whichever the second profile isn't.
@@ -286,7 +287,11 @@ void ProfileShortcutManagerWin::OnProfileAdded(
}
void ProfileShortcutManagerWin::OnProfileWillBeRemoved(
- const string16& profile_name) {
+ const FilePath& profile_path) {
+ ProfileInfoCache& cache =
+ g_browser_process->profile_manager()->GetProfileInfoCache();
+ string16 profile_name = cache.GetNameOfProfileAtIndex(
+ cache.GetIndexOfProfileWithPath(profile_path));
BrowserDistribution* dist = BrowserDistribution::GetDistribution();
string16 shortcut;
if (ShellUtil::GetChromeShortcutName(dist, false, profile_name, &shortcut)) {
@@ -300,6 +305,7 @@ void ProfileShortcutManagerWin::OnProfileWillBeRemoved(
}
void ProfileShortcutManagerWin::OnProfileWasRemoved(
+ const FilePath& profile_path,
const string16& profile_name) {
// If there is one profile left, we want to remove the badge and name from it.
ProfileInfoCache& cache =
@@ -307,11 +313,7 @@ void ProfileShortcutManagerWin::OnProfileWasRemoved(
if (cache.GetNumberOfProfiles() != 1)
return;
- // TODO(stevet): Now that we've sunk our fangs onto ProfileInfoCache, we
- // should clean up the ProfileInfoCacheObserver interface and its users
- // (including us) to not pass every parameter through and instead query the
- // cache when needed.
- FilePath profile_path = cache.GetPathOfProfileAtIndex(0);
+ FilePath last_profile_path = cache.GetPathOfProfileAtIndex(0);
string16 old_shortcut;
string16 new_shortcut;
BrowserDistribution* dist = BrowserDistribution::GetDistribution();
@@ -327,18 +329,23 @@ void ProfileShortcutManagerWin::OnProfileWasRemoved(
base::Bind(&UpdateChromeDesktopShortcutForProfile,
new_shortcut,
CreateProfileShortcutSwitch(UTF8ToUTF16(
- profile_path.BaseName().MaybeAsASCII())),
- profile_path,
+ last_profile_path.BaseName().MaybeAsASCII())),
+ last_profile_path,
static_cast<gfx::Image*>(NULL)));
}
}
void ProfileShortcutManagerWin::OnProfileNameChanged(
- const string16& old_profile_name,
- const string16& new_profile_name) {
+ const FilePath& profile_path,
+ const string16& old_profile_name) {
// Launch task to change name of desktop shortcut on Windows.
// TODO(mirandac): respect master_preferences choice to create no shortcuts
// (see http://crbug.com/104463)
+ ProfileInfoCache& cache =
+ g_browser_process->profile_manager()->GetProfileInfoCache();
+ string16 new_profile_name = cache.GetNameOfProfileAtIndex(
+ cache.GetIndexOfProfileWithPath(profile_path));
+
string16 old_shortcut;
string16 new_shortcut;
BrowserDistribution* dist = BrowserDistribution::GetDistribution();
@@ -354,10 +361,15 @@ void ProfileShortcutManagerWin::OnProfileNameChanged(
}
void ProfileShortcutManagerWin::OnProfileAvatarChanged(
- const string16& profile_name,
- const string16& profile_base_dir,
- const FilePath& profile_path,
- const gfx::Image* avatar_image) {
+ const FilePath& profile_path) {
+ ProfileInfoCache& cache =
+ g_browser_process->profile_manager()->GetProfileInfoCache();
+ size_t index = cache.GetIndexOfProfileWithPath(profile_path);
+ string16 profile_name = cache.GetNameOfProfileAtIndex(index);
+ string16 profile_base_dir =
+ UTF8ToUTF16(profile_path.BaseName().MaybeAsASCII());
+ const gfx::Image& avatar_image = cache.GetAvatarIconOfProfileAtIndex(index);
+
// Launch task to change the icon of the desktop shortcut on windows.
string16 new_shortcut;
BrowserDistribution* dist = BrowserDistribution::GetDistribution();
@@ -365,8 +377,7 @@ void ProfileShortcutManagerWin::OnProfileAvatarChanged(
&new_shortcut)) {
// We make a copy of the Image to ensure that the underlying image data is
// AddRef'd, in case the original copy gets deleted.
- gfx::Image* avatar_copy = avatar_image ?
- new gfx::Image(*avatar_image) : NULL;
+ gfx::Image* avatar_copy = new gfx::Image(avatar_image);
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
base::Bind(&UpdateChromeDesktopShortcutForProfile,
new_shortcut,
diff --git a/chrome/browser/profiles/profile_shortcut_manager_win.h b/chrome/browser/profiles/profile_shortcut_manager_win.h
index 8ac2899..2435e565 100644
--- a/chrome/browser/profiles/profile_shortcut_manager_win.h
+++ b/chrome/browser/profiles/profile_shortcut_manager_win.h
@@ -19,23 +19,16 @@ class ProfileShortcutManagerWin : public ProfileInfoCacheObserver {
virtual ~ProfileShortcutManagerWin();
// ProfileInfoCacheObserver:
- virtual void OnProfileAdded(
- const string16& profile_name,
- const string16& profile_base_dir,
- const FilePath& profile_path,
- const gfx::Image* avatar_image) OVERRIDE;
+ virtual void OnProfileAdded(const FilePath& profile_path) OVERRIDE;
virtual void OnProfileWillBeRemoved(
- const string16& profile_name) OVERRIDE;
+ const FilePath& profile_path) OVERRIDE;
virtual void OnProfileWasRemoved(
+ const FilePath& profile_path,
const string16& profile_name) OVERRIDE;
virtual void OnProfileNameChanged(
- const string16& old_profile_name,
- const string16& new_profile_name) OVERRIDE;
- virtual void OnProfileAvatarChanged(
- const string16& profile_name,
- const string16& profile_base_dir,
const FilePath& profile_path,
- const gfx::Image* avatar_image) OVERRIDE;
+ const string16& old_profile_name) OVERRIDE;
+ virtual void OnProfileAvatarChanged(const FilePath& profile_path) OVERRIDE;
// Takes a vector of profile names (for example: "Sparky") and generates a
// vector of shortcut link names (for example: "Chromium (Sparky).lnk").