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) { ...@@ -207,14 +207,16 @@ void AwQuotaManagerBridgeImpl::DeleteAllData(JNIEnv* env, jobject object) {
void AwQuotaManagerBridgeImpl::DeleteAllDataOnUiThread() { void AwQuotaManagerBridgeImpl::DeleteAllDataOnUiThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
GetStoragePartition()->ClearDataForUnboundedRange( GetStoragePartition()->ClearData(
// Clear all web storage data except cookies. // Clear all web storage data except cookies.
StoragePartition::REMOVE_DATA_MASK_APPCACHE | StoragePartition::REMOVE_DATA_MASK_APPCACHE |
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_LOCAL_STORAGE | StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE |
StoragePartition::REMOVE_DATA_MASK_WEBSQL, 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( void AwQuotaManagerBridgeImpl::DeleteOrigin(
......
...@@ -29,6 +29,7 @@ class Profile; ...@@ -29,6 +29,7 @@ class Profile;
namespace content { namespace content {
class PluginDataRemover; class PluginDataRemover;
class StoragePartition;
} }
namespace disk_cache { namespace disk_cache {
...@@ -158,10 +159,6 @@ class BrowsingDataRemover ...@@ -158,10 +159,6 @@ class BrowsingDataRemover
// Calculate the begin time for the deletion range specified by |time_period|. // Calculate the begin time for the deletion range specified by |time_period|.
static base::Time CalculateBeginDeleteTime(TimePeriod 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? // Is the BrowsingDataRemover currently in the process of removing data?
static bool is_removing() { return is_removing_; } static bool is_removing() { return is_removing_; }
...@@ -176,7 +173,8 @@ class BrowsingDataRemover ...@@ -176,7 +173,8 @@ class BrowsingDataRemover
void OnHistoryDeletionDone(); void OnHistoryDeletionDone();
// Used for testing. // Used for testing.
void OverrideQuotaManagerForTesting(quota::QuotaManager* quota_manager); void OverrideStoragePartitionForTesting(
content::StoragePartition* storage_partition);
private: private:
// The clear API needs to be able to toggle removing_ in order to test that // The clear API needs to be able to toggle removing_ in order to test that
...@@ -305,44 +303,6 @@ class BrowsingDataRemover ...@@ -305,44 +303,6 @@ class BrowsingDataRemover
void ClearPnaclCacheOnIOThread(base::Time begin, base::Time end); void ClearPnaclCacheOnIOThread(base::Time begin, base::Time end);
#endif #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. // Callback for when Cookies has been deleted. Invokes NotifyAndDeleteIfDone.
void OnClearedCookies(int num_deleted); void OnClearedCookies(int num_deleted);
...@@ -369,15 +329,9 @@ class BrowsingDataRemover ...@@ -369,15 +329,9 @@ class BrowsingDataRemover
// been deleted. // been deleted.
void OnClearedAutofillOriginURLs(); 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. // Callback on UI thread when the storage partition related data are cleared.
void ClearShaderCacheOnUIThread(); void OnClearedStoragePartitionData();
// Callback on UI thread when the WebRTC identities are cleared.
void OnClearWebRTCIdentityStore();
// Returns true if we're all done. // Returns true if we're all done.
bool AllDone(); bool AllDone();
...@@ -385,13 +339,6 @@ class BrowsingDataRemover ...@@ -385,13 +339,6 @@ class BrowsingDataRemover
// Profile we're to remove from. // Profile we're to remove from.
Profile* profile_; 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. // 'Protected' origins are not subject to data removal.
scoped_refptr<ExtensionSpecialStoragePolicy> special_storage_policy_; scoped_refptr<ExtensionSpecialStoragePolicy> special_storage_policy_;
...@@ -431,25 +378,16 @@ class BrowsingDataRemover ...@@ -431,25 +378,16 @@ class BrowsingDataRemover
bool waiting_for_clear_form_; bool waiting_for_clear_form_;
bool waiting_for_clear_history_; bool waiting_for_clear_history_;
bool waiting_for_clear_hostname_resolution_cache_; 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_logged_in_predictor_;
bool waiting_for_clear_nacl_cache_; bool waiting_for_clear_nacl_cache_;
bool waiting_for_clear_network_predictor_; bool waiting_for_clear_network_predictor_;
bool waiting_for_clear_networking_history_; bool waiting_for_clear_networking_history_;
bool waiting_for_clear_platform_keys_;
bool waiting_for_clear_plugin_data_; bool waiting_for_clear_plugin_data_;
bool waiting_for_clear_pnacl_cache_; bool waiting_for_clear_pnacl_cache_;
bool waiting_for_clear_quota_managed_data_;
bool waiting_for_clear_server_bound_certs_; bool waiting_for_clear_server_bound_certs_;
bool waiting_for_clear_session_storage_; bool waiting_for_clear_storage_partition_data_;
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_;
// The removal mask for the current removal operation. // The removal mask for the current removal operation.
int remove_mask_; int remove_mask_;
...@@ -467,6 +405,9 @@ class BrowsingDataRemover ...@@ -467,6 +405,9 @@ class BrowsingDataRemover
scoped_ptr<TemplateURLService::Subscription> template_url_sub_; scoped_ptr<TemplateURLService::Subscription> template_url_sub_;
// We do not own this.
content::StoragePartition* storage_partition_for_testing_;
DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover); DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover);
}; };
......
...@@ -439,9 +439,11 @@ bool WebViewGuest::ClearData(const base::Time remove_since, ...@@ -439,9 +439,11 @@ bool WebViewGuest::ClearData(const base::Time remove_since,
if (!partition) if (!partition)
return false; return false;
partition->ClearDataForRange( partition->ClearData(
removal_mask, removal_mask,
content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
NULL,
content::StoragePartition::OriginMatcherFunction(),
remove_since, remove_since,
base::Time::Now(), base::Time::Now(),
callback); callback);
......
This diff is collapsed.
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "content/browser/service_worker/service_worker_context.h" #include "content/browser/service_worker/service_worker_context.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
#include "webkit/browser/quota/special_storage_policy.h"
namespace content { namespace content {
...@@ -22,6 +23,15 @@ class StoragePartitionImpl : public StoragePartition { ...@@ -22,6 +23,15 @@ class StoragePartitionImpl : public StoragePartition {
public: public:
CONTENT_EXPORT virtual ~StoragePartitionImpl(); 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. // StoragePartition interface.
virtual base::FilePath GetPath() OVERRIDE; virtual base::FilePath GetPath() OVERRIDE;
virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE; virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE;
...@@ -38,14 +48,13 @@ class StoragePartitionImpl : public StoragePartition { ...@@ -38,14 +48,13 @@ class StoragePartitionImpl : public StoragePartition {
uint32 quota_storage_remove_mask, uint32 quota_storage_remove_mask,
const GURL& storage_origin, const GURL& storage_origin,
net::URLRequestContextGetter* request_context_getter) OVERRIDE; net::URLRequestContextGetter* request_context_getter) OVERRIDE;
virtual void ClearDataForUnboundedRange( virtual void ClearData(uint32 remove_mask,
uint32 remove_mask, uint32 quota_storage_remove_mask,
uint32 quota_storage_remove_mask) OVERRIDE; const GURL* storage_origin,
virtual void ClearDataForRange(uint32 remove_mask, const OriginMatcherFunction& origin_matcher,
uint32 quota_storage_remove_mask, const base::Time begin,
const base::Time& begin, const base::Time end,
const base::Time& end, const base::Closure& callback) OVERRIDE;
const base::Closure& callback) OVERRIDE;
ServiceWorkerContext* GetServiceWorkerContext(); ServiceWorkerContext* GetServiceWorkerContext();
...@@ -57,6 +66,36 @@ class StoragePartitionImpl : public StoragePartition { ...@@ -57,6 +66,36 @@ class StoragePartitionImpl : public StoragePartition {
private: private:
friend class StoragePartitionImplMap; friend class StoragePartitionImplMap;
FRIEND_TEST_ALL_PREFIXES(StoragePartitionShaderClearTest, ClearShaderCache); 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 // The |partition_path| is the absolute path to the root of this
// StoragePartition's on-disk storage. // StoragePartition's on-disk storage.
...@@ -68,10 +107,6 @@ class StoragePartitionImpl : public StoragePartition { ...@@ -68,10 +107,6 @@ class StoragePartitionImpl : public StoragePartition {
bool in_memory, bool in_memory,
const base::FilePath& profile_path); 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( CONTENT_EXPORT StoragePartitionImpl(
const base::FilePath& partition_path, const base::FilePath& partition_path,
quota::QuotaManager* quota_manager, quota::QuotaManager* quota_manager,
...@@ -81,11 +116,13 @@ class StoragePartitionImpl : public StoragePartition { ...@@ -81,11 +116,13 @@ class StoragePartitionImpl : public StoragePartition {
DOMStorageContextWrapper* dom_storage_context, DOMStorageContextWrapper* dom_storage_context,
IndexedDBContextImpl* indexed_db_context, IndexedDBContextImpl* indexed_db_context,
ServiceWorkerContext* service_worker_context, ServiceWorkerContext* service_worker_context,
WebRTCIdentityStore* webrtc_identity_store); WebRTCIdentityStore* webrtc_identity_store,
quota::SpecialStoragePolicy* special_storage_policy);
void ClearDataImpl(uint32 remove_mask, void ClearDataImpl(uint32 remove_mask,
uint32 quota_storage_remove_mask, uint32 quota_storage_remove_mask,
const GURL& remove_origin, const GURL* remove_origin,
const OriginMatcherFunction& origin_matcher,
net::URLRequestContextGetter* rq_context, net::URLRequestContextGetter* rq_context,
const base::Time begin, const base::Time begin,
const base::Time end, const base::Time end,
...@@ -103,7 +140,8 @@ class StoragePartitionImpl : public StoragePartition { ...@@ -103,7 +140,8 @@ class StoragePartitionImpl : public StoragePartition {
// appropriate time. These should move back into the constructor once // appropriate time. These should move back into the constructor once
// URLRequestContextGetter's lifetime is sorted out. We should also move the // URLRequestContextGetter's lifetime is sorted out. We should also move the
// PostCreateInitialization() out of StoragePartitionImplMap. // PostCreateInitialization() out of StoragePartitionImplMap.
void SetURLRequestContext(net::URLRequestContextGetter* url_request_context); CONTENT_EXPORT void SetURLRequestContext(
net::URLRequestContextGetter* url_request_context);
void SetMediaURLRequestContext( void SetMediaURLRequestContext(
net::URLRequestContextGetter* media_url_request_context); net::URLRequestContextGetter* media_url_request_context);
...@@ -118,6 +156,7 @@ class StoragePartitionImpl : public StoragePartition { ...@@ -118,6 +156,7 @@ class StoragePartitionImpl : public StoragePartition {
scoped_refptr<IndexedDBContextImpl> indexed_db_context_; scoped_refptr<IndexedDBContextImpl> indexed_db_context_;
scoped_refptr<ServiceWorkerContext> service_worker_context_; scoped_refptr<ServiceWorkerContext> service_worker_context_;
scoped_refptr<WebRTCIdentityStore> webrtc_identity_store_; scoped_refptr<WebRTCIdentityStore> webrtc_identity_store_;
scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
DISALLOW_COPY_AND_ASSIGN(StoragePartitionImpl); DISALLOW_COPY_AND_ASSIGN(StoragePartitionImpl);
}; };
......
...@@ -460,11 +460,15 @@ void StoragePartitionImplMap::AsyncObliterate( ...@@ -460,11 +460,15 @@ void StoragePartitionImplMap::AsyncObliterate(
++it) { ++it) {
const StoragePartitionConfig& config = it->first; const StoragePartitionConfig& config = it->first;
if (config.partition_domain == partition_domain) { if (config.partition_domain == partition_domain) {
it->second->ClearDataForUnboundedRange( it->second->ClearData(
// All except shader cache. // All except shader cache.
StoragePartition::REMOVE_DATA_MASK_ALL & StoragePartition::REMOVE_DATA_MASK_ALL &
(~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE), (~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) { if (!config.in_memory) {
paths_to_keep.push_back(it->second->GetPath()); paths_to_keep.push_back(it->second->GetPath());
} }
......
...@@ -26,6 +26,7 @@ class URLRequestContextGetter; ...@@ -26,6 +26,7 @@ class URLRequestContextGetter;
namespace quota { namespace quota {
class QuotaManager; class QuotaManager;
class SpecialStoragePolicy;
} }
namespace webkit_database { namespace webkit_database {
...@@ -97,19 +98,26 @@ class StoragePartition { ...@@ -97,19 +98,26 @@ class StoragePartition {
const GURL& storage_origin, const GURL& storage_origin,
net::URLRequestContextGetter* rq_context) = 0; net::URLRequestContextGetter* rq_context) = 0;
// Similar to ClearDataForOrigin(), but deletes all data out of the // A callback type to check if a given origin matches a storage policy.
// StoragePartition rather than just the data related to this origin. // Can be passed empty/null where used, which means the origin will always
virtual void ClearDataForUnboundedRange(uint32 remove_mask, // match.
uint32 quota_storage_remove_mask) = 0; typedef base::Callback<bool(const GURL&,
quota::SpecialStoragePolicy*)>
// Similar to ClearDataForOrigin(), but deletes all the data out of the OriginMatcherFunction;
// StoragePartion from between the given |begin| and |end| dates rather
// then just the data related to this origin. // Similar to ClearDataForOrigin().
virtual void ClearDataForRange(uint32 remove_mask, // Deletes all data out fo the StoragePartition if |storage_origin| is NULL.
uint32 quota_storage_remove_mask, // |origin_matcher| is present if special storage policy is to be handled,
const base::Time& begin, // otherwise the callback can be null (base::Callback::is_null() == true).
const base::Time& end, // |callback| is called when data deletion is done or at least the deletion is
const base::Closure& callback) = 0; // scheduled.
virtual void ClearData(uint32 remove_mask,
uint32 quota_storage_remove_mask,
const GURL* storage_origin,
const OriginMatcherFunction& origin_matcher,
const base::Time begin,
const base::Time end,
const base::Closure& callback) = 0;
protected: protected:
virtual ~StoragePartition() {} virtual ~StoragePartition() {}
......
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