| Index: content/browser/service_worker/service_worker_cache_listener.cc
|
| diff --git a/content/browser/service_worker/service_worker_cache_listener.cc b/content/browser/service_worker/service_worker_cache_listener.cc
|
| index a2e51db02cb2afd153b64b6f55a8fe613131d436..7a5892ee6d72a80651bdfdd5edffd044b918d077 100644
|
| --- a/content/browser/service_worker/service_worker_cache_listener.cc
|
| +++ b/content/browser/service_worker/service_worker_cache_listener.cc
|
| @@ -49,7 +49,10 @@ WebServiceWorkerCacheError ToWebServiceWorkerCacheError(
|
| ServiceWorkerCacheListener::ServiceWorkerCacheListener(
|
| ServiceWorkerVersion* version,
|
| base::WeakPtr<ServiceWorkerContextCore> context)
|
| - : version_(version), context_(context), weak_factory_(this) {
|
| + : version_(version),
|
| + context_(context),
|
| + next_cache_id_(0),
|
| + weak_factory_(this) {
|
| }
|
|
|
| ServiceWorkerCacheListener::~ServiceWorkerCacheListener() {
|
| @@ -143,13 +146,15 @@ void ServiceWorkerCacheListener::Send(const IPC::Message& message) {
|
|
|
| void ServiceWorkerCacheListener::OnCacheStorageGetCallback(
|
| int request_id,
|
| - int cache_id,
|
| + const scoped_refptr<ServiceWorkerCache>& cache,
|
| ServiceWorkerCacheStorage::CacheStorageError error) {
|
| if (error != ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) {
|
| Send(ServiceWorkerMsg_CacheStorageGetError(
|
| request_id, ToWebServiceWorkerCacheError(error)));
|
| return;
|
| }
|
| +
|
| + CacheID cache_id = StoreCacheReference(cache);
|
| Send(ServiceWorkerMsg_CacheStorageGetSuccess(request_id, cache_id));
|
| }
|
|
|
| @@ -173,13 +178,14 @@ void ServiceWorkerCacheListener::OnCacheStorageHasCallback(
|
|
|
| void ServiceWorkerCacheListener::OnCacheStorageCreateCallback(
|
| int request_id,
|
| - int cache_id,
|
| + const scoped_refptr<ServiceWorkerCache>& cache,
|
| ServiceWorkerCacheStorage::CacheStorageError error) {
|
| if (error != ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) {
|
| Send(ServiceWorkerMsg_CacheStorageCreateError(
|
| request_id, ToWebServiceWorkerCacheError(error)));
|
| return;
|
| }
|
| + CacheID cache_id = StoreCacheReference(cache);
|
| Send(ServiceWorkerMsg_CacheStorageCreateSuccess(request_id, cache_id));
|
| }
|
|
|
| @@ -213,4 +219,28 @@ void ServiceWorkerCacheListener::OnCacheStorageKeysCallback(
|
| Send(ServiceWorkerMsg_CacheStorageKeysSuccess(request_id, string16s));
|
| }
|
|
|
| +ServiceWorkerCacheListener::CacheID
|
| +ServiceWorkerCacheListener::StoreCacheReference(
|
| + const scoped_refptr<ServiceWorkerCache>& cache) {
|
| + CacheToIDMap::iterator it = cache_to_id_map_.find(cache.get());
|
| + if (it == cache_to_id_map_.end()) {
|
| + CacheID cache_id = next_cache_id_++;
|
| + cache_to_id_map_.insert(std::make_pair(cache.get(), cache_id));
|
| + id_to_cache_map_.insert(std::make_pair(cache_id, cache));
|
| + return cache_id;
|
| + }
|
| +
|
| + return it->second;
|
| +}
|
| +
|
| +void ServiceWorkerCacheListener::DropCacheReference(CacheID cache_id) {
|
| + IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id);
|
| + if (it != id_to_cache_map_.end())
|
| + return;
|
| +
|
| + size_t deleted = cache_to_id_map_.erase(it->second.get());
|
| + DCHECK(deleted == 1u);
|
| + id_to_cache_map_.erase(it);
|
| +}
|
| +
|
| } // namespace content
|
|
|