Changeset 179546 in webkit
- Timestamp:
- Feb 3, 2015 4:41:52 AM (9 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r179541 r179546 1 2015-02-02 Antti Koivisto <antti@apple.com> 2 3 Update cache header after revalidation without rewriting the body data 4 https://bugs.webkit.org/show_bug.cgi?id=141182 5 6 Reviewed by Andreas Kling. 7 8 Currently we just rewrite the entire entry after revalidation. 9 10 * NetworkProcess/cache/NetworkCache.cpp: 11 (WebKit::decodeStorageEntry): 12 13 Include the strorage entry to the cache response so we can more easily update it. 14 15 (WebKit::NetworkCache::update): 16 17 Call the storage update function with the new and the exisiting storage entry. 18 19 * NetworkProcess/cache/NetworkCache.h: 20 * NetworkProcess/cache/NetworkCacheStorage.h: 21 * NetworkProcess/cache/NetworkCacheStorageCocoa.mm: 22 (WebKit::openFileForKey): 23 24 Added an option for opening a file for writing without creating a new one. 25 Renamed for clarity. 26 27 (WebKit::encodeEntryHeader): 28 29 Separate header encoding to a function. 30 31 (WebKit::encodeEntry): 32 (WebKit::NetworkCacheStorage::dispatchRetrieveOperation): 33 (WebKit::NetworkCacheStorage::store): 34 (WebKit::NetworkCacheStorage::update): 35 36 New update function. 37 If the page-rounded header size would stay unchanged we can just write the new header over the old one. 38 In the unlikely event it doesn't we rewrite the whole thing. 39 40 (WebKit::createIOChannelForKey): Deleted. 41 1 42 2015-02-02 Commit Queue <commit-queue@webkit.org> 2 43 -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp
r179529 r179546 168 168 169 169 auto entry = std::make_unique<NetworkCache::Entry>(); 170 entry->storageEntry = storageEntry; 170 171 entry->needsRevalidation = needsRevalidation; 171 172 … … 317 318 WebCore::updateResponseHeadersAfterRevalidation(response, validatingResponse); 318 319 319 // FIXME: This rewrites the entire resource instead of just the header.320 320 auto key = makeCacheKey(originalRequest); 321 auto storageEntry = encodeStorageEntry(originalRequest, response, entry.buffer);322 323 m_storage-> store(key,storageEntry, [](bool success) {321 auto updateEntry = encodeStorageEntry(originalRequest, response, entry.buffer); 322 323 m_storage->update(key, updateEntry, entry.storageEntry, [](bool success) { 324 324 LOG(NetworkCache, "(NetworkProcess) updated, success=%d", success); 325 325 }); -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h
r179529 r179546 54 54 55 55 struct Entry { 56 NetworkCacheStorage::Entry storageEntry; 56 57 WebCore::ResourceResponse response; 57 58 RefPtr<WebCore::SharedBuffer> buffer; -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h
r179446 r179546 135 135 void retrieve(const NetworkCacheKey&, unsigned priority, std::function<bool (std::unique_ptr<Entry>)>); 136 136 void store(const NetworkCacheKey&, const Entry&, std::function<void (bool success)>); 137 void update(const NetworkCacheKey&, const Entry& updateEntry, const Entry& existingEntry, std::function<void (bool success)>); 137 138 138 139 void setMaximumSize(size_t); -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorageCocoa.mm
r179446 r179546 162 162 } 163 163 164 enum class IOChannelType { Read, Write };165 static DispatchPtr<dispatch_io_t> createIOChannelForKey(const NetworkCacheKey& key, IOChannelType type, const String& cachePath, int& fd)164 enum class FileOpenType { Read, Write, Create }; 165 static DispatchPtr<dispatch_io_t> openFileForKey(const NetworkCacheKey& key, FileOpenType type, const String& cachePath, int& fd) 166 166 { 167 167 int oflag; … … 169 169 170 170 switch (type) { 171 case IOChannelType::Write:171 case FileOpenType::Create: 172 172 oflag = O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK; 173 173 mode = S_IRUSR | S_IWUSR; 174 174 WebCore::makeAllDirectories(directoryPathForKey(key, cachePath)); 175 175 break; 176 case IOChannelType::Read: 176 case FileOpenType::Write: 177 oflag = O_WRONLY | O_NONBLOCK; 178 mode = S_IRUSR | S_IWUSR; 179 break; 180 case FileOpenType::Read: 177 181 oflag = O_RDONLY | O_NONBLOCK; 178 182 mode = 0; … … 312 316 } 313 317 314 static DispatchPtr<dispatch_data_t> encodeEntry (const NetworkCacheKey& key, const NetworkCacheStorage::Entry& entry)318 static DispatchPtr<dispatch_data_t> encodeEntryHeader(const NetworkCacheKey& key, const NetworkCacheStorage::Entry& entry) 315 319 { 316 320 EntryMetaData metaData(key); … … 330 334 Vector<uint8_t, 4096> filler(dataOffset - headerSize, 0); 331 335 auto alignmentData = adoptDispatch(dispatch_data_create(filler.data(), filler.size(), nullptr, DISPATCH_DATA_DESTRUCTOR_DEFAULT)); 332 333 auto headerWithAlignmentData = adoptDispatch(dispatch_data_create_concat(headerData.get(), alignmentData.get())); 334 335 return adoptDispatch(dispatch_data_create_concat(headerWithAlignmentData.get(), entry.body.dispatchData())); 336 return adoptDispatch(dispatch_data_create_concat(headerData.get(), alignmentData.get())); 337 } 338 339 static DispatchPtr<dispatch_data_t> encodeEntry(const NetworkCacheKey& key, const NetworkCacheStorage::Entry& entry) 340 { 341 auto encodedHeader = encodeEntryHeader(key, entry); 342 return adoptDispatch(dispatch_data_create_concat(encodedHeader.get(), entry.body.dispatchData())); 336 343 } 337 344 … … 361 368 dispatch_async(m_ioQueue.get(), [this, retrieve, cachePathCapture] { 362 369 int fd; 363 auto channel = createIOChannelForKey(retrieve.key, IOChannelType::Read, cachePathCapture.string(), fd);370 auto channel = openFileForKey(retrieve.key, FileOpenType::Read, cachePathCapture.string(), fd); 364 371 365 372 bool didCallCompletionHandler = false; … … 429 436 dispatch_async(m_backgroundIOQueue.get(), [this, key, entry, cachePathCapture, completionHandler] { 430 437 auto data = encodeEntry(key, entry); 438 431 439 int fd; 432 auto channel = createIOChannelForKey(key, IOChannelType::Write, cachePathCapture.string(), fd);440 auto channel = openFileForKey(key, FileOpenType::Create, cachePathCapture.string(), fd); 433 441 dispatch_io_write(channel.get(), 0, data.get(), dispatch_get_main_queue(), [this, key, completionHandler](bool done, dispatch_data_t, int error) { 434 442 ASSERT_UNUSED(done, done); … … 439 447 shrinkIfNeeded(); 440 448 } 449 completionHandler(!error); 450 }); 451 }); 452 } 453 454 void NetworkCacheStorage::update(const NetworkCacheKey& key, const Entry& updateEntry, const Entry& existingEntry, std::function<void (bool success)> completionHandler) 455 { 456 ASSERT(RunLoop::isMain()); 457 458 if (!m_keyFilter.mayContain(key.hash())) { 459 LOG(NetworkCacheStorage, "(NetworkProcess) existing entry not found, storing full entry"); 460 store(key, updateEntry, completionHandler); 461 return; 462 } 463 464 // Try to update the header of an existing entry. 465 StringCapture cachePathCapture(m_directoryPath); 466 dispatch_async(m_backgroundIOQueue.get(), [this, key, updateEntry, existingEntry, cachePathCapture, completionHandler] { 467 auto headerData = encodeEntryHeader(key, updateEntry); 468 auto existingHeaderData = encodeEntryHeader(key, existingEntry); 469 470 bool pageRoundedHeaderSizeChanged = dispatch_data_get_size(headerData.get()) != dispatch_data_get_size(existingHeaderData.get()); 471 if (pageRoundedHeaderSizeChanged) { 472 LOG(NetworkCacheStorage, "(NetworkProcess) page-rounded header size changed, storing full entry"); 473 dispatch_async(dispatch_get_main_queue(), [this, key, updateEntry, completionHandler] { 474 store(key, updateEntry, completionHandler); 475 }); 476 return; 477 } 478 479 int fd; 480 auto channel = openFileForKey(key, FileOpenType::Write, cachePathCapture.string(), fd); 481 dispatch_io_write(channel.get(), 0, headerData.get(), dispatch_get_main_queue(), [this, key, completionHandler](bool done, dispatch_data_t, int error) { 482 ASSERT_UNUSED(done, done); 483 LOG(NetworkCacheStorage, "(NetworkProcess) update complete error=%d", error); 484 485 if (error) 486 removeEntry(key); 487 441 488 completionHandler(!error); 442 489 });
Note: See TracChangeset
for help on using the changeset viewer.