Avoid copying std::functions across threads in NetworkCacheStorage
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Feb 2015 14:31:07 +0000 (14:31 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Feb 2015 14:31:07 +0000 (14:31 +0000)
commit69d85d21c7352ecf841c3026afa1c4512c83ecf5
tree11901ecb9c0f394e8540fce8ac85b095b20ddcf2
parentfd091e113fa7e1791ca43bfab5359aa3bb3320f2
Avoid copying std::functions across threads in NetworkCacheStorage
https://bugs.webkit.org/show_bug.cgi?id=141273

Reviewed by Andreas Kling.

The current approach is risky. There is possiblity that captured variables are
deleted in an unexpected thread.

* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::retrieve):

    The capture trick here is no longer needed.

* NetworkProcess/cache/NetworkCacheStorage.h:

    For each cache operation we create Retrive/Store/UpdateOperation object kept alive by the active operation map.
    This object captures all parameters of the operation including the lambda. When the operation completes
    the object is removed from the map in the main thread, ensuring safe destruction.

* NetworkProcess/cache/NetworkCacheStorageCocoa.mm:
(WebKit::NetworkCacheStorage::dispatchRetrieveOperation):
(WebKit::NetworkCacheStorage::dispatchPendingRetrieveOperations):
(WebKit::retrieveActive):

    Instead of maintaining a separate write cache we just look through the active write and update maps.

(WebKit::NetworkCacheStorage::retrieve):

    Use fixed sized priority array rather than a dynamic one. Vector<Deque<std::unique_ptr>> doesn't quite work.

(WebKit::NetworkCacheStorage::store):
(WebKit::NetworkCacheStorage::update):
(WebKit::NetworkCacheStorage::clear):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@179690 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp
Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h
Source/WebKit2/NetworkProcess/cache/NetworkCacheStorageCocoa.mm