Commit 821ee0da authored by jkarlin's avatar jkarlin Committed by Commit bot

ServiceWorker CacheID update

Previous design:
1. The renderer needed all references to the same ServiceWorekrCache* to have the same CacheID.
2. The renderer would only send an IPC that a CacheID was deleted when the last reference to the CacheID was deleted in javascript.

After https://codereview.chromium.org/474593002/ and https://codereview.chromium.org/433793002/:
1. The renderer doesn't need all references to the same ServiceWorkerCache* to have the same CacheID.
2. The renderer will send an IPC that a CacheID is deleted after each javascript cache object is deleted.

To address the change on the browser side, simply make a new CacheID for every call to GetCache and CreateCache and delete its corresponding refptr when the CacheID is dropped.

BUG=392621

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

Cr-Commit-Position: refs/heads/master@{#296390}
parent c2a8eb06
......@@ -222,25 +222,13 @@ void ServiceWorkerCacheListener::OnCacheStorageKeysCallback(
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;
int cache_id = next_cache_id_++;
id_to_cache_map_[cache_id] = cache;
return cache_id;
}
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);
id_to_cache_map_.erase(cache_id);
}
} // namespace content
......@@ -40,7 +40,6 @@ class ServiceWorkerCacheListener : public EmbeddedWorkerInstance::Listener {
private:
typedef int32_t CacheID; // TODO(jkarlin): Bump to 64 bit.
typedef std::map<ServiceWorkerCache*, CacheID> CacheToIDMap;
typedef std::map<CacheID, scoped_refptr<ServiceWorkerCache> > IDToCacheMap;
void Send(const IPC::Message& message);
......@@ -79,7 +78,6 @@ class ServiceWorkerCacheListener : public EmbeddedWorkerInstance::Listener {
base::WeakPtr<ServiceWorkerContextCore> context_;
IDToCacheMap id_to_cache_map_;
CacheToIDMap cache_to_id_map_;
CacheID next_cache_id_;
base::WeakPtrFactory<ServiceWorkerCacheListener> weak_factory_;
......
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