Changeset 256633 in webkit
- Timestamp:
- Feb 14, 2020 12:06:28 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r256628 r256633 1 2020-02-14 Christopher Reid <chris.reid@sony.com> 2 3 [Win] Implement NetworkCache::Data by using FileSystem::MappedFileData 4 https://bugs.webkit.org/show_bug.cgi?id=197684 5 6 Reviewed by Fujii Hironori. 7 8 * platform/wincairo/TestExpectations: 9 1 10 2020-02-14 Antoine Quint <graouts@webkit.org> 2 11 -
trunk/LayoutTests/platform/wincairo/TestExpectations
r256477 r256633 1162 1162 http/tests/appcache [ Skip ] 1163 1163 http/tests/blink/sendbeacon [ Skip ] 1164 http/tests/cache [ Skip ] 1164 1165 # needs more investigation 1166 http/tests/cache/cancel-multiple-post-xhrs.html [ Failure ] 1167 1168 # fails because of conversion to epoch behavior specific to Mac 1169 http/tests/cache/disk-cache/disk-cache-last-modified.html [ Failure ] 1170 1171 # needs more investigation 1172 http/tests/cache/iframe-304-crash.html [ Failure ] 1173 http/tests/cache/network-error-during-revalidation.html [ Failure ] 1174 http/tests/cache/partitioned-cache-iframe.html [ Failure ] 1175 http/tests/cache/partitioned-cache.html [ Failure ] 1176 http/tests/cache/willsendrequest-returns-null-for-memory-cache-load.html [ Failure ] 1177 1165 1178 http/tests/cache-storage [ Skip ] 1166 1179 http/tests/canvas [ Skip ] -
trunk/Source/WTF/ChangeLog
r256629 r256633 1 2020-02-14 Christopher Reid <chris.reid@sony.com> 2 3 [Win] Implement NetworkCache::Data by using FileSystem::MappedFileData 4 https://bugs.webkit.org/show_bug.cgi?id=197684 5 6 Reviewed by Fujii Hironori. 7 8 * wtf/FileSystem.cpp: 9 * wtf/FileSystem.h: 10 Added FileAccessPermission flag when opening files. 11 Remove default argument for the listDirectory filter since the defaut 12 String() filter doesn't match all files on Mac and Windows. 13 14 * wtf/glib/FileSystemGlib.cpp: 15 * wtf/posix/FileSystemPOSIX.cpp: 16 Added (S_IRUSR | S_IWUSR) file open modes. 17 18 * wtf/win/FileSystemWin.cpp: 19 Implement getVolumeFreeSpace since some of the tests use it when toggling cache. 20 21 * wtf/win/PathWalker.cpp: 22 1 23 2020-02-14 Alex Christensen <achristensen@webkit.org> 2 24 -
trunk/Source/WTF/wtf/FileSystem.cpp
r254046 r256633 288 288 } 289 289 290 MappedFileData::MappedFileData(const String& filePath, MappedFileMode mapMode, bool& success) 291 { 292 auto fd = openFile(filePath, FileSystem::FileOpenMode::Read); 293 294 success = mapFileHandle(fd, FileSystem::FileOpenMode::Read, mapMode); 295 closeFile(fd); 296 } 297 290 298 #if HAVE(MMAP) 291 299 292 MappedFileData::MappedFileData(const String& filePath, MappedFileMode mode, bool& success) 293 { 294 auto fd = openFile(filePath, FileOpenMode::Read); 295 296 success = mapFileHandle(fd, mode); 297 closeFile(fd); 298 } 299 300 bool MappedFileData::mapFileHandle(PlatformFileHandle handle, MappedFileMode mode) 300 bool MappedFileData::mapFileHandle(PlatformFileHandle handle, FileOpenMode openMode, MappedFileMode mapMode) 301 301 { 302 302 if (!isHandleValid(handle)) … … 325 325 } 326 326 327 void* data = mmap(0, size, PROT_READ, MAP_FILE | (mode == MappedFileMode::Shared ? MAP_SHARED : MAP_PRIVATE), fd, 0); 327 int pageProtection = PROT_READ; 328 switch (openMode) { 329 case FileOpenMode::Read: 330 pageProtection = PROT_READ; 331 break; 332 case FileOpenMode::Write: 333 pageProtection = PROT_WRITE; 334 break; 335 #if OS(DARWIN) 336 case FileOpenMode::EventsOnly: 337 ASSERT_NOT_REACHED(); 338 #endif 339 } 340 341 void* data = mmap(0, size, pageProtection, MAP_FILE | (mapMode == MappedFileMode::Shared ? MAP_SHARED : MAP_PRIVATE), fd, 0); 328 342 329 343 if (data == MAP_FAILED) { -
trunk/Source/WTF/wtf/FileSystem.h
r248546 r256633 85 85 }; 86 86 87 enum class FileAccessPermission : bool { 88 User, 89 All 90 }; 91 87 92 enum class FileSeekOrigin { 88 93 Beginning, … … 132 137 bool excludeFromBackup(const String&); // Returns true if successful. 133 138 134 WTF_EXPORT_PRIVATE Vector<String> listDirectory(const String& path, const String& filter = String());139 WTF_EXPORT_PRIVATE Vector<String> listDirectory(const String& path, const String& filter); 135 140 136 141 WTF_EXPORT_PRIVATE CString fileSystemRepresentation(const String&); … … 141 146 // Prefix is what the filename should be prefixed with, not the full path. 142 147 WTF_EXPORT_PRIVATE String openTemporaryFile(const String& prefix, PlatformFileHandle&); 143 WTF_EXPORT_PRIVATE PlatformFileHandle openFile(const String& path, FileOpenMode );148 WTF_EXPORT_PRIVATE PlatformFileHandle openFile(const String& path, FileOpenMode, FileAccessPermission = FileAccessPermission::All); 144 149 WTF_EXPORT_PRIVATE void closeFile(PlatformFileHandle&); 145 150 // Returns the resulting offset from the beginning of the file if successful, -1 otherwise. … … 207 212 WTF_EXPORT_PRIVATE MappedFileData(const String& filePath, MappedFileMode, bool& success); 208 213 WTF_EXPORT_PRIVATE MappedFileData(PlatformFileHandle, MappedFileMode, bool& success); 214 WTF_EXPORT_PRIVATE MappedFileData(PlatformFileHandle, FileOpenMode, MappedFileMode, bool& success); 209 215 WTF_EXPORT_PRIVATE ~MappedFileData(); 210 216 MappedFileData& operator=(MappedFileData&&); … … 217 223 218 224 private: 219 WTF_EXPORT_PRIVATE bool mapFileHandle(PlatformFileHandle, MappedFileMode);225 WTF_EXPORT_PRIVATE bool mapFileHandle(PlatformFileHandle, FileOpenMode, MappedFileMode); 220 226 221 227 void* m_fileData { nullptr }; … … 223 229 }; 224 230 225 inline MappedFileData::MappedFileData(PlatformFileHandle handle, MappedFileMode mode, bool& success) 226 { 227 success = mapFileHandle(handle, mode); 231 inline MappedFileData::MappedFileData(PlatformFileHandle handle, MappedFileMode mapMode, bool& success) 232 { 233 success = mapFileHandle(handle, FileOpenMode::Read, mapMode); 234 } 235 236 inline MappedFileData::MappedFileData(PlatformFileHandle handle, FileOpenMode openMode, MappedFileMode mapMode, bool& success) 237 { 238 success = mapFileHandle(handle, openMode, mapMode); 228 239 } 229 240 -
trunk/Source/WTF/wtf/glib/FileSystemGlib.cpp
r247542 r256633 339 339 } 340 340 341 PlatformFileHandle openFile(const String& path, FileOpenMode mode )341 PlatformFileHandle openFile(const String& path, FileOpenMode mode, FileAccessPermission permission) 342 342 { 343 343 auto filename = fileSystemRepresentation(path); … … 352 352 if (g_file_test(filename.data(), static_cast<GFileTest>(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))) 353 353 ioStream = adoptGRef(g_file_open_readwrite(file.get(), nullptr, nullptr)); 354 else 355 ioStream = adoptGRef(g_file_create_readwrite(file.get(), G_FILE_CREATE_NONE, nullptr, nullptr)); 354 else { 355 GFileCreateFlags permissionFlag = (permission == FileAccessPermission::All) ? G_FILE_CREATE_NONE : G_FILE_CREATE_PRIVATE; 356 ioStream = adoptGRef(g_file_create_readwrite(file.get(), permissionFlag, nullptr, nullptr)); 357 } 356 358 } 357 359 -
trunk/Source/WTF/wtf/posix/FileSystemPOSIX.cpp
r249027 r256633 80 80 } 81 81 82 PlatformFileHandle openFile(const String& path, FileOpenMode mode )82 PlatformFileHandle openFile(const String& path, FileOpenMode mode, FileAccessPermission permission) 83 83 { 84 84 CString fsRep = fileSystemRepresentation(path); … … 88 88 89 89 int platformFlag = 0; 90 if (mode == FileOpenMode::Read) 90 switch (mode) { 91 case FileOpenMode::Read: 91 92 platformFlag |= O_RDONLY; 92 else if (mode == FileOpenMode::Write) 93 break; 94 case FileOpenMode::Write: 93 95 platformFlag |= (O_WRONLY | O_CREAT | O_TRUNC); 96 break; 94 97 #if OS(DARWIN) 95 else if (mode == FileOpenMode::EventsOnly)98 case FileOpenMode::EventsOnly: 96 99 platformFlag |= O_EVTONLY; 100 break; 97 101 #endif 98 99 return open(fsRep.data(), platformFlag, 0666); 102 } 103 104 int permissionFlag = 0; 105 if (permission == FileAccessPermission::User) 106 permissionFlag |= (S_IRUSR | S_IWUSR); 107 else if (permission == FileAccessPermission::All) 108 permissionFlag |= (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); 109 110 return open(fsRep.data(), platformFlag, permissionFlag); 100 111 } 101 112 -
trunk/Source/WTF/wtf/win/FileSystemWin.cpp
r256063 r256633 422 422 } 423 423 424 PlatformFileHandle openFile(const String& path, FileOpenMode mode )424 PlatformFileHandle openFile(const String& path, FileOpenMode mode, FileAccessPermission) 425 425 { 426 426 DWORD desiredAccess = 0; … … 437 437 creationDisposition = CREATE_ALWAYS; 438 438 break; 439 default:440 ASSERT_NOT_REACHED();441 439 } 442 440 … … 550 548 } 551 549 552 bool getVolumeFreeSpace(const String&, uint64_t&) 553 { 554 return false; 550 bool getVolumeFreeSpace(const String& path, uint64_t& freeSpace) 551 { 552 ULARGE_INTEGER freeBytesAvailableToCaller; 553 if (!GetDiskFreeSpaceExW(path.wideCharacters().data(), &freeBytesAvailableToCaller, nullptr, nullptr)) 554 return false; 555 556 freeSpace = freeBytesAvailableToCaller.QuadPart; 557 return true; 555 558 } 556 559 … … 604 607 } 605 608 606 MappedFileData::MappedFileData(const String& filePath, MappedFileMode mode, bool& success) 607 { 608 auto file = CreateFile(filePath.wideCharacters().data(), GENERIC_READ, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); 609 610 success = mapFileHandle(file, mode); 611 closeFile(file); 612 } 613 614 bool MappedFileData::mapFileHandle(PlatformFileHandle handle, MappedFileMode) 609 bool MappedFileData::mapFileHandle(PlatformFileHandle handle, FileOpenMode openMode, MappedFileMode) 615 610 { 616 611 if (!isHandleValid(handle)) … … 626 621 } 627 622 628 auto mapping = CreateFileMapping(handle, nullptr, PAGE_READONLY, 0, 0, nullptr); 623 DWORD pageProtection = PAGE_READONLY; 624 DWORD desiredAccess = FILE_MAP_READ; 625 switch (openMode) { 626 case FileOpenMode::Read: 627 pageProtection = PAGE_READONLY; 628 desiredAccess = FILE_MAP_READ; 629 break; 630 case FileOpenMode::Write: 631 pageProtection = PAGE_READWRITE; 632 desiredAccess = FILE_MAP_WRITE; 633 break; 634 } 635 636 auto mapping = CreateFileMapping(handle, nullptr, pageProtection, 0, 0, nullptr); 629 637 if (!mapping) 630 638 return false; 631 639 632 m_fileData = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, size);640 m_fileData = MapViewOfFile(mapping, desiredAccess, 0, 0, size); 633 641 CloseHandle(mapping); 634 642 if (!m_fileData) -
trunk/Source/WTF/wtf/win/PathWalker.cpp
r242592 r256633 33 33 PathWalker::PathWalker(const String& directory, const String& pattern) 34 34 { 35 String path = directory + "\\" + pattern;35 String path = makeString(directory, '\\', pattern); 36 36 m_handle = ::FindFirstFileW(path.wideCharacters().data(), &m_data); 37 37 } -
trunk/Source/WebKit/ChangeLog
r256632 r256633 1 2020-02-14 Christopher Reid <chris.reid@sony.com> 2 3 [Win] Implement NetworkCache::Data by using FileSystem::MappedFileData 4 https://bugs.webkit.org/show_bug.cgi?id=197684 5 6 Reviewed by Fujii Hironori. 7 8 * NetworkProcess/NetworkProcess.cpp: 9 Ensure that the CacheStorage directory is actually being created. 10 11 * NetworkProcess/cache/NetworkCacheData.cpp: 12 * NetworkProcess/cache/NetworkCacheData.h: 13 * NetworkProcess/cache/NetworkCacheDataCocoa.mm: 14 * NetworkProcess/cache/NetworkCacheDataSoup.cpp: 15 * NetworkProcess/cache/NetworkCacheFileSystem.cpp: 16 Use more FileSystem functionality to share code across platforms. 17 18 * NetworkProcess/cache/NetworkCacheDataCurl.cpp: 19 Use Optional<Vector> for m_buffer since we need to differentiate isEmpty and isNull. 20 1 21 2020-02-14 Yusuke Suzuki <ysuzuki@apple.com> 2 22 -
trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp
r255681 r256633 454 454 return makeUnique<SessionStorageQuotaManager>(cacheRootPath, defaultQuota, defaultThirdPartyQuota); 455 455 }).isNewEntry; 456 if (isNewEntry) 456 if (isNewEntry) { 457 457 SandboxExtension::consumePermanently(cacheRootPathHandle); 458 if (!cacheRootPath.isEmpty()) 459 postStorageTask(createCrossThreadTask(*this, &NetworkProcess::ensurePathExists, cacheRootPath)); 460 } 458 461 } 459 462 -
trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.cpp
r248973 r256633 29 29 #include <fcntl.h> 30 30 #include <wtf/CryptographicallyRandomNumber.h> 31 #include <wtf/FileSystem.h>32 31 33 32 #if !OS(WINDOWS) … … 40 39 namespace NetworkCache { 41 40 42 #if !OS(WINDOWS)43 41 Data Data::mapToFile(const String& path) const 44 42 { 45 int fd = open(FileSystem::fileSystemRepresentation(path).data(), O_CREAT | O_EXCL | O_RDWR , S_IRUSR | S_IWUSR); 46 if (fd < 0) 47 return { }; 48 49 if (ftruncate(fd, m_size) < 0) { 50 close(fd); 43 auto handle = FileSystem::openFile(path, FileSystem::FileOpenMode::Write, FileSystem::FileAccessPermission::User); 44 if (!FileSystem::truncateFile(handle, m_size)) { 45 FileSystem::closeFile(handle); 51 46 return { }; 52 47 } 53 48 54 49 FileSystem::makeSafeToUseMemoryMapForPath(path); 55 56 void* map = mmap(nullptr, m_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);57 if ( map == MAP_FAILED) {58 close(fd);50 bool success; 51 FileSystem::MappedFileData mappedFile(handle, FileSystem::FileOpenMode::Write, FileSystem::MappedFileMode::Shared, success); 52 if (!success) { 53 FileSystem::closeFile(handle); 59 54 return { }; 60 55 } 61 56 57 void* map = const_cast<void*>(mappedFile.data()); 62 58 uint8_t* mapData = static_cast<uint8_t*>(map); 63 59 apply([&mapData](const uint8_t* bytes, size_t bytesSize) { … … 67 63 }); 68 64 65 #if OS(WINDOWS) 66 DWORD oldProtection; 67 VirtualProtect(map, m_size, FILE_MAP_READ, &oldProtection); 68 FlushViewOfFile(map, m_size); 69 #else 69 70 // Drop the write permission. 70 71 mprotect(map, m_size, PROT_READ); … … 72 73 // Flush (asynchronously) to file, turning this into clean memory. 73 74 msync(map, m_size, MS_ASYNC); 74 75 return Data::adoptMap(map, m_size, fd);76 }77 #else78 Data Data::mapToFile(const String& path) const79 {80 auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Write);81 if (!FileSystem::isHandleValid(file))82 return { };83 if (FileSystem::writeToFile(file, reinterpret_cast<const char*>(data()), size()) < 0)84 return { };85 return Data(Vector<uint8_t>(m_buffer));86 }87 75 #endif 88 76 89 #if !OS(WINDOWS) 77 return Data::adoptMap(WTFMove(mappedFile), handle); 78 } 79 90 80 Data mapFile(const char* path) 91 81 { 92 int fd = open(path, O_RDONLY, 0);93 if (fd < 0)94 return { };95 struct stat stat;96 if (fstat(fd, &stat) < 0) {97 close(fd);98 return { };99 }100 size_t size = stat.st_size;101 if (!size) {102 close(fd);103 return Data::empty();104 }105 106 return adoptAndMapFile(fd, 0, size);107 }108 #endif109 110 Data mapFile(const String& path)111 {112 #if !OS(WINDOWS)113 return mapFile(FileSystem::fileSystemRepresentation(path).data());114 #else115 82 auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Read); 116 83 if (!FileSystem::isHandleValid(file)) … … 120 87 return { }; 121 88 return adoptAndMapFile(file, 0, size); 122 #endif123 89 } 124 90 125 #if !OS(WINDOWS) 126 Data adoptAndMapFile(int fd, size_t offset, size_t size) 91 Data mapFile(const String& path) 92 { 93 return mapFile(FileSystem::fileSystemRepresentation(path).data()); 94 } 95 96 Data adoptAndMapFile(FileSystem::PlatformFileHandle handle, size_t offset, size_t size) 127 97 { 128 98 if (!size) { 129 close(fd);99 FileSystem::closeFile(handle); 130 100 return Data::empty(); 131 101 } 132 133 void* map = mmap(nullptr, size, PROT_READ, MAP_PRIVATE, fd, offset);134 if ( map == MAP_FAILED) {135 close(fd);102 bool success; 103 FileSystem::MappedFileData mappedFile(handle, FileSystem::FileOpenMode::Read, FileSystem::MappedFileMode::Private, success); 104 if (!success) { 105 FileSystem::closeFile(handle); 136 106 return { }; 137 107 } 138 108 139 return Data::adoptMap( map, size, fd);109 return Data::adoptMap(WTFMove(mappedFile), handle); 140 110 } 141 #else142 Data adoptAndMapFile(FileSystem::PlatformFileHandle file, size_t offset, size_t size)143 {144 return Data(file, offset, size);145 }146 #endif147 111 148 112 SHA1::Digest computeSHA1(const Data& data, const Salt& salt) … … 180 144 Optional<Salt> readOrMakeSalt(const String& path) 181 145 { 182 #if !OS(WINDOWS) 183 auto cpath = FileSystem::fileSystemRepresentation(path); 184 auto fd = open(cpath.data(), O_RDONLY, 0); 185 Salt salt; 186 auto bytesRead = read(fd, salt.data(), salt.size()); 187 close(fd); 188 if (bytesRead != static_cast<ssize_t>(salt.size())) { 189 salt = makeSalt(); 146 if (fileExists(path)) { 147 auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Read); 148 Salt salt; 149 auto bytesRead = FileSystem::readFromFile(file, reinterpret_cast<char*>(salt.data()), salt.size()); 150 FileSystem::closeFile(file); 151 if (bytesRead != salt.size()) 152 return { }; 190 153 191 unlink(cpath.data()); 192 fd = open(cpath.data(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); 193 bool success = write(fd, salt.data(), salt.size()) == static_cast<ssize_t>(salt.size()); 194 close(fd); 195 if (!success) 196 return { }; 154 return salt; 197 155 } 156 157 Salt salt = makeSalt(); 158 auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Write, FileSystem::FileAccessPermission::User); 159 bool success = FileSystem::writeToFile(file, reinterpret_cast<char*>(salt.data()), salt.size()) == salt.size(); 160 FileSystem::closeFile(file); 161 if (!success) 162 return { }; 163 198 164 return salt; 199 #else200 auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Read);201 Salt salt;202 auto bytesRead = FileSystem::readFromFile(file, reinterpret_cast<char*>(salt.data()), salt.size());203 FileSystem::closeFile(file);204 if (bytesRead != salt.size()) {205 salt = makeSalt();206 207 FileSystem::deleteFile(path);208 file = FileSystem::openFile(path, FileSystem::FileOpenMode::Write);209 bool success = FileSystem::writeToFile(file, reinterpret_cast<char*>(salt.data()), salt.size()) == salt.size();210 FileSystem::closeFile(file);211 if (!success)212 return { };213 }214 return salt;215 #endif216 165 } 217 166 -
trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.h
r245186 r256633 40 40 #endif 41 41 42 #if USE(CURL) 43 #include <wtf/Box.h> 44 #include <wtf/Variant.h> 45 #endif 46 42 47 namespace WebKit { 43 48 … … 54 59 55 60 static Data empty(); 56 #if !OS(WINDOWS) 57 static Data adoptMap(void* map, size_t, int fd); 58 #endif 61 static Data adoptMap(FileSystem::MappedFileData&&, FileSystem::PlatformFileHandle); 59 62 60 63 #if PLATFORM(COCOA) … … 63 66 #endif 64 67 #if USE(SOUP) 65 Data(GRefPtr<SoupBuffer>&&, int fd = -1); 66 #elif OS(WINDOWS) 67 explicit Data(Vector<uint8_t>&&); 68 Data(FileSystem::PlatformFileHandle, size_t offset, size_t); 68 Data(GRefPtr<SoupBuffer>&&, FileSystem::PlatformFileHandle fd = FileSystem::invalidPlatformFileHandle); 69 #elif USE(CURL) 70 Data(Variant<Vector<uint8_t>, FileSystem::MappedFileData>&&); 69 71 #endif 70 72 bool isNull() const; … … 95 97 #if USE(SOUP) 96 98 mutable GRefPtr<SoupBuffer> m_buffer; 97 int m_fileDescriptor { -1};99 FileSystem::PlatformFileHandle m_fileDescriptor { FileSystem::invalidPlatformFileHandle }; 98 100 #endif 99 #if OS(WINDOWS)100 Vector<uint8_t> m_buffer;101 #if USE(CURL) 102 Box<Variant<Vector<uint8_t>, FileSystem::MappedFileData>> m_buffer; 101 103 #endif 102 104 mutable const uint8_t* m_data { nullptr }; … … 107 109 Data concatenate(const Data&, const Data&); 108 110 bool bytesEqual(const Data&, const Data&); 109 #if !OS(WINDOWS)110 Data adoptAndMapFile(int, size_t offset, size_t);111 #else112 111 Data adoptAndMapFile(FileSystem::PlatformFileHandle, size_t offset, size_t); 113 #endif114 #if USE(GLIB) && !PLATFORM(WIN)115 Data adoptAndMapFile(GFileIOStream*, size_t offset, size_t);116 #endif117 #if !OS(WINDOWS)118 112 Data mapFile(const char* path); 119 #endif120 113 Data mapFile(const String& path); 121 114 -
trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataCocoa.mm
r239260 r256633 93 93 } 94 94 95 Data Data::adoptMap( void* map, size_t size, intfd)95 Data Data::adoptMap(FileSystem::MappedFileData&& mappedFile, FileSystem::PlatformFileHandle fd) 96 96 { 97 size_t size = mappedFile.size(); 98 void* map = mappedFile.leakHandle(); 97 99 ASSERT(map); 98 100 ASSERT(map != MAP_FAILED); 99 close(fd);101 FileSystem::closeFile(fd); 100 102 auto bodyMap = adoptOSObject(dispatch_data_create(map, size, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), [map, size] { 101 103 munmap(map, size); -
trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataCurl.cpp
r245186 r256633 31 31 32 32 Data::Data(const uint8_t* data, size_t size) 33 : m_buffer(Box<Variant<Vector<uint8_t>, FileSystem::MappedFileData>>::create(Vector<uint8_t>(size))) 34 , m_size(size) 33 35 { 34 m_buffer.resize(size); 35 m_size = size; 36 memcpy(m_buffer.data(), data, size); 36 memcpy(WTF::get<Vector<uint8_t>>(*m_buffer).data(), data, size); 37 37 } 38 38 39 Data::Data(FileSystem::PlatformFileHandle file, size_t offset, size_t size) 39 Data::Data(Variant<Vector<uint8_t>, FileSystem::MappedFileData>&& data) 40 : m_buffer(Box<Variant<Vector<uint8_t>, FileSystem::MappedFileData>>::create(WTFMove(data))) 41 , m_isMap(WTF::holds_alternative<FileSystem::MappedFileData>(*m_buffer)) 40 42 { 41 m_buffer.resize(size); 42 m_size = size; 43 FileSystem::seekFile(file, offset, FileSystem::FileSeekOrigin::Beginning); 44 FileSystem::readFromFile(file, reinterpret_cast<char*>(m_buffer.data()), size); 45 FileSystem::closeFile(file); 46 } 47 48 Data::Data(Vector<uint8_t>&& buffer) 49 : m_buffer(WTFMove(buffer)) 50 { 51 m_size = m_buffer.size(); 43 m_size = WTF::switchOn(*m_buffer, 44 [](const Vector<uint8_t>& buffer) -> size_t { return buffer.size(); }, 45 [](const FileSystem::MappedFileData& mappedFile) -> size_t { return mappedFile.size(); } 46 ); 52 47 } 53 48 54 49 Data Data::empty() 55 50 { 56 return { }; 51 Vector<uint8_t> buffer; 52 return { WTFMove(buffer) }; 57 53 } 58 54 59 55 const uint8_t* Data::data() const 60 56 { 61 return m_buffer.data(); 57 if (!m_buffer) 58 return nullptr; 59 60 return WTF::switchOn(*m_buffer, 61 [](const Vector<uint8_t>& buffer) -> const uint8_t* { return buffer.data(); }, 62 [](const FileSystem::MappedFileData& mappedFile) -> const uint8_t* { return static_cast<const uint8_t*>(mappedFile.data()); } 63 ); 62 64 } 63 65 64 66 bool Data::isNull() const 65 67 { 66 return m_buffer.isEmpty();68 return !m_buffer; 67 69 } 68 70 … … 72 74 return false; 73 75 74 return applier(reinterpret_cast<const uint8_t*>( m_buffer.data()), m_buffer.size());76 return applier(reinterpret_cast<const uint8_t*>(data()), size()); 75 77 } 76 78 77 79 Data Data::subrange(size_t offset, size_t size) const 78 80 { 79 return { m_buffer.data() + offset, size }; 81 if (!m_buffer) 82 return { }; 83 84 return { data() + offset, size }; 80 85 } 81 86 82 87 Data concatenate(const Data& a, const Data& b) 83 88 { 89 if (a.isNull()) 90 return b; 91 if (b.isNull()) 92 return a; 93 84 94 Vector<uint8_t> buffer(a.size() + b.size()); 85 95 memcpy(buffer.data(), a.data(), a.size()); … … 88 98 } 89 99 100 Data Data::adoptMap(FileSystem::MappedFileData&& mappedFile, FileSystem::PlatformFileHandle fd) 101 { 102 ASSERT(mappedFile.data()); 103 FileSystem::closeFile(fd); 104 105 return { WTFMove(mappedFile) }; 106 } 107 90 108 } // namespace NetworkCache 91 109 } // namespace WebKit -
trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp
r241283 r256633 49 49 } 50 50 51 Data::Data(GRefPtr<SoupBuffer>&& buffer, intfd)51 Data::Data(GRefPtr<SoupBuffer>&& buffer, FileSystem::PlatformFileHandle fd) 52 52 : m_buffer(buffer) 53 53 , m_fileDescriptor(fd) 54 54 , m_size(buffer ? buffer->length : 0) 55 , m_isMap(m_size && fd != -1)55 , m_isMap(m_size && FileSystem::isHandleValid(fd)) 56 56 { 57 57 } … … 109 109 { 110 110 munmap(map, size); 111 close(fileDescriptor);111 FileSystem::closeFile(fileDescriptor); 112 112 } 113 113 114 114 void* map; 115 115 size_t size; 116 intfileDescriptor;116 FileSystem::PlatformFileHandle fileDescriptor; 117 117 }; 118 118 … … 122 122 } 123 123 124 Data Data::adoptMap( void* map, size_t size, intfd)124 Data Data::adoptMap(FileSystem::MappedFileData&& mappedFile, FileSystem::PlatformFileHandle fd) 125 125 { 126 size_t size = mappedFile.size(); 127 void* map = mappedFile.leakHandle(); 126 128 ASSERT(map); 127 129 ASSERT(map != MAP_FAILED); … … 131 133 } 132 134 133 #if USE(GLIB) && !PLATFORM(WIN)134 Data adoptAndMapFile(GFileIOStream* stream, size_t offset, size_t size)135 {136 GInputStream* inputStream = g_io_stream_get_input_stream(G_IO_STREAM(stream));137 int fd = g_file_descriptor_based_get_fd(G_FILE_DESCRIPTOR_BASED(inputStream));138 return adoptAndMapFile(fd, offset, size);139 }140 #endif141 142 135 RefPtr<SharedMemory> Data::tryCreateSharedMemory() const 143 136 { … … 145 138 return nullptr; 146 139 147 return SharedMemory::wrapMap(const_cast<char*>(m_buffer->data), m_buffer->length, m_fileDescriptor); 140 GInputStream* inputStream = g_io_stream_get_input_stream(G_IO_STREAM(m_fileDescriptor)); 141 int fd = g_file_descriptor_based_get_fd(G_FILE_DESCRIPTOR_BASED(inputStream)); 142 return SharedMemory::wrapMap(const_cast<char*>(m_buffer->data), m_buffer->length, fd); 148 143 } 149 144 -
trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp
r245301 r256633 54 54 namespace NetworkCache { 55 55 56 #if !OS(WINDOWS)57 static DirectoryEntryType directoryEntryType(uint8_t dtype)58 {59 switch (dtype) {60 case DT_DIR:61 return DirectoryEntryType::Directory;62 case DT_REG:63 return DirectoryEntryType::File;64 default:65 ASSERT_NOT_REACHED();66 return DirectoryEntryType::File;67 }68 return DirectoryEntryType::File;69 }70 #endif71 72 56 void traverseDirectory(const String& path, const Function<void (const String&, DirectoryEntryType)>& function) 73 57 { 74 #if !OS(WINDOWS) 75 DIR* dir = opendir(FileSystem::fileSystemRepresentation(path).data()); 76 if (!dir) 77 return; 78 dirent* dp; 79 while ((dp = readdir(dir))) { 80 if (dp->d_type != DT_DIR && dp->d_type != DT_REG) 81 continue; 82 const char* name = dp->d_name; 83 if (!strcmp(name, ".") || !strcmp(name, "..")) 84 continue; 85 auto nameString = String::fromUTF8(name); 86 if (nameString.isNull()) 87 continue; 88 function(nameString, directoryEntryType(dp->d_type)); 89 } 90 closedir(dir); 91 #else 92 auto entries = FileSystem::listDirectory(path); 58 auto entries = FileSystem::listDirectory(path, "*"_s); 93 59 for (auto& entry : entries) { 94 60 auto type = FileSystem::fileIsDirectory(entry, FileSystem::ShouldFollowSymbolicLinks::No) ? DirectoryEntryType::Directory : DirectoryEntryType::File; 95 function( entry, type);61 function(FileSystem::pathGetFileName(entry), type); 96 62 } 97 #endif98 63 } 99 64
Note: See TracChangeset
for help on using the changeset viewer.