Commit 9512b33d authored by Randy Smith's avatar Randy Smith Committed by Commit Bot

Refactor use of StoragePartition::ClearData* methods.

This refactor is to remove the passed URLRequestContextGetter as an
argument, preperatory to shifting cookie deletion in StoragePartitionImpl
over to Mojo interfaces.

Bug: 721395
Change-Id: I4568cb5ffd98591605a7c5d8b3850c5d8cd5d9b7
Reviewed-on: https://chromium-review.googlesource.com/754518
Commit-Queue: Randy Smith <rdsmith@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523520}
parent e6b4822d
...@@ -233,8 +233,7 @@ void AwQuotaManagerBridge::DeleteOriginOnUiThread( ...@@ -233,8 +233,7 @@ void AwQuotaManagerBridge::DeleteOriginOnUiThread(
StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
StoragePartition::REMOVE_DATA_MASK_INDEXEDDB | StoragePartition::REMOVE_DATA_MASK_INDEXEDDB |
StoragePartition::REMOVE_DATA_MASK_WEBSQL, StoragePartition::REMOVE_DATA_MASK_WEBSQL,
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_TEMPORARY, GURL(origin), StoragePartition::QUOTA_MANAGED_STORAGE_MASK_TEMPORARY, GURL(origin));
storage_partition->GetURLRequestContext());
} }
void AwQuotaManagerBridge::GetOrigins(JNIEnv* env, void AwQuotaManagerBridge::GetOrigins(JNIEnv* env,
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "chrome/browser/extensions/data_deleter.h" #include "chrome/browser/extensions/data_deleter.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/task_runner.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_special_storage_policy.h" #include "chrome/browser/extensions/extension_special_storage_policy.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -19,6 +22,8 @@ ...@@ -19,6 +22,8 @@
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/manifest_handlers/app_isolation_info.h" #include "extensions/common/manifest_handlers/app_isolation_info.h"
#include "net/cookies/cookie_store.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
using base::WeakPtr; using base::WeakPtr;
...@@ -30,6 +35,21 @@ namespace extensions { ...@@ -30,6 +35,21 @@ namespace extensions {
namespace { namespace {
bool DoesCookieMatchHost(const std::string& host,
const net::CanonicalCookie& cookie) {
return cookie.IsHostCookie() && cookie.IsDomainMatch(host);
}
void ClearCookiesOnIOThread(scoped_refptr<net::URLRequestContextGetter> context,
const GURL& origin) {
net::CookieStore* cookie_store =
context->GetURLRequestContext()->cookie_store();
cookie_store->DeleteAllCreatedBetweenWithPredicateAsync(
base::Time(), base::Time::Max(),
base::BindRepeating(&DoesCookieMatchHost, origin.host()),
net::CookieStore::DeleteCallback());
}
// Helper function that deletes data of a given |storage_origin| in a given // Helper function that deletes data of a given |storage_origin| in a given
// |partition|. // |partition|.
void DeleteOrigin(Profile* profile, void DeleteOrigin(Profile* profile,
...@@ -49,17 +69,26 @@ void DeleteOrigin(Profile* profile, ...@@ -49,17 +69,26 @@ void DeleteOrigin(Profile* profile,
// preserve this code path without checking for isolation because it's // preserve this code path without checking for isolation because it's
// simpler than special casing. This code should go away once we merge // simpler than special casing. This code should go away once we merge
// the various URLRequestContexts (http://crbug.com/159193). // the various URLRequestContexts (http://crbug.com/159193).
partition->ClearDataForOrigin( partition->ClearDataForOrigin(
~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE, ~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE,
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, origin, StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, origin);
profile->GetRequestContextForExtensions());
// Delete cookies separately from other data so that the request context
// for extensions doesn't need to be passed into the StoragePartition.
// TODO(rdsmith): Mojoify this call and get rid of the thread hopping.
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(
&ClearCookiesOnIOThread,
base::WrapRefCounted(profile->GetRequestContextForExtensions()),
origin));
} else { } else {
// We don't need to worry about the media request context because that // We don't need to worry about the media request context because that
// shares the same cookie store as the main request context. // shares the same cookie store as the main request context.
partition->ClearDataForOrigin( partition->ClearDataForOrigin(
~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE, ~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE,
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, origin, StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, origin);
partition->GetURLRequestContext());
} }
} }
......
...@@ -134,8 +134,7 @@ class StoragePartitionRemovalTestStoragePartition ...@@ -134,8 +134,7 @@ class StoragePartitionRemovalTestStoragePartition
void ClearDataForOrigin(uint32_t remove_mask, void ClearDataForOrigin(uint32_t remove_mask,
uint32_t quota_storage_remove_mask, uint32_t quota_storage_remove_mask,
const GURL& storage_origin, const GURL& storage_origin) override {}
net::URLRequestContextGetter* rq_context) override {}
void ClearData(uint32_t remove_mask, void ClearData(uint32_t remove_mask,
uint32_t quota_storage_remove_mask, uint32_t quota_storage_remove_mask,
......
...@@ -307,7 +307,7 @@ Response StorageHandler::ClearDataForOrigin( ...@@ -307,7 +307,7 @@ Response StorageHandler::ClearDataForOrigin(
partition->ClearDataForOrigin( partition->ClearDataForOrigin(
remove_mask, StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, remove_mask, StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
GURL(origin), partition->GetURLRequestContext()); GURL(origin));
return Response::OK(); return Response::OK();
} }
......
...@@ -67,16 +67,16 @@ bool DoesCookieMatchHost(const std::string& host, ...@@ -67,16 +67,16 @@ bool DoesCookieMatchHost(const std::string& host,
return cookie.IsHostCookie() && cookie.IsDomainMatch(host); return cookie.IsHostCookie() && cookie.IsDomainMatch(host);
} }
void OnClearedCookies(const base::Closure& callback, uint32_t num_deleted) { void OnClearedCookies(base::OnceClosure callback, uint32_t num_deleted) {
// The final callback needs to happen from UI thread. // The final callback needs to happen from UI thread.
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::BindOnce(&OnClearedCookies, callback, num_deleted)); base::BindOnce(&OnClearedCookies, std::move(callback), num_deleted));
return; return;
} }
callback.Run(); std::move(callback).Run();
} }
// Cookie matcher and storage_origin are never both populated. // Cookie matcher and storage_origin are never both populated.
...@@ -86,7 +86,7 @@ void ClearCookiesOnIOThread( ...@@ -86,7 +86,7 @@ void ClearCookiesOnIOThread(
const base::Time end, const base::Time end,
const GURL& storage_origin, const GURL& storage_origin,
const StoragePartition::CookieMatcherFunction& cookie_matcher, const StoragePartition::CookieMatcherFunction& cookie_matcher,
const base::Closure& callback) { base::OnceClosure callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(cookie_matcher.is_null() || storage_origin.is_empty()); DCHECK(cookie_matcher.is_null() || storage_origin.is_empty());
net::CookieStore* cookie_store = net::CookieStore* cookie_store =
...@@ -94,7 +94,7 @@ void ClearCookiesOnIOThread( ...@@ -94,7 +94,7 @@ void ClearCookiesOnIOThread(
if (!cookie_matcher.is_null()) { if (!cookie_matcher.is_null()) {
cookie_store->DeleteAllCreatedBetweenWithPredicateAsync( cookie_store->DeleteAllCreatedBetweenWithPredicateAsync(
begin, end, cookie_matcher, begin, end, cookie_matcher,
base::BindOnce(&OnClearedCookies, callback)); base::BindOnce(&OnClearedCookies, std::move(callback)));
return; return;
} }
if (!storage_origin.is_empty()) { if (!storage_origin.is_empty()) {
...@@ -104,11 +104,11 @@ void ClearCookiesOnIOThread( ...@@ -104,11 +104,11 @@ void ClearCookiesOnIOThread(
cookie_store->DeleteAllCreatedBetweenWithPredicateAsync( cookie_store->DeleteAllCreatedBetweenWithPredicateAsync(
begin, end, begin, end,
StoragePartitionImpl::CreatePredicateForHostCookies(storage_origin), StoragePartitionImpl::CreatePredicateForHostCookies(storage_origin),
base::BindOnce(&OnClearedCookies, callback)); base::BindOnce(&OnClearedCookies, std::move(callback)));
return; return;
} }
cookie_store->DeleteAllCreatedBetweenAsync( cookie_store->DeleteAllCreatedBetweenAsync(
begin, end, base::BindOnce(&OnClearedCookies, callback)); begin, end, base::BindOnce(&OnClearedCookies, std::move(callback)));
} }
void CheckQuotaManagedDataDeletionStatus(size_t* deletion_task_count, void CheckQuotaManagedDataDeletionStatus(size_t* deletion_task_count,
...@@ -355,6 +355,30 @@ struct StoragePartitionImpl::QuotaManagedDataDeletionHelper { ...@@ -355,6 +355,30 @@ struct StoragePartitionImpl::QuotaManagedDataDeletionHelper {
// forwarded and updated on each (sub) deletion's callback. The instance is // forwarded and updated on each (sub) deletion's callback. The instance is
// finally destroyed when deletion completes (and |callback| is invoked). // finally destroyed when deletion completes (and |callback| is invoked).
struct StoragePartitionImpl::DataDeletionHelper { struct StoragePartitionImpl::DataDeletionHelper {
// 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:
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)
...@@ -364,7 +388,7 @@ struct StoragePartitionImpl::DataDeletionHelper { ...@@ -364,7 +388,7 @@ struct StoragePartitionImpl::DataDeletionHelper {
task_count(0) {} task_count(0) {}
void IncrementTaskCountOnUI(); void IncrementTaskCountOnUI();
void DecrementTaskCountOnUI(); void DecrementTaskCount(); // Callable on any thread.
void ClearDataOnUIThread( void ClearDataOnUIThread(
const GURL& storage_origin, const GURL& storage_origin,
...@@ -739,7 +763,6 @@ void StoragePartitionImpl::ClearDataImpl( ...@@ -739,7 +763,6 @@ void StoragePartitionImpl::ClearDataImpl(
const GURL& storage_origin, const GURL& storage_origin,
const OriginMatcherFunction& origin_matcher, const OriginMatcherFunction& origin_matcher,
const CookieMatcherFunction& cookie_matcher, const CookieMatcherFunction& cookie_matcher,
net::URLRequestContextGetter* rq_context,
const base::Time begin, const base::Time begin,
const base::Time end, const base::Time end,
base::OnceClosure callback) { base::OnceClosure callback) {
...@@ -747,10 +770,10 @@ void StoragePartitionImpl::ClearDataImpl( ...@@ -747,10 +770,10 @@ void StoragePartitionImpl::ClearDataImpl(
DataDeletionHelper* helper = new DataDeletionHelper( DataDeletionHelper* helper = new DataDeletionHelper(
remove_mask, quota_storage_remove_mask, std::move(callback)); remove_mask, quota_storage_remove_mask, std::move(callback));
// |helper| deletes itself when done in // |helper| deletes itself when done in
// DataDeletionHelper::DecrementTaskCountOnUI(). // DataDeletionHelper::DecrementTaskCount().
helper->ClearDataOnUIThread( helper->ClearDataOnUIThread(
storage_origin, origin_matcher, cookie_matcher, GetPath(), rq_context, storage_origin, origin_matcher, cookie_matcher, GetPath(),
dom_storage_context_.get(), quota_manager_.get(), GetURLRequestContext(), dom_storage_context_.get(), quota_manager_.get(),
special_storage_policy_.get(), filesystem_context_.get(), begin, end); special_storage_policy_.get(), filesystem_context_.get(), begin, end);
} }
...@@ -865,11 +888,11 @@ void StoragePartitionImpl::DataDeletionHelper::IncrementTaskCountOnUI() { ...@@ -865,11 +888,11 @@ void StoragePartitionImpl::DataDeletionHelper::IncrementTaskCountOnUI() {
++task_count; ++task_count;
} }
void StoragePartitionImpl::DataDeletionHelper::DecrementTaskCountOnUI() { void StoragePartitionImpl::DataDeletionHelper::DecrementTaskCount() {
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::BindOnce(&DataDeletionHelper::DecrementTaskCountOnUI, base::BindOnce(&DataDeletionHelper::DecrementTaskCount,
base::Unretained(this))); base::Unretained(this)));
return; return;
} }
...@@ -898,16 +921,21 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread( ...@@ -898,16 +921,21 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
IncrementTaskCountOnUI(); IncrementTaskCountOnUI();
base::Closure decrement_callback = base::Bind( base::Closure decrement_callback = base::Bind(
&DataDeletionHelper::DecrementTaskCountOnUI, base::Unretained(this)); &DataDeletionHelper::DecrementTaskCount, base::Unretained(this));
if (remove_mask & REMOVE_DATA_MASK_COOKIES) { if (remove_mask & REMOVE_DATA_MASK_COOKIES) {
// Handle the cookies. // Handle the cookies.
IncrementTaskCountOnUI();
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
base::BindOnce(&ClearCookiesOnIOThread, base::BindOnce(
base::WrapRefCounted(rq_context), begin, end, &ClearCookiesOnIOThread, base::WrapRefCounted(rq_context), begin,
storage_origin, cookie_matcher, decrement_callback)); end, storage_origin, cookie_matcher,
// Use OwnsReference instead of Increment/DecrementTaskCount*
// to handle the cookie store being destroyed and the callback
// thus not being called.
base::BindOnce(
&OwnsReference::Callback,
base::Passed(std::make_unique<OwnsReference>(this)))));
} }
if (remove_mask & REMOVE_DATA_MASK_INDEXEDDB || if (remove_mask & REMOVE_DATA_MASK_INDEXEDDB ||
...@@ -963,19 +991,17 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread( ...@@ -963,19 +991,17 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
} }
#endif // BUILDFLAG(ENABLE_PLUGINS) #endif // BUILDFLAG(ENABLE_PLUGINS)
DecrementTaskCountOnUI(); DecrementTaskCount();
} }
void StoragePartitionImpl::ClearDataForOrigin( void StoragePartitionImpl::ClearDataForOrigin(
uint32_t remove_mask, uint32_t remove_mask,
uint32_t quota_storage_remove_mask, uint32_t quota_storage_remove_mask,
const GURL& storage_origin, const GURL& storage_origin) {
net::URLRequestContextGetter* request_context_getter) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
ClearDataImpl(remove_mask, quota_storage_remove_mask, storage_origin, ClearDataImpl(remove_mask, quota_storage_remove_mask, storage_origin,
OriginMatcherFunction(), CookieMatcherFunction(), OriginMatcherFunction(), CookieMatcherFunction(), base::Time(),
request_context_getter, base::Time(), base::Time::Max(), base::Time::Max(), base::BindOnce(&base::DoNothing));
base::Bind(&base::DoNothing));
} }
void StoragePartitionImpl::ClearData( void StoragePartitionImpl::ClearData(
...@@ -987,8 +1013,8 @@ void StoragePartitionImpl::ClearData( ...@@ -987,8 +1013,8 @@ void StoragePartitionImpl::ClearData(
const base::Time end, const base::Time end,
base::OnceClosure callback) { base::OnceClosure callback) {
ClearDataImpl(remove_mask, quota_storage_remove_mask, storage_origin, ClearDataImpl(remove_mask, quota_storage_remove_mask, storage_origin,
origin_matcher, CookieMatcherFunction(), GetURLRequestContext(), origin_matcher, CookieMatcherFunction(), begin, end,
begin, end, std::move(callback)); std::move(callback));
} }
void StoragePartitionImpl::ClearData( void StoragePartitionImpl::ClearData(
...@@ -1000,8 +1026,7 @@ void StoragePartitionImpl::ClearData( ...@@ -1000,8 +1026,7 @@ void StoragePartitionImpl::ClearData(
const base::Time end, const base::Time end,
base::OnceClosure callback) { base::OnceClosure callback) {
ClearDataImpl(remove_mask, quota_storage_remove_mask, GURL(), origin_matcher, ClearDataImpl(remove_mask, quota_storage_remove_mask, GURL(), origin_matcher,
cookie_matcher, GetURLRequestContext(), begin, end, cookie_matcher, begin, end, std::move(callback));
std::move(callback));
} }
void StoragePartitionImpl::ClearHttpAndMediaCaches( void StoragePartitionImpl::ClearHttpAndMediaCaches(
......
...@@ -93,11 +93,9 @@ class CONTENT_EXPORT StoragePartitionImpl ...@@ -93,11 +93,9 @@ class CONTENT_EXPORT StoragePartitionImpl
ZoomLevelDelegate* GetZoomLevelDelegate() override; ZoomLevelDelegate* GetZoomLevelDelegate() override;
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
PlatformNotificationContextImpl* GetPlatformNotificationContext() override; PlatformNotificationContextImpl* GetPlatformNotificationContext() override;
void ClearDataForOrigin( void ClearDataForOrigin(uint32_t remove_mask,
uint32_t remove_mask,
uint32_t quota_storage_remove_mask, uint32_t quota_storage_remove_mask,
const GURL& storage_origin, const GURL& storage_origin) override;
net::URLRequestContextGetter* request_context_getter) override;
void ClearData(uint32_t remove_mask, void ClearData(uint32_t remove_mask,
uint32_t quota_storage_remove_mask, uint32_t quota_storage_remove_mask,
const GURL& storage_origin, const GURL& storage_origin,
...@@ -217,7 +215,6 @@ class CONTENT_EXPORT StoragePartitionImpl ...@@ -217,7 +215,6 @@ class CONTENT_EXPORT StoragePartitionImpl
const GURL& remove_origin, const GURL& remove_origin,
const OriginMatcherFunction& origin_matcher, const OriginMatcherFunction& origin_matcher,
const CookieMatcherFunction& cookie_matcher, const CookieMatcherFunction& cookie_matcher,
net::URLRequestContextGetter* rq_context,
const base::Time begin, const base::Time begin,
const base::Time end, const base::Time end,
base::OnceClosure callback); base::OnceClosure callback);
......
...@@ -128,8 +128,7 @@ class CONTENT_EXPORT StoragePartition { ...@@ -128,8 +128,7 @@ class CONTENT_EXPORT StoragePartition {
// is fixed. // is fixed.
virtual void ClearDataForOrigin(uint32_t remove_mask, virtual void ClearDataForOrigin(uint32_t remove_mask,
uint32_t quota_storage_remove_mask, uint32_t quota_storage_remove_mask,
const GURL& storage_origin, const GURL& storage_origin) = 0;
net::URLRequestContextGetter* rq_context) = 0;
// A callback type to check if a given origin matches a storage policy. // A callback type to check if a given origin matches a storage policy.
// Can be passed empty/null where used, which means the origin will always // Can be passed empty/null where used, which means the origin will always
......
...@@ -85,8 +85,7 @@ ZoomLevelDelegate* TestStoragePartition::GetZoomLevelDelegate() { ...@@ -85,8 +85,7 @@ ZoomLevelDelegate* TestStoragePartition::GetZoomLevelDelegate() {
void TestStoragePartition::ClearDataForOrigin( void TestStoragePartition::ClearDataForOrigin(
uint32_t remove_mask, uint32_t remove_mask,
uint32_t quota_storage_remove_mask, uint32_t quota_storage_remove_mask,
const GURL& storage_origin, const GURL& storage_origin) {}
net::URLRequestContextGetter* rq_context) {}
void TestStoragePartition::ClearData( void TestStoragePartition::ClearData(
uint32_t remove_mask, uint32_t remove_mask,
......
...@@ -126,8 +126,7 @@ class TestStoragePartition : public StoragePartition { ...@@ -126,8 +126,7 @@ class TestStoragePartition : public StoragePartition {
void ClearDataForOrigin(uint32_t remove_mask, void ClearDataForOrigin(uint32_t remove_mask,
uint32_t quota_storage_remove_mask, uint32_t quota_storage_remove_mask,
const GURL& storage_origin, const GURL& storage_origin) override;
net::URLRequestContextGetter* rq_context) override;
void ClearData(uint32_t remove_mask, void ClearData(uint32_t remove_mask,
uint32_t quota_storage_remove_mask, uint32_t quota_storage_remove_mask,
......
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