| 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 GAIAInfoUpdateServiceFactory::GetInstance()->GetForProfile(profile); | 164 GAIAInfoUpdateServiceFactory::GetInstance()->GetForProfile(profile); |
| 165 // The service may be null, for example during unit tests. | 165 // The service may be null, for example during unit tests. |
| 166 if (service) | 166 if (service) |
| 167 service->Update(); | 167 service->Update(); |
| 168 } | 168 } |
| 169 | 169 |
| 170 SigninErrorController* GetSigninErrorController(Profile* profile) { | 170 SigninErrorController* GetSigninErrorController(Profile* profile) { |
| 171 return SigninErrorControllerFactory::GetForProfile(profile); | 171 return SigninErrorControllerFactory::GetForProfile(profile); |
| 172 } | 172 } |
| 173 | 173 |
| 174 Profile* SetActiveProfileToGuestIfLocked() { | 174 bool SetActiveProfileToGuestIfLocked() { |
| 175 Profile* active_profile = ProfileManager::GetLastUsedProfile(); | 175 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 176 DCHECK(active_profile); | |
| 177 | 176 |
| 178 if (active_profile->IsGuestSession()) | 177 const base::FilePath& active_profile_path = |
| 179 return active_profile; | 178 profile_manager->GetLastUsedProfileDir(profile_manager->user_data_dir()); |
| 179 const base::FilePath& guest_path = ProfileManager::GetGuestProfilePath(); |
| 180 if (active_profile_path == guest_path) |
| 181 return true; |
| 180 | 182 |
| 181 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 182 const ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 183 const ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 183 size_t index = cache.GetIndexOfProfileWithPath(active_profile->GetPath()); | 184 size_t index = cache.GetIndexOfProfileWithPath(active_profile_path); |
| 184 if (!cache.ProfileIsSigninRequiredAtIndex(index)) | 185 if (!cache.ProfileIsSigninRequiredAtIndex(index)) |
| 185 return NULL; | 186 return false; |
| 186 | |
| 187 // Profile loads synchronously if it was not previously created. | |
| 188 Profile* guest_profile = profile_manager->GetProfile( | |
| 189 ProfileManager::GetGuestProfilePath()); | |
| 190 DCHECK(guest_profile); | |
| 191 | 187 |
| 192 PrefService* local_state = g_browser_process->local_state(); | 188 PrefService* local_state = g_browser_process->local_state(); |
| 193 DCHECK(local_state); | 189 DCHECK(local_state); |
| 194 local_state->SetString(prefs::kProfileLastUsed, | 190 local_state->SetString( |
| 195 guest_profile->GetPath().BaseName().MaybeAsASCII()); | 191 prefs::kProfileLastUsed, |
| 196 return guest_profile; | 192 guest_path.BaseName().MaybeAsASCII()); |
| 193 return true; |
| 197 } | 194 } |
| 198 | 195 |
| 199 } // namespace profiles | 196 } // namespace profiles |
| OLD | NEW |