weblayer: Implement removing profile from disk
Implement Profile.destroyAndDeleteDataFromDisk and deprecate
Profile.destroy. destroyAndDeleteDataFromDisk will mark the profile as
destroyed (ie unusable) and then delete files on a blocking thread poll
thread.
Other changes
* Add tracking of BrowserImpl that's in use in a profile to know when
it's safe to delete a profile.
* Lazy create BrowserContextImpl so that creating a Profile just to
delete files does not cause extra work.
* Centralize code for computing file paths so can be shared with delete.
Have not added API to return profiles currently on disk.
Bug: 1044581
Change-Id: I0c88e6c73faaf62b49cc2212cd4a57e26c5a64f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2043943
Commit-Queue: Bo <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Cr-Commit-Position: refs/heads/master@{#739966}
diff --git a/weblayer/browser/browser_impl.cc b/weblayer/browser/browser_impl.cc
index f2123682..c05336d 100644
--- a/weblayer/browser/browser_impl.cc
+++ b/weblayer/browser/browser_impl.cc
@@ -54,6 +54,7 @@
while (!tabs_.empty())
RemoveTab(tabs_.back().get());
#endif
+ profile_->DecrementBrowserImplCount();
}
TabImpl* BrowserImpl::CreateTabForSessionRestore(
@@ -284,7 +285,9 @@
browser_observers_.RemoveObserver(observer);
}
-BrowserImpl::BrowserImpl(ProfileImpl* profile) : profile_(profile) {}
+BrowserImpl::BrowserImpl(ProfileImpl* profile) : profile_(profile) {
+ profile_->IncrementBrowserImplCount();
+}
void BrowserImpl::RestoreStateIfNecessary(
const PersistenceInfo& persistence_info) {
@@ -305,13 +308,7 @@
}
base::FilePath BrowserImpl::GetSessionServiceDataPath() {
- base::FilePath base_path;
- if (profile_->GetBrowserContext()->IsOffTheRecord()) {
- CHECK(base::PathService::Get(DIR_USER_DATA, &base_path));
- base_path = base_path.AppendASCII("Incognito Restore Data");
- } else {
- base_path = profile_->data_path().AppendASCII("Restore Data");
- }
+ base::FilePath base_path = profile_->GetSessionServiceDataBaseDir();
DCHECK(!GetPersistenceId().empty());
const std::string encoded_name = base32::Base32Encode(GetPersistenceId());
return base_path.AppendASCII("State" + encoded_name);