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

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

Issue 840733002: Properly create a new profile when the last non-supervised profile is deleted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« 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 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 Profile* profile = GetProfileByPath(profile_dir); 635 Profile* profile = GetProfileByPath(profile_dir);
636 if (profile) { 636 if (profile) {
637 DownloadService* service = 637 DownloadService* service =
638 DownloadServiceFactory::GetForBrowserContext(profile); 638 DownloadServiceFactory::GetForBrowserContext(profile);
639 service->CancelDownloads(); 639 service->CancelDownloads();
640 } 640 }
641 641
642 PrefService* local_state = g_browser_process->local_state(); 642 PrefService* local_state = g_browser_process->local_state();
643 ProfileInfoCache& cache = GetProfileInfoCache(); 643 ProfileInfoCache& cache = GetProfileInfoCache();
644 644
645 // If we're deleting the last (non-legacy-supervised) profile, then create a
646 // new profile in its place.
647 base::FilePath last_non_supervised_profile_path;
648 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) {
649 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i);
650 // Make sure that this profile is not pending deletion, and is not
651 // legacy-supervised.
652 if (cur_path != profile_dir &&
653 !cache.ProfileIsLegacySupervisedAtIndex(i) &&
654 !IsProfileMarkedForDeletion(cur_path)) {
655 last_non_supervised_profile_path = cur_path;
656 break;
657 }
658 }
659
660 base::FilePath new_path;
661 if (last_non_supervised_profile_path.empty()) {
662 // If we are using --new-avatar-menu, then assign the default
663 // placeholder avatar and name. Otherwise, use random ones.
664 bool is_new_avatar_menu = switches::IsNewAvatarMenu();
665 int avatar_index = profiles::GetPlaceholderAvatarIndex();
666 base::string16 new_avatar_url = is_new_avatar_menu ?
667 base::UTF8ToUTF16(profiles::GetDefaultAvatarIconUrl(avatar_index)) :
668 base::string16();
669 base::string16 new_profile_name = is_new_avatar_menu ?
670 cache.ChooseNameForNewProfile(avatar_index) : base::string16();
671
672 new_path = GenerateNextProfileDirectoryPath();
673 CreateProfileAsync(new_path,
674 callback,
675 new_profile_name,
676 new_avatar_url,
677 std::string());
678
679 ProfileMetrics::LogProfileAddNewUser(
680 ProfileMetrics::ADD_NEW_USER_LAST_DELETED);
681 }
682
683 // Update the last used profile pref before closing browser windows. This
684 // way the correct last used profile is set for any notification observers.
645 const std::string last_used_profile = 685 const std::string last_used_profile =
646 local_state->GetString(prefs::kProfileLastUsed); 686 local_state->GetString(prefs::kProfileLastUsed);
647
648 if (last_used_profile == profile_dir.BaseName().MaybeAsASCII() || 687 if (last_used_profile == profile_dir.BaseName().MaybeAsASCII() ||
649 last_used_profile == GetGuestProfilePath().BaseName().MaybeAsASCII()) { 688 last_used_profile == GetGuestProfilePath().BaseName().MaybeAsASCII()) {
650 // Update the last used profile pref before closing browser windows. This
651 // way the correct last used profile is set for any notification observers.
652 base::FilePath last_non_supervised_profile_path;
653 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) {
654 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i);
655 // Make sure that this profile is not pending deletion.
656 if (cur_path != profile_dir &&
657 !cache.ProfileIsLegacySupervisedAtIndex(i) &&
658 !IsProfileMarkedForDeletion(cur_path)) {
659 last_non_supervised_profile_path = cur_path;
660 break;
661 }
662 }
663
664 // If we're deleting the last (non-supervised) profile, then create a new
665 // profile in its place.
666 const std::string last_non_supervised_profile = 689 const std::string last_non_supervised_profile =
667 last_non_supervised_profile_path.BaseName().MaybeAsASCII(); 690 last_non_supervised_profile_path.BaseName().MaybeAsASCII();
668 if (last_non_supervised_profile.empty()) { 691 if (last_non_supervised_profile.empty()) {
669 base::FilePath new_path = GenerateNextProfileDirectoryPath(); 692 DCHECK(!new_path.empty());
670 // Make sure the last used profile path is pointing at it. This way the
671 // correct last used profile is set for any notification observers.
672 local_state->SetString(prefs::kProfileLastUsed, 693 local_state->SetString(prefs::kProfileLastUsed,
673 new_path.BaseName().MaybeAsASCII()); 694 new_path.BaseName().MaybeAsASCII());
674
675 // If we are using --new-avatar-menu, then assign the default
676 // placeholder avatar and name. Otherwise, use random ones.
677 bool is_new_avatar_menu = switches::IsNewAvatarMenu();
678 int avatar_index = profiles::GetPlaceholderAvatarIndex();
679 base::string16 new_avatar_url = is_new_avatar_menu ?
680 base::UTF8ToUTF16(profiles::GetDefaultAvatarIconUrl(avatar_index)) :
681 base::string16();
682 base::string16 new_profile_name = is_new_avatar_menu ?
683 cache.ChooseNameForNewProfile(avatar_index) : base::string16();
684
685 CreateProfileAsync(new_path,
686 callback,
687 new_profile_name,
688 new_avatar_url,
689 std::string());
690
691 ProfileMetrics::LogProfileAddNewUser(
692 ProfileMetrics::ADD_NEW_USER_LAST_DELETED);
693 } else { 695 } else {
694 // On the Mac, the browser process is not killed when all browser windows 696 // On the Mac, the browser process is not killed when all browser windows
695 // are closed, so just in case we are deleting the active profile, and no 697 // are closed, so just in case we are deleting the active profile, and no
696 // other profile has been loaded, we must pre-load a next one. 698 // other profile has been loaded, we must pre-load a next one.
697 #if defined(OS_MACOSX) 699 #if defined(OS_MACOSX)
698 CreateProfileAsync(last_non_supervised_profile_path, 700 CreateProfileAsync(last_non_supervised_profile_path,
699 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, 701 base::Bind(&ProfileManager::OnNewActiveProfileLoaded,
700 base::Unretained(this), 702 base::Unretained(this),
701 profile_dir, 703 profile_dir,
702 last_non_supervised_profile_path, 704 last_non_supervised_profile_path,
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 last_non_supervised_profile_path.BaseName().MaybeAsASCII()); 1355 last_non_supervised_profile_path.BaseName().MaybeAsASCII());
1354 FinishDeletingProfile(profile_to_delete_path); 1356 FinishDeletingProfile(profile_to_delete_path);
1355 } 1357 }
1356 } 1358 }
1357 } 1359 }
1358 #endif 1360 #endif
1359 1361
1360 ProfileManagerWithoutInit::ProfileManagerWithoutInit( 1362 ProfileManagerWithoutInit::ProfileManagerWithoutInit(
1361 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { 1363 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) {
1362 } 1364 }
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