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

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

Issue 1119323002: Checking PrefService* validity before its usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/profiles/profile_manager.h" 5 #include "chrome/browser/profiles/profile_manager.h"
6 6
7 #include <set> 7 #include <set>
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 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 700
701 ProfileMetrics::LogProfileAddNewUser( 701 ProfileMetrics::LogProfileAddNewUser(
702 ProfileMetrics::ADD_NEW_USER_LAST_DELETED); 702 ProfileMetrics::ADD_NEW_USER_LAST_DELETED);
703 return; 703 return;
704 } 704 }
705 705
706 #if defined(OS_MACOSX) 706 #if defined(OS_MACOSX)
707 // On the Mac, the browser process is not killed when all browser windows are 707 // On the Mac, the browser process is not killed when all browser windows are
708 // closed, so just in case we are deleting the active profile, and no other 708 // closed, so just in case we are deleting the active profile, and no other
709 // profile has been loaded, we must pre-load a next one. 709 // profile has been loaded, we must pre-load a next one.
710 PrefService* local_state = g_browser_process->local_state();
711 DCHECK(local_state);
710 const std::string last_used_profile = 712 const std::string last_used_profile =
711 g_browser_process->local_state()->GetString(prefs::kProfileLastUsed); 713 local_state->GetString(prefs::kProfileLastUsed);
712 if (last_used_profile == profile_dir.BaseName().MaybeAsASCII() || 714 if (last_used_profile == profile_dir.BaseName().MaybeAsASCII() ||
713 last_used_profile == GetGuestProfilePath().BaseName().MaybeAsASCII()) { 715 last_used_profile == GetGuestProfilePath().BaseName().MaybeAsASCII()) {
714 CreateProfileAsync(last_non_supervised_profile_path, 716 CreateProfileAsync(last_non_supervised_profile_path,
715 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, 717 base::Bind(&ProfileManager::OnNewActiveProfileLoaded,
716 base::Unretained(this), 718 base::Unretained(this),
717 profile_dir, 719 profile_dir,
718 last_non_supervised_profile_path, 720 last_non_supervised_profile_path,
719 callback), 721 callback),
720 base::string16(), 722 base::string16(),
721 base::string16(), 723 base::string16(),
(...skipping 13 matching lines...) Expand all
735 for (std::vector<base::FilePath>::const_iterator it = profile_paths.begin(); 737 for (std::vector<base::FilePath>::const_iterator it = profile_paths.begin();
736 it != profile_paths.end(); ++it) { 738 it != profile_paths.end(); ++it) {
737 NukeProfileFromDisk(*it); 739 NukeProfileFromDisk(*it);
738 } 740 }
739 } 741 }
740 742
741 void ProfileManager::AutoloadProfiles() { 743 void ProfileManager::AutoloadProfiles() {
742 // If running in the background is disabled for the browser, do not autoload 744 // If running in the background is disabled for the browser, do not autoload
743 // any profiles. 745 // any profiles.
744 PrefService* local_state = g_browser_process->local_state(); 746 PrefService* local_state = g_browser_process->local_state();
747 DCHECK(local_state);
745 if (!local_state->HasPrefPath(prefs::kBackgroundModeEnabled) || 748 if (!local_state->HasPrefPath(prefs::kBackgroundModeEnabled) ||
746 !local_state->GetBoolean(prefs::kBackgroundModeEnabled)) { 749 !local_state->GetBoolean(prefs::kBackgroundModeEnabled)) {
747 return; 750 return;
748 } 751 }
749 752
750 ProfileInfoCache& cache = GetProfileInfoCache(); 753 ProfileInfoCache& cache = GetProfileInfoCache();
751 size_t number_of_profiles = cache.GetNumberOfProfiles(); 754 size_t number_of_profiles = cache.GetNumberOfProfiles();
752 for (size_t p = 0; p < number_of_profiles; ++p) { 755 for (size_t p = 0; p < number_of_profiles; ++p) {
753 if (cache.GetBackgroundStatusOfProfileAtIndex(p)) { 756 if (cache.GetBackgroundStatusOfProfileAtIndex(p)) {
754 // If status is true, that profile is running background apps. By calling 757 // If status is true, that profile is running background apps. By calling
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 DCHECK(result); 1170 DCHECK(result);
1168 } 1171 }
1169 return profile; 1172 return profile;
1170 } 1173 }
1171 1174
1172 void ProfileManager::FinishDeletingProfile( 1175 void ProfileManager::FinishDeletingProfile(
1173 const base::FilePath& profile_dir, 1176 const base::FilePath& profile_dir,
1174 const base::FilePath& new_active_profile_dir) { 1177 const base::FilePath& new_active_profile_dir) {
1175 // Update the last used profile pref before closing browser windows. This 1178 // Update the last used profile pref before closing browser windows. This
1176 // way the correct last used profile is set for any notification observers. 1179 // way the correct last used profile is set for any notification observers.
1177 g_browser_process->local_state()->SetString( 1180 PrefService* local_state = g_browser_process->local_state();
1178 prefs::kProfileLastUsed, 1181 DCHECK(local_state);
1179 new_active_profile_dir.BaseName().MaybeAsASCII()); 1182 local_state->SetString(prefs::kProfileLastUsed,
1183 new_active_profile_dir.BaseName().MaybeAsASCII());
1180 1184
1181 ProfileInfoCache& cache = GetProfileInfoCache(); 1185 ProfileInfoCache& cache = GetProfileInfoCache();
1182 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we 1186 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we
1183 // start deleting the profile instance we need to close background apps too. 1187 // start deleting the profile instance we need to close background apps too.
1184 Profile* profile = GetProfileByPath(profile_dir); 1188 Profile* profile = GetProfileByPath(profile_dir);
1185 1189
1186 if (profile) { 1190 if (profile) {
1187 // TODO: Migrate additional code in this block to observe this notification 1191 // TODO: Migrate additional code in this block to observe this notification
1188 // instead of being implemented here. 1192 // instead of being implemented here.
1189 content::NotificationService::current()->Notify( 1193 content::NotificationService::current()->Notify(
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 } 1427 }
1424 1428
1425 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); 1429 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path);
1426 if (!original_callback.is_null()) 1430 if (!original_callback.is_null())
1427 original_callback.Run(loaded_profile, status); 1431 original_callback.Run(loaded_profile, status);
1428 } 1432 }
1429 1433
1430 ProfileManagerWithoutInit::ProfileManagerWithoutInit( 1434 ProfileManagerWithoutInit::ProfileManagerWithoutInit(
1431 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { 1435 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) {
1432 } 1436 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698