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

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

Issue 585653002: After locking a profile and showing the User Manager, make Guest the active profile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: don't do anything if you're already a guest profile Created 6 years, 3 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
OLDNEW
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
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
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
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 if (active_profile->IsGuestSession())
164 return active_profile;
165
166 ProfileManager* profile_manager = g_browser_process->profile_manager();
167 const ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
168 size_t index = cache.GetIndexOfProfileWithPath(active_profile->GetPath());
169 if (!cache.ProfileIsSigninRequiredAtIndex(index))
170 return NULL;
171
172 // The guest profile must have been loaded already.
173 Profile* guest_profile = profile_manager->GetProfile(
174 ProfileManager::GetGuestProfilePath());
175 DCHECK(guest_profile);
176
177 PrefService* local_state = g_browser_process->local_state();
178 DCHECK(local_state);
179 local_state->SetString(prefs::kProfileLastUsed,
180 guest_profile->GetPath().BaseName().MaybeAsASCII());
181 return guest_profile;
182 }
183
159 } // namespace profiles 184 } // namespace profiles
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profiles_state.h ('k') | chrome/browser/ui/cocoa/profiles/user_manager_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698