| 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..9512be685b48d3dbd7e1e4a6971be0b4f6723958 100644
|
| --- a/chrome/browser/browsing_data_remover.cc
|
| +++ b/chrome/browser/browsing_data_remover.cc
|
| @@ -9,6 +9,7 @@
|
|
|
| #include "base/callback.h"
|
| #include "base/file_util.h"
|
| +#include "base/logging.h"
|
| #include "base/platform_file.h"
|
| #include "chrome/browser/autofill/personal_data_manager.h"
|
| #include "chrome/browser/browser_process.h"
|
| @@ -44,11 +45,8 @@
|
| #include "net/http/http_cache.h"
|
| #include "net/url_request/url_request_context.h"
|
| #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_manager.h"
|
| +#include "webkit/quota/quota_types.h"
|
|
|
| // Done so that we can use PostTask on BrowsingDataRemovers and not have
|
| // BrowsingDataRemover implement RefCounted.
|
| @@ -60,29 +58,21 @@ 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),
|
| - ALLOW_THIS_IN_INITIALIZER_LIST(database_cleared_callback_(
|
| - 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_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) {
|
| + waiting_for_clear_lso_data_(false) {
|
| DCHECK(profile);
|
| }
|
|
|
| @@ -90,30 +80,21 @@ 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),
|
| - ALLOW_THIS_IN_INITIALIZER_LIST(database_cleared_callback_(
|
| - 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_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) {
|
| + waiting_for_clear_lso_data_(false) {
|
| DCHECK(profile);
|
| }
|
|
|
| @@ -215,41 +196,18 @@ void BrowsingDataRemover::Remove(int remove_mask) {
|
| profile_->GetWebKitContext()->DeleteDataModifiedSince(delete_begin_);
|
| }
|
|
|
| - database_tracker_ = profile_->GetDatabaseTracker();
|
| - if (database_tracker_.get()) {
|
| - waiting_for_clear_databases_ = true;
|
| - BrowserThread::PostTask(
|
| - BrowserThread::FILE, FROM_HERE,
|
| - NewRunnableMethod(
|
| - this,
|
| - &BrowsingDataRemover::ClearDatabasesOnFILEThread));
|
| - }
|
| -
|
| - appcache_service_ = profile_->GetAppCacheService();
|
| - if (appcache_service_.get()) {
|
| - waiting_for_clear_appcache_ = 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_quota_managed_data_ = true;
|
| BrowserThread::PostTask(
|
| BrowserThread::IO, FROM_HERE,
|
| NewRunnableMethod(
|
| this,
|
| - &BrowsingDataRemover::ClearAppCacheOnIOThread));
|
| + &BrowsingDataRemover::ClearQuotaManagedDataOnIOThread));
|
| }
|
|
|
| - waiting_for_clear_gears_data_ = true;
|
| - BrowserThread::PostTask(
|
| - BrowserThread::FILE, FROM_HERE,
|
| - NewRunnableMethod(
|
| - this,
|
| - &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,
|
| @@ -490,142 +448,104 @@ void BrowsingDataRemover::DoClearCache(int rv) {
|
| }
|
| }
|
|
|
| -void BrowsingDataRemover::OnClearedDatabases(int rv) {
|
| - if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
|
| - bool result = BrowserThread::PostTask(
|
| - BrowserThread::UI, FROM_HERE,
|
| - NewRunnableMethod(this, &BrowsingDataRemover::OnClearedDatabases, rv));
|
| - DCHECK(result);
|
| - return;
|
| +void BrowsingDataRemover::ClearQuotaManagedDataOnIOThread() {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + DCHECK(waiting_for_clear_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().
|
| + quota_managed_origins_to_delete_count_ = 0;
|
| + quota_managed_storage_types_to_delete_count_ = 2;
|
| +
|
| + if (delete_begin_ == base::Time()) {
|
| + // 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.
|
| + profile_->GetQuotaManager()->GetOriginsModifiedSince(
|
| + quota::kStorageTypePersistent, delete_begin_, NewCallback(this,
|
| + &BrowsingDataRemover::OnGotPersistentQuotaManagedOrigins));
|
| + } else {
|
| + // Otherwise, we don't need to deal with persistent storage.
|
| + --quota_managed_storage_types_to_delete_count_;
|
| }
|
| - // Notify the UI thread that we are done.
|
| - database_tracker_ = NULL;
|
| - waiting_for_clear_databases_ = false;
|
| -
|
| - NotifyAndDeleteIfDone();
|
| -}
|
| -
|
| -void BrowsingDataRemover::ClearDatabasesOnFILEThread() {
|
| - // This function should be called on the FILE thread.
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| - int rv = database_tracker_->DeleteDataModifiedSince(
|
| - delete_begin_, &database_cleared_callback_);
|
| - if (rv != net::ERR_IO_PENDING)
|
| - 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;
|
| - }
|
| - waiting_for_clear_appcache_ = false;
|
| - NotifyAndDeleteIfDone();
|
| + // Do the same for temporary quota, regardless, passing the resulting set into
|
| + // OnGotTemporaryQuotaManagedOrigins.
|
| + profile_->GetQuotaManager()->GetOriginsModifiedSince(
|
| + quota::kStorageTypeTemporary, delete_begin_, NewCallback(this,
|
| + &BrowsingDataRemover::OnGotTemporaryQuotaManagedOrigins));
|
| }
|
|
|
| -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.
|
| -}
|
| -
|
| -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) {
|
| + DCHECK_GT(quota_managed_storage_types_to_delete_count_, 0);
|
| + // 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_);
|
| - }
|
| - }
|
| + ++quota_managed_origins_to_delete_count_;
|
| + quota_manager_->DeleteOriginData(origin->GetOrigin(),
|
| + quota::kStorageTypeTemporary, NewCallback(this,
|
| + &BrowsingDataRemover::OnQuotaManagedOriginDeletion));
|
| }
|
|
|
| - if (!appcaches_to_be_deleted_count_)
|
| - OnClearedAppCache();
|
| - // else continues in OnAppCacheDeleted
|
| + --quota_managed_storage_types_to_delete_count_;
|
| + if (quota_managed_storage_types_to_delete_count_ == 0 &&
|
| + quota_managed_origins_to_delete_count_ == 0)
|
| + CheckQuotaManagedDataDeletionStatus();
|
| }
|
|
|
| -void BrowsingDataRemover::OnAppCacheDeleted(int rv) {
|
| - --appcaches_to_be_deleted_count_;
|
| - if (!appcaches_to_be_deleted_count_)
|
| - OnClearedAppCache();
|
| -}
|
| -
|
| -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))
|
| +void BrowsingDataRemover::OnGotPersistentQuotaManagedOrigins(
|
| + const std::set<GURL>& origins) {
|
| + DCHECK_GT(quota_managed_storage_types_to_delete_count_, 0);
|
| + // Walk through the origins passed in, delete persistent 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;
|
| - 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
|
| + ++quota_managed_origins_to_delete_count_;
|
| + quota_manager_->DeleteOriginData(origin->GetOrigin(),
|
| + quota::kStorageTypePersistent, NewCallback(this,
|
| + &BrowsingDataRemover::OnQuotaManagedOriginDeletion));
|
| }
|
|
|
| - BrowserThread::PostTask(
|
| - BrowserThread::UI, FROM_HERE,
|
| - NewRunnableMethod(this, &BrowsingDataRemover::OnClearedFileSystems));
|
| -}
|
| -
|
| -void BrowsingDataRemover::OnClearedFileSystems() {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - waiting_for_clear_file_systems_ = false;
|
| - NotifyAndDeleteIfDone();
|
| -}
|
| -
|
| -// static
|
| -void BrowsingDataRemover::ClearGearsData(const FilePath& profile_dir) {
|
| - FilePath plugin_data = profile_dir.AppendASCII("Plugin Data");
|
| - if (file_util::DirectoryExists(plugin_data))
|
| - file_util::Delete(plugin_data, true);
|
| + --quota_managed_storage_types_to_delete_count_;
|
| + if (quota_managed_storage_types_to_delete_count_ == 0 &&
|
| + quota_managed_origins_to_delete_count_ == 0)
|
| + CheckQuotaManagedDataDeletionStatus();
|
| }
|
|
|
| -void BrowsingDataRemover::OnClearedGearsData() {
|
| - if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
|
| - bool result = BrowserThread::PostTask(
|
| - BrowserThread::UI, FROM_HERE,
|
| - NewRunnableMethod(this, &BrowsingDataRemover::OnClearedGearsData));
|
| - DCHECK(result);
|
| - return;
|
| +void BrowsingDataRemover::OnQuotaManagedOriginDeletion(
|
| + quota::QuotaStatusCode status) {
|
| + DCHECK_GT(quota_managed_origins_to_delete_count_, 0);
|
| + if (status != quota::kQuotaStatusOk) {
|
| + // TODO(mkwst): We should add the GURL to StatusCallback; this is a pretty
|
| + // worthless error message otherwise.
|
| + DLOG(ERROR) << "Couldn't remove origin. Status: " << status;
|
| }
|
| - waiting_for_clear_gears_data_ = false;
|
| - NotifyAndDeleteIfDone();
|
| +
|
| + --quota_managed_origins_to_delete_count_;
|
| + if (quota_managed_storage_types_to_delete_count_ == 0 &&
|
| + quota_managed_origins_to_delete_count_ == 0)
|
| + CheckQuotaManagedDataDeletionStatus();
|
| }
|
|
|
| -void BrowsingDataRemover::ClearGearsDataOnFILEThread(
|
| - const FilePath& profile_dir) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| - DCHECK(waiting_for_clear_gears_data_);
|
| +void BrowsingDataRemover::CheckQuotaManagedDataDeletionStatus() {
|
| + DCHECK_EQ(quota_managed_origins_to_delete_count_, 0);
|
| + DCHECK_EQ(quota_managed_storage_types_to_delete_count_, 0);
|
| + DCHECK(waiting_for_clear_quota_managed_data_);
|
|
|
| - ClearGearsData(profile_dir);
|
| - OnClearedGearsData();
|
| + waiting_for_clear_quota_managed_data_ = false;
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI, FROM_HERE,
|
| + NewRunnableMethod(
|
| + this,
|
| + &BrowsingDataRemover::NotifyAndDeleteIfDone));
|
| }
|
|
|
| void BrowsingDataRemover::OnWaitableEventSignaled(
|
|
|