Move cache coders to WTF
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Jan 2017 12:43:49 +0000 (12:43 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Jan 2017 12:43:49 +0000 (12:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=166825

Rubber-stamped by Sam Weinig.

Source/WebKit2:

* NetworkProcess/cache/NetworkCache.h:
* NetworkProcess/cache/NetworkCacheCoder.h: Removed.
* NetworkProcess/cache/NetworkCacheCoders.cpp:
(WebKit::NetworkCache::Coder<AtomicString>::encode): Deleted.
(WebKit::NetworkCache::Coder<AtomicString>::decode): Deleted.
(WebKit::NetworkCache::Coder<CString>::encode): Deleted.
(WebKit::NetworkCache::Coder<CString>::decode): Deleted.
(WebKit::NetworkCache::Coder<String>::encode): Deleted.
(WebKit::NetworkCache::decodeStringText): Deleted.
(WebKit::NetworkCache::Coder<String>::decode): Deleted.
(WebKit::NetworkCache::Coder<SHA1::Digest>::encode): Deleted.
(WebKit::NetworkCache::Coder<SHA1::Digest>::decode): Deleted.
(WebKit::NetworkCache::Coder<WebCore::HTTPHeaderMap>::encode): Deleted.
(WebKit::NetworkCache::Coder<WebCore::HTTPHeaderMap>::decode): Deleted.
* NetworkProcess/cache/NetworkCacheCoders.h:
(): Deleted.
(WebKit::NetworkCache::Coder<std::optional<T>>::encode): Deleted.
(WebKit::NetworkCache::Coder<std::optional<T>>::decode): Deleted.
* NetworkProcess/cache/NetworkCacheCodersCocoa.cpp:
(WebKit::NetworkCache::encodeCFData): Deleted.
(WebKit::NetworkCache::decodeCFData): Deleted.
(WebKit::NetworkCache::encodeSecTrustRef): Deleted.
(WebKit::NetworkCache::decodeSecTrustRef): Deleted.
(WebKit::NetworkCache::encodeCertificateChain): Deleted.
(WebKit::NetworkCache::decodeCertificateChain): Deleted.
(WebKit::NetworkCache::Coder<WebCore::CertificateInfo>::encode): Deleted.
(WebKit::NetworkCache::Coder<WebCore::CertificateInfo>::decode): Deleted.
* NetworkProcess/cache/NetworkCacheDecoder.cpp: Removed.
* NetworkProcess/cache/NetworkCacheDecoder.h: Removed.
* NetworkProcess/cache/NetworkCacheEncoder.cpp: Removed.
* NetworkProcess/cache/NetworkCacheEncoder.h: Removed.
* NetworkProcess/cache/NetworkCacheEntry.cpp:
(WebKit::NetworkCache::Entry::encodeAsStorageRecord):
(WebKit::NetworkCache::Entry::decodeStorageRecord):
* NetworkProcess/cache/NetworkCacheKey.cpp:
(WebKit::NetworkCache::Key::encode):
(WebKit::NetworkCache::Key::decode):
* NetworkProcess/cache/NetworkCacheKey.h:
* NetworkProcess/cache/NetworkCacheStorage.cpp:
(WebKit::NetworkCache::decodeRecordMetaData):
(WebKit::NetworkCache::encodeRecordMetaData):
* NetworkProcess/cache/NetworkCacheSubresourcesEntry.cpp:
(WebKit::NetworkCache::SubresourceInfo::encode):
(WebKit::NetworkCache::SubresourceInfo::decode):
(WebKit::NetworkCache::SubresourcesEntry::encodeAsStorageRecord):
(WebKit::NetworkCache::SubresourcesEntry::decodeStorageRecord):
* NetworkProcess/cache/NetworkCacheSubresourcesEntry.h:
* UIProcess/API/APIUserContentExtensionStore.cpp:
(API::encodeContentExtensionMetaData):
(API::decodeContentExtensionMetaData):
* WebKit2.xcodeproj/project.pbxproj:

Source/WTF:

Make it possible to use robust serialization of WTF types on the lower levels of the stack.

* WTF.xcodeproj/project.pbxproj:
* wtf/persistence: Added.
* wtf/persistence/Coder.h: Copied from Source/WebKit2/NetworkProcess/cache/NetworkCacheCoder.h.
(WebKit::NetworkCache::Coder::encode): Deleted.
(WebKit::NetworkCache::Coder::decode): Deleted.
* wtf/persistence/Coders.cpp: Copied from Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.cpp.
(WebKit::NetworkCache::Coder<AtomicString>::encode): Deleted.
(WebKit::NetworkCache::Coder<AtomicString>::decode): Deleted.
(WebKit::NetworkCache::Coder<CString>::encode): Deleted.
(WebKit::NetworkCache::Coder<CString>::decode): Deleted.
(WebKit::NetworkCache::Coder<String>::encode): Deleted.
(WebKit::NetworkCache::decodeStringText): Deleted.
(WebKit::NetworkCache::Coder<String>::decode): Deleted.
(WebKit::NetworkCache::Coder<SHA1::Digest>::encode): Deleted.
(WebKit::NetworkCache::Coder<SHA1::Digest>::decode): Deleted.
(WebKit::NetworkCache::Coder<WebCore::HTTPHeaderMap>::encode): Deleted.
(WebKit::NetworkCache::Coder<WebCore::HTTPHeaderMap>::decode): Deleted.
* wtf/persistence/Coders.h: Copied from Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.h.
(WebKit::NetworkCache::Coder<std::optional<T>>::encode): Deleted.
(WebKit::NetworkCache::Coder<std::optional<T>>::decode): Deleted.
* wtf/persistence/Decoder.cpp: Copied from Source/WebKit2/NetworkProcess/cache/NetworkCacheDecoder.cpp.
(WebKit::NetworkCache::Decoder::Decoder): Deleted.
(WebKit::NetworkCache::Decoder::~Decoder): Deleted.
(WebKit::NetworkCache::Decoder::bufferIsLargeEnoughToContain): Deleted.
(WebKit::NetworkCache::Decoder::decodeFixedLengthData): Deleted.
(WebKit::NetworkCache::Decoder::decodeNumber): Deleted.
(WebKit::NetworkCache::Decoder::decode): Deleted.
(WebKit::NetworkCache::Decoder::verifyChecksum): Deleted.
* wtf/persistence/Decoder.h: Copied from Source/WebKit2/NetworkProcess/cache/NetworkCacheDecoder.h.
(WebKit::NetworkCache::Decoder::length): Deleted.
(WebKit::NetworkCache::Decoder::currentOffset): Deleted.
(WebKit::NetworkCache::Decoder::decodeEnum): Deleted.
(WebKit::NetworkCache::Decoder::decode): Deleted.
(WebKit::NetworkCache::Decoder::bufferIsLargeEnoughToContain): Deleted.
* wtf/persistence/Encoder.cpp: Copied from Source/WebKit2/NetworkProcess/cache/NetworkCacheEncoder.cpp.
(WebKit::NetworkCache::Encoder::Encoder): Deleted.
(WebKit::NetworkCache::Encoder::~Encoder): Deleted.
(WebKit::NetworkCache::Encoder::grow): Deleted.
(WebKit::NetworkCache::Encoder::updateChecksumForData): Deleted.
(WebKit::NetworkCache::Encoder::encodeFixedLengthData): Deleted.
(WebKit::NetworkCache::Encoder::encodeNumber): Deleted.
(WebKit::NetworkCache::Encoder::encode): Deleted.
(WebKit::NetworkCache::Encoder::encodeChecksum): Deleted.
* wtf/persistence/Encoder.h: Copied from Source/WebKit2/NetworkProcess/cache/NetworkCacheEncoder.h.
(WebKit::NetworkCache::Encoder::encodeEnum): Deleted.
(WebKit::NetworkCache::Encoder::encode): Deleted.
(WebKit::NetworkCache::Encoder::operator<<): Deleted.
(WebKit::NetworkCache::Encoder::buffer): Deleted.
(WebKit::NetworkCache::Encoder::bufferSize): Deleted.
(WebKit::NetworkCache::Encoder::updateChecksumForNumber): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210502 268f45cc-cd09-0410-ab3c-d52691b4dbfc

24 files changed:
Source/WTF/ChangeLog
Source/WTF/WTF.xcodeproj/project.pbxproj
Source/WTF/wtf/CMakeLists.txt
Source/WTF/wtf/persistence/Coder.h [moved from Source/WebKit2/NetworkProcess/cache/NetworkCacheCoder.h with 92% similarity]
Source/WTF/wtf/persistence/Coders.cpp [new file with mode: 0644]
Source/WTF/wtf/persistence/Coders.h [new file with mode: 0644]
Source/WTF/wtf/persistence/Decoder.cpp [moved from Source/WebKit2/NetworkProcess/cache/NetworkCacheDecoder.cpp with 95% similarity]
Source/WTF/wtf/persistence/Decoder.h [moved from Source/WebKit2/NetworkProcess/cache/NetworkCacheDecoder.h with 76% similarity]
Source/WTF/wtf/persistence/Encoder.cpp [moved from Source/WebKit2/NetworkProcess/cache/NetworkCacheEncoder.cpp with 96% similarity]
Source/WTF/wtf/persistence/Encoder.h [moved from Source/WebKit2/NetworkProcess/cache/NetworkCacheEncoder.h with 81% similarity]
Source/WebKit2/CMakeLists.txt
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.cpp
Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.h
Source/WebKit2/NetworkProcess/cache/NetworkCacheCodersCocoa.cpp
Source/WebKit2/NetworkProcess/cache/NetworkCacheCodersSoup.cpp
Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp
Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.cpp
Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.h
Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp
Source/WebKit2/NetworkProcess/cache/NetworkCacheSubresourcesEntry.cpp
Source/WebKit2/NetworkProcess/cache/NetworkCacheSubresourcesEntry.h
Source/WebKit2/UIProcess/API/APIUserContentExtensionStore.cpp
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

index 2ea0d7f..b988a32 100644 (file)
@@ -1,3 +1,63 @@
+2017-01-08  Antti Koivisto  <antti@apple.com>
+
+        Move cache coders to WTF
+        https://bugs.webkit.org/show_bug.cgi?id=166825
+
+        Rubber-stamped by Sam Weinig.
+
+        Make it possible to use robust serialization of WTF types on the lower levels of the stack.
+
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/persistence: Added.
+        * wtf/persistence/Coder.h: Copied from Source/WebKit2/NetworkProcess/cache/NetworkCacheCoder.h.
+        (WebKit::NetworkCache::Coder::encode): Deleted.
+        (WebKit::NetworkCache::Coder::decode): Deleted.
+        * wtf/persistence/Coders.cpp: Copied from Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.cpp.
+        (WebKit::NetworkCache::Coder<AtomicString>::encode): Deleted.
+        (WebKit::NetworkCache::Coder<AtomicString>::decode): Deleted.
+        (WebKit::NetworkCache::Coder<CString>::encode): Deleted.
+        (WebKit::NetworkCache::Coder<CString>::decode): Deleted.
+        (WebKit::NetworkCache::Coder<String>::encode): Deleted.
+        (WebKit::NetworkCache::decodeStringText): Deleted.
+        (WebKit::NetworkCache::Coder<String>::decode): Deleted.
+        (WebKit::NetworkCache::Coder<SHA1::Digest>::encode): Deleted.
+        (WebKit::NetworkCache::Coder<SHA1::Digest>::decode): Deleted.
+        (WebKit::NetworkCache::Coder<WebCore::HTTPHeaderMap>::encode): Deleted.
+        (WebKit::NetworkCache::Coder<WebCore::HTTPHeaderMap>::decode): Deleted.
+        * wtf/persistence/Coders.h: Copied from Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.h.
+        (WebKit::NetworkCache::Coder<std::optional<T>>::encode): Deleted.
+        (WebKit::NetworkCache::Coder<std::optional<T>>::decode): Deleted.
+        * wtf/persistence/Decoder.cpp: Copied from Source/WebKit2/NetworkProcess/cache/NetworkCacheDecoder.cpp.
+        (WebKit::NetworkCache::Decoder::Decoder): Deleted.
+        (WebKit::NetworkCache::Decoder::~Decoder): Deleted.
+        (WebKit::NetworkCache::Decoder::bufferIsLargeEnoughToContain): Deleted.
+        (WebKit::NetworkCache::Decoder::decodeFixedLengthData): Deleted.
+        (WebKit::NetworkCache::Decoder::decodeNumber): Deleted.
+        (WebKit::NetworkCache::Decoder::decode): Deleted.
+        (WebKit::NetworkCache::Decoder::verifyChecksum): Deleted.
+        * wtf/persistence/Decoder.h: Copied from Source/WebKit2/NetworkProcess/cache/NetworkCacheDecoder.h.
+        (WebKit::NetworkCache::Decoder::length): Deleted.
+        (WebKit::NetworkCache::Decoder::currentOffset): Deleted.
+        (WebKit::NetworkCache::Decoder::decodeEnum): Deleted.
+        (WebKit::NetworkCache::Decoder::decode): Deleted.
+        (WebKit::NetworkCache::Decoder::bufferIsLargeEnoughToContain): Deleted.
+        * wtf/persistence/Encoder.cpp: Copied from Source/WebKit2/NetworkProcess/cache/NetworkCacheEncoder.cpp.
+        (WebKit::NetworkCache::Encoder::Encoder): Deleted.
+        (WebKit::NetworkCache::Encoder::~Encoder): Deleted.
+        (WebKit::NetworkCache::Encoder::grow): Deleted.
+        (WebKit::NetworkCache::Encoder::updateChecksumForData): Deleted.
+        (WebKit::NetworkCache::Encoder::encodeFixedLengthData): Deleted.
+        (WebKit::NetworkCache::Encoder::encodeNumber): Deleted.
+        (WebKit::NetworkCache::Encoder::encode): Deleted.
+        (WebKit::NetworkCache::Encoder::encodeChecksum): Deleted.
+        * wtf/persistence/Encoder.h: Copied from Source/WebKit2/NetworkProcess/cache/NetworkCacheEncoder.h.
+        (WebKit::NetworkCache::Encoder::encodeEnum): Deleted.
+        (WebKit::NetworkCache::Encoder::encode): Deleted.
+        (WebKit::NetworkCache::Encoder::operator<<): Deleted.
+        (WebKit::NetworkCache::Encoder::buffer): Deleted.
+        (WebKit::NetworkCache::Encoder::bufferSize): Deleted.
+        (WebKit::NetworkCache::Encoder::updateChecksumForNumber): Deleted.
+
 2017-01-08  Konstantin Tokarev  <annulen@yandex.ru>
 
         Introduce CPU(X86_SSE2) instead of various SSE2 checks
index 124a4b7..2a78044 100644 (file)
                DE5A09FC1BA36992003D4424 /* CommonCryptoSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = DE5A09FB1BA36992003D4424 /* CommonCryptoSPI.h */; };
                E15556F518A0CC18006F48FB /* CryptographicUtilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E15556F318A0CC18006F48FB /* CryptographicUtilities.cpp */; };
                E15556F618A0CC18006F48FB /* CryptographicUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = E15556F418A0CC18006F48FB /* CryptographicUtilities.h */; };
+               E43A46951E228B9100276B05 /* Decoder.h in Headers */ = {isa = PBXBuildFile; fileRef = E43A46901E228B9100276B05 /* Decoder.h */; };
+               E43A46961E228B9100276B05 /* Encoder.h in Headers */ = {isa = PBXBuildFile; fileRef = E43A46911E228B9100276B05 /* Encoder.h */; };
+               E43A46971E228B9100276B05 /* Decoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43A46921E228B9100276B05 /* Decoder.cpp */; };
+               E43A46981E228B9100276B05 /* Encoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43A46931E228B9100276B05 /* Encoder.cpp */; };
+               E43A46991E228B9100276B05 /* Coder.h in Headers */ = {isa = PBXBuildFile; fileRef = E43A46941E228B9100276B05 /* Coder.h */; };
+               E43A469B1E228FB200276B05 /* Coders.h in Headers */ = {isa = PBXBuildFile; fileRef = E43A469A1E228FB200276B05 /* Coders.h */; };
+               E43A469D1E228FD500276B05 /* Coders.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43A469C1E228FD500276B05 /* Coders.cpp */; };
                E4A0AD391A96245500536DF6 /* WorkQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4A0AD371A96245500536DF6 /* WorkQueue.cpp */; };
                E4A0AD3A1A96245500536DF6 /* WorkQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = E4A0AD381A96245500536DF6 /* WorkQueue.h */; };
                E4A0AD3D1A96253C00536DF6 /* WorkQueueCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4A0AD3C1A96253C00536DF6 /* WorkQueueCocoa.cpp */; };
                DE5A09FB1BA36992003D4424 /* CommonCryptoSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommonCryptoSPI.h; sourceTree = "<group>"; };
                E15556F318A0CC18006F48FB /* CryptographicUtilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptographicUtilities.cpp; sourceTree = "<group>"; };
                E15556F418A0CC18006F48FB /* CryptographicUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptographicUtilities.h; sourceTree = "<group>"; };
+               E43A46901E228B9100276B05 /* Decoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Decoder.h; sourceTree = "<group>"; };
+               E43A46911E228B9100276B05 /* Encoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Encoder.h; sourceTree = "<group>"; };
+               E43A46921E228B9100276B05 /* Decoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Decoder.cpp; sourceTree = "<group>"; };
+               E43A46931E228B9100276B05 /* Encoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Encoder.cpp; sourceTree = "<group>"; };
+               E43A46941E228B9100276B05 /* Coder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Coder.h; sourceTree = "<group>"; };
+               E43A469A1E228FB200276B05 /* Coders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Coders.h; sourceTree = "<group>"; };
+               E43A469C1E228FD500276B05 /* Coders.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Coders.cpp; sourceTree = "<group>"; };
                E4A0AD371A96245500536DF6 /* WorkQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkQueue.cpp; sourceTree = "<group>"; };
                E4A0AD381A96245500536DF6 /* WorkQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkQueue.h; sourceTree = "<group>"; };
                E4A0AD3C1A96253C00536DF6 /* WorkQueueCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkQueueCocoa.cpp; sourceTree = "<group>"; };
                                A8A47281151A825A004123FF /* dtoa */,
                                1FA47C87152502DA00568D1B /* ios */,
                                A8A472C4151A825A004123FF /* mac */,
+                               E43A46851E228B5700276B05 /* persistence */,
                                CEF4820C19DA347600CC04B8 /* spi */,
                                A8A4731B151A825B004123FF /* text */,
                                A8A47339151A825B004123FF /* threads */,
                        name = cf;
                        sourceTree = "<group>";
                };
