Commit a00e5be5 authored by nhiroki's avatar nhiroki Committed by Commit bot

ServiceWorker: Use SimpleCache for the script cache

This CL migrates the backend of ServiceWorkerDiskCache from Default to
SimpleCache on all platforms.

If old DiskCache images exist,
(1) DiskCache backend fails to open an pre-existing data due to incompatible
format (in both Default->SimpleCache and SimpleCache->Default cases),
(2) ServiceWorkerStorage wipes out all cached scripts and registrations via
DeleteAndStartOver, and
(3) navigation falls back to network.

BUG=487482
TEST=manual (use DiskCache and SimpleCache alternately and make sure the system can recover)

Review URL: https://codereview.chromium.org/1140853002

Cr-Commit-Position: refs/heads/master@{#330274}
parent df279583
......@@ -198,8 +198,12 @@ class AppCacheDiskCache::ActiveCall
};
AppCacheDiskCache::AppCacheDiskCache()
: is_disabled_(false),
weak_factory_(this) {
#if defined(APPCACHE_USE_SIMPLE_CACHE)
: AppCacheDiskCache(true)
#else
: AppCacheDiskCache(false)
#endif
{
}
AppCacheDiskCache::~AppCacheDiskCache() {
......@@ -304,6 +308,12 @@ int AppCacheDiskCache::DoomEntry(int64 key,
return ActiveCall::DoomEntry(weak_factory_.GetWeakPtr(), key, callback);
}
AppCacheDiskCache::AppCacheDiskCache(bool use_simple_cache)
: use_simple_cache_(use_simple_cache),
is_disabled_(false),
weak_factory_(this) {
}
AppCacheDiskCache::PendingCall::PendingCall()
: call_type(CREATE),
key(0),
......@@ -333,14 +343,10 @@ int AppCacheDiskCache::Init(
is_disabled_ = false;
create_backend_callback_ = new CreateBackendCallbackShim(this);
#if defined(APPCACHE_USE_SIMPLE_CACHE)
const net::BackendType backend_type = net::CACHE_BACKEND_SIMPLE;
#else
const net::BackendType backend_type = net::CACHE_BACKEND_DEFAULT;
#endif
int rv = disk_cache::CreateCacheBackend(
cache_type,
backend_type,
use_simple_cache_ ? net::CACHE_BACKEND_SIMPLE
: net::CACHE_BACKEND_DEFAULT,
cache_directory,
cache_size,
force,
......
......@@ -52,6 +52,9 @@ class CONTENT_EXPORT AppCacheDiskCache
const net::CompletionCallback& callback) override;
int DoomEntry(int64 key, const net::CompletionCallback& callback) override;
protected:
explicit AppCacheDiskCache(bool use_simple_cache);
private:
class CreateBackendCallbackShim;
class EntryImpl;
......@@ -99,6 +102,7 @@ class CONTENT_EXPORT AppCacheDiskCache
void AddOpenEntry(EntryImpl* entry) { open_entries_.insert(entry); }
void RemoveOpenEntry(EntryImpl* entry) { open_entries_.erase(entry); }
bool use_simple_cache_;
bool is_disabled_;
net::CompletionCallback init_callback_;
scoped_refptr<CreateBackendCallbackShim> create_backend_callback_;
......
......@@ -6,6 +6,10 @@
namespace content {
ServiceWorkerDiskCache::ServiceWorkerDiskCache()
: AppCacheDiskCache(true /* use_simple_cache */) {
}
ServiceWorkerResponseReader::ServiceWorkerResponseReader(
int64 response_id, ServiceWorkerDiskCache* disk_cache)
: AppCacheResponseReader(response_id, 0, disk_cache) {
......
......@@ -18,6 +18,8 @@ namespace content {
class CONTENT_EXPORT ServiceWorkerDiskCache
: public AppCacheDiskCache {
public:
ServiceWorkerDiskCache();
};
class CONTENT_EXPORT ServiceWorkerResponseReader
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment