Commit 88562b51 authored by lazyboy@chromium.org's avatar lazyboy@chromium.org

BrowsingDataRemover, (re)use StoragePartition deletion code.

This CL removes code duplication around storage partition related data removal code from BrowsingDataRemover and re-uses StoragePartition::ClearData* method. 

BUG=180118
Test=

Review URL: https://codereview.chromium.org/37843003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233365 0039d316-1c4b-4281-b951-d872f2087c98
parent 3ca36219
......@@ -207,14 +207,16 @@ void AwQuotaManagerBridgeImpl::DeleteAllData(JNIEnv* env, jobject object) {
void AwQuotaManagerBridgeImpl::DeleteAllDataOnUiThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
GetStoragePartition()->ClearDataForUnboundedRange(
GetStoragePartition()->ClearData(
// Clear all web storage data except cookies.
StoragePartition::REMOVE_DATA_MASK_APPCACHE |
StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
StoragePartition::REMOVE_DATA_MASK_INDEXEDDB |
StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE |
StoragePartition::REMOVE_DATA_MASK_WEBSQL,
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_TEMPORARY);
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_TEMPORARY,
NULL, StoragePartition::OriginMatcherFunction(),
base::Time(), base::Time::Max(), base::Bind(&base::DoNothing));
}
void AwQuotaManagerBridgeImpl::DeleteOrigin(
......
......@@ -29,6 +29,7 @@ class Profile;
namespace content {
class PluginDataRemover;
class StoragePartition;
}
namespace disk_cache {
......@@ -158,10 +159,6 @@ class BrowsingDataRemover
// Calculate the begin time for the deletion range specified by |time_period|.
static base::Time CalculateBeginDeleteTime(TimePeriod time_period);
// Quota managed data uses a different bitmask for types than
// BrowsingDataRemover uses. This method generates that mask.
static int GenerateQuotaClientMask(int remove_mask);
// Is the BrowsingDataRemover currently in the process of removing data?
static bool is_removing() { return is_removing_; }
......@@ -176,7 +173,8 @@ class BrowsingDataRemover
void OnHistoryDeletionDone();
// Used for testing.
void OverrideQuotaManagerForTesting(quota::QuotaManager* quota_manager);
void OverrideStoragePartitionForTesting(
content::StoragePartition* storage_partition);
private:
// The clear API needs to be able to toggle removing_ in order to test that
......@@ -305,44 +303,6 @@ class BrowsingDataRemover
void ClearPnaclCacheOnIOThread(base::Time begin, base::Time end);
#endif
// Invoked on the UI thread to delete local storage.
void ClearLocalStorageOnUIThread();
// Callback to deal with the list gathered in ClearLocalStorageOnUIThread.
void OnGotLocalStorageUsageInfo(
const std::vector<content::LocalStorageUsageInfo>& infos);
// Invoked on the UI thread to delete session storage.
void ClearSessionStorageOnUIThread();
// Callback to deal with the list gathered in ClearSessionStorageOnUIThread.
void OnGotSessionStorageUsageInfo(
const std::vector<content::SessionStorageUsageInfo>& infos);
// Invoked on the IO thread to delete all storage types managed by the quota
// system: AppCache, Databases, FileSystems.
void ClearQuotaManagedDataOnIOThread();
// Callback to respond to QuotaManager::GetOriginsModifiedSince, which is the
// core of 'ClearQuotaManagedDataOnIOThread'.
void OnGotQuotaManagedOrigins(const std::set<GURL>& origins,
quota::StorageType type);
// Callback responding to deletion of a single quota managed origin's
// persistent data
void OnQuotaManagedOriginDeletion(const GURL& origin,
quota::StorageType type,
quota::QuotaStatusCode);
// Called to check whether all temporary and persistent origin data that
// should be deleted has been deleted. If everything's good to go, invokes
// OnQuotaManagedDataDeleted on the UI thread.
void CheckQuotaManagedDataDeletionStatus();
// Completion handler that runs on the UI thread once persistent data has been
// deleted. Updates the waiting flag and invokes NotifyAndDeleteIfDone.
void OnQuotaManagedDataDeleted();
// Callback for when Cookies has been deleted. Invokes NotifyAndDeleteIfDone.
void OnClearedCookies(int num_deleted);
......@@ -369,15 +329,9 @@ class BrowsingDataRemover
// been deleted.
void OnClearedAutofillOriginURLs();
// Callback for when the shader cache has been deleted.
// Invokes NotifyAndDeleteIfDone.
void ClearedShaderCache();
// Invoked on the IO thread to delete from the shader cache.
void ClearShaderCacheOnUIThread();
// Callback on UI thread when the WebRTC identities are cleared.
void OnClearWebRTCIdentityStore();
// Callback on UI thread when the storage partition related data are cleared.
void OnClearedStoragePartitionData();
// Returns true if we're all done.
bool AllDone();
......@@ -385,13 +339,6 @@ class BrowsingDataRemover
// Profile we're to remove from.
Profile* profile_;
// The QuotaManager is owned by the profile; we can use a raw pointer here,
// and rely on the profile to destroy the object whenever it's reasonable.
quota::QuotaManager* quota_manager_;
// The DOMStorageContext is owned by the profile; we'll store a raw pointer.
content::DOMStorageContext* dom_storage_context_;
// 'Protected' origins are not subject to data removal.
scoped_refptr<ExtensionSpecialStoragePolicy> special_storage_policy_;
......@@ -431,25 +378,16 @@ class BrowsingDataRemover
bool waiting_for_clear_form_;
bool waiting_for_clear_history_;
bool waiting_for_clear_hostname_resolution_cache_;
bool waiting_for_clear_local_storage_;
bool waiting_for_clear_keyword_data_;
bool waiting_for_clear_logged_in_predictor_;
bool waiting_for_clear_nacl_cache_;
bool waiting_for_clear_network_predictor_;
bool waiting_for_clear_networking_history_;
bool waiting_for_clear_platform_keys_;
bool waiting_for_clear_plugin_data_;
bool waiting_for_clear_pnacl_cache_;
bool waiting_for_clear_quota_managed_data_;
bool waiting_for_clear_server_bound_certs_;
bool waiting_for_clear_session_storage_;
bool waiting_for_clear_shader_cache_;
bool waiting_for_clear_webrtc_identity_store_;
bool waiting_for_clear_keyword_data_;
bool waiting_for_clear_platform_keys_;
// Tracking how many origins need to be deleted, and whether we're finished
// gathering origins.
int quota_managed_origins_to_delete_count_;
int quota_managed_storage_types_to_delete_count_;
bool waiting_for_clear_storage_partition_data_;
// The removal mask for the current removal operation.
int remove_mask_;
......@@ -467,6 +405,9 @@ class BrowsingDataRemover
scoped_ptr<TemplateURLService::Subscription> template_url_sub_;
// We do not own this.
content::StoragePartition* storage_partition_for_testing_;
DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover);
};
......
......@@ -439,9 +439,11 @@ bool WebViewGuest::ClearData(const base::Time remove_since,
if (!partition)
return false;
partition->ClearDataForRange(
partition->ClearData(
removal_mask,
content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
NULL,
content::StoragePartition::OriginMatcherFunction(),
remove_since,
base::Time::Now(),
callback);
......
This diff is collapsed.
......@@ -15,6 +15,7 @@
#include "content/browser/service_worker/service_worker_context.h"
#include "content/common/content_export.h"
#include "content/public/browser/storage_partition.h"
#include "webkit/browser/quota/special_storage_policy.h"
namespace content {
......@@ -22,6 +23,15 @@ class StoragePartitionImpl : public StoragePartition {
public:
CONTENT_EXPORT virtual ~StoragePartitionImpl();
// Quota managed data uses a different bitmask for types than
// StoragePartition uses. This method generates that mask.
CONTENT_EXPORT static int GenerateQuotaClientMask(uint32 remove_mask);
CONTENT_EXPORT void OverrideQuotaManagerForTesting(
quota::QuotaManager* quota_manager);
CONTENT_EXPORT void OverrideSpecialStoragePolicyForTesting(
quota::SpecialStoragePolicy* special_storage_policy);
// StoragePartition interface.
virtual base::FilePath GetPath() OVERRIDE;
virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE;
......@@ -38,13 +48,12 @@ class StoragePartitionImpl : public StoragePartition {
uint32 quota_storage_remove_mask,
const GURL& storage_origin,
net::URLRequestContextGetter* request_context_getter) OVERRIDE;
virtual void ClearDataForUnboundedRange(
uint32 remove_mask,
uint32 quota_storage_remove_mask) OVERRIDE;
virtual void ClearDataForRange(uint32 remove_mask,
virtual void ClearData(uint32 remove_mask,
uint32 quota_storage_remove_mask,
const base::Time& begin,
const base::Time& end,
const GURL* storage_origin,
const OriginMatcherFunction& origin_matcher,
const base::Time begin,
const base::Time end,
const base::Closure& callback) OVERRIDE;
ServiceWorkerContext* GetServiceWorkerContext();
......@@ -57,6 +66,36 @@ class StoragePartitionImpl : public StoragePartition {
private:
friend class StoragePartitionImplMap;
FRIEND_TEST_ALL_PREFIXES(StoragePartitionShaderClearTest, ClearShaderCache);
FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
RemoveQuotaManagedDataForeverBoth);
FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
RemoveQuotaManagedDataForeverOnlyTemporary);
FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
RemoveQuotaManagedDataForeverOnlyPersistent);
FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
RemoveQuotaManagedDataForeverNeither);
FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
RemoveQuotaManagedDataForeverSpecificOrigin);
FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
RemoveQuotaManagedDataForLastHour);
FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
RemoveQuotaManagedDataForLastWeek);
FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
RemoveQuotaManagedUnprotectedOrigins);
FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
RemoveQuotaManagedProtectedSpecificOrigin);
FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
RemoveQuotaManagedProtectedOrigins);
FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
RemoveQuotaManagedIgnoreDevTools);
FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, RemoveCookieForever);
FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, RemoveCookieLastHour);
FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
RemoveUnprotectedLocalStorageForever);
FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
RemoveProtectedLocalStorageForever);
FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
RemoveLocalStorageForLastWeek);
// The |partition_path| is the absolute path to the root of this
// StoragePartition's on-disk storage.
......@@ -68,10 +107,6 @@ class StoragePartitionImpl : public StoragePartition {
bool in_memory,
const base::FilePath& profile_path);
// Quota managed data uses a different bitmask for types than
// StoragePartition uses. This method generates that mask.
static int GenerateQuotaClientMask(uint32 remove_mask);
CONTENT_EXPORT StoragePartitionImpl(
const base::FilePath& partition_path,
quota::QuotaManager* quota_manager,
......@@ -81,11 +116,13 @@ class StoragePartitionImpl : public StoragePartition {
DOMStorageContextWrapper* dom_storage_context,
IndexedDBContextImpl* indexed_db_context,
ServiceWorkerContext* service_worker_context,
WebRTCIdentityStore* webrtc_identity_store);
WebRTCIdentityStore* webrtc_identity_store,
quota::SpecialStoragePolicy* special_storage_policy);
void ClearDataImpl(uint32 remove_mask,
uint32 quota_storage_remove_mask,
const GURL& remove_origin,
const GURL* remove_origin,
const OriginMatcherFunction& origin_matcher,
net::URLRequestContextGetter* rq_context,
const base::Time begin,
const base::Time end,
......@@ -103,7 +140,8 @@ class StoragePartitionImpl : public StoragePartition {
// appropriate time. These should move back into the constructor once
// URLRequestContextGetter's lifetime is sorted out. We should also move the
// PostCreateInitialization() out of StoragePartitionImplMap.
void SetURLRequestContext(net::URLRequestContextGetter* url_request_context);
CONTENT_EXPORT void SetURLRequestContext(
net::URLRequestContextGetter* url_request_context);
void SetMediaURLRequestContext(
net::URLRequestContextGetter* media_url_request_context);
......@@ -118,6 +156,7 @@ class StoragePartitionImpl : public StoragePartition {
scoped_refptr<IndexedDBContextImpl> indexed_db_context_;
scoped_refptr<ServiceWorkerContext> service_worker_context_;
scoped_refptr<WebRTCIdentityStore> webrtc_identity_store_;
scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
DISALLOW_COPY_AND_ASSIGN(StoragePartitionImpl);
};
......
......@@ -460,11 +460,15 @@ void StoragePartitionImplMap::AsyncObliterate(
++it) {
const StoragePartitionConfig& config = it->first;
if (config.partition_domain == partition_domain) {
it->second->ClearDataForUnboundedRange(
it->second->ClearData(
// All except shader cache.
StoragePartition::REMOVE_DATA_MASK_ALL &
(~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE),
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
NULL,
StoragePartition::OriginMatcherFunction(),
base::Time(), base::Time::Max(),
base::Bind(&base::DoNothing));
if (!config.in_memory) {
paths_to_keep.push_back(it->second->GetPath());
}
......
......@@ -26,6 +26,7 @@ class URLRequestContextGetter;
namespace quota {
class QuotaManager;
class SpecialStoragePolicy;
}
namespace webkit_database {
......@@ -97,18 +98,25 @@ class StoragePartition {
const GURL& storage_origin,
net::URLRequestContextGetter* rq_context) = 0;
// Similar to ClearDataForOrigin(), but deletes all data out of the
// StoragePartition rather than just the data related to this origin.
virtual void ClearDataForUnboundedRange(uint32 remove_mask,
uint32 quota_storage_remove_mask) = 0;
// Similar to ClearDataForOrigin(), but deletes all the data out of the
// StoragePartion from between the given |begin| and |end| dates rather
// then just the data related to this origin.
virtual void ClearDataForRange(uint32 remove_mask,
// 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
// match.
typedef base::Callback<bool(const GURL&,
quota::SpecialStoragePolicy*)>
OriginMatcherFunction;
// Similar to ClearDataForOrigin().
// Deletes all data out fo the StoragePartition if |storage_origin| is NULL.
// |origin_matcher| is present if special storage policy is to be handled,
// otherwise the callback can be null (base::Callback::is_null() == true).
// |callback| is called when data deletion is done or at least the deletion is
// scheduled.
virtual void ClearData(uint32 remove_mask,
uint32 quota_storage_remove_mask,
const base::Time& begin,
const base::Time& end,
const GURL* storage_origin,
const OriginMatcherFunction& origin_matcher,
const base::Time begin,
const base::Time end,
const base::Closure& callback) = 0;
protected:
......
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