Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2701)

Unified Diff: chrome/browser/browsing_data/browsing_data_remover.cc

Issue 1033013003: Refactor http cache removing from a StoragePartition into separate class: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/browsing_data/browsing_data_remover.cc
diff --git a/chrome/browser/browsing_data/browsing_data_remover.cc b/chrome/browser/browsing_data/browsing_data_remover.cc
index 3d7bd207c0d6b67091649f96e5ae059118f334c0..1539390533a6e305ecdf71e768859084844bb350 100644
--- a/chrome/browser/browsing_data/browsing_data_remover.cc
+++ b/chrome/browser/browsing_data/browsing_data_remover.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browsing_data/browsing_data_helper.h"
+#include "chrome/browser/browsing_data/storage_partition_http_cache_data_remover.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/domain_reliability/service_factory.h"
#include "chrome/browser/download/download_prefs.h"
@@ -54,28 +55,20 @@
#include "components/search_engines/template_url_service.h"
#include "components/web_cache/browser/web_cache_manager.h"
#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/dom_storage_context.h"
#include "content/public/browser/download_manager.h"
-#include "content/public/browser/local_storage_usage_info.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/plugin_data_remover.h"
-#include "content/public/browser/session_storage_usage_info.h"
#include "content/public/browser/ssl_host_state_delegate.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/user_metrics.h"
#include "net/base/net_errors.h"
-#include "net/base/sdch_manager.h"
#include "net/cookies/cookie_store.h"
-#include "net/disk_cache/disk_cache.h"
-#include "net/http/http_cache.h"
#include "net/http/transport_security_state.h"
#include "net/ssl/channel_id_service.h"
#include "net/ssl/channel_id_store.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
-#include "storage/browser/quota/quota_manager.h"
#include "storage/browser/quota/special_storage_policy.h"
-#include "storage/common/quota/quota_types.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/profiles/profile_helper.h"
@@ -208,8 +201,6 @@ BrowsingDataRemover::BrowsingDataRemover(Profile* profile,
: profile_(profile),
delete_begin_(delete_begin),
delete_end_(delete_end),
- next_cache_state_(STATE_NONE),
- cache_(NULL),
main_context_getter_(profile->GetRequestContext()),
media_context_getter_(profile->GetMediaRequestContext()),
deauthorize_content_licenses_request_id_(0),
@@ -614,14 +605,15 @@ void BrowsingDataRemover::RemoveImpl(int remove_mask,
// Tell the renderers to clear their cache.
web_cache::WebCacheManager::GetInstance()->ClearCache();
- // Invoke DoClearCache on the IO thread.
- waiting_for_clear_cache_ = true;
content::RecordAction(UserMetricsAction("ClearBrowsingData_Cache"));
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&BrowsingDataRemover::ClearCacheOnIOThread,
- base::Unretained(this)));
+ waiting_for_clear_cache_ = true;
+ // StoragePartitionHttpCacheDataRemover deletes itself when it is done.
+ StoragePartitionHttpCacheDataRemover::CreateForRange(
+ BrowserContext::GetDefaultStoragePartition(profile_), delete_begin_,
+ delete_end_)
+ ->Remove(base::Bind(&BrowsingDataRemover::ClearedCache,
+ base::Unretained(this)));
#if !defined(DISABLE_NACL)
waiting_for_clear_nacl_cache_ = true;
@@ -963,98 +955,6 @@ void BrowsingDataRemover::ClearedCache() {
NotifyAndDeleteIfDone();
}
-void BrowsingDataRemover::ClearCacheOnIOThread() {
- // This function should be called on the IO thread.
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- DCHECK_EQ(STATE_NONE, next_cache_state_);
- DCHECK(main_context_getter_.get());
- DCHECK(media_context_getter_.get());
-
- next_cache_state_ = STATE_CREATE_MAIN;
- DoClearCache(net::OK);
-}
-
-// The expected state sequence is STATE_NONE --> STATE_CREATE_MAIN -->
-// STATE_DELETE_MAIN --> STATE_CREATE_MEDIA --> STATE_DELETE_MEDIA -->
-// STATE_DONE, and any errors are ignored.
-void BrowsingDataRemover::DoClearCache(int rv) {
- DCHECK_NE(STATE_NONE, next_cache_state_);
-
- while (rv != net::ERR_IO_PENDING && next_cache_state_ != STATE_NONE) {
- switch (next_cache_state_) {
- case STATE_CREATE_MAIN:
- case STATE_CREATE_MEDIA: {
- // Get a pointer to the cache.
- net::URLRequestContextGetter* getter =
- (next_cache_state_ == STATE_CREATE_MAIN)
- ? main_context_getter_.get()
- : media_context_getter_.get();
- net::HttpCache* http_cache =
- getter->GetURLRequestContext()->http_transaction_factory()->
- GetCache();
-
- next_cache_state_ = (next_cache_state_ == STATE_CREATE_MAIN) ?
- STATE_DELETE_MAIN : STATE_DELETE_MEDIA;
-
- // Clear QUIC server information from memory and the disk cache.
- http_cache->GetSession()->quic_stream_factory()->
- ClearCachedStatesInCryptoConfig();
-
- // Clear SDCH dictionary state.
- net::SdchManager* sdch_manager =
- getter->GetURLRequestContext()->sdch_manager();
- // The test is probably overkill, since chrome should always have an
- // SdchManager. But in general the URLRequestContext is *not*
- // guaranteed to have an SdchManager, so checking is wise.
- if (sdch_manager)
- sdch_manager->ClearData();
-
- rv = http_cache->GetBackend(
- &cache_, base::Bind(&BrowsingDataRemover::DoClearCache,
- base::Unretained(this)));
- break;
- }
- case STATE_DELETE_MAIN:
- case STATE_DELETE_MEDIA: {
- next_cache_state_ = (next_cache_state_ == STATE_DELETE_MAIN) ?
- STATE_CREATE_MEDIA : STATE_DONE;
-
- // |cache_| can be null if it cannot be initialized.
- if (cache_) {
- if (delete_begin_.is_null()) {
- rv = cache_->DoomAllEntries(
- base::Bind(&BrowsingDataRemover::DoClearCache,
- base::Unretained(this)));
- } else {
- rv = cache_->DoomEntriesBetween(
- delete_begin_, delete_end_,
- base::Bind(&BrowsingDataRemover::DoClearCache,
- base::Unretained(this)));
- }
- cache_ = NULL;
- }
- break;
- }
- case STATE_DONE: {
- cache_ = NULL;
- next_cache_state_ = STATE_NONE;
-
- // Notify the UI thread that we are done.
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&BrowsingDataRemover::ClearedCache,
- base::Unretained(this)));
- return;
- }
- default: {
- NOTREACHED() << "bad state";
- next_cache_state_ = STATE_NONE; // Stop looping.
- return;
- }
- }
- }
-}
-
#if !defined(DISABLE_NACL)
void BrowsingDataRemover::ClearedNaClCache() {
// This function should be called on the UI thread.

Powered by Google App Engine
This is Rietveld 408576698