Changeset 181140 in webkit
- Timestamp:
- Mar 6, 2015, 12:00:22 AM (10 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r181138 r181140 1 2015-03-05 Antti Koivisto <antti@apple.com> 2 3 Move disk cache classes to namespace 4 https://bugs.webkit.org/show_bug.cgi?id=142339 5 6 Reviewed by Anders Carlsson. 7 8 Move everything to NetworkCache namespace. 9 1 10 2015-03-05 Carlos Garcia Campos <cgarcia@igalia.com> 2 11 -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp
r181020 r181140 50 50 51 51 namespace WebKit { 52 53 NetworkCache& NetworkCache::singleton() 54 { 55 static NeverDestroyed<NetworkCache> instance; 52 namespace NetworkCache { 53 54 Cache& singleton() 55 { 56 static NeverDestroyed<Cache> instance; 56 57 return instance; 57 58 } 58 59 59 bool NetworkCache::initialize(const String& cachePath, bool enableEfficacyLogging)60 { 61 m_storage = NetworkCacheStorage::open(cachePath);60 bool Cache::initialize(const String& cachePath, bool enableEfficacyLogging) 61 { 62 m_storage = Storage::open(cachePath); 62 63 63 64 if (enableEfficacyLogging) 64 m_statistics = NetworkCacheStatistics::open(cachePath);65 m_statistics = Statistics::open(cachePath); 65 66 66 67 #if PLATFORM(COCOA) … … 78 79 } 79 80 80 void NetworkCache::setMaximumSize(size_t maximumSize)81 void Cache::setMaximumSize(size_t maximumSize) 81 82 { 82 83 if (!m_storage) … … 85 86 } 86 87 87 static NetworkCacheKey makeCacheKey(const WebCore::ResourceRequest& request)88 static Key makeCacheKey(const WebCore::ResourceRequest& request) 88 89 { 89 90 #if ENABLE(CACHE_PARTITIONING) … … 97 98 } 98 99 99 static NetworkCacheStorage::Entry encodeStorageEntry(const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response, PassRefPtr<WebCore::SharedBuffer> responseData)100 { 101 NetworkCacheEncoder encoder;100 static Storage::Entry encodeStorageEntry(const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response, PassRefPtr<WebCore::SharedBuffer> responseData) 101 { 102 Encoder encoder; 102 103 encoder << response; 103 104 … … 121 122 122 123 auto timeStamp = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()); 123 NetworkCacheData header(encoder.buffer(), encoder.bufferSize());124 NetworkCacheData body;124 Data header(encoder.buffer(), encoder.bufferSize()); 125 Data body; 125 126 if (responseData) 126 127 body = { reinterpret_cast<const uint8_t*>(responseData->data()), responseData->size() }; … … 156 157 } 157 158 158 static std::unique_ptr< NetworkCache::Entry> decodeStorageEntry(const NetworkCacheStorage::Entry& storageEntry, const WebCore::ResourceRequest& request, NetworkCache::CachedEntryReuseFailure& failure)159 { 160 NetworkCacheDecoder decoder(storageEntry.header.data(), storageEntry.header.size());159 static std::unique_ptr<Entry> decodeStorageEntry(const Storage::Entry& storageEntry, const WebCore::ResourceRequest& request, CachedEntryReuseFailure& failure) 160 { 161 Decoder decoder(storageEntry.header.data(), storageEntry.header.size()); 161 162 162 163 WebCore::ResourceResponse cachedResponse; 163 164 if (!decoder.decode(cachedResponse)) { 164 165 LOG(NetworkCache, "(NetworkProcess) response decoding failed\n"); 165 failure = NetworkCache::CachedEntryReuseFailure::Other;166 failure = CachedEntryReuseFailure::Other; 166 167 return nullptr; 167 168 } … … 169 170 bool hasVaryingRequestHeaders; 170 171 if (!decoder.decode(hasVaryingRequestHeaders)) { 171 failure = NetworkCache::CachedEntryReuseFailure::Other;172 failure = CachedEntryReuseFailure::Other; 172 173 return nullptr; 173 174 } … … 176 177 Vector<std::pair<String, String>> varyingRequestHeaders; 177 178 if (!decoder.decode(varyingRequestHeaders)) { 178 failure = NetworkCache::CachedEntryReuseFailure::Other;179 failure = CachedEntryReuseFailure::Other; 179 180 return nullptr; 180 181 } … … 182 183 if (!verifyVaryingRequestHeaders(varyingRequestHeaders, request)) { 183 184 LOG(NetworkCache, "(NetworkProcess) varying header mismatch\n"); 184 failure = NetworkCache::CachedEntryReuseFailure::VaryingHeaderMismatch;185 failure = CachedEntryReuseFailure::VaryingHeaderMismatch; 185 186 return nullptr; 186 187 } … … 188 189 if (!decoder.verifyChecksum()) { 189 190 LOG(NetworkCache, "(NetworkProcess) checksum verification failure\n"); 190 failure = NetworkCache::CachedEntryReuseFailure::Other;191 failure = CachedEntryReuseFailure::Other; 191 192 return nullptr; 192 193 } … … 203 204 LOG(NetworkCache, "(NetworkProcess) needsRevalidation hasValidatorFields=%d isExpired=%d age=%f lifetime=%f", isExpired, hasValidatorFields, age, lifetime); 204 205 if (!hasValidatorFields) { 205 failure = NetworkCache::CachedEntryReuseFailure::MissingValidatorFields;206 failure = CachedEntryReuseFailure::MissingValidatorFields; 206 207 return nullptr; 207 208 } 208 209 } 209 210 210 auto entry = std::make_unique< NetworkCache::Entry>();211 auto entry = std::make_unique<Entry>(); 211 212 entry->storageEntry = storageEntry; 212 213 entry->needsRevalidation = needsRevalidation; … … 228 229 } 229 230 230 static NetworkCache::RetrieveDecision canRetrieve(const WebCore::ResourceRequest& request)231 static RetrieveDecision canRetrieve(const WebCore::ResourceRequest& request) 231 232 { 232 233 if (!request.url().protocolIsInHTTPFamily()) 233 return NetworkCache::RetrieveDecision::NoDueToProtocol;234 return RetrieveDecision::NoDueToProtocol; 234 235 // FIXME: Support HEAD and OPTIONS requests. 235 236 if (request.httpMethod() != "GET") 236 return NetworkCache::RetrieveDecision::NoDueToHTTPMethod;237 return RetrieveDecision::NoDueToHTTPMethod; 237 238 // FIXME: We should be able to validate conditional requests using cache. 238 239 if (request.isConditional()) 239 return NetworkCache::RetrieveDecision::NoDueToConditionalRequest;240 return RetrieveDecision::NoDueToConditionalRequest; 240 241 if (request.cachePolicy() == WebCore::ReloadIgnoringCacheData) 241 return NetworkCache::RetrieveDecision::NoDueToReloadIgnoringCache;242 243 return NetworkCache::RetrieveDecision::Yes;244 } 245 246 void NetworkCache::retrieve(const WebCore::ResourceRequest& originalRequest, uint64_t webPageID, std::function<void (std::unique_ptr<Entry>)> completionHandler)242 return RetrieveDecision::NoDueToReloadIgnoringCache; 243 244 return RetrieveDecision::Yes; 245 } 246 247 void Cache::retrieve(const WebCore::ResourceRequest& originalRequest, uint64_t webPageID, std::function<void (std::unique_ptr<Entry>)> completionHandler) 247 248 { 248 249 ASSERT(isEnabled()); … … 250 251 LOG(NetworkCache, "(NetworkProcess) retrieving %s priority %u", originalRequest.url().string().ascii().data(), originalRequest.priority()); 251 252 252 NetworkCacheKey storageKey = makeCacheKey(originalRequest);253 Key storageKey = makeCacheKey(originalRequest); 253 254 RetrieveDecision retrieveDecision = canRetrieve(originalRequest); 254 255 if (retrieveDecision != RetrieveDecision::Yes) { … … 263 264 unsigned priority = originalRequest.priority(); 264 265 265 m_storage->retrieve(storageKey, priority, [this, originalRequest, completionHandler, startTime, storageKey, webPageID](std::unique_ptr< NetworkCacheStorage::Entry> entry) {266 m_storage->retrieve(storageKey, priority, [this, originalRequest, completionHandler, startTime, storageKey, webPageID](std::unique_ptr<Storage::Entry> entry) { 266 267 if (!entry) { 267 268 LOG(NetworkCache, "(NetworkProcess) not found in storage"); … … 290 291 } 291 292 292 static NetworkCache::StoreDecision canStore(const WebCore::ResourceRequest& originalRequest, const WebCore::ResourceResponse& response)293 static StoreDecision canStore(const WebCore::ResourceRequest& originalRequest, const WebCore::ResourceResponse& response) 293 294 { 294 295 if (!originalRequest.url().protocolIsInHTTPFamily() || !response.isHTTP()) { 295 296 LOG(NetworkCache, "(NetworkProcess) not HTTP"); 296 return NetworkCache::StoreDecision::NoDueToProtocol;297 return StoreDecision::NoDueToProtocol; 297 298 } 298 299 if (originalRequest.httpMethod() != "GET") { 299 300 LOG(NetworkCache, "(NetworkProcess) method %s", originalRequest.httpMethod().utf8().data()); 300 return NetworkCache::StoreDecision::NoDueToHTTPMethod;301 return StoreDecision::NoDueToHTTPMethod; 301 302 } 302 303 if (response.isAttachment()) { 303 304 LOG(NetworkCache, "(NetworkProcess) attachment"); 304 return NetworkCache::StoreDecision::NoDueToAttachmentResponse;305 return StoreDecision::NoDueToAttachmentResponse; 305 306 } 306 307 … … 315 316 if (response.cacheControlContainsNoStore()) { 316 317 LOG(NetworkCache, "(NetworkProcess) Cache-control:no-store"); 317 return NetworkCache::StoreDecision::NoDueToNoStoreResponse;318 } 319 return NetworkCache::StoreDecision::Yes;318 return StoreDecision::NoDueToNoStoreResponse; 319 } 320 return StoreDecision::Yes; 320 321 default: 321 322 LOG(NetworkCache, "(NetworkProcess) status code %d", response.httpStatusCode()); 322 323 } 323 324 324 return NetworkCache::StoreDecision::NoDueToHTTPStatusCode;325 } 326 327 void NetworkCache::store(const WebCore::ResourceRequest& originalRequest, const WebCore::ResourceResponse& response, RefPtr<WebCore::SharedBuffer>&& responseData, std::function<void (MappedBody&)> completionHandler)325 return StoreDecision::NoDueToHTTPStatusCode; 326 } 327 328 void Cache::store(const WebCore::ResourceRequest& originalRequest, const WebCore::ResourceResponse& response, RefPtr<WebCore::SharedBuffer>&& responseData, std::function<void (MappedBody&)> completionHandler) 328 329 { 329 330 ASSERT(isEnabled()); … … 344 345 auto storageEntry = encodeStorageEntry(originalRequest, response, WTF::move(responseData)); 345 346 346 m_storage->store(storageEntry, [completionHandler](bool success, const NetworkCacheData& bodyData) {347 m_storage->store(storageEntry, [completionHandler](bool success, const Data& bodyData) { 347 348 MappedBody mappedBody; 348 349 #if ENABLE(SHAREABLE_RESOURCE) … … 359 360 } 360 361 361 void NetworkCache::update(const WebCore::ResourceRequest& originalRequest, const Entry& entry, const WebCore::ResourceResponse& validatingResponse)362 void Cache::update(const WebCore::ResourceRequest& originalRequest, const Entry& entry, const WebCore::ResourceResponse& validatingResponse) 362 363 { 363 364 LOG(NetworkCache, "(NetworkProcess) updating %s", originalRequest.url().string().latin1().data()); … … 368 369 auto updateEntry = encodeStorageEntry(originalRequest, response, entry.buffer); 369 370 370 m_storage->update(updateEntry, entry.storageEntry, [](bool success, const NetworkCacheData&) {371 m_storage->update(updateEntry, entry.storageEntry, [](bool success, const Data&) { 371 372 LOG(NetworkCache, "(NetworkProcess) updated, success=%d", success); 372 373 }); 373 374 } 374 375 375 void NetworkCache::traverse(std::function<void (const Entry*)>&& traverseHandler)376 void Cache::traverse(std::function<void (const Entry*)>&& traverseHandler) 376 377 { 377 378 ASSERT(isEnabled()); 378 379 379 m_storage->traverse([traverseHandler](const NetworkCacheStorage::Entry* entry) {380 m_storage->traverse([traverseHandler](const Storage::Entry* entry) { 380 381 if (!entry) { 381 382 traverseHandler(nullptr); … … 383 384 } 384 385 385 NetworkCache::Entry cacheEntry;386 Entry cacheEntry; 386 387 cacheEntry.storageEntry = *entry; 387 388 388 NetworkCacheDecoder decoder(cacheEntry.storageEntry.header.data(), cacheEntry.storageEntry.header.size());389 Decoder decoder(cacheEntry.storageEntry.header.data(), cacheEntry.storageEntry.header.size()); 389 390 if (!decoder.decode(cacheEntry.response)) 390 391 return; … … 394 395 } 395 396 396 String NetworkCache::dumpFilePath() const397 String Cache::dumpFilePath() const 397 398 { 398 399 return WebCore::pathByAppendingComponent(m_storage->baseDirectoryPath(), "dump.json"); 399 400 } 400 401 401 static bool entryAsJSON(StringBuilder& json, const NetworkCacheStorage::Entry& entry)402 { 403 NetworkCacheDecoder decoder(entry.header.data(), entry.header.size());402 static bool entryAsJSON(StringBuilder& json, const Storage::Entry& entry) 403 { 404 Decoder decoder(entry.header.data(), entry.header.size()); 404 405 WebCore::ResourceResponse cachedResponse; 405 406 if (!decoder.decode(cachedResponse)) … … 434 435 } 435 436 436 void NetworkCache::dumpContentsToFile()437 void Cache::dumpContentsToFile() 437 438 { 438 439 if (!m_storage) … … 442 443 return; 443 444 WebCore::writeToFile(dumpFileHandle, "[\n", 2); 444 m_storage->traverse([dumpFileHandle](const NetworkCacheStorage::Entry* entry) {445 m_storage->traverse([dumpFileHandle](const Storage::Entry* entry) { 445 446 if (!entry) { 446 447 WebCore::writeToFile(dumpFileHandle, "{}\n]\n", 5); … … 458 459 } 459 460 460 void NetworkCache::clear()461 void Cache::clear() 461 462 { 462 463 LOG(NetworkCache, "(NetworkProcess) clearing cache"); … … 474 475 } 475 476 476 String NetworkCache::storagePath() const477 String Cache::storagePath() const 477 478 { 478 479 return m_storage ? m_storage->directoryPath() : String(); … … 480 481 481 482 } 482 483 #endif 483 } 484 485 #endif -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h
r180899 r181140 1 1 /* 2 * Copyright (C) 2014 Apple Inc. All rights reserved.2 * Copyright (C) 2014-2015 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 41 41 42 42 namespace WebKit { 43 namespace NetworkCache { 43 44 44 class NetworkCacheStatistics; 45 class Cache; 46 class Statistics; 45 47 46 class NetworkCache { 47 WTF_MAKE_NONCOPYABLE(NetworkCache); 48 friend class WTF::NeverDestroyed<NetworkCache>; 48 Cache& singleton(); 49 50 struct MappedBody { 51 #if ENABLE(SHAREABLE_RESOURCE) 52 RefPtr<ShareableResource> shareableResource; 53 ShareableResource::Handle shareableResourceHandle; 54 #endif 55 }; 56 57 struct Entry { 58 Storage::Entry storageEntry; 59 WebCore::ResourceResponse response; 60 RefPtr<WebCore::SharedBuffer> buffer; 61 #if ENABLE(SHAREABLE_RESOURCE) 62 ShareableResource::Handle shareableResourceHandle; 63 #endif 64 bool needsRevalidation; 65 }; 66 67 enum class RetrieveDecision { 68 Yes, 69 NoDueToProtocol, 70 NoDueToHTTPMethod, 71 NoDueToConditionalRequest, 72 NoDueToReloadIgnoringCache 73 }; 74 75 enum class StoreDecision { 76 Yes, 77 NoDueToProtocol, 78 NoDueToHTTPMethod, 79 NoDueToAttachmentResponse, 80 NoDueToNoStoreResponse, 81 NoDueToHTTPStatusCode 82 }; 83 84 enum class CachedEntryReuseFailure { 85 None, 86 VaryingHeaderMismatch, 87 MissingValidatorFields, 88 Other, 89 }; 90 91 class Cache { 92 WTF_MAKE_NONCOPYABLE(Cache); 93 friend class WTF::NeverDestroyed<Cache>; 49 94 public: 50 enum class RetrieveDecision {51 Yes,52 NoDueToProtocol,53 NoDueToHTTPMethod,54 NoDueToConditionalRequest,55 NoDueToReloadIgnoringCache56 };57 58 enum class StoreDecision {59 Yes,60 NoDueToProtocol,61 NoDueToHTTPMethod,62 NoDueToAttachmentResponse,63 NoDueToNoStoreResponse,64 NoDueToHTTPStatusCode65 };66 67 enum class CachedEntryReuseFailure {68 None,69 VaryingHeaderMismatch,70 MissingValidatorFields,71 Other,72 };73 74 static NetworkCache& singleton();75 76 95 bool initialize(const String& cachePath, bool enableEfficacyLogging); 77 96 void setMaximumSize(size_t); … … 79 98 bool isEnabled() const { return !!m_storage; } 80 99 81 struct Entry {82 NetworkCacheStorage::Entry storageEntry;83 WebCore::ResourceResponse response;84 RefPtr<WebCore::SharedBuffer> buffer;85 #if ENABLE(SHAREABLE_RESOURCE)86 ShareableResource::Handle shareableResourceHandle;87 #endif88 bool needsRevalidation;89 };90 100 // Completion handler may get called back synchronously on failure. 91 101 void retrieve(const WebCore::ResourceRequest&, uint64_t webPageID, std::function<void (std::unique_ptr<Entry>)>); 92 93 struct MappedBody {94 #if ENABLE(SHAREABLE_RESOURCE)95 RefPtr<ShareableResource> shareableResource;96 ShareableResource::Handle shareableResourceHandle;97 #endif98 };99 102 void store(const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, RefPtr<WebCore::SharedBuffer>&&, std::function<void (MappedBody&)>); 100 103 void update(const WebCore::ResourceRequest&, const Entry&, const WebCore::ResourceResponse& validatingResponse); … … 109 112 110 113 private: 111 NetworkCache() = default;112 ~ NetworkCache() = delete;114 Cache() = default; 115 ~Cache() = delete; 113 116 114 117 String dumpFilePath() const; 115 118 116 std::unique_ptr< NetworkCacheStorage> m_storage;117 std::unique_ptr< NetworkCacheStatistics> m_statistics;119 std::unique_ptr<Storage> m_storage; 120 std::unique_ptr<Statistics> m_statistics; 118 121 }; 119 122 120 123 } 124 } 121 125 #endif 122 126 #endif -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoder.h
r175748 r181140 30 30 31 31 namespace WebKit { 32 namespace NetworkCache { 32 33 33 class NetworkCacheDecoder;34 class NetworkCacheEncoder;34 class Decoder; 35 class Encoder; 35 36 36 template<typename T> struct NetworkCacheCoder {37 static void encode( NetworkCacheEncoder& encoder, const T& t)37 template<typename T> struct Coder { 38 static void encode(Encoder& encoder, const T& t) 38 39 { 39 40 t.encode(encoder); 40 41 } 41 42 42 static bool decode( NetworkCacheDecoder& decoder, T& t)43 static bool decode(Decoder& decoder, T& t) 43 44 { 44 45 return T::decode(decoder, t); … … 47 48 48 49 } 50 } 49 51 50 52 #endif -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.cpp
r179779 r181140 34 34 35 35 namespace WebKit { 36 namespace NetworkCache { 36 37 37 void NetworkCacheCoder<AtomicString>::encode(NetworkCacheEncoder& encoder, const AtomicString& atomicString)38 void Coder<AtomicString>::encode(Encoder& encoder, const AtomicString& atomicString) 38 39 { 39 40 encoder << atomicString.string(); 40 41 } 41 42 42 bool NetworkCacheCoder<AtomicString>::decode(NetworkCacheDecoder& decoder, AtomicString& atomicString)43 bool Coder<AtomicString>::decode(Decoder& decoder, AtomicString& atomicString) 43 44 { 44 45 String string; … … 50 51 } 51 52 52 void NetworkCacheCoder<CString>::encode(NetworkCacheEncoder& encoder, const CString& string)53 void Coder<CString>::encode(Encoder& encoder, const CString& string) 53 54 { 54 55 // Special case the null string. … … 63 64 } 64 65 65 bool NetworkCacheCoder<CString>::decode(NetworkCacheDecoder& decoder, CString& result)66 bool Coder<CString>::decode(Decoder& decoder, CString& result) 66 67 { 67 68 uint32_t length; … … 91 92 92 93 93 void NetworkCacheCoder<String>::encode(NetworkCacheEncoder& encoder, const String& string)94 void Coder<String>::encode(Encoder& encoder, const String& string) 94 95 { 95 96 // Special case the null string. … … 111 112 112 113 template <typename CharacterType> 113 static inline bool decodeStringText( NetworkCacheDecoder& decoder, uint32_t length, String& result)114 static inline bool decodeStringText(Decoder& decoder, uint32_t length, String& result) 114 115 { 115 116 // Before allocating the string, make sure that the decoder buffer is big enough. … … 128 129 } 129 130 130 bool NetworkCacheCoder<String>::decode(NetworkCacheDecoder& decoder, String& result)131 bool Coder<String>::decode(Decoder& decoder, String& result) 131 132 { 132 133 uint32_t length; … … 149 150 } 150 151 151 void NetworkCacheCoder<WebCore::CertificateInfo>::encode(NetworkCacheEncoder& encoder, const WebCore::CertificateInfo& certificateInfo)152 void Coder<WebCore::CertificateInfo>::encode(Encoder& encoder, const WebCore::CertificateInfo& certificateInfo) 152 153 { 153 154 // FIXME: Cocoa CertificateInfo is a CF object tree. Generalize CF type coding so we don't need to use ArgumentCoder here. … … 158 159 } 159 160 160 bool NetworkCacheCoder<WebCore::CertificateInfo>::decode(NetworkCacheDecoder& decoder, WebCore::CertificateInfo& certificateInfo)161 bool Coder<WebCore::CertificateInfo>::decode(Decoder& decoder, WebCore::CertificateInfo& certificateInfo) 161 162 { 162 163 uint64_t certificateSize; … … 174 175 } 175 176 176 void NetworkCacheCoder<MD5::Digest>::encode(NetworkCacheEncoder& encoder, const MD5::Digest& digest)177 void Coder<MD5::Digest>::encode(Encoder& encoder, const MD5::Digest& digest) 177 178 { 178 179 encoder.encodeFixedLengthData(digest.data(), sizeof(digest)); 179 180 } 180 181 181 bool NetworkCacheCoder<MD5::Digest>::decode(NetworkCacheDecoder& decoder, MD5::Digest& digest)182 bool Coder<MD5::Digest>::decode(Decoder& decoder, MD5::Digest& digest) 182 183 { 183 184 return decoder.decodeFixedLengthData(digest.data(), sizeof(digest)); … … 185 186 186 187 } 188 } 187 189 188 190 #endif -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.h
r179781 r181140 40 40 41 41 namespace WebKit { 42 43 template<typename T, typename U> struct NetworkCacheCoder<std::pair<T, U>> { 44 static void encode(NetworkCacheEncoder& encoder, const std::pair<T, U>& pair) 42 namespace NetworkCache { 43 44 template<typename T, typename U> struct Coder<std::pair<T, U>> { 45 static void encode(Encoder& encoder, const std::pair<T, U>& pair) 45 46 { 46 47 encoder << pair.first << pair.second; 47 48 } 48 49 49 static bool decode( NetworkCacheDecoder& decoder, std::pair<T, U>& pair)50 static bool decode(Decoder& decoder, std::pair<T, U>& pair) 50 51 { 51 52 T first; … … 63 64 }; 64 65 65 template<typename Rep, typename Period> struct NetworkCacheCoder<std::chrono::duration<Rep, Period>> {66 static void encode( NetworkCacheEncoder& encoder, const std::chrono::duration<Rep, Period>& duration)66 template<typename Rep, typename Period> struct Coder<std::chrono::duration<Rep, Period>> { 67 static void encode(Encoder& encoder, const std::chrono::duration<Rep, Period>& duration) 67 68 { 68 69 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."); … … 70 71 } 71 72 72 static bool decode( NetworkCacheDecoder& decoder, std::chrono::duration<Rep, Period>& result)73 static bool decode(Decoder& decoder, std::chrono::duration<Rep, Period>& result) 73 74 { 74 75 int64_t count; … … 80 81 }; 81 82 82 template<typename KeyType, typename ValueType> struct NetworkCacheCoder<WTF::KeyValuePair<KeyType, ValueType>> {83 static void encode( NetworkCacheEncoder& encoder, const WTF::KeyValuePair<KeyType, ValueType>& pair)83 template<typename KeyType, typename ValueType> struct Coder<WTF::KeyValuePair<KeyType, ValueType>> { 84 static void encode(Encoder& encoder, const WTF::KeyValuePair<KeyType, ValueType>& pair) 84 85 { 85 86 encoder << pair.key << pair.value; 86 87 } 87 88 88 static bool decode( NetworkCacheDecoder& decoder, WTF::KeyValuePair<KeyType, ValueType>& pair)89 static bool decode(Decoder& decoder, WTF::KeyValuePair<KeyType, ValueType>& pair) 89 90 { 90 91 KeyType key; … … 102 103 }; 103 104 104 template<bool fixedSizeElements, typename T, size_t inlineCapacity> struct Vector NetworkCacheCoder;105 106 template<typename T, size_t inlineCapacity> struct Vector NetworkCacheCoder<false, T, inlineCapacity> {107 static void encode( NetworkCacheEncoder& encoder, const Vector<T, inlineCapacity>& vector)105 template<bool fixedSizeElements, typename T, size_t inlineCapacity> struct VectorCoder; 106 107 template<typename T, size_t inlineCapacity> struct VectorCoder<false, T, inlineCapacity> { 108 static void encode(Encoder& encoder, const Vector<T, inlineCapacity>& vector) 108 109 { 109 110 encoder << static_cast<uint64_t>(vector.size()); … … 112 113 } 113 114 114 static bool decode( NetworkCacheDecoder& decoder, Vector<T, inlineCapacity>& vector)115 static bool decode(Decoder& decoder, Vector<T, inlineCapacity>& vector) 115 116 { 116 117 uint64_t size; … … 133 134 }; 134 135 135 template<typename T, size_t inlineCapacity> struct Vector NetworkCacheCoder<true, T, inlineCapacity> {136 static void encode( NetworkCacheEncoder& encoder, const Vector<T, inlineCapacity>& vector)136 template<typename T, size_t inlineCapacity> struct VectorCoder<true, T, inlineCapacity> { 137 static void encode(Encoder& encoder, const Vector<T, inlineCapacity>& vector) 137 138 { 138 139 encoder << static_cast<uint64_t>(vector.size()); … … 140 141 } 141 142 142 static bool decode( NetworkCacheDecoder& decoder, Vector<T, inlineCapacity>& vector)143 static bool decode(Decoder& decoder, Vector<T, inlineCapacity>& vector) 143 144 { 144 145 uint64_t size; … … 164 165 }; 165 166 166 template<typename T, size_t inlineCapacity> struct NetworkCacheCoder<Vector<T, inlineCapacity>> : VectorNetworkCacheCoder<std::is_arithmetic<T>::value, T, inlineCapacity> { };167 168 template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg> struct NetworkCacheCoder<HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>> {167 template<typename T, size_t inlineCapacity> struct Coder<Vector<T, inlineCapacity>> : VectorCoder<std::is_arithmetic<T>::value, T, inlineCapacity> { }; 168 169 template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg> struct Coder<HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>> { 169 170 typedef HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg> HashMapType; 170 171 171 static void encode( NetworkCacheEncoder& encoder, const HashMapType& hashMap)172 static void encode(Encoder& encoder, const HashMapType& hashMap) 172 173 { 173 174 encoder << static_cast<uint64_t>(hashMap.size()); … … 176 177 } 177 178 178 static bool decode( NetworkCacheDecoder& decoder, HashMapType& hashMap)179 static bool decode(Decoder& decoder, HashMapType& hashMap) 179 180 { 180 181 uint64_t hashMapSize; … … 203 204 }; 204 205 205 template<typename KeyArg, typename HashArg, typename KeyTraitsArg> struct NetworkCacheCoder<HashSet<KeyArg, HashArg, KeyTraitsArg>> {206 template<typename KeyArg, typename HashArg, typename KeyTraitsArg> struct Coder<HashSet<KeyArg, HashArg, KeyTraitsArg>> { 206 207 typedef HashSet<KeyArg, HashArg, KeyTraitsArg> HashSetType; 207 208 208 static void encode( NetworkCacheEncoder& encoder, const HashSetType& hashSet)209 static void encode(Encoder& encoder, const HashSetType& hashSet) 209 210 { 210 211 encoder << static_cast<uint64_t>(hashSet.size()); … … 213 214 } 214 215 215 static bool decode( NetworkCacheDecoder& decoder, HashSetType& hashSet)216 static bool decode(Decoder& decoder, HashSetType& hashSet) 216 217 { 217 218 uint64_t hashSetSize; … … 237 238 }; 238 239 239 template<> struct NetworkCacheCoder<AtomicString> {240 static void encode( NetworkCacheEncoder&, const AtomicString&);241 static bool decode( NetworkCacheDecoder&, AtomicString&);242 }; 243 244 template<> struct NetworkCacheCoder<CString> {245 static void encode( NetworkCacheEncoder&, const CString&);246 static bool decode( NetworkCacheDecoder&, CString&);247 }; 248 249 template<> struct NetworkCacheCoder<String> {250 static void encode( NetworkCacheEncoder&, const String&);251 static bool decode( NetworkCacheDecoder&, String&);252 }; 253 254 template<> struct NetworkCacheCoder<WebCore::CertificateInfo> {255 static void encode( NetworkCacheEncoder&, const WebCore::CertificateInfo&);256 static bool decode( NetworkCacheDecoder&, WebCore::CertificateInfo&);257 }; 258 259 template<> struct NetworkCacheCoder<MD5::Digest> {260 static void encode( NetworkCacheEncoder&, const MD5::Digest&);261 static bool decode( NetworkCacheDecoder&, MD5::Digest&);240 template<> struct Coder<AtomicString> { 241 static void encode(Encoder&, const AtomicString&); 242 static bool decode(Decoder&, AtomicString&); 243 }; 244 245 template<> struct Coder<CString> { 246 static void encode(Encoder&, const CString&); 247 static bool decode(Decoder&, CString&); 248 }; 249 250 template<> struct Coder<String> { 251 static void encode(Encoder&, const String&); 252 static bool decode(Decoder&, String&); 253 }; 254 255 template<> struct Coder<WebCore::CertificateInfo> { 256 static void encode(Encoder&, const WebCore::CertificateInfo&); 257 static bool decode(Decoder&, WebCore::CertificateInfo&); 258 }; 259 260 template<> struct Coder<MD5::Digest> { 261 static void encode(Encoder&, const MD5::Digest&); 262 static bool decode(Decoder&, MD5::Digest&); 262 263 }; 263 264 264 265 } 265 266 } 266 267 #endif 267 268 #endif -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheData.h
r181020 r181140 35 35 36 36 namespace WebKit { 37 namespace NetworkCache { 37 38 38 39 #if PLATFORM(COCOA) … … 93 94 #endif 94 95 95 class NetworkCacheData {96 class Data { 96 97 public: 97 NetworkCacheData() { }98 NetworkCacheData(const uint8_t*, size_t);98 Data() { } 99 Data(const uint8_t*, size_t); 99 100 100 101 enum class Backing { Buffer, Map }; 101 102 #if PLATFORM(COCOA) 102 NetworkCacheData(DispatchPtr<dispatch_data_t>, Backing = Backing::Buffer);103 Data(DispatchPtr<dispatch_data_t>, Backing = Backing::Buffer); 103 104 #endif 104 105 bool isNull() const; … … 121 122 122 123 } 124 } 123 125 124 126 #endif -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDataCocoa.mm
r181020 r181140 25 25 26 26 #include "config.h" 27 #include "NetworkCache data.h"27 #include "NetworkCacheData.h" 28 28 29 29 #if ENABLE(NETWORK_CACHE) … … 32 32 33 33 namespace WebKit { 34 namespace NetworkCache { 34 35 35 NetworkCacheData::NetworkCacheData(const uint8_t* data, size_t size)36 Data::Data(const uint8_t* data, size_t size) 36 37 : m_dispatchData(adoptDispatch(dispatch_data_create(data, size, nullptr, DISPATCH_DATA_DESTRUCTOR_DEFAULT))) 37 38 , m_size(size) … … 39 40 } 40 41 41 NetworkCacheData::NetworkCacheData(DispatchPtr<dispatch_data_t> dispatchData, Backing backing)42 Data::Data(DispatchPtr<dispatch_data_t> dispatchData, Backing backing) 42 43 { 43 44 if (!dispatchData) … … 49 50 } 50 51 51 const uint8_t* NetworkCacheData::data() const52 const uint8_t* Data::data() const 52 53 { 53 54 if (!m_data) { … … 61 62 } 62 63 63 bool NetworkCacheData::isNull() const64 bool Data::isNull() const 64 65 { 65 66 return !m_dispatchData; … … 67 68 68 69 } 70 } 69 71 70 72 #endif -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDecoder.cpp
r176398 r181140 32 32 33 33 namespace WebKit { 34 namespace NetworkCache { 34 35 35 NetworkCacheDecoder::NetworkCacheDecoder(const uint8_t* buffer, size_t bufferSize)36 Decoder::Decoder(const uint8_t* buffer, size_t bufferSize) 36 37 : m_buffer(buffer) 37 38 , m_bufferPosition(buffer) … … 41 42 } 42 43 43 NetworkCacheDecoder::~NetworkCacheDecoder()44 Decoder::~Decoder() 44 45 { 45 46 } 46 47 47 bool NetworkCacheDecoder::bufferIsLargeEnoughToContain(size_t size) const48 bool Decoder::bufferIsLargeEnoughToContain(size_t size) const 48 49 { 49 50 return m_bufferPosition + size <= m_bufferEnd; 50 51 } 51 52 52 bool NetworkCacheDecoder::decodeFixedLengthData(uint8_t* data, size_t size)53 bool Decoder::decodeFixedLengthData(uint8_t* data, size_t size) 53 54 { 54 55 if (!bufferIsLargeEnoughToContain(size)) … … 58 59 m_bufferPosition += size; 59 60 60 NetworkCacheEncoder::updateChecksumForData(m_checksum, data, size);61 Encoder::updateChecksumForData(m_checksum, data, size); 61 62 return true; 62 63 } 63 64 64 65 template<typename Type> 65 bool NetworkCacheDecoder::decodeNumber(Type& value)66 bool Decoder::decodeNumber(Type& value) 66 67 { 67 68 if (!bufferIsLargeEnoughToContain(sizeof(value))) … … 71 72 m_bufferPosition += sizeof(Type); 72 73 73 NetworkCacheEncoder::updateChecksumForNumber(m_checksum, value);74 Encoder::updateChecksumForNumber(m_checksum, value); 74 75 return true; 75 76 } 76 77 77 bool NetworkCacheDecoder::decode(bool& result)78 bool Decoder::decode(bool& result) 78 79 { 79 80 return decodeNumber(result); 80 81 } 81 82 82 bool NetworkCacheDecoder::decode(uint8_t& result)83 bool Decoder::decode(uint8_t& result) 83 84 { 84 85 return decodeNumber(result); 85 86 } 86 87 87 bool NetworkCacheDecoder::decode(uint16_t& result)88 bool Decoder::decode(uint16_t& result) 88 89 { 89 90 return decodeNumber(result); 90 91 } 91 92 92 bool NetworkCacheDecoder::decode(uint32_t& result)93 bool Decoder::decode(uint32_t& result) 93 94 { 94 95 return decodeNumber(result); 95 96 } 96 97 97 bool NetworkCacheDecoder::decode(uint64_t& result)98 bool Decoder::decode(uint64_t& result) 98 99 { 99 100 return decodeNumber(result); 100 101 } 101 102 102 bool NetworkCacheDecoder::decode(int32_t& result)103 bool Decoder::decode(int32_t& result) 103 104 { 104 105 return decodeNumber(result); 105 106 } 106 107 107 bool NetworkCacheDecoder::decode(int64_t& result)108 bool Decoder::decode(int64_t& result) 108 109 { 109 110 return decodeNumber(result); 110 111 } 111 112 112 bool NetworkCacheDecoder::decode(float& result)113 bool Decoder::decode(float& result) 113 114 { 114 115 return decodeNumber(result); 115 116 } 116 117 117 bool NetworkCacheDecoder::decode(double& result)118 bool Decoder::decode(double& result) 118 119 { 119 120 return decodeNumber(result); 120 121 } 121 122 122 bool NetworkCacheDecoder::verifyChecksum()123 bool Decoder::verifyChecksum() 123 124 { 124 125 unsigned computedChecksum = m_checksum; … … 130 131 131 132 } 133 } 132 134 133 135 #endif -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDecoder.h
r176398 r181140 32 32 33 33 namespace WebKit { 34 namespace NetworkCache { 34 35 35 class NetworkCacheDecoder {36 class Decoder { 36 37 WTF_MAKE_FAST_ALLOCATED; 37 38 public: 38 NetworkCacheDecoder(const uint8_t* buffer, size_t bufferSize);39 virtual ~ NetworkCacheDecoder();39 Decoder(const uint8_t* buffer, size_t bufferSize); 40 virtual ~Decoder(); 40 41 41 42 size_t length() const { return m_bufferEnd - m_buffer; } … … 73 74 template<typename T> bool decode(T& t) 74 75 { 75 return NetworkCacheCoder<T>::decode(*this, t);76 return Coder<T>::decode(*this, t); 76 77 } 77 78 … … 99 100 100 101 } 102 } 101 103 102 104 #endif -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEncoder.cpp
r177294 r181140 30 30 31 31 namespace WebKit { 32 namespace NetworkCache { 32 33 33 NetworkCacheEncoder::NetworkCacheEncoder()34 Encoder::Encoder() 34 35 : m_checksum(0) 35 36 { 36 37 } 37 38 38 NetworkCacheEncoder::~NetworkCacheEncoder()39 Encoder::~Encoder() 39 40 { 40 41 } 41 42 42 uint8_t* NetworkCacheEncoder::grow(size_t size)43 uint8_t* Encoder::grow(size_t size) 43 44 { 44 45 size_t newPosition = m_buffer.size(); … … 47 48 } 48 49 49 void NetworkCacheEncoder::updateChecksumForData(unsigned& checksum, const uint8_t* data, size_t size)50 void Encoder::updateChecksumForData(unsigned& checksum, const uint8_t* data, size_t size) 50 51 { 51 52 // FIXME: hashMemory should not require alignment. 52 53 size_t hashSize = size - size % 2; 53 unsigned hash = StringHasher::hashMemory(data, hashSize) ^ NetworkCacheEncoder::Salt<uint8_t*>::value;54 unsigned hash = StringHasher::hashMemory(data, hashSize) ^ Encoder::Salt<uint8_t*>::value; 54 55 checksum = WTF::pairIntHash(checksum, hash); 55 56 } 56 57 57 void NetworkCacheEncoder::encodeFixedLengthData(const uint8_t* data, size_t size)58 void Encoder::encodeFixedLengthData(const uint8_t* data, size_t size) 58 59 { 59 60 updateChecksumForData(m_checksum, data, size); … … 64 65 65 66 template<typename Type> 66 void NetworkCacheEncoder::encodeNumber(Type value)67 void Encoder::encodeNumber(Type value) 67 68 { 68 NetworkCacheEncoder::updateChecksumForNumber(m_checksum, value);69 Encoder::updateChecksumForNumber(m_checksum, value); 69 70 70 71 uint8_t* buffer = grow(sizeof(Type)); … … 72 73 } 73 74 74 void NetworkCacheEncoder::encode(bool value)75 void Encoder::encode(bool value) 75 76 { 76 77 encodeNumber(value); 77 78 } 78 79 79 void NetworkCacheEncoder::encode(uint8_t value)80 void Encoder::encode(uint8_t value) 80 81 { 81 82 encodeNumber(value); 82 83 } 83 84 84 void NetworkCacheEncoder::encode(uint16_t value)85 void Encoder::encode(uint16_t value) 85 86 { 86 87 encodeNumber(value); 87 88 } 88 89 89 void NetworkCacheEncoder::encode(uint32_t value)90 void Encoder::encode(uint32_t value) 90 91 { 91 92 encodeNumber(value); 92 93 } 93 94 94 void NetworkCacheEncoder::encode(uint64_t value)95 void Encoder::encode(uint64_t value) 95 96 { 96 97 encodeNumber(value); 97 98 } 98 99 99 void NetworkCacheEncoder::encode(int32_t value)100 void Encoder::encode(int32_t value) 100 101 { 101 102 encodeNumber(value); 102 103 } 103 104 104 void NetworkCacheEncoder::encode(int64_t value)105 void Encoder::encode(int64_t value) 105 106 { 106 107 encodeNumber(value); 107 108 } 108 109 109 void NetworkCacheEncoder::encode(float value)110 void Encoder::encode(float value) 110 111 { 111 112 encodeNumber(value); 112 113 } 113 114 114 void NetworkCacheEncoder::encode(double value)115 void Encoder::encode(double value) 115 116 { 116 117 encodeNumber(value); 117 118 } 118 119 119 void NetworkCacheEncoder::encodeChecksum()120 void Encoder::encodeChecksum() 120 121 { 121 122 encodeNumber(m_checksum); … … 123 124 124 125 } 126 } 125 127 126 128 #endif -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEncoder.h
r176398 r181140 35 35 36 36 namespace WebKit { 37 namespace NetworkCache { 37 38 38 class NetworkCacheEncoder;39 class Encoder; 39 40 class DataReference; 40 41 41 class NetworkCacheEncoder {42 class Encoder { 42 43 WTF_MAKE_FAST_ALLOCATED; 43 44 public: 44 NetworkCacheEncoder();45 virtual ~ NetworkCacheEncoder();45 Encoder(); 46 virtual ~Encoder(); 46 47 47 48 void encodeChecksum(); … … 57 58 template<typename T> void encode(const T& t) 58 59 { 59 NetworkCacheCoder<T>::encode(*this, t);60 Coder<T>::encode(*this, t); 60 61 } 61 62 62 template<typename T> NetworkCacheEncoder& operator<<(const T& t)63 template<typename T> Encoder& operator<<(const T& t) 63 64 { 64 65 encode(t); … … 93 94 }; 94 95 95 template <> struct NetworkCacheEncoder::Salt<bool> { static const unsigned value = 3; };96 template <> struct NetworkCacheEncoder::Salt<uint8_t> { static const unsigned value = 5; };97 template <> struct NetworkCacheEncoder::Salt<uint16_t> { static const unsigned value = 7; };98 template <> struct NetworkCacheEncoder::Salt<uint32_t> { static const unsigned value = 11; };99 template <> struct NetworkCacheEncoder::Salt<uint64_t> { static const unsigned value = 13; };100 template <> struct NetworkCacheEncoder::Salt<int32_t> { static const unsigned value = 17; };101 template <> struct NetworkCacheEncoder::Salt<int64_t> { static const unsigned value = 19; };102 template <> struct NetworkCacheEncoder::Salt<float> { static const unsigned value = 23; };103 template <> struct NetworkCacheEncoder::Salt<double> { static const unsigned value = 29; };104 template <> struct NetworkCacheEncoder::Salt<uint8_t*> { static const unsigned value = 101; };96 template <> struct Encoder::Salt<bool> { static const unsigned value = 3; }; 97 template <> struct Encoder::Salt<uint8_t> { static const unsigned value = 5; }; 98 template <> struct Encoder::Salt<uint16_t> { static const unsigned value = 7; }; 99 template <> struct Encoder::Salt<uint32_t> { static const unsigned value = 11; }; 100 template <> struct Encoder::Salt<uint64_t> { static const unsigned value = 13; }; 101 template <> struct Encoder::Salt<int32_t> { static const unsigned value = 17; }; 102 template <> struct Encoder::Salt<int64_t> { static const unsigned value = 19; }; 103 template <> struct Encoder::Salt<float> { static const unsigned value = 23; }; 104 template <> struct Encoder::Salt<double> { static const unsigned value = 29; }; 105 template <> struct Encoder::Salt<uint8_t*> { static const unsigned value = 101; }; 105 106 106 107 template <typename Type> 107 void NetworkCacheEncoder::updateChecksumForNumber(unsigned& checksum, Type value)108 void Encoder::updateChecksumForNumber(unsigned& checksum, Type value) 108 109 { 109 unsigned hash = WTF::intHash(static_cast<uint64_t>(value)) ^ NetworkCacheEncoder::Salt<Type>::value;110 unsigned hash = WTF::intHash(static_cast<uint64_t>(value)) ^ Encoder::Salt<Type>::value; 110 111 checksum = WTF::pairIntHash(checksum, hash); 111 112 } 112 113 113 114 } 115 } 114 116 115 117 #endif -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystemPosix.h
r180947 r181140 35 35 36 36 namespace WebKit { 37 namespace NetworkCache { 37 38 38 39 template <typename Function> … … 60 61 String partitionPath = WebCore::pathByAppendingComponent(cachePath, subdirName); 61 62 traverseDirectory(partitionPath, DT_REG, [&function, &partitionPath](const String& fileName) { 62 if (fileName.length() != NetworkCacheKey::hashStringLength())63 if (fileName.length() != Key::hashStringLength()) 63 64 return; 64 65 function(fileName, partitionPath); … … 67 68 } 68 69 69 } // namespace WebKit 70 } 71 } 70 72 71 73 #endif // ENABLE(NETWORK_CACHE) -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannel.h
r181020 r181140 35 35 36 36 namespace WebKit { 37 namespace NetworkCache { 37 38 38 class NetworkCacheIOChannel : public ThreadSafeRefCounted<NetworkCacheIOChannel> {39 class IOChannel : public ThreadSafeRefCounted<IOChannel> { 39 40 public: 40 41 enum class Type { Read, Write, Create }; 41 static Ref< NetworkCacheIOChannel> open(const String& file, Type);42 static Ref<IOChannel> open(const String& file, Type); 42 43 43 void read(size_t offset, size_t, std::function<void ( NetworkCacheData&, int error)>);44 void write(size_t offset, const NetworkCacheData&, std::function<void (int error)>);44 void read(size_t offset, size_t, std::function<void (Data&, int error)>); 45 void write(size_t offset, const Data&, std::function<void (int error)>); 45 46 46 47 int fileDescriptor() const { return m_fileDescriptor; } 47 48 48 49 private: 49 NetworkCacheIOChannel(int fd);50 IOChannel(int fd); 50 51 51 52 #if PLATFORM(COCOA) … … 56 57 57 58 } 59 } 58 60 59 61 #endif -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm
r181020 r181140 38 38 39 39 namespace WebKit { 40 namespace NetworkCache { 40 41 41 NetworkCacheIOChannel::NetworkCacheIOChannel(int fd)42 IOChannel::IOChannel(int fd) 42 43 : m_fileDescriptor(fd) 43 44 { … … 50 51 } 51 52 52 Ref< NetworkCacheIOChannel> NetworkCacheIOChannel::open(const String& filePath, NetworkCacheIOChannel::Type type)53 Ref<IOChannel> IOChannel::open(const String& filePath, IOChannel::Type type) 53 54 { 54 55 int oflag; … … 72 73 int fd = ::open(path.data(), oflag, mode); 73 74 74 return adoptRef(*new NetworkCacheIOChannel(fd));75 return adoptRef(*new IOChannel(fd)); 75 76 } 76 77 77 void NetworkCacheIOChannel::read(size_t offset, size_t size, std::function<void ( NetworkCacheData&, int error)> completionHandler)78 void IOChannel::read(size_t offset, size_t size, std::function<void ( Data&, int error)> completionHandler) 78 79 { 79 RefPtr< NetworkCacheIOChannel> channel(this);80 RefPtr<IOChannel> channel(this); 80 81 bool didCallCompletionHandler = false; 81 82 dispatch_io_read(m_dispatchIO.get(), offset, size, dispatch_get_main_queue(), [channel, completionHandler, didCallCompletionHandler](bool done, dispatch_data_t fileData, int error) mutable { 82 83 if (done) { 83 84 if (!didCallCompletionHandler) { 84 NetworkCacheData nullData;85 Data nullData; 85 86 completionHandler(nullData, error); 86 87 } … … 88 89 } 89 90 ASSERT(!didCallCompletionHandler); 90 NetworkCacheData data(fileData);91 Data data(fileData); 91 92 completionHandler(data, error); 92 93 didCallCompletionHandler = true; … … 94 95 } 95 96 96 void NetworkCacheIOChannel::write(size_t offset, const NetworkCacheData& data, std::function<void (int error)> completionHandler)97 void IOChannel::write(size_t offset, const Data& data, std::function<void (int error)> completionHandler) 97 98 { 98 RefPtr< NetworkCacheIOChannel> channel(this);99 RefPtr<IOChannel> channel(this); 99 100 auto dispatchData = data.dispatchData(); 100 101 dispatch_io_write(m_dispatchIO.get(), offset, dispatchData, dispatch_get_main_queue(), [channel, completionHandler](bool done, dispatch_data_t fileData, int error) { … … 105 106 106 107 } 108 } 109 107 110 #endif -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.cpp
r180949 r181140 35 35 36 36 namespace WebKit { 37 namespace NetworkCache { 37 38 38 NetworkCacheKey::NetworkCacheKey(const NetworkCacheKey& o)39 Key::Key(const Key& o) 39 40 : m_method(o.m_method.isolatedCopy()) 40 41 , m_partition(o.m_partition.isolatedCopy()) … … 44 45 } 45 46 46 NetworkCacheKey::NetworkCacheKey(NetworkCacheKey&& o)47 Key::Key(Key&& o) 47 48 : m_method(WTF::move(o.m_method)) 48 49 , m_partition(WTF::move(o.m_partition)) … … 52 53 } 53 54 54 NetworkCacheKey::NetworkCacheKey(const String& method, const String& partition, const String& identifier)55 Key::Key(const String& method, const String& partition, const String& identifier) 55 56 : m_method(method.isolatedCopy()) 56 57 , m_partition(partition.isolatedCopy()) … … 60 61 } 61 62 62 NetworkCacheKey& NetworkCacheKey::operator=(const NetworkCacheKey& other)63 Key& Key::operator=(const Key& other) 63 64 { 64 65 m_method = other.m_method.isolatedCopy(); … … 82 83 } 83 84 84 NetworkCacheKey::HashType NetworkCacheKey::computeHash() const85 Key::HashType Key::computeHash() const 85 86 { 86 87 // We don't really need a cryptographic hash. The key is always verified against the entry header. … … 95 96 } 96 97 97 String NetworkCacheKey::hashAsString() const98 String Key::hashAsString() const 98 99 { 99 100 StringBuilder builder; … … 106 107 } 107 108 108 template <typename CharType> bool hexDigitsToHash(CharType* characters, NetworkCacheKey::HashType& hash)109 template <typename CharType> bool hexDigitsToHash(CharType* characters, Key::HashType& hash) 109 110 { 110 111 for (unsigned i = 0; i < sizeof(hash); ++i) { … … 118 119 } 119 120 120 bool NetworkCacheKey::stringToHash(const String& string, HashType& hash)121 bool Key::stringToHash(const String& string, HashType& hash) 121 122 { 122 123 if (string.length() != hashStringLength()) … … 127 128 } 128 129 129 bool NetworkCacheKey::operator==(const NetworkCacheKey& other) const130 bool Key::operator==(const Key& other) const 130 131 { 131 132 return m_hash == other.m_hash && m_method == other.m_method && m_partition == other.m_partition && m_identifier == other.m_identifier; 132 133 } 133 134 134 void NetworkCacheKey::encode(NetworkCacheEncoder& encoder) const135 void Key::encode(Encoder& encoder) const 135 136 { 136 137 encoder << m_method; … … 140 141 } 141 142 142 bool NetworkCacheKey::decode(NetworkCacheDecoder& decoder, NetworkCacheKey& key)143 bool Key::decode(Decoder& decoder, Key& key) 143 144 { 144 145 return decoder.decode(key.m_method) && decoder.decode(key.m_partition) && decoder.decode(key.m_identifier) && decoder.decode(key.m_hash); … … 146 147 147 148 } 149 } 148 150 149 151 #endif -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.h
r180949 r181140 33 33 34 34 namespace WebKit { 35 namespace NetworkCache { 35 36 36 class NetworkCacheEncoder;37 class NetworkCacheDecoder;37 class Encoder; 38 class Decoder; 38 39 39 class NetworkCacheKey {40 class Key { 40 41 public: 41 42 typedef MD5::Digest HashType; 42 43 43 NetworkCacheKey() { }44 NetworkCacheKey(const NetworkCacheKey&);45 NetworkCacheKey(NetworkCacheKey&&);46 NetworkCacheKey(const String& method, const String& partition, const String& identifier);44 Key() { } 45 Key(const Key&); 46 Key(Key&&); 47 Key(const String& method, const String& partition, const String& identifier); 47 48 48 NetworkCacheKey& operator=(const NetworkCacheKey&);49 Key& operator=(const Key&); 49 50 50 51 bool isNull() const { return m_identifier.isNull(); } … … 63 64 String hashAsString() const; 64 65 65 void encode( NetworkCacheEncoder&) const;66 static bool decode( NetworkCacheDecoder&, NetworkCacheKey&);66 void encode(Encoder&) const; 67 static bool decode(Decoder&, Key&); 67 68 68 bool operator==(const NetworkCacheKey&) const;69 bool operator!=(const NetworkCacheKey& other) const { return !(*this == other); }69 bool operator==(const Key&) const; 70 bool operator!=(const Key& other) const { return !(*this == other); } 70 71 71 72 private: … … 79 80 80 81 } 82 } 81 83 82 84 #endif -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.h
r181086 r181140 40 40 41 41 namespace WebKit { 42 namespace NetworkCache { 42 43 43 class NetworkCacheStatistics {44 class Statistics { 44 45 public: 45 static std::unique_ptr< NetworkCacheStatistics> open(const String& cachePath);46 static std::unique_ptr<Statistics> open(const String& cachePath); 46 47 47 48 void clear(); 48 49 49 void recordNotCachingResponse(const NetworkCacheKey&, NetworkCache::StoreDecision);50 void recordNotUsingCacheForRequest(uint64_t webPageID, const NetworkCacheKey&, const WebCore::ResourceRequest&, NetworkCache::RetrieveDecision);51 void recordRetrievalFailure(uint64_t webPageID, const NetworkCacheKey&, const WebCore::ResourceRequest&);52 void recordRetrievedCachedEntry(uint64_t webPageID, const NetworkCacheKey&, const WebCore::ResourceRequest&, NetworkCache::CachedEntryReuseFailure);50 void recordNotCachingResponse(const Key&, StoreDecision); 51 void recordNotUsingCacheForRequest(uint64_t webPageID, const Key&, const WebCore::ResourceRequest&, RetrieveDecision); 52 void recordRetrievalFailure(uint64_t webPageID, const Key&, const WebCore::ResourceRequest&); 53 void recordRetrievedCachedEntry(uint64_t webPageID, const Key&, const WebCore::ResourceRequest&, CachedEntryReuseFailure); 53 54 54 55 private: 55 explicit NetworkCacheStatistics(const String& databasePath);56 explicit Statistics(const String& databasePath); 56 57 57 58 void initialize(const String& databasePath); … … 63 64 void writeTimerFired(); 64 65 65 typedef std::function<void (bool wasEverRequested, const Optional< NetworkCache::StoreDecision>&)> RequestedCompletionHandler;66 typedef std::function<void (bool wasEverRequested, const Optional<StoreDecision>&)> RequestedCompletionHandler; 66 67 enum class NeedUncachedReason { No, Yes }; 67 68 void queryWasEverRequested(const String&, NeedUncachedReason, const RequestedCompletionHandler&); … … 86 87 }; 87 88 88 } // namespace WebKit 89 } 90 } 89 91 90 92 #endif // ENABLE(NETWORK_CACHE) -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatisticsCocoa.mm
r181086 r181140 42 42 43 43 namespace WebKit { 44 45 static const char* networkCacheStatisticsDatabaseName = "WebKitCacheStatistics.db"; 44 namespace NetworkCache { 45 46 static const char* StatisticsDatabaseName = "WebKitCacheStatistics.db"; 46 47 static const std::chrono::milliseconds mininumWriteInterval = std::chrono::milliseconds(10000); 47 48 … … 73 74 } 74 75 75 std::unique_ptr< NetworkCacheStatistics> NetworkCacheStatistics::open(const String& cachePath)76 { 77 ASSERT(RunLoop::isMain()); 78 79 String databasePath = WebCore::pathByAppendingComponent(cachePath, networkCacheStatisticsDatabaseName);80 return std::unique_ptr< NetworkCacheStatistics>(new NetworkCacheStatistics(databasePath));81 } 82 83 NetworkCacheStatistics::NetworkCacheStatistics(const String& databasePath)76 std::unique_ptr<Statistics> Statistics::open(const String& cachePath) 77 { 78 ASSERT(RunLoop::isMain()); 79 80 String databasePath = WebCore::pathByAppendingComponent(cachePath, StatisticsDatabaseName); 81 return std::unique_ptr<Statistics>(new Statistics(databasePath)); 82 } 83 84 Statistics::Statistics(const String& databasePath) 84 85 : m_backgroundIOQueue(adoptDispatch(dispatch_queue_create("com.apple.WebKit.Cache.Statistics.Background", DISPATCH_QUEUE_SERIAL))) 85 , m_writeTimer(*this, & NetworkCacheStatistics::writeTimerFired)86 , m_writeTimer(*this, &Statistics::writeTimerFired) 86 87 { 87 88 dispatch_set_target_queue(m_backgroundIOQueue.get(), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)); … … 90 91 } 91 92 92 void NetworkCacheStatistics::initialize(const String& databasePath)93 void Statistics::initialize(const String& databasePath) 93 94 { 94 95 ASSERT(RunLoop::isMain()); … … 97 98 98 99 StringCapture databasePathCapture(databasePath); 99 StringCapture networkCachePathCapture( NetworkCache::singleton().storagePath());100 StringCapture networkCachePathCapture(singleton().storagePath()); 100 101 dispatch_async(m_backgroundIOQueue.get(), [this, databasePathCapture, networkCachePathCapture, startTime] { 101 102 WebCore::SQLiteTransactionInProgressAutoCounter transactionCounter; … … 139 140 } 140 141 141 void NetworkCacheStatistics::bootstrapFromNetworkCache(const String& networkCachePath)142 void Statistics::bootstrapFromNetworkCache(const String& networkCachePath) 142 143 { 143 144 ASSERT(!RunLoop::isMain()); … … 159 160 } 160 161 161 void NetworkCacheStatistics::shrinkIfNeeded()162 void Statistics::shrinkIfNeeded() 162 163 { 163 164 ASSERT(RunLoop::isMain()); … … 171 172 clear(); 172 173 173 StringCapture networkCachePathCapture( NetworkCache::singleton().storagePath());174 StringCapture networkCachePathCapture(singleton().storagePath()); 174 175 dispatch_async(m_backgroundIOQueue.get(), [this, networkCachePathCapture] { 175 176 bootstrapFromNetworkCache(networkCachePathCapture.string()); … … 178 179 } 179 180 180 void NetworkCacheStatistics::recordNotCachingResponse(const NetworkCacheKey& key, NetworkCache::StoreDecision storeDecision)181 { 182 ASSERT(storeDecision != NetworkCache::StoreDecision::Yes);181 void Statistics::recordNotCachingResponse(const Key& key, StoreDecision storeDecision) 182 { 183 ASSERT(storeDecision != StoreDecision::Yes); 183 184 184 185 m_storeDecisionsToAdd.set(key.hashAsString(), storeDecision); … … 187 188 } 188 189 189 static String retrieveDecisionToDiagnosticKey( NetworkCache::RetrieveDecision retrieveDecision)190 static String retrieveDecisionToDiagnosticKey(RetrieveDecision retrieveDecision) 190 191 { 191 192 switch (retrieveDecision) { 192 case NetworkCache::RetrieveDecision::NoDueToProtocol:193 case RetrieveDecision::NoDueToProtocol: 193 194 return WebCore::DiagnosticLoggingKeys::notHTTPFamilyKey(); 194 case NetworkCache::RetrieveDecision::NoDueToHTTPMethod:195 case RetrieveDecision::NoDueToHTTPMethod: 195 196 return WebCore::DiagnosticLoggingKeys::unsupportedHTTPMethodKey(); 196 case NetworkCache::RetrieveDecision::NoDueToConditionalRequest:197 case RetrieveDecision::NoDueToConditionalRequest: 197 198 return WebCore::DiagnosticLoggingKeys::isConditionalRequestKey(); 198 case NetworkCache::RetrieveDecision::NoDueToReloadIgnoringCache:199 case RetrieveDecision::NoDueToReloadIgnoringCache: 199 200 return WebCore::DiagnosticLoggingKeys::isReloadIgnoringCacheDataKey(); 200 case NetworkCache::RetrieveDecision::Yes:201 case RetrieveDecision::Yes: 201 202 ASSERT_NOT_REACHED(); 202 203 break; … … 205 206 } 206 207 207 void NetworkCacheStatistics::recordNotUsingCacheForRequest(uint64_t webPageID, const NetworkCacheKey& key, const WebCore::ResourceRequest& request, NetworkCache::RetrieveDecision retrieveDecision)208 { 209 ASSERT(retrieveDecision != NetworkCache::RetrieveDecision::Yes);208 void Statistics::recordNotUsingCacheForRequest(uint64_t webPageID, const Key& key, const WebCore::ResourceRequest& request, RetrieveDecision retrieveDecision) 209 { 210 ASSERT(retrieveDecision != RetrieveDecision::Yes); 210 211 211 212 String hash = key.hashAsString(); 212 213 WebCore::URL requestURL = request.url(); 213 queryWasEverRequested(hash, NeedUncachedReason::No, [this, hash, requestURL, webPageID, retrieveDecision](bool wasEverRequested, const Optional< NetworkCache::StoreDecision>&) {214 queryWasEverRequested(hash, NeedUncachedReason::No, [this, hash, requestURL, webPageID, retrieveDecision](bool wasEverRequested, const Optional<StoreDecision>&) { 214 215 if (wasEverRequested) { 215 216 String diagnosticKey = retrieveDecisionToDiagnosticKey(retrieveDecision); … … 221 222 } 222 223 223 static String storeDecisionToDiagnosticKey( NetworkCache::StoreDecision storeDecision)224 static String storeDecisionToDiagnosticKey(StoreDecision storeDecision) 224 225 { 225 226 switch (storeDecision) { 226 case NetworkCache::StoreDecision::NoDueToProtocol:227 case StoreDecision::NoDueToProtocol: 227 228 return WebCore::DiagnosticLoggingKeys::notHTTPFamilyKey(); 228 case NetworkCache::StoreDecision::NoDueToHTTPMethod:229 case StoreDecision::NoDueToHTTPMethod: 229 230 return WebCore::DiagnosticLoggingKeys::unsupportedHTTPMethodKey(); 230 case NetworkCache::StoreDecision::NoDueToAttachmentResponse:231 case StoreDecision::NoDueToAttachmentResponse: 231 232 return WebCore::DiagnosticLoggingKeys::isAttachmentKey(); 232 case NetworkCache::StoreDecision::NoDueToNoStoreResponse:233 case StoreDecision::NoDueToNoStoreResponse: 233 234 return WebCore::DiagnosticLoggingKeys::cacheControlNoStoreKey(); 234 case NetworkCache::StoreDecision::NoDueToHTTPStatusCode:235 case StoreDecision::NoDueToHTTPStatusCode: 235 236 return WebCore::DiagnosticLoggingKeys::uncacheableStatusCodeKey(); 236 case NetworkCache::StoreDecision::Yes:237 case StoreDecision::Yes: 237 238 // It was stored but could not be retrieved so it must have been pruned from the cache. 238 239 return WebCore::DiagnosticLoggingKeys::noLongerInCacheKey(); … … 241 242 } 242 243 243 void NetworkCacheStatistics::recordRetrievalFailure(uint64_t webPageID, const NetworkCacheKey& key, const WebCore::ResourceRequest& request)244 void Statistics::recordRetrievalFailure(uint64_t webPageID, const Key& key, const WebCore::ResourceRequest& request) 244 245 { 245 246 String hash = key.hashAsString(); 246 247 WebCore::URL requestURL = request.url(); 247 queryWasEverRequested(hash, NeedUncachedReason::Yes, [this, hash, requestURL, webPageID](bool wasPreviouslyRequested, const Optional< NetworkCache::StoreDecision>& storeDecision) {248 queryWasEverRequested(hash, NeedUncachedReason::Yes, [this, hash, requestURL, webPageID](bool wasPreviouslyRequested, const Optional<StoreDecision>& storeDecision) { 248 249 if (wasPreviouslyRequested) { 249 250 String diagnosticKey = storeDecisionToDiagnosticKey(storeDecision.value()); … … 255 256 } 256 257 257 static String cachedEntryReuseFailureToDiagnosticKey( NetworkCache::CachedEntryReuseFailure failure)258 static String cachedEntryReuseFailureToDiagnosticKey(CachedEntryReuseFailure failure) 258 259 { 259 260 switch (failure) { 260 case NetworkCache::CachedEntryReuseFailure::VaryingHeaderMismatch:261 case CachedEntryReuseFailure::VaryingHeaderMismatch: 261 262 return WebCore::DiagnosticLoggingKeys::varyingHeaderMismatchKey(); 262 case NetworkCache::CachedEntryReuseFailure::MissingValidatorFields:263 case CachedEntryReuseFailure::MissingValidatorFields: 263 264 return WebCore::DiagnosticLoggingKeys::missingValidatorFieldsKey(); 264 case NetworkCache::CachedEntryReuseFailure::Other:265 case CachedEntryReuseFailure::Other: 265 266 return WebCore::DiagnosticLoggingKeys::otherKey(); 266 case NetworkCache::CachedEntryReuseFailure::None:267 case CachedEntryReuseFailure::None: 267 268 ASSERT_NOT_REACHED(); 268 269 break; … … 271 272 } 272 273 273 void NetworkCacheStatistics::recordRetrievedCachedEntry(uint64_t webPageID, const NetworkCacheKey& key, const WebCore::ResourceRequest& request, NetworkCache::CachedEntryReuseFailure failure)274 void Statistics::recordRetrievedCachedEntry(uint64_t webPageID, const Key& key, const WebCore::ResourceRequest& request, CachedEntryReuseFailure failure) 274 275 { 275 276 WebCore::URL requestURL = request.url(); 276 if (failure == NetworkCache::CachedEntryReuseFailure::None) {277 if (failure == CachedEntryReuseFailure::None) { 277 278 LOG(NetworkCache, "(NetworkProcess) webPageID %llu: %s is in the cache and is used", webPageID, requestURL.string().ascii().data()); 278 279 NetworkProcess::singleton().logDiagnosticMessageWithResult(webPageID, WebCore::DiagnosticLoggingKeys::networkCacheKey(), WebCore::DiagnosticLoggingKeys::retrievalKey(), WebCore::DiagnosticLoggingResultPass, WebCore::ShouldSample::Yes); … … 285 286 } 286 287 287 void NetworkCacheStatistics::markAsRequested(const String& hash)288 void Statistics::markAsRequested(const String& hash) 288 289 { 289 290 ASSERT(RunLoop::isMain()); … … 294 295 } 295 296 296 void NetworkCacheStatistics::writeTimerFired()297 void Statistics::writeTimerFired() 297 298 { 298 299 ASSERT(RunLoop::isMain()); … … 302 303 m_hashesToAdd.clear(); 303 304 304 Vector<std::pair<StringCapture, NetworkCache::StoreDecision>> storeDecisionsToAdd;305 Vector<std::pair<StringCapture, StoreDecision>> storeDecisionsToAdd; 305 306 copyToVector(m_storeDecisionsToAdd, storeDecisionsToAdd); 306 307 m_storeDecisionsToAdd.clear(); … … 323 324 } 324 325 325 void NetworkCacheStatistics::queryWasEverRequested(const String& hash, NeedUncachedReason needUncachedReason, const RequestedCompletionHandler& completionHandler)326 void Statistics::queryWasEverRequested(const String& hash, NeedUncachedReason needUncachedReason, const RequestedCompletionHandler& completionHandler) 326 327 { 327 328 ASSERT(RunLoop::isMain()); … … 344 345 dispatch_async(m_backgroundIOQueue.get(), [this, wasAlreadyRequested, &query] () mutable { 345 346 WebCore::SQLiteTransactionInProgressAutoCounter transactionCounter; 346 Optional< NetworkCache::StoreDecision> storeDecision;347 Optional<StoreDecision> storeDecision; 347 348 if (m_database.isOpen()) { 348 349 if (!wasAlreadyRequested) { … … 355 356 if (wasAlreadyRequested && query.needUncachedReason) { 356 357 WebCore::SQLiteStatement statement(m_database, ASCIILiteral("SELECT reason FROM UncachedReason WHERE hash=?")); 357 storeDecision = NetworkCache::StoreDecision::Yes;358 storeDecision = StoreDecision::Yes; 358 359 if (statement.prepare() == WebCore::SQLResultOk) { 359 360 statement.bindText(1, query.hash); 360 361 if (statement.step() == WebCore::SQLResultRow) 361 storeDecision = static_cast< NetworkCache::StoreDecision>(statement.getColumnInt(0));362 storeDecision = static_cast<StoreDecision>(statement.getColumnInt(0)); 362 363 } 363 364 } … … 370 371 } 371 372 372 void NetworkCacheStatistics::clear()373 void Statistics::clear() 373 374 { 374 375 ASSERT(RunLoop::isMain()); … … 387 388 } 388 389 389 void NetworkCacheStatistics::addHashesToDatabase(const Vector<StringCapture>& hashes)390 void Statistics::addHashesToDatabase(const Vector<StringCapture>& hashes) 390 391 { 391 392 ASSERT(!RunLoop::isMain()); … … 405 406 } 406 407 407 void NetworkCacheStatistics::addStoreDecisionsToDatabase(const Vector<std::pair<StringCapture, NetworkCache::StoreDecision>>& storeDecisions)408 void Statistics::addStoreDecisionsToDatabase(const Vector<std::pair<StringCapture, StoreDecision>>& storeDecisions) 408 409 { 409 410 ASSERT(!RunLoop::isMain()); … … 423 424 } 424 425 425 } // namespace WebKit 426 } 427 } 426 428 427 429 #endif // ENABLE(NETWORK_CACHE) -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h
r181079 r181140 38 38 #include <wtf/text/WTFString.h> 39 39 40 namespace WebCore { 41 class SharedBuffer; 42 } 40 namespace WebKit { 41 namespace NetworkCache { 43 42 44 namespace IPC { 45 class ArgumentEncoder; 46 class ArgumentDecoder; 47 } 48 49 namespace WebKit { 50 51 class NetworkCacheStorage { 52 WTF_MAKE_NONCOPYABLE(NetworkCacheStorage); 43 class Storage { 44 WTF_MAKE_NONCOPYABLE(Storage); 53 45 public: 54 static std::unique_ptr< NetworkCacheStorage> open(const String& cachePath);46 static std::unique_ptr<Storage> open(const String& cachePath); 55 47 56 48 struct Entry { 57 NetworkCacheKey key;49 Key key; 58 50 std::chrono::milliseconds timeStamp; 59 NetworkCacheData header;60 NetworkCacheData body;51 Data header; 52 Data body; 61 53 }; 62 54 // This may call completion handler synchronously on failure. 63 55 typedef std::function<bool (std::unique_ptr<Entry>)> RetrieveCompletionHandler; 64 void retrieve(const NetworkCacheKey&, unsigned priority, RetrieveCompletionHandler&&);56 void retrieve(const Key&, unsigned priority, RetrieveCompletionHandler&&); 65 57 66 typedef std::function<void (bool success, const NetworkCacheData& mappedBody)> StoreCompletionHandler;58 typedef std::function<void (bool success, const Data& mappedBody)> StoreCompletionHandler; 67 59 void store(const Entry&, StoreCompletionHandler&&); 68 60 void update(const Entry& updateEntry, const Entry& existingEntry, StoreCompletionHandler&&); … … 80 72 81 73 private: 82 NetworkCacheStorage(const String& directoryPath);74 Storage(const String& directoryPath); 83 75 84 76 void initialize(); … … 86 78 void shrinkIfNeeded(); 87 79 88 void removeEntry(const NetworkCacheKey&);80 void removeEntry(const Key&); 89 81 90 82 struct ReadOperation { 91 NetworkCacheKey key;83 Key key; 92 84 RetrieveCompletionHandler completionHandler; 93 85 }; … … 128 120 129 121 } 122 } 130 123 #endif 131 124 #endif -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorageCocoa.mm
r181079 r181140 47 47 48 48 namespace WebKit { 49 namespace NetworkCache { 49 50 50 51 static const char networkCacheSubdirectory[] = "WebKitCache"; 51 52 static const char versionDirectoryPrefix[] = "Version "; 52 53 53 std::unique_ptr< NetworkCacheStorage> NetworkCacheStorage::open(const String& cachePath)54 std::unique_ptr<Storage> Storage::open(const String& cachePath) 54 55 { 55 56 ASSERT(RunLoop::isMain()); … … 58 59 if (!WebCore::makeAllDirectories(networkCachePath)) 59 60 return nullptr; 60 return std::unique_ptr< NetworkCacheStorage>(new NetworkCacheStorage(networkCachePath));61 return std::unique_ptr<Storage>(new Storage(networkCachePath)); 61 62 } 62 63 63 64 static String makeVersionedDirectoryPath(const String& baseDirectoryPath) 64 65 { 65 String versionSubdirectory = versionDirectoryPrefix + String::number( NetworkCacheStorage::version);66 String versionSubdirectory = versionDirectoryPrefix + String::number(Storage::version); 66 67 return WebCore::pathByAppendingComponent(baseDirectoryPath, versionSubdirectory); 67 68 } 68 69 69 NetworkCacheStorage::NetworkCacheStorage(const String& baseDirectoryPath)70 Storage::Storage(const String& baseDirectoryPath) 70 71 : m_baseDirectoryPath(baseDirectoryPath) 71 72 , m_directoryPath(makeVersionedDirectoryPath(baseDirectoryPath)) … … 77 78 } 78 79 79 void NetworkCacheStorage::initialize()80 void Storage::initialize() 80 81 { 81 82 ASSERT(RunLoop::isMain()); … … 86 87 String cachePath = cachePathCapture.string(); 87 88 traverseCacheFiles(cachePath, [this](const String& fileName, const String& partitionPath) { 88 NetworkCacheKey::HashType hash;89 if (! NetworkCacheKey::stringToHash(fileName, hash))89 Key::HashType hash; 90 if (!Key::stringToHash(fileName, hash)) 90 91 return; 91 unsigned shortHash = NetworkCacheKey::toShortHash(hash);92 unsigned shortHash = Key::toShortHash(hash); 92 93 RunLoop::main().dispatch([this, shortHash] { 93 94 m_contentsFilter.add(shortHash); … … 101 102 } 102 103 103 static String directoryPathForKey(const NetworkCacheKey& key, const String& cachePath)104 static String directoryPathForKey(const Key& key, const String& cachePath) 104 105 { 105 106 ASSERT(!key.partition().isEmpty()); … … 107 108 } 108 109 109 static String fileNameForKey(const NetworkCacheKey& key)110 static String fileNameForKey(const Key& key) 110 111 { 111 112 return key.hashAsString(); 112 113 } 113 114 114 static String filePathForKey(const NetworkCacheKey& key, const String& cachePath)115 static String filePathForKey(const Key& key, const String& cachePath) 115 116 { 116 117 return WebCore::pathByAppendingComponent(directoryPathForKey(key, cachePath), fileNameForKey(key)); 117 118 } 118 119 119 static Ref< NetworkCacheIOChannel> openFileForKey(const NetworkCacheKey& key, NetworkCacheIOChannel::Type type, const String& cachePath)120 static Ref<IOChannel> openFileForKey(const Key& key, IOChannel::Type type, const String& cachePath) 120 121 { 121 122 auto directoryPath = directoryPathForKey(key, cachePath); 122 123 auto filePath = WebCore::pathByAppendingComponent(directoryPath, fileNameForKey(key)); 123 if (type == NetworkCacheIOChannel::Type::Create)124 if (type == IOChannel::Type::Create) 124 125 WebCore::makeAllDirectories(directoryPath); 125 return NetworkCacheIOChannel::open(filePath, type);126 return IOChannel::open(filePath, type); 126 127 } 127 128 … … 140 141 struct EntryMetaData { 141 142 EntryMetaData() { } 142 explicit EntryMetaData(const NetworkCacheKey& key) : cacheStorageVersion(NetworkCacheStorage::version), key(key) { } 143 explicit EntryMetaData(const Key& key) 144 : cacheStorageVersion(Storage::version) 145 , key(key) 146 { } 143 147 144 148 unsigned cacheStorageVersion; 145 NetworkCacheKey key;149 Key key; 146 150 std::chrono::milliseconds timeStamp; 147 151 unsigned headerChecksum; … … 153 157 }; 154 158 155 static bool decodeEntryMetaData(EntryMetaData& metaData, const NetworkCacheData& fileData)159 static bool decodeEntryMetaData(EntryMetaData& metaData, const Data& fileData) 156 160 { 157 161 bool success = false; 158 162 dispatch_data_apply(fileData.dispatchData(), [&metaData, &success](dispatch_data_t, size_t, const void* data, size_t size) { 159 NetworkCacheDecoder decoder(reinterpret_cast<const uint8_t*>(data), size);163 Decoder decoder(reinterpret_cast<const uint8_t*>(data), size); 160 164 if (!decoder.decode(metaData.cacheStorageVersion)) 161 165 return false; … … 193 197 } 194 198 195 static bool decodeEntryHeader(const NetworkCacheData& fileData, EntryMetaData& metaData, NetworkCacheData& data)199 static bool decodeEntryHeader(const Data& fileData, EntryMetaData& metaData, Data& data) 196 200 { 197 201 if (!decodeEntryMetaData(metaData, fileData)) 198 202 return false; 199 if (metaData.cacheStorageVersion != NetworkCacheStorage::version)203 if (metaData.cacheStorageVersion != Storage::version) 200 204 return false; 201 205 if (metaData.headerOffset + metaData.headerSize > metaData.bodyOffset) … … 211 215 } 212 216 213 static std::unique_ptr< NetworkCacheStorage::Entry> decodeEntry(const NetworkCacheData& fileData, int fd, const NetworkCacheKey& key)217 static std::unique_ptr<Storage::Entry> decodeEntry(const Data& fileData, int fd, const Key& key) 214 218 { 215 219 EntryMetaData metaData; 216 NetworkCacheData headerData;220 Data headerData; 217 221 if (!decodeEntryHeader(fileData, metaData, headerData)) 218 222 return nullptr; … … 234 238 } 235 239 236 return std::unique_ptr< NetworkCacheStorage::Entry>(new NetworkCacheStorage::Entry {240 return std::unique_ptr<Storage::Entry>(new Storage::Entry { 237 241 metaData.key, 238 242 metaData.timeStamp, 239 243 headerData, 240 { bodyData, NetworkCacheData::Backing::Map }244 { bodyData, Data::Backing::Map } 241 245 }); 242 246 } … … 244 248 static DispatchPtr<dispatch_data_t> encodeEntryMetaData(const EntryMetaData& entry) 245 249 { 246 NetworkCacheEncoder encoder;250 Encoder encoder; 247 251 248 252 encoder << entry.cacheStorageVersion; … … 259 263 } 260 264 261 static NetworkCacheData encodeEntryHeader(const NetworkCacheStorage::Entry& entry)265 static Data encodeEntryHeader(const Storage::Entry& entry) 262 266 { 263 267 EntryMetaData metaData(entry.key); … … 280 284 } 281 285 282 void NetworkCacheStorage::removeEntry(const NetworkCacheKey& key)286 void Storage::removeEntry(const Key& key) 283 287 { 284 288 ASSERT(RunLoop::isMain()); … … 296 300 } 297 301 298 void NetworkCacheStorage::dispatchReadOperation(const ReadOperation& read)302 void Storage::dispatchReadOperation(const ReadOperation& read) 299 303 { 300 304 ASSERT(RunLoop::isMain()); … … 303 307 StringCapture cachePathCapture(m_directoryPath); 304 308 ioQueue().dispatch([this, &read, cachePathCapture] { 305 auto channel = openFileForKey(read.key, NetworkCacheIOChannel::Type::Read, cachePathCapture.string());309 auto channel = openFileForKey(read.key, IOChannel::Type::Read, cachePathCapture.string()); 306 310 int fd = channel->fileDescriptor(); 307 channel->read(0, std::numeric_limits<size_t>::max(), [this, &read, fd]( NetworkCacheData& fileData, int error) {311 channel->read(0, std::numeric_limits<size_t>::max(), [this, &read, fd](Data& fileData, int error) { 308 312 if (error) { 309 313 removeEntry(read.key); … … 325 329 } 326 330 327 void NetworkCacheStorage::dispatchPendingReadOperations()331 void Storage::dispatchPendingReadOperations() 328 332 { 329 333 ASSERT(RunLoop::isMain()); … … 346 350 } 347 351 348 template <class T> bool retrieveFromMemory(const T& operations, const NetworkCacheKey& key, NetworkCacheStorage::RetrieveCompletionHandler& completionHandler)352 template <class T> bool retrieveFromMemory(const T& operations, const Key& key, Storage::RetrieveCompletionHandler& completionHandler) 349 353 { 350 354 for (auto& operation : operations) { … … 353 357 auto entry = operation->entry; 354 358 RunLoop::main().dispatch([entry, completionHandler] { 355 completionHandler(std::make_unique< NetworkCacheStorage::Entry>(entry));359 completionHandler(std::make_unique<Storage::Entry>(entry)); 356 360 }); 357 361 return true; … … 361 365 } 362 366 363 void NetworkCacheStorage::retrieve(const NetworkCacheKey& key, unsigned priority, RetrieveCompletionHandler&& completionHandler)367 void Storage::retrieve(const Key& key, unsigned priority, RetrieveCompletionHandler&& completionHandler) 364 368 { 365 369 ASSERT(RunLoop::isMain()); … … 386 390 } 387 391 388 void NetworkCacheStorage::store(const Entry& entry, StoreCompletionHandler&& completionHandler)392 void Storage::store(const Entry& entry, StoreCompletionHandler&& completionHandler) 389 393 { 390 394 ASSERT(RunLoop::isMain()); … … 404 408 } 405 409 406 void NetworkCacheStorage::update(const Entry& updateEntry, const Entry& existingEntry, StoreCompletionHandler&& completionHandler)410 void Storage::update(const Entry& updateEntry, const Entry& existingEntry, StoreCompletionHandler&& completionHandler) 407 411 { 408 412 ASSERT(RunLoop::isMain()); … … 420 424 } 421 425 422 void NetworkCacheStorage::traverse(std::function<void (const Entry*)>&& traverseHandler)426 void Storage::traverse(std::function<void (const Entry*)>&& traverseHandler) 423 427 { 424 428 StringCapture cachePathCapture(m_directoryPath); … … 428 432 traverseCacheFiles(cachePath, [this, &semaphore, &traverseHandler](const String& fileName, const String& partitionPath) { 429 433 auto filePath = WebCore::pathByAppendingComponent(partitionPath, fileName); 430 auto channel = NetworkCacheIOChannel::open(filePath, NetworkCacheIOChannel::Type::Read);434 auto channel = IOChannel::open(filePath, IOChannel::Type::Read); 431 435 const size_t headerReadSize = 16 << 10; 432 channel->read(0, headerReadSize, [this, &semaphore, &traverseHandler]( NetworkCacheData& fileData, int) {436 channel->read(0, headerReadSize, [this, &semaphore, &traverseHandler](Data& fileData, int) { 433 437 EntryMetaData metaData; 434 NetworkCacheData headerData;438 Data headerData; 435 439 if (decodeEntryHeader(fileData, metaData, headerData)) { 436 440 Entry entry { metaData.key, metaData.timeStamp, headerData, { } }; … … 447 451 } 448 452 449 void NetworkCacheStorage::dispatchPendingWriteOperations()453 void Storage::dispatchPendingWriteOperations() 450 454 { 451 455 ASSERT(RunLoop::isMain()); … … 470 474 } 471 475 472 void NetworkCacheStorage::dispatchFullWriteOperation(const WriteOperation& write)476 void Storage::dispatchFullWriteOperation(const WriteOperation& write) 473 477 { 474 478 ASSERT(RunLoop::isMain()); … … 483 487 auto headerAndBodyData = adoptDispatch(dispatch_data_create_concat(encodedHeader.dispatchData(), write.entry.body.dispatchData())); 484 488 485 NetworkCacheData writeData(headerAndBodyData);486 487 auto channel = openFileForKey(write.entry.key, NetworkCacheIOChannel::Type::Create, cachePathCapture.string());489 Data writeData(headerAndBodyData); 490 491 auto channel = openFileForKey(write.entry.key, IOChannel::Type::Create, cachePathCapture.string()); 488 492 int fd = channel->fileDescriptor(); 489 493 size_t bodyOffset = encodedHeader.size(); … … 503 507 auto bodyMap = shouldMapBody ? mapFile(fd, bodyOffset, bodySize) : nullptr; 504 508 505 NetworkCacheData bodyData(bodyMap, NetworkCacheData::Backing::Map);509 Data bodyData(bodyMap, Data::Backing::Map); 506 510 write.completionHandler(!error, bodyData); 507 511 … … 515 519 } 516 520 517 void NetworkCacheStorage::dispatchHeaderWriteOperation(const WriteOperation& write)521 void Storage::dispatchHeaderWriteOperation(const WriteOperation& write) 518 522 { 519 523 ASSERT(RunLoop::isMain()); … … 537 541 } 538 542 539 auto channel = openFileForKey(write.entry.key, NetworkCacheIOChannel::Type::Write, cachePathCapture.string());543 auto channel = openFileForKey(write.entry.key, IOChannel::Type::Write, cachePathCapture.string()); 540 544 channel->write(0, headerData, [this, &write](int error) { 541 545 LOG(NetworkCacheStorage, "(NetworkProcess) update complete error=%d", error); … … 553 557 } 554 558 555 void NetworkCacheStorage::setMaximumSize(size_t size)559 void Storage::setMaximumSize(size_t size) 556 560 { 557 561 ASSERT(RunLoop::isMain()); … … 561 565 } 562 566 563 void NetworkCacheStorage::clear()567 void Storage::clear() 564 568 { 565 569 ASSERT(RunLoop::isMain()); … … 583 587 } 584 588 585 void NetworkCacheStorage::shrinkIfNeeded()589 void Storage::shrinkIfNeeded() 586 590 { 587 591 ASSERT(RunLoop::isMain()); … … 614 618 615 619 WebCore::deleteFile(filePath); 616 NetworkCacheKey::HashType hash;617 if (! NetworkCacheKey::stringToHash(fileName, hash))620 Key::HashType hash; 621 if (!Key::stringToHash(fileName, hash)) 618 622 return; 619 unsigned shortHash = NetworkCacheKey::toShortHash(hash);623 unsigned shortHash = Key::toShortHash(hash); 620 624 RunLoop::main().dispatch([this, shortHash] { 621 625 if (m_contentsFilter.mayContain(shortHash)) … … 636 640 } 637 641 638 void NetworkCacheStorage::deleteOldVersions()642 void Storage::deleteOldVersions() 639 643 { 640 644 // Delete V1 cache. … … 655 659 656 660 } 661 } 657 662 658 663 #endif
Note:
See TracChangeset
for help on using the changeset viewer.