Commit 6afd9401 authored by Rayan Kanso's avatar Rayan Kanso Committed by Commit Bot

Fix WeakPtr bug when cache is created with a MemoryLoader.

I was writing a unittest where OpenCache is called with a MemoryLoader.
It kept crashing, and it seems to me that this was due to WriteIndex
running without callbacks. The CacheStorageCacheHandle was going out of
scope, and when a new one was being created by NotifyCacheCreated, there
was a crash due to some WeakPtr ref count internals.

This fix makes sure that the ref count is non-zero until all callbacks
consume the CacheStorageCacheHandle.

Bug: 838908
Change-Id: I610b2cad26d5608bacd18a4daa60edc976093fb4
Reviewed-on: https://chromium-review.googlesource.com/1069350Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561028}
parent 820e864f
...@@ -907,13 +907,14 @@ void CacheStorage::CreateCacheDidCreateCache( ...@@ -907,13 +907,14 @@ void CacheStorage::CreateCacheDidCreateCache(
cache_name, cache_ptr->cache_size(), cache_ptr->cache_padding(), cache_name, cache_ptr->cache_size(), cache_ptr->cache_padding(),
cache_ptr->cache_padding_key()->key())); cache_ptr->cache_padding_key()->key()));
CacheStorageCacheHandle handle = CreateCacheHandle(cache_ptr);
cache_loader_->WriteIndex( cache_loader_->WriteIndex(
*cache_index_, *cache_index_,
base::BindOnce(&CacheStorage::CreateCacheDidWriteIndex, base::BindOnce(&CacheStorage::CreateCacheDidWriteIndex,
weak_factory_.GetWeakPtr(), std::move(callback), weak_factory_.GetWeakPtr(), std::move(callback),
CreateCacheHandle(cache_ptr))); CreateCacheHandle(cache_ptr)));
cache_loader_->NotifyCacheCreated(cache_name, CreateCacheHandle(cache_ptr)); cache_loader_->NotifyCacheCreated(cache_name, std::move(handle));
if (cache_storage_manager_) if (cache_storage_manager_)
cache_storage_manager_->NotifyCacheListChanged(origin_); cache_storage_manager_->NotifyCacheListChanged(origin_);
} }
......
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