+               E43A46851E228B5700276B05 /* persistence */ = {
+                       isa = PBXGroup;
+                       children = (
+                               E43A46941E228B9100276B05 /* Coder.h */,
+                               E43A469A1E228FB200276B05 /* Coders.h */,
+                               E43A469C1E228FD500276B05 /* Coders.cpp */,
+                               E43A46921E228B9100276B05 /* Decoder.cpp */,
+                               E43A46901E228B9100276B05 /* Decoder.h */,
+                               E43A46931E228B9100276B05 /* Encoder.cpp */,
+                               E43A46911E228B9100276B05 /* Encoder.h */,
+                       );
+                       path = persistence;
+                       sourceTree = "<group>";
+               };
                E4A0AD3B1A96251900536DF6 /* cocoa */ = {
                        isa = PBXGroup;
                        children = (
                                A8A47391151A825B004123FF /* BumpPointerAllocator.h in Headers */,
                                EB95E1F0161A72410089A2F5 /* ByteOrder.h in Headers */,
                                A8A473AD151A825B004123FF /* cached-powers.h in Headers */,
+                               E43A469B1E228FB200276B05 /* Coders.h in Headers */,
                                DCEE21FB1CEA7538000C2396 /* CFBundleSPI.h in Headers */,
                                A8A4745E151A825B004123FF /* CharacterNames.h in Headers */,
                                A8A47394151A825B004123FF /* CheckedArithmetic.h in Headers */,
                                A8A473B2151A825B004123FF /* double.h in Headers */,
                                A8A473A7151A825B004123FF /* DoublyLinkedList.h in Headers */,
                                A8A473BB151A825B004123FF /* dtoa.h in Headers */,
+                               E43A46961E228B9100276B05 /* Encoder.h in Headers */,
                                93DDE9321CDC052D00FD3491 /* dyldSPI.h in Headers */,
                                1AEA88E21D6BBCF400E5AD64 /* EnumTraits.h in Headers */,
                                AD7C434B1DD2A4A70026888B /* Expected.h in Headers */,
                                A8A47454151A825B004123FF /* ThreadSafeRefCounted.h in Headers */,
                                A8A47455151A825B004123FF /* ThreadSpecific.h in Headers */,
                                0F66B2911DC97BAB004A1D3F /* TimeWithDynamicClockType.h in Headers */,
+                               E43A46951E228B9100276B05 /* Decoder.h in Headers */,
                                553071CA1C40427200384898 /* TinyLRUCache.h in Headers */,
                                0FED67B61B22D4D80066CE15 /* TinyPtrSet.h in Headers */,
                                149EF16316BBFE0D000A4331 /* TriState.h in Headers */,
                                A8A47446151A825B004123FF /* WTFString.h in Headers */,
                                A8A47487151A825B004123FF /* WTFThreadData.h in Headers */,
                                CE73E02519DCB7AB00580D5C /* XPCSPI.h in Headers */,
+                               E43A46991E228B9100276B05 /* Coder.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                A8A47414151A825B004123FF /* RandomNumber.cpp in Sources */,
                                A8A4741A151A825B004123FF /* RefCountedLeakCounter.cpp in Sources */,
                                2CDED0F318115C85004DBA70 /* RunLoop.cpp in Sources */,
+                               E43A46981E228B9100276B05 /* Encoder.cpp in Sources */,
                                2CDED0EF18115C38004DBA70 /* RunLoopCF.cpp in Sources */,
                                1469419316EAAF6D0024E146 /* RunLoopTimerCF.cpp in Sources */,
+                               E43A469D1E228FD500276B05 /* Coders.cpp in Sources */,
                                1469419916EAB0410024E146 /* SchedulePairCF.cpp in Sources */,
                                1469419716EAAFF80024E146 /* SchedulePairMac.mm in Sources */,
                                0F66B28E1DC97BAB004A1D3F /* Seconds.cpp in Sources */,
                                A5BA15FC182435A600A82E69 /* StringImplCF.cpp in Sources */,
                                A5BA15F51824348000A82E69 /* StringImplMac.mm in Sources */,
                                A5BA15F3182433A900A82E69 /* StringMac.mm in Sources */,
+                               E43A46971E228B9100276B05 /* Decoder.cpp in Sources */,
                                0FDDBFA71666DFA300C55FEF /* StringPrintStream.cpp in Sources */,
                                A8A47443151A825B004123FF /* StringStatics.cpp in Sources */,
                                93F1993E19D7958D00C2390B /* StringView.cpp in Sources */,
index e34d37f..58c116b 100644 (file)
@@ -240,6 +240,10 @@ set(WTF_SOURCES
     dtoa/fixed-dtoa.cc
     dtoa/strtod.cc
 
+    persistence/Coders.cpp
+    persistence/Decoder.cpp
+    persistence/Encoder.cpp
+
     text/AtomicString.cpp
     text/AtomicStringImpl.cpp
     text/AtomicStringTable.cpp
@@ -268,6 +272,7 @@ set(WTF_INCLUDE_DIRECTORIES
     "${WTF_DIR}"
     "${WTF_DIR}/wtf"
     "${WTF_DIR}/wtf/dtoa"
+    "${WTF_DIR}/wtf/persistence"
     "${WTF_DIR}/wtf/text"
     "${WTF_DIR}/wtf/text/icu"
     "${WTF_DIR}/wtf/threads"
similarity index 92%
rename from Source/WebKit2/NetworkProcess/cache/NetworkCacheCoder.h
rename to Source/WTF/wtf/persistence/Coder.h
index 4b4be36..f7d98c4 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef NetworkCacheCoder_h
-#define NetworkCacheCoder_h
+#pragma once
 
-#if ENABLE(NETWORK_CACHE)
-
-namespace WebKit {
-namespace NetworkCache {
+namespace WTF {
+namespace Persistence {
 
 class Decoder;
 class Encoder;
@@ -48,6 +45,3 @@ template<typename T> struct Coder {
 
 }
 }
-
-#endif
-#endif
diff --git a/Source/WTF/wtf/persistence/Coders.cpp b/Source/WTF/wtf/persistence/Coders.cpp
new file mode 100644 (file)
index 0000000..7cd42f4
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2011, 2014-2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "Coders.h"
+
+#include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
+
+namespace WTF {
+namespace Persistence {
+
+void Coder<AtomicString>::encode(Encoder& encoder, const AtomicString& atomicString)
+{
+    encoder << atomicString.string();
+}
+
+bool Coder<AtomicString>::decode(Decoder& decoder, AtomicString& atomicString)
+{
+    String string;
+    if (!decoder.decode(string))
+        return false;
+
+    atomicString = string;
+    return true;
+}
+
+void Coder<CString>::encode(Encoder& encoder, const CString& string)
+{
+    // Special case the null string.
+    if (string.isNull()) {
+        encoder << std::numeric_limits<uint32_t>::max();
+        return;
+    }
+
+    uint32_t length = string.length();
+    encoder << length;
+    encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.data()), length);
+}
+
+bool Coder<CString>::decode(Decoder& decoder, CString& result)
+{
+    uint32_t length;
+    if (!decoder.decode(length))
+        return false;
+
+    if (length == std::numeric_limits<uint32_t>::max()) {
+        // This is the null string.
+        result = CString();
+        return true;
+    }
+
+    // Before allocating the string, make sure that the decoder buffer is big enough.
+    if (!decoder.bufferIsLargeEnoughToContain<char>(length))
+        return false;
+
+    char* buffer;
+    CString string = CString::newUninitialized(length, buffer);
+    if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(buffer), length))
+        return false;
+
+    result = string;
+    return true;
+}
+
+
+void Coder<String>::encode(Encoder& encoder, const String& string)
+{
+    // Special case the null string.
+    if (string.isNull()) {
+        encoder << std::numeric_limits<uint32_t>::max();
+        return;
+    }
+
+    uint32_t length = string.length();
+    bool is8Bit = string.is8Bit();
+
+    encoder << length << is8Bit;
+
+    if (is8Bit)
+        encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.characters8()), length * sizeof(LChar));
+    else
+        encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.characters16()), length * sizeof(UChar));
+}
+
+template <typename CharacterType>
+static inline bool decodeStringText(Decoder& decoder, uint32_t length, String& result)
+{
+    // Before allocating the string, make sure that the decoder buffer is big enough.
+    if (!decoder.bufferIsLargeEnoughToContain<CharacterType>(length))
+        return false;
+
+    CharacterType* buffer;
+    String string = String::createUninitialized(length, buffer);
+    if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(buffer), length * sizeof(CharacterType)))
+        return false;
+    
+    result = string;
+    return true;    
+}
+
+bool Coder<String>::decode(Decoder& decoder, String& result)
+{
+    uint32_t length;
+    if (!decoder.decode(length))
+        return false;
+
+    if (length == std::numeric_limits<uint32_t>::max()) {
+        // This is the null string.
+        result = String();
+        return true;
+    }
+
+    bool is8Bit;
+    if (!decoder.decode(is8Bit))
+        return false;
+
+    if (is8Bit)
+        return decodeStringText<LChar>(decoder, length, result);
+    return decodeStringText<UChar>(decoder, length, result);
+}
+
+void Coder<SHA1::Digest>::encode(Encoder& encoder, const SHA1::Digest& digest)
+{
+    encoder.encodeFixedLengthData(digest.data(), sizeof(digest));
+}
+
+bool Coder<SHA1::Digest>::decode(Decoder& decoder, SHA1::Digest& digest)
+{
+    return decoder.decodeFixedLengthData(digest.data(), sizeof(digest));
+}
+
+}
+}
diff --git a/Source/WTF/wtf/persistence/Coders.h b/Source/WTF/wtf/persistence/Coders.h
new file mode 100644 (file)
index 0000000..a6692bc
--- /dev/null
@@ -0,0 +1,285 @@
+/*
+ * Copyright (C) 2010, 2014-2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <utility>
+#include <wtf/Forward.h>
+#include <wtf/HashMap.h>
+#include <wtf/HashSet.h>
+#include <wtf/SHA1.h>
+#include <wtf/Vector.h>
+#include <wtf/persistence/Decoder.h>
+#include <wtf/persistence/Encoder.h>
+
+namespace WTF {
+namespace Persistence {
+
+template<typename T, typename U> struct Coder<std::pair<T, U>> {
+    static void encode(Encoder& encoder, const std::pair<T, U>& pair)
+    {
+        encoder << pair.first << pair.second;
+    }
+
+    static bool decode(Decoder& decoder, std::pair<T, U>& pair)
+    {
+        T first;
+        if (!decoder.decode(first))
+            return false;
+
+        U second;
+        if (!decoder.decode(second))
+            return false;
+
+        pair.first = first;
+        pair.second = second;
+        return true;
+    }
+};
+
+template<typename Rep, typename Period> struct Coder<std::chrono::duration<Rep, Period>> {
+    static void encode(Encoder& encoder, const std::chrono::duration<Rep, Period>& duration)
+    {
+        static_assert(std::is_integral<Rep>::value && std::is_signed<Rep>::value && sizeof(Rep) <= sizeof(int64_t), "Serialization of this Rep type is not supported yet. Only signed integer type which can be fit in an int64_t is currently supported.");
+        encoder << static_cast<int64_t>(duration.count());
+    }
+
+    static bool decode(Decoder& decoder, std::chrono::duration<Rep, Period>& result)
+    {
+        int64_t count;
+        if (!decoder.decode(count))
+            return false;
+        result = std::chrono::duration<Rep, Period>(static_cast<Rep>(count));
+        return true;
+    }
+};
+
+template<typename T> struct Coder<std::optional<T>> {
+    static void encode(Encoder& encoder, const std::optional<T>& optional)
+    {
+        if (!optional) {
+            encoder << false;
+            return;
+        }
+        
+        encoder << true;
+        encoder << optional.value();
+    }
+    
+    static bool decode(Decoder& decoder, std::optional<T>& optional)
+    {
+        bool isEngaged;
+        if (!decoder.decode(isEngaged))
+            return false;
+        
+        if (!isEngaged) {
+            optional = std::nullopt;
+            return true;
+        }
+        
+        T value;
+        if (!decoder.decode(value))
+            return false;
+        
+        optional = WTFMove(value);
+        return true;
+    }
+};
+
+template<typename KeyType, typename ValueType> struct Coder<WTF::KeyValuePair<KeyType, ValueType>> {
+    static void encode(Encoder& encoder, const WTF::KeyValuePair<KeyType, ValueType>& pair)
+    {
+        encoder << pair.key << pair.value;
+    }
+
+    static bool decode(Decoder& decoder, WTF::KeyValuePair<KeyType, ValueType>& pair)
+    {
+        KeyType key;
+        if (!decoder.decode(key))
+            return false;
+
+        ValueType value;
+        if (!decoder.decode(value))
+            return false;
+
+        pair.key = key;
+        pair.value = value;
+        return true;
+    }
+};
+
+template<bool fixedSizeElements, typename T, size_t inlineCapacity> struct VectorCoder;
+
+template<typename T, size_t inlineCapacity> struct VectorCoder<false, T, inlineCapacity> {
+    static void encode(Encoder& encoder, const Vector<T, inlineCapacity>& vector)
+    {
+        encoder << static_cast<uint64_t>(vector.size());
+        for (size_t i = 0; i < vector.size(); ++i)
+            encoder << vector[i];
+    }
+
+    static bool decode(Decoder& decoder, Vector<T, inlineCapacity>& vector)
+    {
+        uint64_t size;
+        if (!decoder.decode(size))
+            return false;
+
+        Vector<T, inlineCapacity> tmp;
+        for (size_t i = 0; i < size; ++i) {
+            T element;
+            if (!decoder.decode(element))
+                return false;
+            
+            tmp.append(WTFMove(element));
+        }
+
+        tmp.shrinkToFit();
+        vector.swap(tmp);
+        return true;
+    }
+};
+
+template<typename T, size_t inlineCapacity> struct VectorCoder<true, T, inlineCapacity> {
+    static void encode(Encoder& encoder, const Vector<T, inlineCapacity>& vector)
+    {
+        encoder << static_cast<uint64_t>(vector.size());
+        encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(vector.data()), vector.size() * sizeof(T), alignof(T));
+    }
+    
+    static bool decode(Decoder& decoder, Vector<T, inlineCapacity>& vector)
+    {
+        uint64_t size;
+        if (!decoder.decode(size))
+            return false;
+
+        // Since we know the total size of the elements, we can allocate the vector in
+        // one fell swoop. Before allocating we must however make sure that the decoder buffer
+        // is big enough.
+        if (!decoder.bufferIsLargeEnoughToContain<T>(size))
+            return false;
+
+        Vector<T, inlineCapacity> temp;
+        temp.resize(size);
+
+        decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(temp.data()), size * sizeof(T));
+
+        vector.swap(temp);
+        return true;
+    }
+};
+
+template<typename T, size_t inlineCapacity> struct Coder<Vector<T, inlineCapacity>> : VectorCoder<std::is_arithmetic<T>::value, T, inlineCapacity> { };
+
+template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg> struct Coder<HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>> {
+    typedef HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg> HashMapType;
+
+    static void encode(Encoder& encoder, const HashMapType& hashMap)
+    {
+        encoder << static_cast<uint64_t>(hashMap.size());
+        for (typename HashMapType::const_iterator it = hashMap.begin(), end = hashMap.end(); it != end; ++it)
+            encoder << *it;
+    }
+
+    static bool decode(Decoder& decoder, HashMapType& hashMap)
+    {
+        uint64_t hashMapSize;
+        if (!decoder.decode(hashMapSize))
+            return false;
+
+        HashMapType tempHashMap;
+        for (uint64_t i = 0; i < hashMapSize; ++i) {
+            KeyArg key;
+            MappedArg value;
+            if (!decoder.decode(key))
+                return false;
+            if (!decoder.decode(value))
+                return false;
+
+            if (!tempHashMap.add(key, value).isNewEntry) {
+                // The hash map already has the specified key, bail.
+                return false;
+            }
+        }
+
+        hashMap.swap(tempHashMap);
+        return true;
+    }
+};
+
+template<typename KeyArg, typename HashArg, typename KeyTraitsArg> struct Coder<HashSet<KeyArg, HashArg, KeyTraitsArg>> {
+    typedef HashSet<KeyArg, HashArg, KeyTraitsArg> HashSetType;
+
+    static void encode(Encoder& encoder, const HashSetType& hashSet)
+    {
+        encoder << static_cast<uint64_t>(hashSet.size());
+        for (typename HashSetType::const_iterator it = hashSet.begin(), end = hashSet.end(); it != end; ++it)
+            encoder << *it;
+    }
+
+    static bool decode(Decoder& decoder, HashSetType& hashSet)
+    {
+        uint64_t hashSetSize;
+        if (!decoder.decode(hashSetSize))
+            return false;
+
+        HashSetType tempHashSet;
+        for (uint64_t i = 0; i < hashSetSize; ++i) {
+            KeyArg key;
+            if (!decoder.decode(key))
+                return false;
+
+            if (!tempHashSet.add(key).isNewEntry) {
+                // The hash map already has the specified key, bail.
+                return false;
+            }
+        }
+
+        hashSet.swap(tempHashSet);
+        return true;
+    }
+};
+
+template<> struct Coder<AtomicString> {
+    WTF_EXPORT_PRIVATE static void encode(Encoder&, const AtomicString&);
+    WTF_EXPORT_PRIVATE static bool decode(Decoder&, AtomicString&);
+};
+
+template<> struct Coder<CString> {
+    WTF_EXPORT_PRIVATE static void encode(Encoder&, const CString&);
+    WTF_EXPORT_PRIVATE static bool decode(Decoder&, CString&);
+};
+
+template<> struct Coder<String> {
+    WTF_EXPORT_PRIVATE static void encode(Encoder&, const String&);
+    WTF_EXPORT_PRIVATE static bool decode(Decoder&, String&);
+};
+
+template<> struct Coder<SHA1::Digest> {
+    WTF_EXPORT_PRIVATE static void encode(Encoder&, const SHA1::Digest&);
+    WTF_EXPORT_PRIVATE static bool decode(Decoder&, SHA1::Digest&);
+};
+
+}
+}
  */
 
 #include "config.h"
-#include "NetworkCacheDecoder.h"
+#include "Decoder.h"
 
-#if ENABLE(NETWORK_CACHE)
+#include <wtf/persistence/Encoder.h>
 
-#include "NetworkCacheEncoder.h"
-
-namespace WebKit {
-namespace NetworkCache {
+namespace WTF {
+namespace Persistence {
 
 Decoder::Decoder(const uint8_t* buffer, size_t bufferSize)
     : m_buffer(buffer)
@@ -133,5 +131,3 @@ bool Decoder::verifyChecksum()
 
 }
 }
-
-#endif
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef NetworkCacheDecoder_h
-#define NetworkCacheDecoder_h
+#pragma once
 
-#if ENABLE(NETWORK_CACHE)
-
-#include "NetworkCacheCoder.h"
 #include <wtf/SHA1.h>
+#include <wtf/persistence/Coder.h>
 
-namespace WebKit {
-namespace NetworkCache {
+namespace WTF {
+namespace Persistence {
 
 class Decoder {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    Decoder(const uint8_t* buffer, size_t bufferSize);
-    virtual ~Decoder();
+    WTF_EXPORT_PRIVATE Decoder(const uint8_t* buffer, size_t bufferSize);
+    WTF_EXPORT_PRIVATE ~Decoder();
 
     size_t length() const { return m_bufferEnd - m_buffer; }
     size_t currentOffset() const { return m_bufferPosition - m_buffer; }
 
-    bool verifyChecksum();
+    WTF_EXPORT_PRIVATE bool verifyChecksum();
 
-    bool decodeFixedLengthData(uint8_t*, size_t);
+    WTF_EXPORT_PRIVATE bool decodeFixedLengthData(uint8_t*, size_t);
 
-    bool decode(bool&);
-    bool decode(uint8_t&);
-    bool decode(uint16_t&);
-    bool decode(uint32_t&);
-    bool decode(uint64_t&);
-    bool decode(int32_t&);
-    bool decode(int64_t&);
-    bool decode(float&);
-    bool decode(double&);
+    WTF_EXPORT_PRIVATE bool decode(bool&);
+    WTF_EXPORT_PRIVATE bool decode(uint8_t&);
+    WTF_EXPORT_PRIVATE bool decode(uint16_t&);
+    WTF_EXPORT_PRIVATE bool decode(uint32_t&);
+    WTF_EXPORT_PRIVATE bool decode(uint64_t&);
+    WTF_EXPORT_PRIVATE bool decode(int32_t&);
+    WTF_EXPORT_PRIVATE bool decode(int64_t&);
+    WTF_EXPORT_PRIVATE bool decode(float&);
+    WTF_EXPORT_PRIVATE bool decode(double&);
 
     template<typename T> bool decodeEnum(T& result)
     {
@@ -88,7 +85,7 @@ public:
     static const bool isIPCDecoder = false;
 
 private:
-    bool bufferIsLargeEnoughToContain(size_t) const;
+    WTF_EXPORT_PRIVATE bool bufferIsLargeEnoughToContain(size_t) const;
     template<typename Type> bool decodeNumber(Type&);
 
     const uint8_t* m_buffer;
@@ -101,5 +98,3 @@ private:
 } 
 }
 
-#endif
-#endif
  */
 
 #include "config.h"
-#include "NetworkCacheEncoder.h"
+#include "Encoder.h"
 
-#if ENABLE(NETWORK_CACHE)
+#include "SHA1.h"
 
-namespace WebKit {
-namespace NetworkCache {
+namespace WTF {
+namespace Persistence {
 
 Encoder::Encoder()
 {
@@ -124,5 +124,3 @@ void Encoder::encodeChecksum()
 
 }
 }
-
-#endif
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef NetworkCacheEncoder_h
-#define NetworkCacheEncoder_h
+#pragma once
 
-#if ENABLE(NETWORK_CACHE)
-
-#include "NetworkCacheCoder.h"
 #include <wtf/SHA1.h>
 #include <wtf/Vector.h>
+#include <wtf/persistence/Coder.h>
 
-namespace WebKit {
-namespace NetworkCache {
+namespace WTF {
+namespace Persistence {
 
 class Encoder;
 class DataReference;
@@ -41,11 +38,11 @@ class DataReference;
 class Encoder {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    Encoder();
-    virtual ~Encoder();
+    WTF_EXPORT_PRIVATE Encoder();
+    WTF_EXPORT_PRIVATE ~Encoder();
 
-    void encodeChecksum();
-    void encodeFixedLengthData(const uint8_t*, size_t);
+    WTF_EXPORT_PRIVATE void encodeChecksum();
+    WTF_EXPORT_PRIVATE void encodeFixedLengthData(const uint8_t*, size_t);
 
     template<typename T> void encodeEnum(T t)
     {
@@ -68,21 +65,21 @@ public:
     const uint8_t* buffer() const { return m_buffer.data(); }
     size_t bufferSize() const { return m_buffer.size(); }
 
-    static void updateChecksumForData(SHA1&, const uint8_t*, size_t);
+    WTF_EXPORT_PRIVATE static void updateChecksumForData(SHA1&, const uint8_t*, size_t);
     template <typename Type> static void updateChecksumForNumber(SHA1&, Type);
 
     static const bool isIPCEncoder = false;
 
 private:
-    void encode(bool);
-    void encode(uint8_t);
-    void encode(uint16_t);
-    void encode(uint32_t);
-    void encode(uint64_t);
-    void encode(int32_t);
-    void encode(int64_t);
-    void encode(float);
-    void encode(double);
+    WTF_EXPORT_PRIVATE void encode(bool);
+    WTF_EXPORT_PRIVATE void encode(uint8_t);
+    WTF_EXPORT_PRIVATE void encode(uint16_t);
+    WTF_EXPORT_PRIVATE void encode(uint32_t);
+    WTF_EXPORT_PRIVATE void encode(uint64_t);
+    WTF_EXPORT_PRIVATE void encode(int32_t);
+    WTF_EXPORT_PRIVATE void encode(int64_t);
+    WTF_EXPORT_PRIVATE void encode(float);
+    WTF_EXPORT_PRIVATE void encode(double);
 
     template<typename Type> void encodeNumber(Type);
 
@@ -115,6 +112,3 @@ void Encoder::updateChecksumForNumber(SHA1& sha1, Type value)
 
 }
 }
-
-#endif
-#endif
index be9d4b7..f07402a 100644 (file)
@@ -110,8 +110,6 @@ set(NetworkProcess_COMMON_SOURCES
     NetworkProcess/cache/NetworkCacheBlobStorage.cpp
     NetworkProcess/cache/NetworkCacheCoders.cpp
     NetworkProcess/cache/NetworkCacheData.cpp
-    NetworkProcess/cache/NetworkCacheDecoder.cpp
-    NetworkProcess/cache/NetworkCacheEncoder.cpp
     NetworkProcess/cache/NetworkCacheEntry.cpp
     NetworkProcess/cache/NetworkCacheFileSystem.cpp
     NetworkProcess/cache/NetworkCacheKey.cpp
index 0aeca8d..7d830a6 100644 (file)
@@ -1,3 +1,62 @@
+2017-01-08  Antti Koivisto  <antti@apple.com>
+
+        Move cache coders to WTF
+        https://bugs.webkit.org/show_bug.cgi?id=166825
+
+        Rubber-stamped by Sam Weinig.
+
+        * NetworkProcess/cache/NetworkCache.h:
+        * NetworkProcess/cache/NetworkCacheCoder.h: Removed.
+        * NetworkProcess/cache/NetworkCacheCoders.cpp:
+        (WebKit::NetworkCache::Coder<AtomicString>::encode): Deleted.
+        (WebKit::NetworkCache::Coder<AtomicString>::decode): Deleted.
+        (WebKit::NetworkCache::Coder<CString>::encode): Deleted.
+        (WebKit::NetworkCache::Coder<CString>::decode): Deleted.
+        (WebKit::NetworkCache::Coder<String>::encode): Deleted.
+        (WebKit::NetworkCache::decodeStringText): Deleted.
+        (WebKit::NetworkCache::Coder<String>::decode): Deleted.
+        (WebKit::NetworkCache::Coder<SHA1::Digest>::encode): Deleted.
+        (WebKit::NetworkCache::Coder<SHA1::Digest>::decode): Deleted.
+        (WebKit::NetworkCache::Coder<WebCore::HTTPHeaderMap>::encode): Deleted.
+        (WebKit::NetworkCache::Coder<WebCore::HTTPHeaderMap>::decode): Deleted.
+        * NetworkProcess/cache/NetworkCacheCoders.h:
+        (): Deleted.
+        (WebKit::NetworkCache::Coder<std::optional<T>>::encode): Deleted.
+        (WebKit::NetworkCache::Coder<std::optional<T>>::decode): Deleted.
+        * NetworkProcess/cache/NetworkCacheCodersCocoa.cpp:
+        (WebKit::NetworkCache::encodeCFData): Deleted.
+        (WebKit::NetworkCache::decodeCFData): Deleted.
+        (WebKit::NetworkCache::encodeSecTrustRef): Deleted.
+        (WebKit::NetworkCache::decodeSecTrustRef): Deleted.
+        (WebKit::NetworkCache::encodeCertificateChain): Deleted.
+        (WebKit::NetworkCache::decodeCertificateChain): Deleted.
+        (WebKit::NetworkCache::Coder<WebCore::CertificateInfo>::encode): Deleted.
+        (WebKit::NetworkCache::Coder<WebCore::CertificateInfo>::decode): Deleted.
+        * NetworkProcess/cache/NetworkCacheDecoder.cpp: Removed.
+        * NetworkProcess/cache/NetworkCacheDecoder.h: Removed.
+        * NetworkProcess/cache/NetworkCacheEncoder.cpp: Removed.
+        * NetworkProcess/cache/NetworkCacheEncoder.h: Removed.
+        * NetworkProcess/cache/NetworkCacheEntry.cpp:
+        (WebKit::NetworkCache::Entry::encodeAsStorageRecord):
+        (WebKit::NetworkCache::Entry::decodeStorageRecord):
+        * NetworkProcess/cache/NetworkCacheKey.cpp:
+        (WebKit::NetworkCache::Key::encode):
+        (WebKit::NetworkCache::Key::decode):
+        * NetworkProcess/cache/NetworkCacheKey.h:
+        * NetworkProcess/cache/NetworkCacheStorage.cpp:
+        (WebKit::NetworkCache::decodeRecordMetaData):
+        (WebKit::NetworkCache::encodeRecordMetaData):
+        * NetworkProcess/cache/NetworkCacheSubresourcesEntry.cpp:
+        (WebKit::NetworkCache::SubresourceInfo::encode):
+        (WebKit::NetworkCache::SubresourceInfo::decode):
+        (WebKit::NetworkCache::SubresourcesEntry::encodeAsStorageRecord):
+        (WebKit::NetworkCache::SubresourcesEntry::decodeStorageRecord):
+        * NetworkProcess/cache/NetworkCacheSubresourcesEntry.h:
+        * UIProcess/API/APIUserContentExtensionStore.cpp:
+        (API::encodeContentExtensionMetaData):
+        (API::decodeContentExtensionMetaData):
+        * WebKit2.xcodeproj/project.pbxproj:
+
 2017-01-09  Tomas Popela  <tpopela@redhat.com>
 
         [GTK] Replace WebKitWebSettings with WebKitSettings in documentation
index b883686..8423b31 100644 (file)
 
 #if ENABLE(NETWORK_CACHE)
 
-#include <wtf/text/CString.h>
-#include <wtf/text/WTFString.h>
-
-namespace WebKit {
-namespace NetworkCache {
-
-void Coder<AtomicString>::encode(Encoder& encoder, const AtomicString& atomicString)
-{
-    encoder << atomicString.string();
-}
-
-bool Coder<AtomicString>::decode(Decoder& decoder, AtomicString& atomicString)
-{
-    String string;
-    if (!decoder.decode(string))
-        return false;
-
-    atomicString = string;
-    return true;
-}
-
-void Coder<CString>::encode(Encoder& encoder, const CString& string)
-{
-    // Special case the null string.
-    if (string.isNull()) {
-        encoder << std::numeric_limits<uint32_t>::max();
-        return;
-    }
-
-    uint32_t length = string.length();
-    encoder << length;
-    encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.data()), length);
-}
-
-bool Coder<CString>::decode(Decoder& decoder, CString& result)
-{
-    uint32_t length;
-    if (!decoder.decode(length))
-        return false;
-
-    if (length == std::numeric_limits<uint32_t>::max()) {
-        // This is the null string.
-        result = CString();
-        return true;
-    }
-
-    // Before allocating the string, make sure that the decoder buffer is big enough.
-    if (!decoder.bufferIsLargeEnoughToContain<char>(length))
-        return false;
-
-    char* buffer;
-    CString string = CString::newUninitialized(length, buffer);
-    if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(buffer), length))
-        return false;
-
-    result = string;
-    return true;
-}
-
-
-void Coder<String>::encode(Encoder& encoder, const String& string)
-{
-    // Special case the null string.
-    if (string.isNull()) {
-        encoder << std::numeric_limits<uint32_t>::max();
-        return;
-    }
-
-    uint32_t length = string.length();
-    bool is8Bit = string.is8Bit();
-
-    encoder << length << is8Bit;
-
-    if (is8Bit)
-        encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.characters8()), length * sizeof(LChar));
-    else
-        encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.characters16()), length * sizeof(UChar));
-}
-
-template <typename CharacterType>
-static inline bool decodeStringText(Decoder& decoder, uint32_t length, String& result)
-{
-    // Before allocating the string, make sure that the decoder buffer is big enough.
-    if (!decoder.bufferIsLargeEnoughToContain<CharacterType>(length))
-        return false;
-
-    CharacterType* buffer;
-    String string = String::createUninitialized(length, buffer);
-    if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(buffer), length * sizeof(CharacterType)))
-        return false;
-    
-    result = string;
-    return true;    
-}
-
-bool Coder<String>::decode(Decoder& decoder, String& result)
-{
-    uint32_t length;
-    if (!decoder.decode(length))
-        return false;
-
-    if (length == std::numeric_limits<uint32_t>::max()) {
-        // This is the null string.
-        result = String();
-        return true;
-    }
-
-    bool is8Bit;
-    if (!decoder.decode(is8Bit))
-        return false;
-
-    if (is8Bit)
-        return decodeStringText<LChar>(decoder, length, result);
-    return decodeStringText<UChar>(decoder, length, result);
-}
-
-
-void Coder<SHA1::Digest>::encode(Encoder& encoder, const SHA1::Digest& digest)
-{
-    encoder.encodeFixedLengthData(digest.data(), sizeof(digest));
-}
-
-bool Coder<SHA1::Digest>::decode(Decoder& decoder, SHA1::Digest& digest)
-{
-    return decoder.decodeFixedLengthData(digest.data(), sizeof(digest));
-}
+namespace WTF {
+namespace Persistence {
 
 // Store common HTTP headers as strings instead of using their value in the HTTPHeaderName enumeration
 // so that the headers stored in the cache stays valid even after HTTPHeaderName.in gets updated.
index 4171ace..8cac8c4 100644 (file)
@@ -27,8 +27,6 @@
 
 #if ENABLE(NETWORK_CACHE)
 
-#include "NetworkCacheDecoder.h"
-#include "NetworkCacheEncoder.h"
 #include <WebCore/CertificateInfo.h>
 #include <WebCore/HTTPHeaderMap.h>
 #include <utility>
 #include <wtf/HashSet.h>
 #include <wtf/SHA1.h>
 #include <wtf/Vector.h>
+#include <wtf/persistence/Coders.h>
+#include <wtf/persistence/Decoder.h>
+#include <wtf/persistence/Encoder.h>
 
-namespace WebKit {
-namespace NetworkCache {
-
-template<typename T, typename U> struct Coder<std::pair<T, U>> {
-    static void encode(Encoder& encoder, const std::pair<T, U>& pair)
-    {
-        encoder << pair.first << pair.second;
-    }
-
-    static bool decode(Decoder& decoder, std::pair<T, U>& pair)
-    {
-        T first;
-        if (!decoder.decode(first))
-            return false;
-
-        U second;
-        if (!decoder.decode(second))
-            return false;
-
-        pair.first = first;
-        pair.second = second;
-        return true;
-    }
-};
-
-template<typename Rep, typename Period> struct Coder<std::chrono::duration<Rep, Period>> {
-    static void encode(Encoder& encoder, const std::chrono::duration<Rep, Period>& duration)
-    {
-        static_assert(std::is_integral<Rep>::value && std::is_signed<Rep>::value && sizeof(Rep) <= sizeof(int64_t), "Serialization of this Rep type is not supported yet. Only signed integer type which can be fit in an int64_t is currently supported.");
-        encoder << static_cast<int64_t>(duration.count());
-    }
-
-    static bool decode(Decoder& decoder, std::chrono::duration<Rep, Period>& result)
-    {
-        int64_t count;
-        if (!decoder.decode(count))
-            return false;
-        result = std::chrono::duration<Rep, Period>(static_cast<Rep>(count));
-        return true;
-    }
-};
-
-template<typename T> struct Coder<std::optional<T>> {
-    static void encode(Encoder& encoder, const std::optional<T>& optional)
-    {
-        if (!optional) {
-            encoder << false;
-            return;
-        }
-        
-        encoder << true;
-        encoder << optional.value();
-    }
-    
-    static bool decode(Decoder& decoder, std::optional<T>& optional)
-    {
-        bool isEngaged;
-        if (!decoder.decode(isEngaged))
-            return false;
-        
-        if (!isEngaged) {
-            optional = std::nullopt;
-            return true;
-        }
-        
-        T value;
-        if (!decoder.decode(value))
-            return false;
-        
-        optional = WTFMove(value);
-        return true;
-    }
-};
-
-template<typename KeyType, typename ValueType> struct Coder<WTF::KeyValuePair<KeyType, ValueType>> {
-    static void encode(Encoder& encoder, const WTF::KeyValuePair<KeyType, ValueType>& pair)
-    {
-        encoder << pair.key << pair.value;
-    }
-
-    static bool decode(Decoder& decoder, WTF::KeyValuePair<KeyType, ValueType>& pair)
-    {
-        KeyType key;
-        if (!decoder.decode(key))
-            return false;
-
-        ValueType value;
-        if (!decoder.decode(value))
-            return false;
-
-        pair.key = key;
-        pair.value = value;
-        return true;
-    }
-};
-
-template<bool fixedSizeElements, typename T, size_t inlineCapacity> struct VectorCoder;
-
-template<typename T, size_t inlineCapacity> struct VectorCoder<false, T, inlineCapacity> {
-    static void encode(Encoder& encoder, const Vector<T, inlineCapacity>& vector)
-    {
-        encoder << static_cast<uint64_t>(vector.size());
-        for (size_t i = 0; i < vector.size(); ++i)
-            encoder << vector[i];
-    }
-
-    static bool decode(Decoder& decoder, Vector<T, inlineCapacity>& vector)
-    {
-        uint64_t size;
-        if (!decoder.decode(size))
-            return false;
-
-        Vector<T, inlineCapacity> tmp;
-        for (size_t i = 0; i < size; ++i) {
-            T element;
-            if (!decoder.decode(element))
-                return false;
-            
-            tmp.append(WTFMove(element));
-        }
-
-        tmp.shrinkToFit();
-        vector.swap(tmp);
-        return true;
-    }
-};
-
-template<typename T, size_t inlineCapacity> struct VectorCoder<true, T, inlineCapacity> {
-    static void encode(Encoder& encoder, const Vector<T, inlineCapacity>& vector)
-    {
-        encoder << static_cast<uint64_t>(vector.size());
-        encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(vector.data()), vector.size() * sizeof(T), alignof(T));
-    }
-    
-    static bool decode(Decoder& decoder, Vector<T, inlineCapacity>& vector)
-    {
-        uint64_t size;
-        if (!decoder.decode(size))
-            return false;
-
-        // Since we know the total size of the elements, we can allocate the vector in
-        // one fell swoop. Before allocating we must however make sure that the decoder buffer
-        // is big enough.
-        if (!decoder.bufferIsLargeEnoughToContain<T>(size))
-            return false;
-
-        Vector<T, inlineCapacity> temp;
-        temp.resize(size);
-
-        decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(temp.data()), size * sizeof(T));
-
-        vector.swap(temp);
-        return true;
-    }
-};
-
-template<typename T, size_t inlineCapacity> struct Coder<Vector<T, inlineCapacity>> : VectorCoder<std::is_arithmetic<T>::value, T, inlineCapacity> { };
-
-template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg> struct Coder<HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>> {
-    typedef HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg> HashMapType;
-
-    static void encode(Encoder& encoder, const HashMapType& hashMap)
-    {
-        encoder << static_cast<uint64_t>(hashMap.size());
-        for (typename HashMapType::const_iterator it = hashMap.begin(), end = hashMap.end(); it != end; ++it)
-            encoder << *it;
-    }
-
-    static bool decode(Decoder& decoder, HashMapType& hashMap)
-    {
-        uint64_t hashMapSize;
-        if (!decoder.decode(hashMapSize))
-            return false;
-
-        HashMapType tempHashMap;
-        for (uint64_t i = 0; i < hashMapSize; ++i) {
-            KeyArg key;
-            MappedArg value;
-            if (!decoder.decode(key))
-                return false;
-            if (!decoder.decode(value))
-                return false;
-
-            if (!tempHashMap.add(key, value).isNewEntry) {
-                // The hash map already has the specified key, bail.
-                return false;
-            }
-        }
-
-        hashMap.swap(tempHashMap);
-        return true;
-    }
-};
-
-template<typename KeyArg, typename HashArg, typename KeyTraitsArg> struct Coder<HashSet<KeyArg, HashArg, KeyTraitsArg>> {
-    typedef HashSet<KeyArg, HashArg, KeyTraitsArg> HashSetType;
-
-    static void encode(Encoder& encoder, const HashSetType& hashSet)
-    {
-        encoder << static_cast<uint64_t>(hashSet.size());
-        for (typename HashSetType::const_iterator it = hashSet.begin(), end = hashSet.end(); it != end; ++it)
-            encoder << *it;
-    }
-
-    static bool decode(Decoder& decoder, HashSetType& hashSet)
-    {
-        uint64_t hashSetSize;
-        if (!decoder.decode(hashSetSize))
-            return false;
-
-        HashSetType tempHashSet;
-        for (uint64_t i = 0; i < hashSetSize; ++i) {
-            KeyArg key;
-            if (!decoder.decode(key))
-                return false;
-
-            if (!tempHashSet.add(key).isNewEntry) {
-                // The hash map already has the specified key, bail.
-                return false;
-            }
-        }
-
-        hashSet.swap(tempHashSet);
-        return true;
-    }
-};
-
-template<> struct Coder<AtomicString> {
-    static void encode(Encoder&, const AtomicString&);
-    static bool decode(Decoder&, AtomicString&);
-};
-
-template<> struct Coder<CString> {
-    static void encode(Encoder&, const CString&);
-    static bool decode(Decoder&, CString&);
-};
-
-template<> struct Coder<String> {
-    static void encode(Encoder&, const String&);
-    static bool decode(Decoder&, String&);
-};
+namespace WTF {
+namespace Persistence {
 
 template<> struct Coder<WebCore::CertificateInfo> {
     static void encode(Encoder&, const WebCore::CertificateInfo&);
     static bool decode(Decoder&, WebCore::CertificateInfo&);
 };
 
-template<> struct Coder<SHA1::Digest> {
-    static void encode(Encoder&, const SHA1::Digest&);
-    static bool decode(Decoder&, SHA1::Digest&);
-};
-
 template<> struct Coder<WebCore::HTTPHeaderMap> {
     static void encode(Encoder&, const WebCore::HTTPHeaderMap&);
     static bool decode(Decoder&, WebCore::HTTPHeaderMap&);
index 82bc6b4..5de5095 100644 (file)
@@ -34,8 +34,8 @@
 #include <wtf/spi/cocoa/SecuritySPI.h>
 #endif
 
-namespace WebKit {
-namespace NetworkCache {
+namespace WTF {
+namespace Persistence {
 
 static void encodeCFData(Encoder& encoder, CFDataRef data)
 {
index 3a3338b..0cef6ae 100644 (file)
@@ -28,8 +28,8 @@
 
 #if ENABLE(NETWORK_CACHE)
 
-namespace WebKit {
-namespace NetworkCache {
+namespace WTF {
+namespace Persistence {
 
 void Coder<WebCore::CertificateInfo>::encode(Encoder& encoder, const WebCore::CertificateInfo& certificateInfo)
 {
index 33fb53f..312dc87 100644 (file)
@@ -28,8 +28,6 @@
 
 #include "Logging.h"
 #include "NetworkCacheCoders.h"
-#include "NetworkCacheDecoder.h"
-#include "NetworkCacheEncoder.h"
 #include <WebCore/ResourceRequest.h>
 #include <WebCore/SharedBuffer.h>
 #include <wtf/text/StringBuilder.h>
@@ -83,7 +81,7 @@ Entry::Entry(const Storage::Record& storageEntry)
 
 Storage::Record Entry::encodeAsStorageRecord() const
 {
-    Encoder encoder;
+    WTF::Persistence::Encoder encoder;
     encoder << m_response;
 
     bool hasVaryingRequestHeaders = !m_varyingRequestHeaders.isEmpty();
@@ -110,7 +108,7 @@ std::unique_ptr<Entry> Entry::decodeStorageRecord(const Storage::Record& storage
 {
     auto entry = std::make_unique<Entry>(storageEntry);
 
-    Decoder decoder(storageEntry.header.data(), storageEntry.header.size());
+    WTF::Persistence::Decoder decoder(storageEntry.header.data(), storageEntry.header.size());
     if (!decoder.decode(entry->m_response))
         return nullptr;
     entry->m_response.setSource(WebCore::ResourceResponse::Source::DiskCache);
index 7c217cf..faa9f6c 100644 (file)
@@ -31,6 +31,8 @@
 #include "NetworkCacheCoders.h"
 #include <wtf/ASCIICType.h>
 #include <wtf/NeverDestroyed.h>
+#include <wtf/persistence/Decoder.h>
+#include <wtf/persistence/Encoder.h>
 #include <wtf/text/CString.h>
 #include <wtf/text/StringBuilder.h>
 
@@ -155,7 +157,7 @@ bool Key::operator==(const Key& other) const
     return m_hash == other.m_hash && m_partition == other.m_partition && m_type == other.m_type && m_identifier == other.m_identifier && m_range == other.m_range;
 }
 
-void Key::encode(Encoder& encoder) const
+void Key::encode(WTF::Persistence::Encoder& encoder) const
 {
     encoder << m_partition;
     encoder << m_type;
@@ -165,7 +167,7 @@ void Key::encode(Encoder& encoder) const
     encoder << m_partitionHash;
 }
 
-bool Key::decode(Decoder& decoder, Key& key)
+bool Key::decode(WTF::Persistence::Decoder& decoder, Key& key)
 {
     return decoder.decode(key.m_partition) && decoder.decode(key.m_type) && decoder.decode(key.m_identifier) && decoder.decode(key.m_range) && decoder.decode(key.m_hash) && decoder.decode(key.m_partitionHash);
 }
index 067350b..a25a83c 100644 (file)
 
 #include "NetworkCacheData.h"
 #include <wtf/SHA1.h>
+#include <wtf/persistence/Coder.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebKit {
 namespace NetworkCache {
 
-class Encoder;
-class Decoder;
-
 class Key {
 public:
     typedef SHA1::Digest HashType;
@@ -69,8 +67,8 @@ public:
     String hashAsString() const { return hashAsString(m_hash); }
     String partitionHashAsString() const { return hashAsString(m_partitionHash); }
 
-    void encode(Encoder&) const;
-    static bool decode(Decoder&, Key&);
+    void encode(WTF::Persistence::Encoder&) const;
+    static bool decode(WTF::Persistence::Decoder&, Key&);
 
     bool operator==(const Key&) const;
     bool operator!=(const Key& other) const { return !(*this == other); }
index 8f7c4f3..8f7b6e3 100644 (file)
@@ -380,7 +380,7 @@ static bool decodeRecordMetaData(RecordMetaData& metaData, const Data& fileData)
 {
     bool success = false;
     fileData.apply([&metaData, &success](const uint8_t* data, size_t size) {
-        Decoder decoder(data, size);
+        WTF::Persistence::Decoder decoder(data, size);
         if (!decoder.decode(metaData.cacheStorageVersion))
             return false;
         if (!decoder.decode(metaData.key))
@@ -464,7 +464,7 @@ void Storage::readRecord(ReadOperation& readOperation, const Data& recordData)
 
 static Data encodeRecordMetaData(const RecordMetaData& metaData)
 {
-    Encoder encoder;
+    WTF::Persistence::Encoder encoder;
 
     encoder << metaData.cacheStorageVersion;
     encoder << metaData.key;
index 4726979..d47a527 100644 (file)
 
 #include "Logging.h"
 #include "NetworkCacheCoders.h"
-#include "NetworkCacheDecoder.h"
-#include "NetworkCacheEncoder.h"
 
 namespace WebKit {
 namespace NetworkCache {
 
-void SubresourceInfo::encode(Encoder& encoder) const
+void SubresourceInfo::encode(WTF::Persistence::Encoder& encoder) const
 {
     encoder << m_isTransient;
 
@@ -48,7 +46,7 @@ void SubresourceInfo::encode(Encoder& encoder) const
     encoder << m_requestHeaders;
 }
 
-bool SubresourceInfo::decode(Decoder& decoder, SubresourceInfo& info)
+bool SubresourceInfo::decode(WTF::Persistence::Decoder& decoder, SubresourceInfo& info)
 {
     if (!decoder.decode(info.m_isTransient))
         return false;
@@ -67,7 +65,7 @@ bool SubresourceInfo::decode(Decoder& decoder, SubresourceInfo& info)
 
 Storage::Record SubresourcesEntry::encodeAsStorageRecord() const
 {
-    Encoder encoder;
+    WTF::Persistence::Encoder encoder;
     encoder << m_subresources;
 
     encoder.encodeChecksum();
@@ -79,7 +77,7 @@ std::unique_ptr<SubresourcesEntry> SubresourcesEntry::decodeStorageRecord(const
 {
     auto entry = std::make_unique<SubresourcesEntry>(storageEntry);
 
-    Decoder decoder(storageEntry.header.data(), storageEntry.header.size());
+    WTF::Persistence::Decoder decoder(storageEntry.header.data(), storageEntry.header.size());
     if (!decoder.decode(entry->m_subresources))
         return nullptr;
 
index 007f705..0d69d7d 100644 (file)
@@ -28,8 +28,6 @@
 
 #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
 
-#include "NetworkCacheDecoder.h"
-#include "NetworkCacheEncoder.h"
 #include "NetworkCacheStorage.h"
 #include <WebCore/ResourceRequest.h>
 #include <WebCore/URL.h>
@@ -41,8 +39,8 @@ namespace NetworkCache {
 class SubresourceInfo {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    void encode(Encoder&) const;
-    static bool decode(Decoder&, SubresourceInfo&);
+    void encode(WTF::Persistence::Encoder&) const;
+    static bool decode(WTF::Persistence::Decoder&, SubresourceInfo&);
 
     SubresourceInfo() = default;
     SubresourceInfo(const WebCore::ResourceRequest& request, bool isTransient = false)
index 86c3324..3a740fd 100644 (file)
@@ -30,8 +30,6 @@
 
 #include "APIUserContentExtension.h"
 #include "NetworkCacheData.h"
-#include "NetworkCacheDecoder.h"
-#include "NetworkCacheEncoder.h"
 #include "NetworkCacheFileSystem.h"
 #include "SharedMemory.h"
 #include "WebCompiledContentExtension.h"
@@ -41,6 +39,8 @@
 #include <wtf/NeverDestroyed.h>
 #include <wtf/RunLoop.h>
 #include <wtf/WorkQueue.h>
+#include <wtf/persistence/Decoder.h>
+#include <wtf/persistence/Encoder.h>
 
 using namespace WebKit::NetworkCache;
 
@@ -99,7 +99,7 @@ struct ContentExtensionMetaData {
 
 static Data encodeContentExtensionMetaData(const ContentExtensionMetaData& metaData)
 {
-    WebKit::NetworkCache::Encoder encoder;
+    WTF::Persistence::Encoder encoder;
 
     encoder << metaData.version;
     encoder << metaData.actionsSize;
@@ -120,7 +120,7 @@ static bool decodeContentExtensionMetaData(ContentExtensionMetaData& metaData, c
         if (size != fileData.size())
             return false;
 
-        WebKit::NetworkCache::Decoder decoder(data, size);
+        WTF::Persistence::Decoder decoder(data, size);
         if (!decoder.decode(metaData.version))
             return false;
         if (!decoder.decode(metaData.actionsSize))
index e61160f..2636f67 100644 (file)
                E4436ED01A0D040B00EAD204 /* NetworkCacheStorage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4436EC31A0CFDB200EAD204 /* NetworkCacheStorage.cpp */; };
                E4697CCD1B25EB8F001B0A6C /* NetworkCacheFileSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4697CCC1B25EB8F001B0A6C /* NetworkCacheFileSystem.cpp */; };
                E47D1E981B0649FB002676A8 /* NetworkCacheData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47D1E961B062B66002676A8 /* NetworkCacheData.cpp */; };
-               E489D28A1A0A2DB80078C06A /* NetworkCacheCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = E489D2831A0A2DB80078C06A /* NetworkCacheCoder.h */; };
                E489D28B1A0A2DB80078C06A /* NetworkCacheCoders.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E489D2841A0A2DB80078C06A /* NetworkCacheCoders.cpp */; };
                E489D28C1A0A2DB80078C06A /* NetworkCacheCoders.h in Headers */ = {isa = PBXBuildFile; fileRef = E489D2851A0A2DB80078C06A /* NetworkCacheCoders.h */; };
-               E489D28D1A0A2DB80078C06A /* NetworkCacheDecoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E489D2861A0A2DB80078C06A /* NetworkCacheDecoder.cpp */; };
-               E489D28E1A0A2DB80078C06A /* NetworkCacheDecoder.h in Headers */ = {isa = PBXBuildFile; fileRef = E489D2871A0A2DB80078C06A /* NetworkCacheDecoder.h */; };
-               E489D28F1A0A2DB80078C06A /* NetworkCacheEncoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E489D2881A0A2DB80078C06A /* NetworkCacheEncoder.cpp */; };
-               E489D2901A0A2DB80078C06A /* NetworkCacheEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = E489D2891A0A2DB80078C06A /* NetworkCacheEncoder.h */; };
                E49D40D71AD3FB170066B7B9 /* NetworkCacheBlobStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = E49D40D61AD3FB170066B7B9 /* NetworkCacheBlobStorage.h */; };
                E49D40D91AD3FB210066B7B9 /* NetworkCacheBlobStorage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E49D40D81AD3FB210066B7B9 /* NetworkCacheBlobStorage.cpp */; };
                E4E864921B16750100C82F40 /* VersionChecks.mm in Sources */ = {isa = PBXBuildFile; fileRef = E4E8648F1B1673FB00C82F40 /* VersionChecks.mm */; };
                E4436EC31A0CFDB200EAD204 /* NetworkCacheStorage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCacheStorage.cpp; sourceTree = "<group>"; };
                E4697CCC1B25EB8F001B0A6C /* NetworkCacheFileSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCacheFileSystem.cpp; sourceTree = "<group>"; };
                E47D1E961B062B66002676A8 /* NetworkCacheData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCacheData.cpp; sourceTree = "<group>"; };
-               E489D2831A0A2DB80078C06A /* NetworkCacheCoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCacheCoder.h; sourceTree = "<group>"; };
                E489D2841A0A2DB80078C06A /* NetworkCacheCoders.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCacheCoders.cpp; sourceTree = "<group>"; };
                E489D2851A0A2DB80078C06A /* NetworkCacheCoders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCacheCoders.h; sourceTree = "<group>"; };
-               E489D2861A0A2DB80078C06A /* NetworkCacheDecoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCacheDecoder.cpp; sourceTree = "<group>"; };
-               E489D2871A0A2DB80078C06A /* NetworkCacheDecoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCacheDecoder.h; sourceTree = "<group>"; };
-               E489D2881A0A2DB80078C06A /* NetworkCacheEncoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCacheEncoder.cpp; sourceTree = "<group>"; };
-               E489D2891A0A2DB80078C06A /* NetworkCacheEncoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCacheEncoder.h; sourceTree = "<group>"; };
                E49D40D61AD3FB170066B7B9 /* NetworkCacheBlobStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCacheBlobStorage.h; sourceTree = "<group>"; };
                E49D40D81AD3FB210066B7B9 /* NetworkCacheBlobStorage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCacheBlobStorage.cpp; sourceTree = "<group>"; };
                E4E8648E1B1673FB00C82F40 /* VersionChecks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VersionChecks.h; sourceTree = "<group>"; };
                                E4436EBF1A0CFDB200EAD204 /* NetworkCache.h */,
                                E49D40D81AD3FB210066B7B9 /* NetworkCacheBlobStorage.cpp */,
                                E49D40D61AD3FB170066B7B9 /* NetworkCacheBlobStorage.h */,
-                               E489D2831A0A2DB80078C06A /* NetworkCacheCoder.h */,
                                E489D2841A0A2DB80078C06A /* NetworkCacheCoders.cpp */,
                                E489D2851A0A2DB80078C06A /* NetworkCacheCoders.h */,
                                7CAB93791D459E4B0070F540 /* NetworkCacheCodersCocoa.cpp */,
                                E47D1E961B062B66002676A8 /* NetworkCacheData.cpp */,
                                E42E06111AA75ABD00B11699 /* NetworkCacheData.h */,
                                E42E06131AA75B7000B11699 /* NetworkCacheDataCocoa.mm */,
-                               E489D2861A0A2DB80078C06A /* NetworkCacheDecoder.cpp */,
-                               E489D2871A0A2DB80078C06A /* NetworkCacheDecoder.h */,
-                               E489D2881A0A2DB80078C06A /* NetworkCacheEncoder.cpp */,
-                               E489D2891A0A2DB80078C06A /* NetworkCacheEncoder.h */,
                                E413F59E1AC1AF9D00345360 /* NetworkCacheEntry.cpp */,
                                E413F59B1AC1ADB600345360 /* NetworkCacheEntry.h */,
                                E4697CCC1B25EB8F001B0A6C /* NetworkCacheFileSystem.cpp */,
                                E1798C7A16E6818800240139 /* NetworkBlobRegistry.h in Headers */,
                                E4436ECC1A0D040B00EAD204 /* NetworkCache.h in Headers */,
                                E49D40D71AD3FB170066B7B9 /* NetworkCacheBlobStorage.h in Headers */,
-                               E489D28A1A0A2DB80078C06A /* NetworkCacheCoder.h in Headers */,
                                E489D28C1A0A2DB80078C06A /* NetworkCacheCoders.h in Headers */,
                                E42E06121AA75ABD00B11699 /* NetworkCacheData.h in Headers */,
-                               E489D28E1A0A2DB80078C06A /* NetworkCacheDecoder.h in Headers */,
-                               E489D2901A0A2DB80078C06A /* NetworkCacheEncoder.h in Headers */,
                                E413F59D1AC1ADC400345360 /* NetworkCacheEntry.h in Headers */,
                                834B250F1A831A8D00CFB150 /* NetworkCacheFileSystem.h in Headers */,
                                E42E06101AA7523B00B11699 /* NetworkCacheIOChannel.h in Headers */,
                                7CAB937A1D459E510070F540 /* NetworkCacheCodersCocoa.cpp in Sources */,
                                E47D1E981B0649FB002676A8 /* NetworkCacheData.cpp in Sources */,
                                E42E06141AA75B7000B11699 /* NetworkCacheDataCocoa.mm in Sources */,
-                               E489D28D1A0A2DB80078C06A /* NetworkCacheDecoder.cpp in Sources */,
-                               E489D28F1A0A2DB80078C06A /* NetworkCacheEncoder.cpp in Sources */,
                                E413F59F1AC1AF9D00345360 /* NetworkCacheEntry.cpp in Sources */,
                                E4697CCD1B25EB8F001B0A6C /* NetworkCacheFileSystem.cpp in Sources */,
                                E42E060F1AA7523400B11699 /* NetworkCacheIOChannelCocoa.mm in Sources */,