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

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

Issue 8502033: Add Windows desktop shortcut for multiple profiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: add three additional files Created 9 years, 1 month 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_info_cache.cc
===================================================================
--- chrome/browser/profiles/profile_info_cache.cc (revision 109887)
+++ chrome/browser/profiles/profile_info_cache.cc (working copy)
@@ -12,10 +12,13 @@
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
+#include "chrome/installer/util/browser_distribution.h"
+#include "chrome/installer/util/shell_util.h"
#include "content/public/browser/notification_service.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
@@ -86,7 +89,7 @@
IDS_DEFAULT_AVATAR_NAME_25
};
-} // namespace
+} // namespace
ProfileInfoCache::ProfileInfoCache(PrefService* prefs,
const FilePath& user_data_dir)
@@ -127,17 +130,37 @@
sorted_keys_.insert(FindPositionForProfile(key, name), key);
+ FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
+ observer_list_,
+ OnProfileAdded(name, UTF8ToUTF16(key)));
+
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
content::NotificationService::AllSources(),
content::NotificationService::NoDetails());
}
+void ProfileInfoCache::AddObserver(ProfileInfoCacheObserver* obs) {
+ observer_list_.AddObserver(obs);
+}
+
+void ProfileInfoCache::RemoveObserver(ProfileInfoCacheObserver* obs) {
+ observer_list_.RemoveObserver(obs);
+}
+
void ProfileInfoCache::DeleteProfileFromCache(const FilePath& profile_path) {
DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache);
DictionaryValue* cache = update.Get();
+ std::string key = CacheKeyFromProfilePath(profile_path);
+ DictionaryValue* info = NULL;
+ cache->GetDictionary(key, &info);
robertshield 2011/11/18 03:58:57 check that cache is non null?
Miranda Callahan 2011/11/18 19:00:36 Done.
+ string16 name;
+ info->GetString(kNameKey, &name);
robertshield 2011/11/18 03:58:57 check that info is non null? I notice that most of
Miranda Callahan 2011/11/18 19:00:36 Done.
- std::string key = CacheKeyFromProfilePath(profile_path);
+ FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
+ observer_list_,
+ OnProfileRemoved(name));
+
cache->Remove(key, NULL);
sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key));
@@ -215,6 +238,8 @@
void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index,
const string16& name) {
scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
+ string16 old_name;
+ info->GetString(kNameKey, &old_name);
robertshield 2011/11/18 03:58:57 same null check grumbling as above, ignore me if n
Miranda Callahan 2011/11/18 19:00:36 Added null DCHECK directly to GetInfoForProfileAtI
info->SetString(kNameKey, name);
// This takes ownership of |info|.
SetInfoForProfileAtIndex(index, info.release());
@@ -227,6 +252,10 @@
sorted_keys_.erase(key_it);
sorted_keys_.insert(FindPositionForProfile(key, name), key);
+ FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
+ observer_list_,
+ OnProfileNameChanged(old_name, name));
+
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
content::NotificationService::AllSources(),
@@ -423,6 +452,28 @@
return sorted_keys_.end();
}
+// static
+std::vector<string16> ProfileInfoCache::GetProfileNames() {
+ BrowserDistribution* dist = BrowserDistribution::GetDistribution();
+ std::vector<string16> names;
+ PrefService* local_state = g_browser_process->local_state();
+ const DictionaryValue* cache = local_state->GetDictionary(
+ prefs::kProfileInfoCache);
+ for (base::DictionaryValue::key_iterator it = cache->begin_keys();
+ it != cache->end_keys();
+ ++it) {
+ base::DictionaryValue* info = NULL;
+ cache->GetDictionary(*it, &info);
+ string16 name;
+ info->GetString(kNameKey, &name);
+ string16 shortcut;
+ if (ShellUtil::GetChromeShortcutName(dist, false, name, &shortcut))
+ names.push_back(shortcut);
+ }
+ return names;
+}
+
+// static
void ProfileInfoCache::RegisterPrefs(PrefService* prefs) {
prefs->RegisterDictionaryPref(prefs::kProfileInfoCache);
}

Powered by Google App Engine
This is Rietveld 408576698