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

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

Issue 1113333003: Don't create a new profile when cleaning up stale ephemeral profiles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: fix? 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
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 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 } 638 }
639 return *profile_info_cache_.get(); 639 return *profile_info_cache_.get();
640 } 640 }
641 641
642 ProfileShortcutManager* ProfileManager::profile_shortcut_manager() { 642 ProfileShortcutManager* ProfileManager::profile_shortcut_manager() {
643 return profile_shortcut_manager_.get(); 643 return profile_shortcut_manager_.get();
644 } 644 }
645 645
646 void ProfileManager::ScheduleProfileForDeletion( 646 void ProfileManager::ScheduleProfileForDeletion(
647 const base::FilePath& profile_dir, 647 const base::FilePath& profile_dir,
648 bool suppress_profile_creation,
648 const CreateCallback& callback) { 649 const CreateCallback& callback) {
649 DCHECK(profiles::IsMultipleProfilesEnabled()); 650 DCHECK(profiles::IsMultipleProfilesEnabled());
650 651
651 // Cancel all in-progress downloads before deleting the profile to prevent a 652 // Cancel all in-progress downloads before deleting the profile to prevent a
652 // "Do you want to exit Google Chrome and cancel the downloads?" prompt 653 // "Do you want to exit Google Chrome and cancel the downloads?" prompt
653 // (crbug.com/336725). 654 // (crbug.com/336725).
654 Profile* profile = GetProfileByPath(profile_dir); 655 Profile* profile = GetProfileByPath(profile_dir);
655 if (profile) { 656 if (profile) {
656 DownloadService* service = 657 DownloadService* service =
657 DownloadServiceFactory::GetForBrowserContext(profile); 658 DownloadServiceFactory::GetForBrowserContext(profile);
(...skipping 10 matching lines...) Expand all
668 // Make sure that this profile is not pending deletion, and is not 669 // Make sure that this profile is not pending deletion, and is not
669 // legacy-supervised. 670 // legacy-supervised.
670 if (cur_path != profile_dir && 671 if (cur_path != profile_dir &&
671 !cache.ProfileIsLegacySupervisedAtIndex(i) && 672 !cache.ProfileIsLegacySupervisedAtIndex(i) &&
672 !IsProfileMarkedForDeletion(cur_path)) { 673 !IsProfileMarkedForDeletion(cur_path)) {
673 last_non_supervised_profile_path = cur_path; 674 last_non_supervised_profile_path = cur_path;
674 break; 675 break;
675 } 676 }
676 } 677 }
677 678
678 base::FilePath new_path; 679 base::FilePath new_path = last_non_supervised_profile_path;
679 if (last_non_supervised_profile_path.empty()) { 680 if (new_path.empty()) {
680 // If we are using --new-avatar-menu, then assign the default 681 // If we are using --new-avatar-menu, then assign the default
681 // placeholder avatar and name. Otherwise, use random ones. 682 // placeholder avatar and name. Otherwise, use random ones.
682 bool is_new_avatar_menu = switches::IsNewAvatarMenu(); 683 base::string16 new_avatar_url;
683 int avatar_index = profiles::GetPlaceholderAvatarIndex(); 684 base::string16 new_profile_name;
684 base::string16 new_avatar_url = is_new_avatar_menu ? 685 if (switches::IsNewAvatarMenu()) {
685 base::UTF8ToUTF16(profiles::GetDefaultAvatarIconUrl(avatar_index)) : 686 int avatar_index = profiles::GetPlaceholderAvatarIndex();
686 base::string16(); 687 new_avatar_url =
687 base::string16 new_profile_name = is_new_avatar_menu ? 688 base::UTF8ToUTF16(profiles::GetDefaultAvatarIconUrl(avatar_index));
688 cache.ChooseNameForNewProfile(avatar_index) : base::string16(); 689 new_profile_name = cache.ChooseNameForNewProfile(avatar_index);
690 }
689 691
690 new_path = GenerateNextProfileDirectoryPath(); 692 new_path = GenerateNextProfileDirectoryPath();
691 CreateProfileAsync(new_path, 693 if (!suppress_profile_creation) {
692 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, 694 CreateProfileAsync(new_path,
693 base::Unretained(this), 695 base::Bind(&ProfileManager::OnNewActiveProfileLoaded,
694 profile_dir, 696 base::Unretained(this),
695 new_path, 697 profile_dir,
696 callback), 698 new_path,
697 new_profile_name, 699 callback),
698 new_avatar_url, 700 new_profile_name,
699 std::string()); 701 new_avatar_url,
702 std::string());
700 703
701 ProfileMetrics::LogProfileAddNewUser( 704 ProfileMetrics::LogProfileAddNewUser(
702 ProfileMetrics::ADD_NEW_USER_LAST_DELETED); 705 ProfileMetrics::ADD_NEW_USER_LAST_DELETED);
703 return; 706 return;
707 }
704 } 708 }
705 709
706 #if defined(OS_MACOSX) 710 #if defined(OS_MACOSX)
707 // On the Mac, the browser process is not killed when all browser windows are 711 // 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 712 // 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. 713 // profile has been loaded, we must pre-load a next one.
710 const std::string last_used_profile = 714 const std::string last_used_profile =
711 g_browser_process->local_state()->GetString(prefs::kProfileLastUsed); 715 g_browser_process->local_state()->GetString(prefs::kProfileLastUsed);
712 if (last_used_profile == profile_dir.BaseName().MaybeAsASCII() || 716 if ((last_used_profile == profile_dir.BaseName().MaybeAsASCII() ||
713 last_used_profile == GetGuestProfilePath().BaseName().MaybeAsASCII()) { 717 last_used_profile == GetGuestProfilePath().BaseName().MaybeAsASCII()) &&
718 !suppress_profile_creation) {
719 DCHECK(!last_non_supervised_profile_path.empty());
714 CreateProfileAsync(last_non_supervised_profile_path, 720 CreateProfileAsync(last_non_supervised_profile_path,
715 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, 721 base::Bind(&ProfileManager::OnNewActiveProfileLoaded,
716 base::Unretained(this), 722 base::Unretained(this),
717 profile_dir, 723 profile_dir,
718 last_non_supervised_profile_path, 724 last_non_supervised_profile_path,
719 callback), 725 callback),
720 base::string16(), 726 base::string16(),
721 base::string16(), 727 base::string16(),
722 std::string()); 728 std::string());
723 return; 729 return;
724 } 730 }
725 #endif // defined(OS_MACOSX) 731 #endif // defined(OS_MACOSX)
726 732
727 FinishDeletingProfile(profile_dir, last_non_supervised_profile_path); 733 FinishDeletingProfile(profile_dir, new_path);
728 }
729
730 // static
731 void ProfileManager::CleanUpStaleProfiles(
732 const std::vector<base::FilePath>& profile_paths) {
733 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
734
735 for (std::vector<base::FilePath>::const_iterator it = profile_paths.begin();
736 it != profile_paths.end(); ++it) {
737 NukeProfileFromDisk(*it);
738 }
739 } 734 }
740 735
741 void ProfileManager::AutoloadProfiles() { 736 void ProfileManager::AutoloadProfiles() {
742 // If running in the background is disabled for the browser, do not autoload 737 // If running in the background is disabled for the browser, do not autoload
743 // any profiles. 738 // any profiles.
744 PrefService* local_state = g_browser_process->local_state(); 739 PrefService* local_state = g_browser_process->local_state();
745 if (!local_state->HasPrefPath(prefs::kBackgroundModeEnabled) || 740 if (!local_state->HasPrefPath(prefs::kBackgroundModeEnabled) ||
746 !local_state->GetBoolean(prefs::kBackgroundModeEnabled)) { 741 !local_state->GetBoolean(prefs::kBackgroundModeEnabled)) {
747 return; 742 return;
748 } 743 }
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
1370 // Not the last window for this profile. 1365 // Not the last window for this profile.
1371 return; 1366 return;
1372 } 1367 }
1373 1368
1374 // If the last browser of a profile that is scheduled for deletion is closed 1369 // If the last browser of a profile that is scheduled for deletion is closed
1375 // do that now. 1370 // do that now.
1376 base::FilePath path = profile->GetPath(); 1371 base::FilePath path = profile->GetPath();
1377 if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles) && 1372 if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles) &&
1378 !IsProfileMarkedForDeletion(path)) { 1373 !IsProfileMarkedForDeletion(path)) {
1379 g_browser_process->profile_manager()->ScheduleProfileForDeletion( 1374 g_browser_process->profile_manager()->ScheduleProfileForDeletion(
1380 path, ProfileManager::CreateCallback()); 1375 path, false /* suppress_profile_creation */,
1376 ProfileManager::CreateCallback());
1381 } 1377 }
1382 } 1378 }
1383 1379
1384 void ProfileManager::BrowserListObserver::OnBrowserSetLastActive( 1380 void ProfileManager::BrowserListObserver::OnBrowserSetLastActive(
1385 Browser* browser) { 1381 Browser* browser) {
1386 // If all browsers are being closed (e.g. the user is in the process of 1382 // If all browsers are being closed (e.g. the user is in the process of
1387 // shutting down), this event will be fired after each browser is 1383 // shutting down), this event will be fired after each browser is
1388 // closed. This does not represent a user intention to change the active 1384 // closed. This does not represent a user intention to change the active
1389 // browser so is not handled here. 1385 // browser so is not handled here.
1390 if (profile_manager_->closing_all_browsers_) 1386 if (profile_manager_->closing_all_browsers_)
(...skipping 20 matching lines...) Expand all
1411 status != Profile::CREATE_STATUS_REMOTE_FAIL); 1407 status != Profile::CREATE_STATUS_REMOTE_FAIL);
1412 1408
1413 // Only run the code if the profile initialization has finished completely. 1409 // Only run the code if the profile initialization has finished completely.
1414 if (status != Profile::CREATE_STATUS_INITIALIZED) 1410 if (status != Profile::CREATE_STATUS_INITIALIZED)
1415 return; 1411 return;
1416 1412
1417 if (IsProfileMarkedForDeletion(new_active_profile_path)) { 1413 if (IsProfileMarkedForDeletion(new_active_profile_path)) {
1418 // If the profile we tried to load as the next active profile has been 1414 // If the profile we tried to load as the next active profile has been
1419 // deleted, then retry deleting this profile to redo the logic to load 1415 // deleted, then retry deleting this profile to redo the logic to load
1420 // the next available profile. 1416 // the next available profile.
1421 ScheduleProfileForDeletion(profile_to_delete_path, original_callback); 1417 ScheduleProfileForDeletion(profile_to_delete_path,
1418 false /* suppress_profile_creation */,
1419 original_callback);
1422 return; 1420 return;
1423 } 1421 }
1424 1422
1425 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); 1423 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path);
1426 if (!original_callback.is_null()) 1424 if (!original_callback.is_null())
1427 original_callback.Run(loaded_profile, status); 1425 original_callback.Run(loaded_profile, status);
1428 } 1426 }
1429 1427
1430 ProfileManagerWithoutInit::ProfileManagerWithoutInit( 1428 ProfileManagerWithoutInit::ProfileManagerWithoutInit(
1431 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { 1429 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) {
1432 } 1430 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698