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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 registry->RegisterBooleanPref(prefs::kBrowserGuestModeEnabled, true); | 50 registry->RegisterBooleanPref(prefs::kBrowserGuestModeEnabled, true); |
51 registry->RegisterBooleanPref(prefs::kBrowserAddPersonEnabled, true); | 51 registry->RegisterBooleanPref(prefs::kBrowserAddPersonEnabled, true); |
52 } | 52 } |
53 | 53 |
54 base::string16 GetAvatarNameForProfile(const base::FilePath& profile_path) { | 54 base::string16 GetAvatarNameForProfile(const base::FilePath& profile_path) { |
55 base::string16 display_name; | 55 base::string16 display_name; |
56 | 56 |
57 if (profile_path == ProfileManager::GetGuestProfilePath()) { | 57 if (profile_path == ProfileManager::GetGuestProfilePath()) { |
58 display_name = l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME); | 58 display_name = l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME); |
59 } else { | 59 } else { |
60 ProfileInfoCache& cache = | 60 const ProfileInfoCache& cache = |
61 g_browser_process->profile_manager()->GetProfileInfoCache(); | 61 g_browser_process->profile_manager()->GetProfileInfoCache(); |
62 size_t index = cache.GetIndexOfProfileWithPath(profile_path); | 62 size_t index = cache.GetIndexOfProfileWithPath(profile_path); |
63 | 63 |
64 if (index == std::string::npos) | 64 if (index == std::string::npos) |
65 return l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | 65 return l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
66 | 66 |
67 // Using the --new-avatar-menu flag, there's a couple of rules about what | 67 // Using the --new-avatar-menu flag, there's a couple of rules about what |
68 // the avatar button displays. If there's a single profile, with a default | 68 // the avatar button displays. If there's a single profile, with a default |
69 // name (i.e. of the form Person %d) not manually set, it should display | 69 // name (i.e. of the form Person %d) not manually set, it should display |
70 // IDS_SINGLE_PROFILE_DISPLAY_NAME. If the profile is signed in but is using | 70 // IDS_SINGLE_PROFILE_DISPLAY_NAME. If the profile is signed in but is using |
(...skipping 20 matching lines...) Expand all Loading... | |
91 gfx::CHARACTER_BREAK); | 91 gfx::CHARACTER_BREAK); |
92 if (profile->IsSupervised()) { | 92 if (profile->IsSupervised()) { |
93 name = l10n_util::GetStringFUTF16(IDS_SUPERVISED_USER_NEW_AVATAR_LABEL, | 93 name = l10n_util::GetStringFUTF16(IDS_SUPERVISED_USER_NEW_AVATAR_LABEL, |
94 name); | 94 name); |
95 } | 95 } |
96 return name; | 96 return name; |
97 } | 97 } |
98 | 98 |
99 void UpdateProfileName(Profile* profile, | 99 void UpdateProfileName(Profile* profile, |
100 const base::string16& new_profile_name) { | 100 const base::string16& new_profile_name) { |
101 ProfileInfoCache& cache = | 101 const ProfileInfoCache& cache = |
102 g_browser_process->profile_manager()->GetProfileInfoCache(); | 102 g_browser_process->profile_manager()->GetProfileInfoCache(); |
103 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 103 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
104 if (profile_index == std::string::npos) | 104 if (profile_index == std::string::npos) |
105 return; | 105 return; |
106 | 106 |
107 if (new_profile_name == cache.GetNameOfProfileAtIndex(profile_index)) | 107 if (new_profile_name == cache.GetNameOfProfileAtIndex(profile_index)) |
108 return; | 108 return; |
109 | 109 |
110 // This is only called when updating the profile name through the UI, | 110 // This is only called when updating the profile name through the UI, |
111 // so we can assume the user has done this on purpose. | 111 // so we can assume the user has done this on purpose. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 DCHECK(profile); | 149 DCHECK(profile); |
150 GAIAInfoUpdateServiceFactory::GetInstance()->GetForProfile(profile)->Update(); | 150 GAIAInfoUpdateServiceFactory::GetInstance()->GetForProfile(profile)->Update(); |
151 } | 151 } |
152 | 152 |
153 SigninErrorController* GetSigninErrorController(Profile* profile) { | 153 SigninErrorController* GetSigninErrorController(Profile* profile) { |
154 ProfileOAuth2TokenService* token_service = | 154 ProfileOAuth2TokenService* token_service = |
155 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 155 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
156 return token_service ? token_service->signin_error_controller() : NULL; | 156 return token_service ? token_service->signin_error_controller() : NULL; |
157 } | 157 } |
158 | 158 |
159 Profile* SetActiveProfileToGuestIfLocked() { | |
160 Profile* active_profile = ProfileManager::GetLastUsedProfile(); | |
161 DCHECK(active_profile); | |
162 | |
163 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
164 const ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | |
165 size_t index = cache.GetIndexOfProfileWithPath(active_profile->GetPath()); | |
166 if (!cache.ProfileIsSigninRequiredAtIndex(index)) | |
167 return NULL; | |
168 | |
169 // The guest profile must have been loaded already. | |
170 Profile* guest_profile = profile_manager->GetProfile( | |
171 ProfileManager::GetGuestProfilePath()); | |
172 CHECK(guest_profile); | |
Alexei Svitkine (slow)
2014/09/22 16:58:00
Nit: DCHECK().
If it's NULL, it will crash on lin
noms (inactive)
2014/09/22 21:41:49
Done.
| |
173 | |
174 PrefService* local_state = g_browser_process->local_state(); | |
175 DCHECK(local_state); | |
176 local_state->SetString(prefs::kProfileLastUsed, | |
177 guest_profile->GetPath().BaseName().MaybeAsASCII()); | |
178 return guest_profile; | |
179 } | |
180 | |
159 } // namespace profiles | 181 } // namespace profiles |
OLD | NEW |