Commit d7899881 authored by Nicolas Ouellet-Payeur's avatar Nicolas Ouellet-Payeur Committed by Chromium LUCI CQ

Use ScopedProfileKeepAlive in BrowsingDataRemover

It already had a ScopedKeepAlive to keep the BrowserProcess from
shutting down while clearing data. But it also needs a
ScopedProfileKeepAlive, to keep the Profile* from being deleted while
clearing.

ScopedProfileKeepAlive is a no-op when DestroyProfileOnBrowserClose is
false (which is the default for now).

Bug: 88586
Change-Id: Ie5a133f99e2b67c0901abc3935cdbe804f2b4030
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2625996Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: Nicolas Ouellet-Payeur <nicolaso@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843782}
parent 71263453
......@@ -21,7 +21,9 @@
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
#include "chrome/browser/lifetime/browser_shutdown.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_keep_alive_types.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/scoped_profile_keep_alive.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
......@@ -49,12 +51,6 @@ using ScheduledRemovalSettings =
// An observer of all the browsing data removal tasks that are started by the
// ChromeBrowsingDataLifetimeManager that records the the tasks starts and
// completed states as well as their durations.
// TODO(crbug.com/88586): While the profile lifetime is tied to the browser's,
// the profile is kept from being deleted until |OnBrowsingDataRemoverDone| is
// called and |keep_alive| is not null. Once the profile lifetime is untied from
// the browser's and could be deleted before the browser's shutdown, it should
// still be kept from being deleted until |OnBrowsingDataRemoverDone| when
// |keep_alive| is not null.
class BrowsingDataRemoverObserver
: public content::BrowsingDataRemover::Observer {
public:
......@@ -101,6 +97,10 @@ class BrowsingDataRemoverObserver
filterable_deletion_(filterable_deletion),
profile_(profile),
keep_alive_(std::move(keep_alive)) {
if (keep_alive_ && !profile_->IsOffTheRecord()) {
profile_keep_alive_ = std::make_unique<ScopedProfileKeepAlive>(
profile_, ProfileKeepAliveOrigin::kClearingBrowsingData);
}
browsing_data_remover_observer_.Observe(remover);
base::UmaHistogramBoolean(state_histogram(),
/*BooleanStartedCompleted.Started*/ false);
......@@ -140,6 +140,7 @@ class BrowsingDataRemoverObserver
Profile* const profile_;
std::unique_ptr<ScopedKeepAlive> keep_alive_;
std::unique_ptr<ScopedProfileKeepAlive> profile_keep_alive_;
};
uint64_t GetOriginTypeMask(const base::Value& data_types) {
......
......@@ -21,6 +21,8 @@ std::ostream& operator<<(std::ostream& out,
return out << "kDownloadInProgress";
case ProfileKeepAliveOrigin::kAppControllerMac:
return out << "kAppControllerMac";
case ProfileKeepAliveOrigin::kClearingBrowsingData:
return out << "kClearingBrowsingData";
}
NOTREACHED();
return out << static_cast<int>(origin);
......
......@@ -41,7 +41,11 @@ enum class ProfileKeepAliveOrigin {
// "launches" Chrome again.
kAppControllerMac = 5,
kMaxValue = kAppControllerMac,
// In the middle of clearing browsing data during browsing exit, for the
// ClearBrowsingDataOnExistList policy.
kClearingBrowsingData = 6,
kMaxValue = kClearingBrowsingData,
};
std::ostream& operator<<(std::ostream& out,
......
......@@ -61742,6 +61742,7 @@ https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_2.7.1.pdf
<int value="3" label="kOffTheRecordProfile"/>
<int value="4" label="kDownloadInProgress"/>
<int value="5" label="kAppControllerMac"/>
<int value="6" label="kClearingBrowsingData"/>
</enum>
<enum name="ProfileMenuActionableItem">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment