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

Unified Diff: components/browsing_data/storage_partition_http_cache_data_remover.cc

Issue 1304363013: Add a size estimation mechanism to StoragePartitionHttpCacheDataRemover. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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: components/browsing_data/storage_partition_http_cache_data_remover.cc
diff --git a/components/browsing_data/storage_partition_http_cache_data_remover.cc b/components/browsing_data/storage_partition_http_cache_data_remover.cc
index c53c0be6409300347be7e76bc47cb98a9f1d1032..f8519fe3a8a1fccadc21836798e43d15006be7b1 100644
--- a/components/browsing_data/storage_partition_http_cache_data_remover.cc
+++ b/components/browsing_data/storage_partition_http_cache_data_remover.cc
@@ -7,7 +7,10 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "net/base/sdch_manager.h"
+#include "net/disk_cache/blockfile/backend_impl.h"
#include "net/disk_cache/disk_cache.h"
+#include "net/disk_cache/memory/mem_backend_impl.h"
+#include "net/disk_cache/simple/simple_backend_impl.h"
#include "net/http/http_cache.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
@@ -26,7 +29,9 @@ StoragePartitionHttpCacheDataRemover::StoragePartitionHttpCacheDataRemover(
main_context_getter_(main_context_getter),
media_context_getter_(media_context_getter),
next_cache_state_(STATE_NONE),
- cache_(nullptr) {
+ cache_(nullptr),
+ count_only_(false),
+ calculation_result_(0) {
}
StoragePartitionHttpCacheDataRemover::~StoragePartitionHttpCacheDataRemover() {
@@ -48,6 +53,22 @@ void StoragePartitionHttpCacheDataRemover::Remove(
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!done_callback.is_null());
done_callback_ = done_callback;
+ count_only_ = false;
+
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(
+ &StoragePartitionHttpCacheDataRemover::ClearHttpCacheOnIOThread,
+ base::Unretained(this)));
+}
+
+void StoragePartitionHttpCacheDataRemover::Count(
+ const net::Int64CompletionCallback& result_callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ DCHECK(!result_callback.is_null());
+ result_callback_ = result_callback;
+ calculation_result_ = 0;
+ count_only_ = true;
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
@@ -69,7 +90,10 @@ void StoragePartitionHttpCacheDataRemover::ClearHttpCacheOnIOThread() {
void StoragePartitionHttpCacheDataRemover::ClearedHttpCache() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- done_callback_.Run();
+ if (count_only_)
+ result_callback_.Run(calculation_result_);
+ else
+ done_callback_.Run();
base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
}
@@ -96,19 +120,21 @@ void StoragePartitionHttpCacheDataRemover::DoClearCache(int rv) {
? 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();
+ if (!count_only_) {
+ // 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_,
@@ -125,14 +151,34 @@ void StoragePartitionHttpCacheDataRemover::DoClearCache(int rv) {
// |cache_| can be null if it cannot be initialized.
if (cache_) {
if (delete_begin_.is_null()) {
- rv = cache_->DoomAllEntries(
- base::Bind(&StoragePartitionHttpCacheDataRemover::DoClearCache,
- base::Unretained(this)));
+ if (count_only_) {
+ // TODO(msramek): Implement analogous |CalculateSizeOfAllEntries|.
+ rv = cache_->CalculateSizeOfEntriesBetween(
+ base::Time(), base::Time::Max(),
+ base::Bind(
+ &StoragePartitionHttpCacheDataRemover::
+ OnCalculationComplete,
+ base::Unretained(this)));
+ } else {
+ rv = cache_->DoomAllEntries(base::Bind(
+ &StoragePartitionHttpCacheDataRemover::DoClearCache,
+ base::Unretained(this)));
+ }
} else {
- rv = cache_->DoomEntriesBetween(
- delete_begin_, delete_end_,
- base::Bind(&StoragePartitionHttpCacheDataRemover::DoClearCache,
- base::Unretained(this)));
+ if (count_only_) {
+ rv = cache_->CalculateSizeOfEntriesBetween(
+ delete_begin_, delete_end_,
+ base::Bind(
+ &StoragePartitionHttpCacheDataRemover::
+ OnCalculationComplete,
+ base::Unretained(this)));
+ } else {
+ rv = cache_->DoomEntriesBetween(
+ delete_begin_, delete_end_,
+ base::Bind(
+ &StoragePartitionHttpCacheDataRemover::DoClearCache,
+ base::Unretained(this)));
+ }
}
cache_ = NULL;
}
@@ -158,4 +204,17 @@ void StoragePartitionHttpCacheDataRemover::DoClearCache(int rv) {
}
}
+void StoragePartitionHttpCacheDataRemover::OnCalculationComplete(int rv) {
+ // If the calculation was successful, add the size to the sum. If it was not,
+ // finish and return the error code.
+ if (rv < 0) {
+ calculation_result_ = rv;
+ next_cache_state_ = STATE_DONE;
+ DoClearCache(rv);
+ } else {
+ calculation_result_ += rv;
+ DoClearCache(net::OK);
+ }
+}
+
} // namespace browsing_data

Powered by Google App Engine
This is Rietveld 408576698