summaryrefslogtreecommitdiffstats
path: root/webkit/appcache/appcache_storage_impl.cc
diff options
context:
space:
mode:
authormichaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-17 22:02:28 +0000
committermichaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-17 22:02:28 +0000
commitfd2885ab79962663f474a39b13cfbfdb4827534e (patch)
tree1ce0e0967d005178a64cf0d4a7e11e16a76fd3d8 /webkit/appcache/appcache_storage_impl.cc
parent9348c1f762db498d399d07c0295e36d75ee7fa08 (diff)
downloadchromium_src-fd2885ab79962663f474a39b13cfbfdb4827534e.zip
chromium_src-fd2885ab79962663f474a39b13cfbfdb4827534e.tar.gz
chromium_src-fd2885ab79962663f474a39b13cfbfdb4827534e.tar.bz2
AppCache: Migrate to the DiskCache's async interface and use the CacheType::APP_CACHE value.
BUG=38273 TEST=existing layout tests and unit tests apply Review URL: http://codereview.chromium.org/886003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41884 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_storage_impl.cc')
-rw-r--r--webkit/appcache/appcache_storage_impl.cc54
1 files changed, 41 insertions, 13 deletions
diff --git a/webkit/appcache/appcache_storage_impl.cc b/webkit/appcache/appcache_storage_impl.cc
index 54afc9a..d700d24c 100644
--- a/webkit/appcache/appcache_storage_impl.cc
+++ b/webkit/appcache/appcache_storage_impl.cc
@@ -815,8 +815,12 @@ AppCacheStorageImpl::AppCacheStorageImpl(AppCacheService* service)
: AppCacheStorage(service), is_incognito_(false),
is_response_deletion_scheduled_(false),
did_start_deleting_responses_(false),
- last_deletable_response_rowid_(0), database_(NULL),
- is_disabled_(false),
+ last_deletable_response_rowid_(0),
+ ALLOW_THIS_IN_INITIALIZER_LIST(doom_callback_(
+ this, &AppCacheStorageImpl::OnDeletedOneResponse)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(init_callback_(
+ this, &AppCacheStorageImpl::OnDiskCacheInitialized)),
+ database_(NULL), is_disabled_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
}
@@ -851,6 +855,8 @@ void AppCacheStorageImpl::Disable() {
is_disabled_ = true;
origins_with_groups_.clear();
working_set()->Disable();
+ if (disk_cache_.get())
+ disk_cache_->Disable();
scoped_refptr<DisableDatabaseTask> task = new DisableDatabaseTask(this);
task->Schedule();
}
@@ -1159,19 +1165,29 @@ void AppCacheStorageImpl::DeleteOneResponse() {
DCHECK(is_response_deletion_scheduled_);
DCHECK(!deletable_response_ids_.empty());
- is_response_deletion_scheduled_ = false;
-
if (!disk_cache()) {
DCHECK(is_disabled_);
deletable_response_ids_.clear();
deleted_response_ids_.clear();
+ is_response_deletion_scheduled_ = false;
return;
}
int64 id = deletable_response_ids_.front();
+ int rv = disk_cache_->DoomEntry(id, &doom_callback_);
+ if (rv != net::ERR_IO_PENDING)
+ OnDeletedOneResponse(rv);
+}
+
+void AppCacheStorageImpl::OnDeletedOneResponse(int rv) {
+ is_response_deletion_scheduled_ = false;
+ if (is_disabled_)
+ return;
+
+ int64 id = deletable_response_ids_.front();
deletable_response_ids_.pop_front();
- disk_cache_->DoomEntry(Int64ToString(id));
- deleted_response_ids_.push_back(id);
+ if (rv != net::ERR_ABORTED)
+ deleted_response_ids_.push_back(id);
const size_t kBatchSize = 50U;
if (deleted_response_ids_.size() >= kBatchSize ||
@@ -1233,24 +1249,36 @@ void AppCacheStorageImpl::RunOnePendingSimpleTask() {
delete task;
}
-disk_cache::Backend* AppCacheStorageImpl::disk_cache() {
+AppCacheDiskCache* AppCacheStorageImpl::disk_cache() {
+ DCHECK(IsInitTaskComplete());
+
if (is_disabled_)
return NULL;
if (!disk_cache_.get()) {
+ int rv = net::OK;
+ disk_cache_.reset(new AppCacheDiskCache);
if (is_incognito_) {
- disk_cache_.reset(
- disk_cache::CreateInMemoryCacheBackend(kMaxMemDiskCacheSize));
+ rv = disk_cache_->InitWithMemBackend(
+ kMaxMemDiskCacheSize, &init_callback_);
} else {
- disk_cache_.reset(disk_cache::CreateCacheBackend(
+ rv = disk_cache_->InitWithDiskBackend(
cache_directory_.AppendASCII(kDiskCacheDirectoryName),
- false, kMaxDiskCacheSize, net::DISK_CACHE));
+ kMaxDiskCacheSize, false, &init_callback_);
}
- if (!disk_cache_.get())
- Disable();
+ if (rv != net::ERR_IO_PENDING)
+ OnDiskCacheInitialized(rv);
}
return disk_cache_.get();
}
+void AppCacheStorageImpl::OnDiskCacheInitialized(int rv) {
+ if (rv != net::OK) {
+ // TODO(michaeln): We're unable to open the disk cache, how
+ // do we recover from this error?
+ Disable();
+ }
+}
+
} // namespace appcache