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 { ...@@ -461,30 +461,6 @@ class StoragePartitionImpl::QuotaManagedDataDeletionHelper {
// finally destroyed when deletion completes (and |callback| is invoked). // finally destroyed when deletion completes (and |callback| is invoked).
class StoragePartitionImpl::DataDeletionHelper { class StoragePartitionImpl::DataDeletionHelper {
public: 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, DataDeletionHelper(uint32_t remove_mask,
uint32_t quota_storage_remove_mask, uint32_t quota_storage_remove_mask,
base::OnceClosure callback) base::OnceClosure callback)
...@@ -495,9 +471,6 @@ class StoragePartitionImpl::DataDeletionHelper { ...@@ -495,9 +471,6 @@ class StoragePartitionImpl::DataDeletionHelper {
~DataDeletionHelper() {} ~DataDeletionHelper() {}
void IncrementTaskCountOnUI();
void DecrementTaskCount(); // Callable on any thread.
void ClearDataOnUIThread( void ClearDataOnUIThread(
const GURL& storage_origin, const GURL& storage_origin,
const OriginMatcherFunction& origin_matcher, const OriginMatcherFunction& origin_matcher,
...@@ -523,6 +496,19 @@ class StoragePartitionImpl::DataDeletionHelper { ...@@ -523,6 +496,19 @@ class StoragePartitionImpl::DataDeletionHelper {
base::OnceClosure callback); base::OnceClosure callback);
private: 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 remove_mask_;
uint32_t quota_storage_remove_mask_; uint32_t quota_storage_remove_mask_;
...@@ -1166,21 +1152,32 @@ void StoragePartitionImpl::QuotaManagedDataDeletionHelper:: ...@@ -1166,21 +1152,32 @@ void StoragePartitionImpl::QuotaManagedDataDeletionHelper::
CheckQuotaManagedDataDeletionStatus(deletion_task_count, done_callback); CheckQuotaManagedDataDeletionStatus(deletion_task_count, done_callback);
} }
void StoragePartitionImpl::DataDeletionHelper::IncrementTaskCountOnUI() { base::OnceClosure
StoragePartitionImpl::DataDeletionHelper::CreateTaskCompletionClosure(
TracingDataType data_type) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
++task_count_; ++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)) { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
base::PostTaskWithTraits( base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI}, FROM_HERE, {BrowserThread::UI},
base::BindOnce(&DataDeletionHelper::DecrementTaskCount, base::BindOnce(&DataDeletionHelper::OnTaskComplete,
base::Unretained(this))); base::Unretained(this), tracing_id));
return; return;
} }
DCHECK_GT(task_count_, 0); DCHECK_GT(task_count_, 0);
--task_count_; --task_count_;
TRACE_EVENT_ASYNC_END0("browsing_data", "StoragePartitionImpl", tracing_id);
if (!task_count_) { if (!task_count_) {
std::move(callback_).Run(); std::move(callback_).Run();
delete this; delete this;
...@@ -1203,9 +1200,8 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread( ...@@ -1203,9 +1200,8 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
DCHECK_NE(remove_mask_, 0u); DCHECK_NE(remove_mask_, 0u);
DCHECK(!callback_.is_null()); DCHECK(!callback_.is_null());
IncrementTaskCountOnUI(); base::ScopedClosureRunner synchronous_clear_operations(
base::RepeatingClosure decrement_callback = base::BindRepeating( CreateTaskCompletionClosure(TracingDataType::kSynchronous));
&DataDeletionHelper::DecrementTaskCount, base::Unretained(this));
if (remove_mask_ & REMOVE_DATA_MASK_COOKIES) { if (remove_mask_ & REMOVE_DATA_MASK_COOKIES) {
// The CookieDeletionFilter has a redundant time interval to |begin| and // The CookieDeletionFilter has a redundant time interval to |begin| and
...@@ -1223,11 +1219,10 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread( ...@@ -1223,11 +1219,10 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
std::move(cookie_deletion_filter), std::move(cookie_deletion_filter),
base::BindOnce( base::BindOnce(
&OnClearedCookies, &OnClearedCookies,
// Use OwnsReference instead of Increment/DecrementTaskCount* // Handle the cookie store being destroyed and the callback thus not
// to handle the cookie store being destroyed and the callback // being called.
// thus not being called. mojo::WrapCallbackWithDefaultInvokeIfNotRun(
base::BindOnce(&OwnsReference::Callback, CreateTaskCompletionClosure(TracingDataType::kCookies))));
std::make_unique<OwnsReference>(this))));
} }
if (remove_mask_ & REMOVE_DATA_MASK_INDEXEDDB || if (remove_mask_ & REMOVE_DATA_MASK_INDEXEDDB ||
...@@ -1236,29 +1231,27 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread( ...@@ -1236,29 +1231,27 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
remove_mask_ & REMOVE_DATA_MASK_FILE_SYSTEMS || remove_mask_ & REMOVE_DATA_MASK_FILE_SYSTEMS ||
remove_mask_ & REMOVE_DATA_MASK_SERVICE_WORKERS || remove_mask_ & REMOVE_DATA_MASK_SERVICE_WORKERS ||
remove_mask_ & REMOVE_DATA_MASK_CACHE_STORAGE) { remove_mask_ & REMOVE_DATA_MASK_CACHE_STORAGE) {
IncrementTaskCountOnUI();
base::PostTaskWithTraits( base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO}, FROM_HERE, {BrowserThread::IO},
base::BindOnce( base::BindOnce(
&DataDeletionHelper::ClearQuotaManagedDataOnIOThread, &DataDeletionHelper::ClearQuotaManagedDataOnIOThread,
base::Unretained(this), base::WrapRefCounted(quota_manager), begin, base::Unretained(this), base::WrapRefCounted(quota_manager), begin,
storage_origin, base::WrapRefCounted(special_storage_policy), 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) { if (remove_mask_ & REMOVE_DATA_MASK_LOCAL_STORAGE) {
IncrementTaskCountOnUI(); ClearLocalStorageOnUIThread(
ClearLocalStorageOnUIThread(base::WrapRefCounted(dom_storage_context), base::WrapRefCounted(dom_storage_context),
base::WrapRefCounted(special_storage_policy), base::WrapRefCounted(special_storage_policy), origin_matcher,
origin_matcher, storage_origin, storage_origin, perform_storage_cleanup, begin, end,
perform_storage_cleanup, begin, end, CreateTaskCompletionClosure(TracingDataType::kLocalStorage));
decrement_callback);
// ClearDataImpl cannot clear session storage data when a particular origin // ClearDataImpl cannot clear session storage data when a particular origin
// is specified. Therefore we ignore clearing session storage in this case. // is specified. Therefore we ignore clearing session storage in this case.
// TODO(lazyboy): Fix. // TODO(lazyboy): Fix.
if (storage_origin.is_empty()) { if (storage_origin.is_empty()) {
IncrementTaskCountOnUI();
// TODO(crbug.com/960325): Sometimes SessionStorage fails to call its // TODO(crbug.com/960325): Sometimes SessionStorage fails to call its
// callback. Figure out why. // callback. Figure out why.
ClearSessionStorageOnUIThread( ClearSessionStorageOnUIThread(
...@@ -1266,30 +1259,32 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread( ...@@ -1266,30 +1259,32 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
base::WrapRefCounted(special_storage_policy), origin_matcher, base::WrapRefCounted(special_storage_policy), origin_matcher,
perform_storage_cleanup, perform_storage_cleanup,
mojo::WrapCallbackWithDefaultInvokeIfNotRun( mojo::WrapCallbackWithDefaultInvokeIfNotRun(
static_cast<base::OnceClosure>(decrement_callback))); CreateTaskCompletionClosure(TracingDataType::kSessionStorage)));
} }
} }
if (remove_mask_ & REMOVE_DATA_MASK_SHADER_CACHE) { if (remove_mask_ & REMOVE_DATA_MASK_SHADER_CACHE) {
IncrementTaskCountOnUI(); base::PostTaskWithTraits(
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::IO}, FROM_HERE, {BrowserThread::IO},
base::BindOnce(&ClearShaderCacheOnIOThread, path, base::BindOnce(
begin, end, decrement_callback)); &ClearShaderCacheOnIOThread, path, begin, end,
CreateTaskCompletionClosure(TracingDataType::kShaderCache)));
} }
#if BUILDFLAG(ENABLE_PLUGINS) #if BUILDFLAG(ENABLE_PLUGINS)
if (remove_mask_ & REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA) { if (remove_mask_ & REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA) {
IncrementTaskCountOnUI();
filesystem_context->default_file_task_runner()->PostTask( filesystem_context->default_file_task_runner()->PostTask(
FROM_HERE, base::BindOnce(&ClearPluginPrivateDataOnFileTaskRunner, FROM_HERE,
base::WrapRefCounted(filesystem_context), base::BindOnce(
storage_origin, origin_matcher, &ClearPluginPrivateDataOnFileTaskRunner,
base::WrapRefCounted(special_storage_policy), base::WrapRefCounted(filesystem_context), storage_origin,
begin, end, std::move(decrement_callback))); origin_matcher, base::WrapRefCounted(special_storage_policy), begin,
end,
base::AdaptCallbackForRepeating(
CreateTaskCompletionClosure(TracingDataType::kPluginPrivate))));
} }
#endif // BUILDFLAG(ENABLE_PLUGINS) #endif // BUILDFLAG(ENABLE_PLUGINS)
DecrementTaskCount();
} }
void StoragePartitionImpl::ClearDataForOrigin( 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