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

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: 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 #if defined(ENABLE_APP_LIST)
848 prefs->RegisterStringPref(prefs::kAppListProfile, "");
sail 2013/01/23 16:55:24 This should go in the app list code base. Not prof
koz (OOO until 15th September) 2013/01/25 00:32:46 Done.
849 #endif
843 prefs->RegisterStringPref(prefs::kProfileLastUsed, ""); 850 prefs->RegisterStringPref(prefs::kProfileLastUsed, "");
844 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); 851 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1);
845 prefs->RegisterListPref(prefs::kProfilesLastActive); 852 prefs->RegisterListPref(prefs::kProfilesLastActive);
846 } 853 }
847 854
848 size_t ProfileManager::GetNumberOfProfiles() { 855 size_t ProfileManager::GetNumberOfProfiles() {
849 return GetProfileInfoCache().GetNumberOfProfiles(); 856 return GetProfileInfoCache().GetNumberOfProfiles();
850 } 857 }
851 858
852 bool ProfileManager::CompareProfilePathAndName( 859 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) { 992 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) {
986 FilePath cur_path = cache.GetPathOfProfileAtIndex(i); 993 FilePath cur_path = cache.GetPathOfProfileAtIndex(i);
987 if (cur_path != profile_dir) { 994 if (cur_path != profile_dir) {
988 local_state->SetString( 995 local_state->SetString(
989 prefs::kProfileLastUsed, cur_path.BaseName().MaybeAsASCII()); 996 prefs::kProfileLastUsed, cur_path.BaseName().MaybeAsASCII());
990 break; 997 break;
991 } 998 }
992 } 999 }
993 } 1000 }
994 1001
1002 #if defined(ENABLE_APP_LIST)
1003 // If the profile the app list uses just got deleted, reset it to the last
1004 // used profile.
1005 // TODO(koz): Manage the kAppListProfile preference not in this class.
1006 std::string app_list_last_profile = local_state->GetString(
sail 2013/01/23 16:55:24 same, don't put your feature code here if you need
koz (OOO until 15th September) 2013/01/25 00:32:46 Done.
1007 prefs::kAppListProfile);
1008 if (profile_dir.BaseName().MaybeAsASCII() == app_list_last_profile) {
1009 local_state->SetString(prefs::kAppListProfile,
1010 local_state->GetString(prefs::kProfileLastUsed));
1011 }
1012 #endif
1013
995 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we 1014 // 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. 1015 // start deleting the profile instance we need to close background apps too.
997 Profile* profile = GetProfileByPath(profile_dir); 1016 Profile* profile = GetProfileByPath(profile_dir);
998 if (profile) { 1017 if (profile) {
999 BrowserList::CloseAllBrowsersWithProfile(profile); 1018 BrowserList::CloseAllBrowsersWithProfile(profile);
1000 1019
1001 // Disable sync for doomed profile. 1020 // Disable sync for doomed profile.
1002 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( 1021 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService(
1003 profile)) { 1022 profile)) {
1004 ProfileSyncServiceFactory::GetInstance()->GetForProfile( 1023 ProfileSyncServiceFactory::GetInstance()->GetForProfile(
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 ProfileManager::ProfileInfo::ProfileInfo( 1090 ProfileManager::ProfileInfo::ProfileInfo(
1072 Profile* profile, 1091 Profile* profile,
1073 bool created) 1092 bool created)
1074 : profile(profile), 1093 : profile(profile),
1075 created(created) { 1094 created(created) {
1076 } 1095 }
1077 1096
1078 ProfileManager::ProfileInfo::~ProfileInfo() { 1097 ProfileManager::ProfileInfo::~ProfileInfo() {
1079 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); 1098 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release());
1080 } 1099 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698