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

Side by Side Diff: chrome/browser/profiles/profile_info_cache.cc

Issue 171523004: Stop using the old-style profile names when using --new-profile-management (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moved new tests behind no-android/no-cros ifdef Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/profiles/profile_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/profiles/profile_info_cache.h" 5 #include "chrome/browser/profiles/profile_info_cache.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/i18n/case_conversion.h" 10 #include "base/i18n/case_conversion.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/prefs/pref_registry_simple.h" 13 #include "base/prefs/pref_registry_simple.h"
14 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
15 #include "base/prefs/scoped_user_pref_update.h" 15 #include "base/prefs/scoped_user_pref_update.h"
16 #include "base/rand_util.h" 16 #include "base/rand_util.h"
17 #include "base/stl_util.h" 17 #include "base/stl_util.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_piece.h" 19 #include "base/strings/string_piece.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
22 #include "base/values.h" 22 #include "base/values.h"
23 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/chrome_notification_types.h" 24 #include "chrome/browser/chrome_notification_types.h"
25 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
26 #include "chrome/common/profile_management_switches.h"
26 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
28 #include "grit/generated_resources.h" 29 #include "grit/generated_resources.h"
29 #include "grit/theme_resources.h" 30 #include "grit/theme_resources.h"
30 #include "third_party/skia/include/core/SkBitmap.h" 31 #include "third_party/skia/include/core/SkBitmap.h"
31 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
32 #include "ui/base/resource/resource_bundle.h" 33 #include "ui/base/resource/resource_bundle.h"
33 #include "ui/gfx/image/image.h" 34 #include "ui/gfx/image/image.h"
34 #include "ui/gfx/image/image_util.h" 35 #include "ui/gfx/image/image_util.h"
35 36
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 GetInfoForProfileAtIndex(index)->DeepCopy()); 759 GetInfoForProfileAtIndex(index)->DeepCopy());
759 info->SetBoolean(kProfileIsEphemeral, value); 760 info->SetBoolean(kProfileIsEphemeral, value);
760 // This takes ownership of |info|. 761 // This takes ownership of |info|.
761 SetInfoForProfileAtIndex(index, info.release()); 762 SetInfoForProfileAtIndex(index, info.release());
762 } 763 }
763 764
764 base::string16 ProfileInfoCache::ChooseNameForNewProfile( 765 base::string16 ProfileInfoCache::ChooseNameForNewProfile(
765 size_t icon_index) const { 766 size_t icon_index) const {
766 base::string16 name; 767 base::string16 name;
767 for (int name_index = 1; ; ++name_index) { 768 for (int name_index = 1; ; ++name_index) {
768 if (icon_index < kGenericIconCount) { 769 if (switches::IsNewProfileManagement()) {
770 name = l10n_util::GetStringFUTF16Int(IDS_NEW_NUMBERED_PROFILE_NAME,
771 name_index);
772 } else if (icon_index < kGenericIconCount) {
769 name = l10n_util::GetStringFUTF16Int(IDS_NUMBERED_PROFILE_NAME, 773 name = l10n_util::GetStringFUTF16Int(IDS_NUMBERED_PROFILE_NAME,
770 name_index); 774 name_index);
771 } else { 775 } else {
772 name = l10n_util::GetStringUTF16( 776 name = l10n_util::GetStringUTF16(
773 kDefaultNames[icon_index - kGenericIconCount]); 777 kDefaultNames[icon_index - kGenericIconCount]);
774 if (name_index > 1) 778 if (name_index > 1)
775 name.append(base::UTF8ToUTF16(base::IntToString(name_index))); 779 name.append(base::UTF8ToUTF16(base::IntToString(name_index)));
776 } 780 }
777 781
778 // Loop through previously named profiles to ensure we're not duplicating. 782 // Loop through previously named profiles to ensure we're not duplicating.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 if (GetAvatarIconIndexOfProfileAtIndex(i) == icon_index) 814 if (GetAvatarIconIndexOfProfileAtIndex(i) == icon_index)
811 return false; 815 return false;
812 } 816 }
813 return true; 817 return true;
814 } 818 }
815 819
816 bool ProfileInfoCache::ChooseAvatarIconIndexForNewProfile( 820 bool ProfileInfoCache::ChooseAvatarIconIndexForNewProfile(
817 bool allow_generic_icon, 821 bool allow_generic_icon,
818 bool must_be_unique, 822 bool must_be_unique,
819 size_t* out_icon_index) const { 823 size_t* out_icon_index) const {
824 // Always allow all icons for new profiles if using the
825 // --new-profile-management flag.
826 if (switches::IsNewProfileManagement())
827 allow_generic_icon = true;
820 size_t start = allow_generic_icon ? 0 : kGenericIconCount; 828 size_t start = allow_generic_icon ? 0 : kGenericIconCount;
821 size_t end = GetDefaultAvatarIconCount(); 829 size_t end = GetDefaultAvatarIconCount();
822 size_t count = end - start; 830 size_t count = end - start;
823 831
824 int rand = base::RandInt(0, count); 832 int rand = base::RandInt(0, count);
825 for (size_t i = 0; i < count; ++i) { 833 for (size_t i = 0; i < count; ++i) {
826 size_t icon_index = start + (rand + i) % count; 834 size_t icon_index = start + (rand + i) % count;
827 if (!must_be_unique || IconIndexIsUnique(icon_index)) { 835 if (!must_be_unique || IconIndexIsUnique(icon_index)) {
828 *out_icon_index = icon_index; 836 *out_icon_index = icon_index;
829 return true; 837 return true;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 info->GetString(kNameKey, &name); 989 info->GetString(kNameKey, &name);
982 names.push_back(name); 990 names.push_back(name);
983 } 991 }
984 return names; 992 return names;
985 } 993 }
986 994
987 // static 995 // static
988 void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) { 996 void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) {
989 registry->RegisterDictionaryPref(prefs::kProfileInfoCache); 997 registry->RegisterDictionaryPref(prefs::kProfileInfoCache);
990 } 998 }
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/profiles/profile_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698