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

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

Issue 2698683002: Forced ephemeral profile deletion on browser removal crash fix. (Closed)
Patch Set: Changed active profile selection logic upon ephemeral profile deletion. Created 3 years, 9 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "chrome/browser/sessions/session_service_factory.h" 48 #include "chrome/browser/sessions/session_service_factory.h"
49 #include "chrome/browser/signin/account_fetcher_service_factory.h" 49 #include "chrome/browser/signin/account_fetcher_service_factory.h"
50 #include "chrome/browser/signin/account_reconcilor_factory.h" 50 #include "chrome/browser/signin/account_reconcilor_factory.h"
51 #include "chrome/browser/signin/account_tracker_service_factory.h" 51 #include "chrome/browser/signin/account_tracker_service_factory.h"
52 #include "chrome/browser/signin/cross_device_promo.h" 52 #include "chrome/browser/signin/cross_device_promo.h"
53 #include "chrome/browser/signin/cross_device_promo_factory.h" 53 #include "chrome/browser/signin/cross_device_promo_factory.h"
54 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h" 54 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
55 #include "chrome/browser/signin/signin_manager_factory.h" 55 #include "chrome/browser/signin/signin_manager_factory.h"
56 #include "chrome/browser/sync/profile_sync_service_factory.h" 56 #include "chrome/browser/sync/profile_sync_service_factory.h"
57 #include "chrome/browser/ui/browser.h" 57 #include "chrome/browser/ui/browser.h"
58 #include "chrome/browser/ui/browser_finder.h"
58 #include "chrome/browser/ui/browser_list.h" 59 #include "chrome/browser/ui/browser_list.h"
59 #include "chrome/browser/ui/sync/sync_promo_ui.h" 60 #include "chrome/browser/ui/sync/sync_promo_ui.h"
60 #include "chrome/common/chrome_constants.h" 61 #include "chrome/common/chrome_constants.h"
61 #include "chrome/common/chrome_paths_internal.h" 62 #include "chrome/common/chrome_paths_internal.h"
62 #include "chrome/common/chrome_switches.h" 63 #include "chrome/common/chrome_switches.h"
63 #include "chrome/common/features.h" 64 #include "chrome/common/features.h"
64 #include "chrome/common/logging_chrome.h" 65 #include "chrome/common/logging_chrome.h"
65 #include "chrome/common/pref_names.h" 66 #include "chrome/common/pref_names.h"
66 #include "chrome/common/url_constants.h" 67 #include "chrome/common/url_constants.h"
67 #include "chrome/grit/generated_resources.h" 68 #include "chrome/grit/generated_resources.h"
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 } 317 }
317 if (status != Profile::CREATE_STATUS_INITIALIZED) { 318 if (status != Profile::CREATE_STATUS_INITIALIZED) {
318 LOG(WARNING) << "Profile not loaded correctly"; 319 LOG(WARNING) << "Profile not loaded correctly";
319 client_callback.Run(nullptr); 320 client_callback.Run(nullptr);
320 return; 321 return;
321 } 322 }
322 DCHECK(profile); 323 DCHECK(profile);
323 client_callback.Run(incognito ? profile->GetOffTheRecordProfile() : profile); 324 client_callback.Run(incognito ? profile->GetOffTheRecordProfile() : profile);
324 } 325 }
325 326
327 #if !defined(OS_ANDROID)
328 // Helper function for ScheduleForcedEphemeralProfileForDeletion.
329 bool IsProfileEphemeral(ProfileAttributesStorage* storage,
330 const base::FilePath& profile_dir) {
331 ProfileAttributesEntry* entry = nullptr;
332 return storage->GetProfileAttributesWithPath(profile_dir, &entry) &&
333 entry->IsEphemeral();
334 }
335 #endif
336
326 } // namespace 337 } // namespace
327 338
328 ProfileManager::ProfileManager(const base::FilePath& user_data_dir) 339 ProfileManager::ProfileManager(const base::FilePath& user_data_dir)
329 : user_data_dir_(user_data_dir), 340 : user_data_dir_(user_data_dir),
330 logged_in_(false), 341 logged_in_(false),
331 #if !defined(OS_ANDROID) 342 #if !defined(OS_ANDROID)
332 browser_list_observer_(this), 343 browser_list_observer_(this),
333 #endif 344 #endif
334 closing_all_browsers_(false) { 345 closing_all_browsers_(false) {
335 #if defined(OS_CHROMEOS) 346 #if defined(OS_CHROMEOS)
(...skipping 1323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1659 for (auto* browser : *BrowserList::GetInstance()) { 1670 for (auto* browser : *BrowserList::GetInstance()) {
1660 if (browser->profile()->GetOriginalProfile() == original_profile) 1671 if (browser->profile()->GetOriginalProfile() == original_profile)
1661 return; 1672 return;
1662 } 1673 }
1663 1674
1664 base::FilePath path = profile->GetPath(); 1675 base::FilePath path = profile->GetPath();
1665 if (IsProfileDirectoryMarkedForDeletion(path)) { 1676 if (IsProfileDirectoryMarkedForDeletion(path)) {
1666 // Do nothing if the profile is already being deleted. 1677 // Do nothing if the profile is already being deleted.
1667 } else if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) { 1678 } else if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) {
1668 // Delete if the profile is an ephemeral profile. 1679 // Delete if the profile is an ephemeral profile.
1669 g_browser_process->profile_manager()->ScheduleProfileForDeletion( 1680 g_browser_process->profile_manager()
1670 path, ProfileManager::CreateCallback()); 1681 ->ScheduleForcedEphemeralProfileForDeletion(path);
1671 } else { 1682 } else {
1672 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS) 1683 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS)
1673 // Gather statistics and store into ProfileInfoCache. For incognito profile 1684 // Gather statistics and store into ProfileInfoCache. For incognito profile
1674 // we gather the statistics of its parent profile instead, because a window 1685 // we gather the statistics of its parent profile instead, because a window
1675 // of the parent profile was open. 1686 // of the parent profile was open.
1676 if (!profile->IsSystemProfile() && !original_profile->IsSystemProfile()) { 1687 if (!profile->IsSystemProfile() && !original_profile->IsSystemProfile()) {
1677 ProfileStatisticsFactory::GetForProfile(original_profile)-> 1688 ProfileStatisticsFactory::GetForProfile(original_profile)->
1678 GatherStatistics(profiles::ProfileStatisticsCallback()); 1689 GatherStatistics(profiles::ProfileStatisticsCallback());
1679 } 1690 }
1680 #endif 1691 #endif
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1719 // the next available profile. 1730 // the next available profile.
1720 EnsureActiveProfileExistsBeforeDeletion(original_callback, 1731 EnsureActiveProfileExistsBeforeDeletion(original_callback,
1721 profile_to_delete_path); 1732 profile_to_delete_path);
1722 return; 1733 return;
1723 } 1734 }
1724 1735
1725 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); 1736 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path);
1726 if (!original_callback.is_null()) 1737 if (!original_callback.is_null())
1727 original_callback.Run(loaded_profile, status); 1738 original_callback.Run(loaded_profile, status);
1728 } 1739 }
1740
1741 void ProfileManager::ScheduleForcedEphemeralProfileForDeletion(
1742 const base::FilePath& profile_dir) {
1743 DCHECK_EQ(0u, chrome::GetBrowserCount(GetProfileByPath(profile_dir)));
1744 DCHECK(IsProfileEphemeral(&GetProfileAttributesStorage(), profile_dir));
1745
1746 // Search for latest active profile, already loaded preferably.
1747 bool found_entry_loaded = false;
1748 ProfileAttributesEntry* found_entry = nullptr;
1749 ProfileAttributesStorage& storage = GetProfileAttributesStorage();
1750 for (ProfileAttributesEntry* entry : storage.GetAllProfilesAttributes()) {
1751 // Skip all profiles forbidden to rollback.
1752 base::FilePath entry_path = entry->GetPath();
1753 if (entry_path == profile_dir ||
1754 entry_path == GetGuestProfilePath() ||
1755 entry->IsLegacySupervised() ||
1756 IsProfileDirectoryMarkedForDeletion(entry_path))
1757 continue;
1758 // Check if |entry| preferable over |found_entry|.
1759 bool entry_loaded = !!GetProfileByPath(entry_path);
1760 if (!found_entry || (!found_entry_loaded && entry_loaded) ||
1761 found_entry->GetActiveTime() < entry->GetActiveTime()) {
1762 found_entry = entry;
1763 found_entry_loaded = entry_loaded;
1764 }
1765 }
1766
1767 const base::FilePath new_active_profile_dir =
1768 found_entry ? found_entry->GetPath() : GenerateNextProfileDirectoryPath();
1769 FinishDeletingProfile(profile_dir, new_active_profile_dir);
1770 }
1729 #endif // !defined(OS_ANDROID) 1771 #endif // !defined(OS_ANDROID)
1730 1772
1731 ProfileManagerWithoutInit::ProfileManagerWithoutInit( 1773 ProfileManagerWithoutInit::ProfileManagerWithoutInit(
1732 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { 1774 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) {
1733 } 1775 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_manager.h ('k') | chrome/browser/profiles/profile_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698