OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/profiles_state.h" | 5 #include "chrome/browser/profiles/profiles_state.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/prefs/pref_registry_simple.h" | 8 #include "base/prefs/pref_registry_simple.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 display_name = l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | 77 display_name = l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
78 } else { | 78 } else { |
79 display_name = profile_name; | 79 display_name = profile_name; |
80 } | 80 } |
81 } | 81 } |
82 return display_name; | 82 return display_name; |
83 } | 83 } |
84 | 84 |
85 void UpdateProfileName(Profile* profile, | 85 void UpdateProfileName(Profile* profile, |
86 const base::string16& new_profile_name) { | 86 const base::string16& new_profile_name) { |
87 ProfileInfoCache& cache = | 87 PrefService* pref_service = profile->GetPrefs(); |
88 g_browser_process->profile_manager()->GetProfileInfoCache(); | 88 // Updating the profile preference will cause the cache to be updated for |
89 base::FilePath profile_file_path = profile->GetPath(); | 89 // this preference. |
90 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); | 90 pref_service->SetString(prefs::kProfileName, |
91 | 91 base::UTF16ToUTF8(new_profile_name)); |
rpetterson
2014/03/20 22:58:17
Do you need to know if it's a GAIA name or custom
noms (inactive)
2014/03/21 14:32:00
You don't. You're just updating the display, custo
| |
92 if ((new_profile_name == | |
93 cache.GetGAIAGivenNameOfProfileAtIndex(profile_index)) || | |
94 (new_profile_name == cache.GetGAIANameOfProfileAtIndex(profile_index))) { | |
95 // Set the profile to use the GAIA name as the profile name. Note, this | |
96 // is a little weird if the user typed their GAIA name manually but | |
97 // it's not a big deal. | |
98 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, true); | |
99 } else { | |
100 PrefService* pref_service = profile->GetPrefs(); | |
101 // Updating the profile preference will cause the cache to be updated for | |
102 // this preference. | |
103 pref_service->SetString(prefs::kProfileName, | |
104 base::UTF16ToUTF8(new_profile_name)); | |
105 | |
106 // Changing the profile name can invalidate the profile index. | |
107 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); | |
108 if (profile_index == std::string::npos) | |
109 return; | |
110 | |
111 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, false); | |
112 } | |
113 } | 92 } |
114 | 93 |
115 std::vector<std::string> GetSecondaryAccountsForProfile( | 94 std::vector<std::string> GetSecondaryAccountsForProfile( |
116 Profile* profile, | 95 Profile* profile, |
117 const std::string& primary_account) { | 96 const std::string& primary_account) { |
118 std::vector<std::string> accounts = | 97 std::vector<std::string> accounts = |
119 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)->GetAccounts(); | 98 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)->GetAccounts(); |
120 | 99 |
121 // The vector returned by ProfileOAuth2TokenService::GetAccounts() contains | 100 // The vector returned by ProfileOAuth2TokenService::GetAccounts() contains |
122 // the primary account too, so we need to remove it from the list. | 101 // the primary account too, so we need to remove it from the list. |
123 std::vector<std::string>::iterator primary_index = | 102 std::vector<std::string>::iterator primary_index = |
124 std::find_if(accounts.begin(), accounts.end(), | 103 std::find_if(accounts.begin(), accounts.end(), |
125 std::bind1st(std::equal_to<std::string>(), primary_account)); | 104 std::bind1st(std::equal_to<std::string>(), primary_account)); |
126 DCHECK(primary_index != accounts.end()); | 105 DCHECK(primary_index != accounts.end()); |
127 accounts.erase(primary_index); | 106 accounts.erase(primary_index); |
128 | 107 |
129 return accounts; | 108 return accounts; |
130 } | 109 } |
131 | 110 |
132 bool IsRegularOrGuestSession(Browser* browser) { | 111 bool IsRegularOrGuestSession(Browser* browser) { |
133 Profile* profile = browser->profile(); | 112 Profile* profile = browser->profile(); |
134 return profile->IsGuestSession() || !profile->IsOffTheRecord(); | 113 return profile->IsGuestSession() || !profile->IsOffTheRecord(); |
135 } | 114 } |
136 | 115 |
137 } // namespace profiles | 116 } // namespace profiles |
OLD | NEW |