Commit e1ccb0aa authored by Christian Dullweber's avatar Christian Dullweber Committed by Commit Bot

Add tracing for StoragePartition

Add tracing for tasks executed by StoragePartition to figure out why
deletions sometimes don't finish.

Bug: 932083
Change-Id: I105fe2e246ceeaa5cba36f213f87b531353d2468
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1595871
Commit-Queue: Christian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659031}
parent 37ca67ee
......@@ -461,30 +461,6 @@ class StoragePartitionImpl::QuotaManagedDataDeletionHelper {
// finally destroyed when deletion completes (and |callback| is invoked).
class StoragePartitionImpl::DataDeletionHelper {
public:
// An instance of this class is used instead of a callback to
// DecrementTaskCount when the callback may be destroyed
// rather than invoked. The destruction of this object (which also
// occurs if the null callback is called) will automatically decrement
// the task count.
// Note that this object may be destroyed on any thread, as
// DecrementTaskCount() is thread-neutral.
// Note that the DataDeletionHelper must outlive this object. This
// should be guaranteed by the fact that the object holds a reference
// to the DataDeletionHelper.
class OwnsReference {
public:
explicit OwnsReference(DataDeletionHelper* helper) : helper_(helper) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
helper->IncrementTaskCountOnUI();
}
~OwnsReference() { helper_->DecrementTaskCount(); }
static void Callback(std::unique_ptr<OwnsReference> reference) {}
DataDeletionHelper* helper_;
};
DataDeletionHelper(uint32_t remove_mask,
uint32_t quota_storage_remove_mask,
base::OnceClosure callback)
......@@ -495,9 +471,6 @@ class StoragePartitionImpl::DataDeletionHelper {
~DataDeletionHelper() {}
void IncrementTaskCountOnUI();
void DecrementTaskCount(); // Callable on any thread.
void ClearDataOnUIThread(
const GURL& storage_origin,
const OriginMatcherFunction& origin_matcher,
......@@ -523,6 +496,19 @@ class StoragePartitionImpl::DataDeletionHelper {
base::OnceClosure callback);
private:
enum class TracingDataType {
kSynchronous = 1,
kCookies = 2,
kQuota = 3,
kLocalStorage = 4,
kSessionStorage = 5,
kShaderCache = 6,
kPluginPrivate = 7,
};
base::OnceClosure CreateTaskCompletionClosure(TracingDataType data_type);
void OnTaskComplete(int tracing_id); // Callable on any thread.
uint32_t remove_mask_;
uint32_t quota_storage_remove_mask_;
......@@ -1166,21 +1152,32 @@ void StoragePartitionImpl::QuotaManagedDataDeletionHelper::
CheckQuotaManagedDataDeletionStatus(deletion_task_count, done_callback);
}
void StoragePartitionImpl::DataDeletionHelper::IncrementTaskCountOnUI() {
base::OnceClosure
StoragePartitionImpl::DataDeletionHelper::CreateTaskCompletionClosure(
TracingDataType data_type) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
++task_count_;
static int tracing_id = 0;
TRACE_EVENT_ASYNC_BEGIN1("browsing_data", "StoragePartitionImpl",
++tracing_id, "data_type",
static_cast<int>(data_type));
return base::BindOnce(
&StoragePartitionImpl::DataDeletionHelper::OnTaskComplete,
base::Unretained(this), tracing_id);
}
void StoragePartitionImpl::DataDeletionHelper::DecrementTaskCount() {
void StoragePartitionImpl::DataDeletionHelper::OnTaskComplete(int tracing_id) {
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(&DataDeletionHelper::DecrementTaskCount,
base::Unretained(this)));
base::BindOnce(&DataDeletionHelper::OnTaskComplete,
base::Unretained(this), tracing_id));
return;
}
DCHECK_GT(task_count_, 0);
--task_count_;
TRACE_EVENT_ASYNC_END0("browsing_data", "StoragePartitionImpl", tracing_id);
if (!task_count_) {
std::move(callback_).Run();
delete this;
......@@ -1203,9 +1200,8 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
DCHECK_NE(remove_mask_, 0u);
DCHECK(!callback_.is_null());
IncrementTaskCountOnUI();
base::RepeatingClosure decrement_callback = base::BindRepeating(
&DataDeletionHelper::DecrementTaskCount, base::Unretained(this));
base::ScopedClosureRunner synchronous_clear_operations(
CreateTaskCompletionClosure(TracingDataType::kSynchronous));
if (remove_mask_ & REMOVE_DATA_MASK_COOKIES) {
// The CookieDeletionFilter has a redundant time interval to |begin| and
......@@ -1223,11 +1219,10 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
std::move(cookie_deletion_filter),
base::BindOnce(
&OnClearedCookies,
// Use OwnsReference instead of Increment/DecrementTaskCount*
// to handle the cookie store being destroyed and the callback
// thus not being called.
base::BindOnce(&OwnsReference::Callback,
std::make_unique<OwnsReference>(this))));
// Handle the cookie store being destroyed and the callback thus not
// being called.
mojo::WrapCallbackWithDefaultInvokeIfNotRun(
CreateTaskCompletionClosure(TracingDataType::kCookies))));
}
if (remove_mask_ & REMOVE_DATA_MASK_INDEXEDDB ||
......@@ -1236,29 +1231,27 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
remove_mask_ & REMOVE_DATA_MASK_FILE_SYSTEMS ||
remove_mask_ & REMOVE_DATA_MASK_SERVICE_WORKERS ||
remove_mask_ & REMOVE_DATA_MASK_CACHE_STORAGE) {
IncrementTaskCountOnUI();
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(
&DataDeletionHelper::ClearQuotaManagedDataOnIOThread,
base::Unretained(this), base::WrapRefCounted(quota_manager), begin,
storage_origin, base::WrapRefCounted(special_storage_policy),
origin_matcher, perform_storage_cleanup, decrement_callback));
origin_matcher, perform_storage_cleanup,
CreateTaskCompletionClosure(TracingDataType::kQuota)));
}
if (remove_mask_ & REMOVE_DATA_MASK_LOCAL_STORAGE) {
IncrementTaskCountOnUI();
ClearLocalStorageOnUIThread(base::WrapRefCounted(dom_storage_context),
base::WrapRefCounted(special_storage_policy),
origin_matcher, storage_origin,
perform_storage_cleanup, begin, end,
decrement_callback);
ClearLocalStorageOnUIThread(
base::WrapRefCounted(dom_storage_context),
base::WrapRefCounted(special_storage_policy), origin_matcher,
storage_origin, perform_storage_cleanup, begin, end,
CreateTaskCompletionClosure(TracingDataType::kLocalStorage));
// ClearDataImpl cannot clear session storage data when a particular origin
// is specified. Therefore we ignore clearing session storage in this case.
// TODO(lazyboy): Fix.
if (storage_origin.is_empty()) {
IncrementTaskCountOnUI();
// TODO(crbug.com/960325): Sometimes SessionStorage fails to call its
// callback. Figure out why.
ClearSessionStorageOnUIThread(
......@@ -1266,30 +1259,32 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
base::WrapRefCounted(special_storage_policy), origin_matcher,
perform_storage_cleanup,
mojo::WrapCallbackWithDefaultInvokeIfNotRun(
static_cast<base::OnceClosure>(decrement_callback)));
CreateTaskCompletionClosure(TracingDataType::kSessionStorage)));
}
}
if (remove_mask_ & REMOVE_DATA_MASK_SHADER_CACHE) {
IncrementTaskCountOnUI();
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::IO},
base::BindOnce(&ClearShaderCacheOnIOThread, path,
begin, end, decrement_callback));
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(
&ClearShaderCacheOnIOThread, path, begin, end,
CreateTaskCompletionClosure(TracingDataType::kShaderCache)));
}
#if BUILDFLAG(ENABLE_PLUGINS)
if (remove_mask_ & REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA) {
IncrementTaskCountOnUI();
filesystem_context->default_file_task_runner()->PostTask(
FROM_HERE, base::BindOnce(&ClearPluginPrivateDataOnFileTaskRunner,
base::WrapRefCounted(filesystem_context),
storage_origin, origin_matcher,
base::WrapRefCounted(special_storage_policy),
begin, end, std::move(decrement_callback)));
FROM_HERE,
base::BindOnce(
&ClearPluginPrivateDataOnFileTaskRunner,
base::WrapRefCounted(filesystem_context), storage_origin,
origin_matcher, base::WrapRefCounted(special_storage_policy), begin,
end,
base::AdaptCallbackForRepeating(
CreateTaskCompletionClosure(TracingDataType::kPluginPrivate))));
}
#endif // BUILDFLAG(ENABLE_PLUGINS)
DecrementTaskCount();
}
void StoragePartitionImpl::ClearDataForOrigin(
......
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