diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-06 17:31:32 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-06 17:31:32 +0000 |
commit | 66fa0acfa2d06fe00fdb461603122329ef06ba3c (patch) | |
tree | e99cd98ea4bc7eec51b2877dc489510d6d9ac705 /chrome/browser/profiles/profile_info_cache.cc | |
parent | d9884f501247498d6687ea762afbbab13e4045c9 (diff) | |
download | chromium_src-66fa0acfa2d06fe00fdb461603122329ef06ba3c.zip chromium_src-66fa0acfa2d06fe00fdb461603122329ef06ba3c.tar.gz chromium_src-66fa0acfa2d06fe00fdb461603122329ef06ba3c.tar.bz2 |
Multi-Profiles: New Profile Setup UI
This change adds DOM UI to setup a new profile. When the user clicks Wrench Menu -> New Profile the following happens:
1 we create a new profile and give it a good default name and icon
2 we open a browser window and navigate it to chrome://newprofile
3 user customizes the name and icon if they wish and then click Create
4 we navigate to the new tab page where we optionally show the Sign In To Sync promo page
This change implements 3 and 4. Screenshots:
- http://www.dropmocks.com/mW4un
BUG=None
TEST=Navigated to chrome://newprofile and verified that things looked ok
Review URL: http://codereview.chromium.org/7256002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91573 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/profiles/profile_info_cache.cc')
-rw-r--r-- | chrome/browser/profiles/profile_info_cache.cc | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/chrome/browser/profiles/profile_info_cache.cc b/chrome/browser/profiles/profile_info_cache.cc index 4a71e02..eecbbd2 100644 --- a/chrome/browser/profiles/profile_info_cache.cc +++ b/chrome/browser/profiles/profile_info_cache.cc @@ -29,7 +29,7 @@ const int kDefaultAvatarIconResources[] = { IDR_PROFILE_AVATAR_3, }; -const int kDefaultAvatarIconsCount = arraysize(kDefaultAvatarIconResources); +const size_t kDefaultAvatarIconsCount = arraysize(kDefaultAvatarIconResources); // Checks if the given URL points to one of the default avatar icons. if it is, // returns true and its index through |icon_index|. If not, returns false. @@ -42,7 +42,8 @@ bool IsDefaultAvatarIconUrl(const std::string& url, size_t* icon_index) { if (base::StringToInt(url.begin() + strlen(kDefaultUrlPrefix), url.end(), &int_value)) { - if (int_value < 0 || int_value >= kDefaultAvatarIconsCount) + if (int_value < 0 || + int_value >= static_cast<int>(kDefaultAvatarIconsCount)) return false; *icon_index = int_value; return true; @@ -51,12 +52,6 @@ bool IsDefaultAvatarIconUrl(const std::string& url, size_t* icon_index) { return false; } -// Returns a URL for the default avatar icon with specified index. -std::string GetDefaultAvatarIconUrl(int icon_index) { - DCHECK_LT(icon_index, kDefaultAvatarIconsCount); - return StringPrintf("%s%d", kDefaultUrlPrefix, icon_index); -} - } // namespace ProfileInfoCache::ProfileInfoCache(PrefService* prefs, @@ -108,6 +103,18 @@ size_t ProfileInfoCache::GetNumberOfProfiles() const { return sorted_keys_.size(); } +size_t ProfileInfoCache::GetIndexOfProfileWithPath( + const FilePath& profile_path) const { + if (profile_path.DirName() != user_data_dir_) + return std::string::npos; + std::string search_key = profile_path.BaseName().MaybeAsASCII(); + for (size_t i = 0; i < sorted_keys_.size(); ++i) { + if (sorted_keys_[i] == search_key) + return i; + } + return std::string::npos; +} + string16 ProfileInfoCache::GetNameOfProfileAtIndex(size_t index) const { string16 name; GetInfoForProfileAtIndex(index)->GetString(kNameKey, &name); @@ -126,17 +133,21 @@ FilePath ProfileInfoCache::GetPathOfProfileAtIndex(size_t index) const { const gfx::Image& ProfileInfoCache::GetAvatarIconOfProfileAtIndex( size_t index) const { + int resource_id = GetDefaultAvatarIconResourceIDAtIndex( + GetAvatarIconIndexOfProfileAtIndex(index)); + return ResourceBundle::GetSharedInstance().GetImageNamed(resource_id); +} + +size_t ProfileInfoCache::GetAvatarIconIndexOfProfileAtIndex(size_t index) + const { std::string icon_url; GetInfoForProfileAtIndex(index)->GetString(kAvatarIconKey, &icon_url); size_t icon_index = 0; - if (IsDefaultAvatarIconUrl(icon_url, &icon_index)) { - int resource_id = GetDefaultAvatarIconResourceIDAtIndex(icon_index); - return ResourceBundle::GetSharedInstance().GetImageNamed(resource_id); - } + if (IsDefaultAvatarIconUrl(icon_url, &icon_index)) + return icon_index; DLOG(WARNING) << "Unknown avatar icon: " << icon_url; - return ResourceBundle::GetSharedInstance().GetImageNamed( - GetDefaultAvatarIconResourceIDAtIndex(0)); + return GetDefaultAvatarIconResourceIDAtIndex(0); } void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index, @@ -164,6 +175,11 @@ int ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(size_t index) { return kDefaultAvatarIconResources[index]; } +std::string ProfileInfoCache::GetDefaultAvatarIconUrl(size_t index) { + DCHECK_LT(index, kDefaultAvatarIconsCount); + return StringPrintf("%s%zu", kDefaultUrlPrefix, index); +} + const DictionaryValue* ProfileInfoCache::GetInfoForProfileAtIndex( size_t index) const { DCHECK_LT(index, GetNumberOfProfiles()); |