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

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

Issue 11968034: Enable profile switching for standalone App Launcher via the Settings App. (Closed) Base URL: git://nomatter.syd/chromium/src.git@master
Patch Set: track pending profile loads, respond to comments Created 7 years, 11 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 (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 <set> 5 #include <set>
6 6
7 #include "chrome/browser/profiles/profile_manager.h" 7 #include "chrome/browser/profiles/profile_manager.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 return relative_profile_dir; 303 return relative_profile_dir;
304 } 304 }
305 305
306 Profile* ProfileManager::GetLastUsedProfile(const FilePath& user_data_dir) { 306 Profile* ProfileManager::GetLastUsedProfile(const FilePath& user_data_dir) {
307 #if defined(OS_CHROMEOS) 307 #if defined(OS_CHROMEOS)
308 // Use default login profile if user has not logged in yet. 308 // Use default login profile if user has not logged in yet.
309 if (!logged_in_) 309 if (!logged_in_)
310 return GetDefaultProfile(user_data_dir); 310 return GetDefaultProfile(user_data_dir);
311 #endif 311 #endif
312 312
313 return GetProfile(GetLastUsedProfilePath(user_data_dir));
314 }
315
316 FilePath ProfileManager::GetLastUsedProfilePath(const FilePath& user_data_dir) {
313 FilePath last_used_profile_dir(user_data_dir); 317 FilePath last_used_profile_dir(user_data_dir);
314 std::string last_profile_used; 318 std::string last_used_profile;
315 PrefService* local_state = g_browser_process->local_state(); 319 PrefService* local_state = g_browser_process->local_state();
316 DCHECK(local_state); 320 DCHECK(local_state);
317 321
318 if (local_state->HasPrefPath(prefs::kProfileLastUsed)) 322 if (local_state->HasPrefPath(prefs::kProfileLastUsed)) {
319 last_profile_used = local_state->GetString(prefs::kProfileLastUsed); 323 return last_used_profile_dir.AppendASCII(
320 last_used_profile_dir = last_profile_used.empty() ? 324 local_state->GetString(prefs::kProfileLastUsed));
321 last_used_profile_dir.AppendASCII(chrome::kInitialProfile) : 325 }
322 last_used_profile_dir.AppendASCII(last_profile_used); 326
323 return GetProfile(last_used_profile_dir); 327 return last_used_profile_dir.AppendASCII(chrome::kInitialProfile);
324 } 328 }
325 329
326 std::vector<Profile*> ProfileManager::GetLastOpenedProfiles( 330 std::vector<Profile*> ProfileManager::GetLastOpenedProfiles(
327 const FilePath& user_data_dir) { 331 const FilePath& user_data_dir) {
328 PrefService* local_state = g_browser_process->local_state(); 332 PrefService* local_state = g_browser_process->local_state();
329 DCHECK(local_state); 333 DCHECK(local_state);
330 334
331 std::vector<Profile*> to_return; 335 std::vector<Profile*> to_return;
332 if (local_state->HasPrefPath(prefs::kProfilesLastActive)) { 336 if (local_state->HasPrefPath(prefs::kProfilesLastActive)) {
333 const ListValue* profile_list = 337 const ListValue* profile_list =
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 base::Bind(&OnOpenWindowForNewProfile, 837 base::Bind(&OnOpenWindowForNewProfile,
834 desktop_type, 838 desktop_type,
835 callback), 839 callback),
836 name, 840 name,
837 icon_url, 841 icon_url,
838 is_managed); 842 is_managed);
839 } 843 }
840 844
841 // static 845 // static
842 void ProfileManager::RegisterPrefs(PrefServiceSimple* prefs) { 846 void ProfileManager::RegisterPrefs(PrefServiceSimple* prefs) {
847 prefs->RegisterStringPref(prefs::kAppListProfile, "");
tapted 2013/01/22 03:01:08 sorry for not noticing this sooner - but if these
koz (OOO until 15th September) 2013/01/23 00:07:55 Good catch. I'll add the #ifdefs for now and see w
843 prefs->RegisterStringPref(prefs::kProfileLastUsed, ""); 848 prefs->RegisterStringPref(prefs::kProfileLastUsed, "");
844 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); 849 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1);
845 prefs->RegisterListPref(prefs::kProfilesLastActive); 850 prefs->RegisterListPref(prefs::kProfilesLastActive);
846 } 851 }
847 852
848 size_t ProfileManager::GetNumberOfProfiles() { 853 size_t ProfileManager::GetNumberOfProfiles() {
849 return GetProfileInfoCache().GetNumberOfProfiles(); 854 return GetProfileInfoCache().GetNumberOfProfiles();
850 } 855 }
851 856
852 bool ProfileManager::CompareProfilePathAndName( 857 bool ProfileManager::CompareProfilePathAndName(
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { 990 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) {
986 FilePath cur_path = cache.GetPathOfProfileAtIndex(i); 991 FilePath cur_path = cache.GetPathOfProfileAtIndex(i);
987 if (cur_path != profile_dir) { 992 if (cur_path != profile_dir) {
988 local_state->SetString( 993 local_state->SetString(
989 prefs::kProfileLastUsed, cur_path.BaseName().MaybeAsASCII()); 994 prefs::kProfileLastUsed, cur_path.BaseName().MaybeAsASCII());
990 break; 995 break;
991 } 996 }
992 } 997 }
993 } 998 }
994 999
1000 // If the profile the app list uses just got deleted, reset it to the last
1001 // used profile.
1002 // TODO(koz): Manage the kAppListProfile preference not in this class.
1003 std::string app_list_last_profile = local_state->GetString(
1004 prefs::kAppListProfile);
1005 if (profile_dir.BaseName().MaybeAsASCII() == app_list_last_profile) {
1006 local_state->SetString(prefs::kAppListProfile,
1007 local_state->GetString(prefs::kProfileLastUsed));
1008 }
1009
995 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we 1010 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we
996 // start deleting the profile instance we need to close background apps too. 1011 // start deleting the profile instance we need to close background apps too.
997 Profile* profile = GetProfileByPath(profile_dir); 1012 Profile* profile = GetProfileByPath(profile_dir);
998 if (profile) { 1013 if (profile) {
999 BrowserList::CloseAllBrowsersWithProfile(profile); 1014 BrowserList::CloseAllBrowsersWithProfile(profile);
1000 1015
1001 // Disable sync for doomed profile. 1016 // Disable sync for doomed profile.
1002 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( 1017 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService(
1003 profile)) { 1018 profile)) {
1004 ProfileSyncServiceFactory::GetInstance()->GetForProfile( 1019 ProfileSyncServiceFactory::GetInstance()->GetForProfile(
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 ProfileManager::ProfileInfo::ProfileInfo( 1086 ProfileManager::ProfileInfo::ProfileInfo(
1072 Profile* profile, 1087 Profile* profile,
1073 bool created) 1088 bool created)
1074 : profile(profile), 1089 : profile(profile),
1075 created(created) { 1090 created(created) {
1076 } 1091 }
1077 1092
1078 ProfileManager::ProfileInfo::~ProfileInfo() { 1093 ProfileManager::ProfileInfo::~ProfileInfo() {
1079 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); 1094 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release());
1080 } 1095 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698