Index: chrome/browser/browsing_data_remover.cc |
diff --git a/chrome/browser/browsing_data_remover.cc b/chrome/browser/browsing_data_remover.cc |
index 70083fec65abd80c63ab05dcb2768e0dac006baf..f36b51d462692ba8d5456c697921b60094f8970a 100644 |
--- a/chrome/browser/browsing_data_remover.cc |
+++ b/chrome/browser/browsing_data_remover.cc |
@@ -7,6 +7,8 @@ |
#include <map> |
#include <set> |
+#include "base/logging.h" |
jochen (gone - plz use gerrit)
2011/07/26 08:55:33
why separate from the other includes?
Mike West
2011/07/26 12:08:32
I'd intended to remove it before committing, but g
|
+ |
#include "base/callback.h" |
#include "base/file_util.h" |
#include "base/platform_file.h" |
@@ -46,9 +48,8 @@ |
#include "net/url_request/url_request_context_getter.h" |
#include "webkit/database/database_tracker.h" |
#include "webkit/database/database_util.h" |
-#include "webkit/fileapi/file_system_context.h" |
-#include "webkit/fileapi/file_system_operation_context.h" |
-#include "webkit/fileapi/sandbox_mount_point_provider.h" |
+#include "webkit/quota/quota_types.h" |
+#include "webkit/quota/quota_manager.h" |
jochen (gone - plz use gerrit)
2011/07/26 08:55:33
alphabetical ordering
Mike West
2011/07/26 12:08:32
Done.
|
// Done so that we can use PostTask on BrowsingDataRemovers and not have |
// BrowsingDataRemover implement RefCounted. |
@@ -60,6 +61,7 @@ BrowsingDataRemover::BrowsingDataRemover(Profile* profile, |
base::Time delete_begin, |
base::Time delete_end) |
: profile_(profile), |
+ quota_manager_(NULL), |
special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), |
delete_begin_(delete_begin), |
delete_end_(delete_end), |
@@ -67,22 +69,18 @@ BrowsingDataRemover::BrowsingDataRemover(Profile* profile, |
this, &BrowsingDataRemover::OnClearedDatabases)), |
ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( |
this, &BrowsingDataRemover::DoClearCache)), |
- ALLOW_THIS_IN_INITIALIZER_LIST(appcache_got_info_callback_( |
- this, &BrowsingDataRemover::OnGotAppCacheInfo)), |
- ALLOW_THIS_IN_INITIALIZER_LIST(appcache_deleted_callback_( |
- this, &BrowsingDataRemover::OnAppCacheDeleted)), |
- appcaches_to_be_deleted_count_(0), |
next_cache_state_(STATE_NONE), |
cache_(NULL), |
main_context_getter_(profile->GetRequestContext()), |
media_context_getter_(profile->GetRequestContextForMedia()), |
waiting_for_clear_databases_(false), |
waiting_for_clear_history_(false), |
+ waiting_for_clear_temporary_quota_managed_data_(false), |
+ waiting_for_clear_persistent_quota_managed_data_(false), |
waiting_for_clear_networking_history_(false), |
waiting_for_clear_cache_(false), |
- waiting_for_clear_appcache_(false), |
waiting_for_clear_gears_data_(false), |
- waiting_for_clear_file_systems_(false) { |
+ temporary_quota_origins_to_delete_count_(0) { |
DCHECK(profile); |
} |
@@ -90,6 +88,7 @@ BrowsingDataRemover::BrowsingDataRemover(Profile* profile, |
TimePeriod time_period, |
base::Time delete_end) |
: profile_(profile), |
+ quota_manager_(NULL), |
special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), |
delete_begin_(CalculateBeginDeleteTime(time_period)), |
delete_end_(delete_end), |
@@ -97,23 +96,18 @@ BrowsingDataRemover::BrowsingDataRemover(Profile* profile, |
this, &BrowsingDataRemover::OnClearedDatabases)), |
ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( |
this, &BrowsingDataRemover::DoClearCache)), |
- ALLOW_THIS_IN_INITIALIZER_LIST(appcache_got_info_callback_( |
- this, &BrowsingDataRemover::OnGotAppCacheInfo)), |
- ALLOW_THIS_IN_INITIALIZER_LIST(appcache_deleted_callback_( |
- this, &BrowsingDataRemover::OnAppCacheDeleted)), |
- appcaches_to_be_deleted_count_(0), |
next_cache_state_(STATE_NONE), |
cache_(NULL), |
main_context_getter_(profile->GetRequestContext()), |
media_context_getter_(profile->GetRequestContextForMedia()), |
waiting_for_clear_databases_(false), |
waiting_for_clear_history_(false), |
+ waiting_for_clear_temporary_quota_managed_data_(false), |
+ waiting_for_clear_persistent_quota_managed_data_(false), |
waiting_for_clear_networking_history_(false), |
waiting_for_clear_cache_(false), |
- waiting_for_clear_appcache_(false), |
- waiting_for_clear_lso_data_(false), |
waiting_for_clear_gears_data_(false), |
- waiting_for_clear_file_systems_(false) { |
+ temporary_quota_origins_to_delete_count_(0) { |
DCHECK(profile); |
} |
@@ -215,24 +209,27 @@ void BrowsingDataRemover::Remove(int remove_mask) { |
profile_->GetWebKitContext()->DeleteDataModifiedSince(delete_begin_); |
} |
- database_tracker_ = profile_->GetDatabaseTracker(); |
- if (database_tracker_.get()) { |
- waiting_for_clear_databases_ = true; |
+ // We'll start by using the quota system to clear out AppCaches, WebSQL DBs, |
+ // and File Systems. |
+ quota_manager_ = profile_->GetQuotaManager(); |
+ if (quota_manager_) { |
+ waiting_for_clear_temporary_quota_managed_data_ = true; |
+ waiting_for_clear_persistent_quota_managed_data_ = true; |
BrowserThread::PostTask( |
- BrowserThread::FILE, FROM_HERE, |
+ BrowserThread::IO, FROM_HERE, |
NewRunnableMethod( |
this, |
- &BrowsingDataRemover::ClearDatabasesOnFILEThread)); |
+ &BrowsingDataRemover::ClearQuotaManagedDataOnIOThread)); |
} |
- appcache_service_ = profile_->GetAppCacheService(); |
- if (appcache_service_.get()) { |
- waiting_for_clear_appcache_ = true; |
+ database_tracker_ = profile_->GetDatabaseTracker(); |
+ if (database_tracker_.get()) { |
+ waiting_for_clear_databases_ = true; |
BrowserThread::PostTask( |
- BrowserThread::IO, FROM_HERE, |
+ BrowserThread::FILE, FROM_HERE, |
NewRunnableMethod( |
this, |
- &BrowsingDataRemover::ClearAppCacheOnIOThread)); |
+ &BrowsingDataRemover::ClearDatabasesOnFILEThread)); |
} |
waiting_for_clear_gears_data_ = true; |
@@ -243,13 +240,6 @@ void BrowsingDataRemover::Remove(int remove_mask) { |
&BrowsingDataRemover::ClearGearsDataOnFILEThread, |
profile_->GetPath())); |
- waiting_for_clear_file_systems_ = true; |
- BrowserThread::PostTask( |
- BrowserThread::FILE, FROM_HERE, |
- NewRunnableMethod( |
- this, |
- &BrowsingDataRemover::ClearFileSystemsOnFILEThread)); |
- |
if (profile_->GetTransportSecurityState()) { |
BrowserThread::PostTask( |
BrowserThread::IO, FROM_HERE, |
@@ -514,90 +504,115 @@ void BrowsingDataRemover::ClearDatabasesOnFILEThread() { |
OnClearedDatabases(rv); |
} |
-void BrowsingDataRemover::OnClearedAppCache() { |
- if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
- bool result = BrowserThread::PostTask( |
- BrowserThread::UI, FROM_HERE, |
- NewRunnableMethod(this, &BrowsingDataRemover::OnClearedAppCache)); |
- DCHECK(result); |
- return; |
+void BrowsingDataRemover::ClearQuotaManagedDataOnIOThread() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ DCHECK(waiting_for_clear_temporary_quota_managed_data_); |
+ DCHECK(waiting_for_clear_persistent_quota_managed_data_); |
+ |
+ // Ask the QuotaManager for all origins with temporary quota modified within |
+ // the user-specified timeframe, and deal with the resulting set in |
+ // OnGotQuotaManagedOrigins(). |
+ temporary_quota_origins_to_delete_count_ = 0; |
+ persistent_quota_origins_to_delete_count_ = 0; |
+ |
+ // If we're deleting since the beginning of time, ask the QuotaManager for all |
+ // origins with persistent quota modified within the user-specified timeframe, |
+ // and deal with the resulting set in OnGotPersistentQuotaManagedOrigins. |
+ if (delete_begin_ == base::Time()) { |
+// FIXME(mkwst): This is broken. If I run persistent and temp, I get segfaults. |
+// I suspect that my mock sucks. :) |
+ // profile_->GetQuotaManager()->GetOriginsModifiedSince( |
+ // quota::kStorageTypePersistent, delete_begin_, NewCallback(this, |
+ // &BrowsingDataRemover::OnGotPersistentQuotaManagedOrigins)); |
+ waiting_for_clear_persistent_quota_managed_data_ = false; |
+ } else { |
+ // If not deleting since the beginning of time, we're done with any |
+ // persistent quota. |
+ waiting_for_clear_persistent_quota_managed_data_ = false; |
} |
- waiting_for_clear_appcache_ = false; |
- NotifyAndDeleteIfDone(); |
-} |
-void BrowsingDataRemover::ClearAppCacheOnIOThread() { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- DCHECK(waiting_for_clear_appcache_); |
- appcache_info_ = new appcache::AppCacheInfoCollection; |
- appcache_service_->GetAllAppCacheInfo( |
- appcache_info_, &appcache_got_info_callback_); |
- // continues in OnGotAppCacheInfo. |
+ // Do the same for temporary quota, regardless. |
+ profile_->GetQuotaManager()->GetOriginsModifiedSince( |
+ quota::kStorageTypeTemporary, delete_begin_, NewCallback(this, |
+ &BrowsingDataRemover::OnGotTemporaryQuotaManagedOrigins)); |
} |
-void BrowsingDataRemover::OnGotAppCacheInfo(int rv) { |
- using appcache::AppCacheInfoVector; |
- typedef std::map<GURL, AppCacheInfoVector> InfoByOrigin; |
- |
- for (InfoByOrigin::const_iterator origin = |
- appcache_info_->infos_by_origin.begin(); |
- origin != appcache_info_->infos_by_origin.end(); ++origin) { |
- if (special_storage_policy_->IsStorageProtected(origin->first)) |
+void BrowsingDataRemover::OnGotTemporaryQuotaManagedOrigins( |
+ const std::set<GURL>& origins) { |
+ // Walk through the origins passed in, delete temporary quota from each that |
+ // isn't protected. |
+ std::set<GURL>::const_iterator origin; |
+ for (origin = origins.begin(); origin != origins.end(); ++origin) { |
+ if (special_storage_policy_->IsStorageProtected(origin->GetOrigin())) |
continue; |
- for (AppCacheInfoVector::const_iterator info = origin->second.begin(); |
- info != origin->second.end(); ++info) { |
- if (info->creation_time > delete_begin_) { |
- ++appcaches_to_be_deleted_count_; |
- appcache_service_->DeleteAppCacheGroup( |
- info->manifest_url, &appcache_deleted_callback_); |
- } |
- } |
+ ++temporary_quota_origins_to_delete_count_; |
+ quota_manager_->DeleteOriginData(origin->GetOrigin(), |
+ quota::kStorageTypeTemporary, NewCallback(this, |
+ &BrowsingDataRemover::OnTemporaryQuotaManagedOriginDeletion)); |
} |
+ CheckTemporaryQuotaManagedDataDeletionStatus(); |
+} |
- if (!appcaches_to_be_deleted_count_) |
- OnClearedAppCache(); |
- // else continues in OnAppCacheDeleted |
+void BrowsingDataRemover::OnGotPersistentQuotaManagedOrigins( |
+ const std::set<GURL>& origins) { |
+ // Walk through the origins passed in, delete temporary quota from each that |
+ // isn't protected. |
+ bool deleting = false; |
+ std::set<GURL>::const_iterator origin; |
+ for (origin = origins.begin(); origin != origins.end(); ++origin) { |
+ if (special_storage_policy_->IsStorageProtected(origin->GetOrigin())) |
+ continue; |
+ deleting = true; |
+ ++persistent_quota_origins_to_delete_count_; |
+ quota_manager_->DeleteOriginData(origin->GetOrigin(), |
+ quota::kStorageTypePersistent, NewCallback(this, |
+ &BrowsingDataRemover::OnPersistentQuotaManagedOriginDeletion)); |
+ } |
+ CheckPersistentQuotaManagedDataDeletionStatus(); |
} |
-void BrowsingDataRemover::OnAppCacheDeleted(int rv) { |
- --appcaches_to_be_deleted_count_; |
- if (!appcaches_to_be_deleted_count_) |
- OnClearedAppCache(); |
+void BrowsingDataRemover::OnTemporaryQuotaManagedOriginDeletion( |
+ quota::QuotaStatusCode status) { |
+ if (status != quota::kQuotaStatusOk) { |
+ // TODO(mkwst): Not really anything pretty I can think of to do here. |
jochen (gone - plz use gerrit)
2011/07/26 08:55:33
DLOG the status at least?
Mike West
2011/07/26 12:08:32
Done. But it's pretty useless to be honest; the ca
|
+ } |
+ |
+ --temporary_quota_origins_to_delete_count_; |
jochen (gone - plz use gerrit)
2011/07/26 08:55:33
DCHECK for >= 0?
Mike West
2011/07/26 12:08:32
Good idea. Done.
|
+ CheckTemporaryQuotaManagedDataDeletionStatus(); |
} |
-void BrowsingDataRemover::ClearFileSystemsOnFILEThread() { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
- DCHECK(waiting_for_clear_file_systems_); |
- scoped_refptr<fileapi::FileSystemContext> |
- fs_context(profile_->GetFileSystemContext()); |
- scoped_ptr<fileapi::SandboxMountPointProvider::OriginEnumerator> |
- origin_enumerator(fs_context->path_manager()->sandbox_provider()-> |
- CreateOriginEnumerator()); |
- |
- GURL origin; |
- while (!(origin = origin_enumerator->Next()).is_empty()) { |
- if (special_storage_policy_->IsStorageProtected(origin)) |
- continue; |
- if (delete_begin_ == base::Time()) { |
- // If the user chooses to delete browsing data "since the beginning of |
- // time" remove both temporary and persistent file systems entirely. |
- fs_context->DeleteDataForOriginAndTypeOnFileThread(origin, |
- fileapi::kFileSystemTypeTemporary); |
- fs_context->DeleteDataForOriginAndTypeOnFileThread(origin, |
- fileapi::kFileSystemTypePersistent); |
- } |
- // TODO(mkwst): Else? Decide what to do for time-based deletion: crbug/63700 |
+void BrowsingDataRemover::OnPersistentQuotaManagedOriginDeletion( |
+ quota::QuotaStatusCode status) { |
+ if (status != quota::kQuotaStatusOk) { |
+ // TODO(mkwst): Not really anything pretty I can think of to do here. |
} |
- BrowserThread::PostTask( |
- BrowserThread::UI, FROM_HERE, |
- NewRunnableMethod(this, &BrowsingDataRemover::OnClearedFileSystems)); |
+ --persistent_quota_origins_to_delete_count_; |
+ CheckPersistentQuotaManagedDataDeletionStatus(); |
} |
-void BrowsingDataRemover::OnClearedFileSystems() { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- waiting_for_clear_file_systems_ = false; |
- NotifyAndDeleteIfDone(); |
+void BrowsingDataRemover::CheckTemporaryQuotaManagedDataDeletionStatus() { |
+ if (temporary_quota_origins_to_delete_count_ == 0 && |
+ waiting_for_clear_temporary_quota_managed_data_) { |
+ waiting_for_clear_temporary_quota_managed_data_ = false; |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, FROM_HERE, |
+ NewRunnableMethod( |
+ this, |
+ &BrowsingDataRemover::NotifyAndDeleteIfDone)); |
+ } |
+} |
+ |
+void BrowsingDataRemover::CheckPersistentQuotaManagedDataDeletionStatus() { |
+ if (persistent_quota_origins_to_delete_count_ == 0 && |
+ waiting_for_clear_persistent_quota_managed_data_) { |
+ waiting_for_clear_persistent_quota_managed_data_ = false; |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, FROM_HERE, |
+ NewRunnableMethod( |
+ this, |
+ &BrowsingDataRemover::NotifyAndDeleteIfDone)); |
+ } |
} |
// static |