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

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

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