Changeset 218901 in webkit
- Timestamp:
- Jun 28, 2017 4:21:11 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r218872 r218901 1 2017-06-28 Brent Fulgham <bfulgham@apple.com> 2 3 Teach ResourceLoadStatistics to recognize changes in the file system 4 https://bugs.webkit.org/show_bug.cgi?id=173800 5 <rdar://problem/32937842> 6 7 Reviewed by Chris Dumez. 8 9 * wtf/DispatchPtr.h: Added (moved from WebKit2) 10 * wtf/Platform.h: Make sure USE_FILE_LOCK is enabled. 11 1 12 2017-06-28 David Kilzer <ddkilzer@apple.com> 2 13 -
trunk/Source/WTF/WTF.xcodeproj/project.pbxproj
r218151 r218901 383 383 A8A4727E151A825A004123FF /* Deque.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Deque.h; sourceTree = "<group>"; }; 384 384 A8A4727F151A825A004123FF /* DisallowCType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisallowCType.h; sourceTree = "<group>"; }; 385 A8A4727F151A825A004123FF /* DispatchPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DispatchPtr.h; sourceTree = "<group>"; }; 385 386 A8A47280151A825A004123FF /* DoublyLinkedList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DoublyLinkedList.h; sourceTree = "<group>"; }; 386 387 A8A47282151A825A004123FF /* bignum-dtoa.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "bignum-dtoa.cc"; sourceTree = "<group>"; }; … … 773 774 A8A4727E151A825A004123FF /* Deque.h */, 774 775 A8A4727F151A825A004123FF /* DisallowCType.h */, 776 A8A4727F151A825A004123FF /* DispatchPtr.h */, 775 777 0F4570421BE5B58F0062A629 /* Dominators.h */, 776 778 A8A47280151A825A004123FF /* DoublyLinkedList.h */, -
trunk/Source/WTF/wtf/Platform.h
r218782 r218901 546 546 #define HAVE_OUT_OF_PROCESS_LAYER_HOSTING 1 547 547 #define HAVE_DTRACE 0 548 #define USE_FILE_LOCK 1 548 549 549 550 #if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV) -
trunk/Source/WebCore/CMakeLists.txt
r218843 r218901 2178 2178 platform/FileChooser.cpp 2179 2179 platform/FileHandle.cpp 2180 platform/FileMonitor.cpp 2180 2181 platform/FileStream.cpp 2181 2182 platform/FileSystem.cpp -
trunk/Source/WebCore/ChangeLog
r218896 r218901 1 2017-06-28 Brent Fulgham <bfulgham@apple.com> 2 3 Teach ResourceLoadStatistics to recognize changes in the file system 4 https://bugs.webkit.org/show_bug.cgi?id=173800 5 <rdar://problem/32937842> 6 7 Reviewed by Chris Dumez. 8 9 We want to support the case where multiple UI processes choose to share the same 10 statistics file. To support this, update the ResourceLoadStatistics logic to be aware 11 that the statistics data file might change underneath it, and to take appropriate 12 action when it does. 13 14 * WebCore.xcodeproj/project.pbxproj: Update for new sources. 15 * WebCore/CMakeLists.txt: Update for new FileMonitor source file. 16 * loader/ResourceLoadStatisticsStore.cpp: 17 (WebCore::ResourceLoadStatisticsStore::clearInMemoryAndPersistent): Use the new deletion 18 handler for the data file instead of writing out an empty file. 19 (WebCore::ResourceLoadStatisticsStore::setDeletePersistentStoreCallback): Added. 20 * loader/ResourceLoadStatisticsStore.h: 21 * platform/FileMonitor.cpp: Added. 22 (WebCore::FileMonitor::create): 23 (WebCore::FileMonitor::FileMonitor): Register handlers and begin monitoring file. 24 (WebCore::FileMonitor::~FileMonitor): Stop any active file monitoring. 25 (WebCore::FileMonitor::startMonitoringPath): Stub implementation. 26 (WebCore::FileMonitor::stopMonitoring): Ditto. 27 * platform/FileMonitor.h: Added. 28 * platform/FileSystem.h: Export files needed by WebKit2. Add support for O_EVTONLY 29 Darwin file handles. 30 * platform/Logging.h: Add 'ResourceLoadStatistics' category. 31 * platform/cocoa/FileMonitorCocoa.mm: Added. 32 (WebCore::FileMonitor::startMonitoringPath): Create a new VNODE type dispatch_source 33 to receive notifications when the specified file changes. 34 (WebCore::FileMonitor::stopMonitoring): Cancel the dispatch_source when we are done 35 monitoring the file. 36 * platform/posix/FileSystemPOSIX.cpp: Update 'openFile' to understand the O_EVTONLY 37 mode of file handles (Darwin-only). 38 1 39 2017-06-28 Brady Eidson <beidson@apple.com> 2 40 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r218746 r218901 3067 3067 79F2F5A11091939A000D87CB /* CompositionEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 79F2F59E1091939A000D87CB /* CompositionEvent.cpp */; }; 3068 3068 79F2F5A21091939A000D87CB /* CompositionEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 79F2F59F1091939A000D87CB /* CompositionEvent.h */; }; 3069 7A09CEF11F02069B00E93BDB /* FileMonitor.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A09CEEC1F01CC9300E93BDB /* FileMonitor.h */; settings = {ATTRIBUTES = (Private, ); }; }; 3069 3070 7A0E770E10C00A8800A0276E /* InspectorFrontendHost.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A0E770B10C00A8800A0276E /* InspectorFrontendHost.cpp */; }; 3070 3071 7A0E770F10C00A8800A0276E /* InspectorFrontendHost.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A0E770C10C00A8800A0276E /* InspectorFrontendHost.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 3077 3078 7A29BA6A187B7C1D00F29CEB /* TemporaryOpenGLSetting.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A29BA69187B781C00F29CEB /* TemporaryOpenGLSetting.cpp */; }; 3078 3079 7A29F57218C69514004D0F81 /* OutOfBandTextTrackPrivateAVF.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A29F57118C69514004D0F81 /* OutOfBandTextTrackPrivateAVF.h */; }; 3080 7A32D7471F020EED00162C44 /* FileMonitorCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7A09CEF01F01D1F700E93BDB /* FileMonitorCocoa.mm */; }; 3081 7A32D7481F020EFF00162C44 /* FileMonitor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A09CEEB1F01CC9300E93BDB /* FileMonitor.cpp */; }; 3079 3082 7A45032F18DB717200377B34 /* BufferedLineReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A45032D18DB717200377B34 /* BufferedLineReader.cpp */; }; 3080 3083 7A45033018DB717200377B34 /* BufferedLineReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A45032E18DB717200377B34 /* BufferedLineReader.h */; }; … … 11130 11133 79F2F59F1091939A000D87CB /* CompositionEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompositionEvent.h; sourceTree = "<group>"; }; 11131 11134 79F2F5A01091939A000D87CB /* CompositionEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CompositionEvent.idl; sourceTree = "<group>"; }; 11135 7A09CEEB1F01CC9300E93BDB /* FileMonitor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FileMonitor.cpp; sourceTree = "<group>"; }; 11136 7A09CEEC1F01CC9300E93BDB /* FileMonitor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FileMonitor.h; sourceTree = "<group>"; }; 11137 7A09CEF01F01D1F700E93BDB /* FileMonitorCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FileMonitorCocoa.mm; sourceTree = "<group>"; }; 11132 11138 7A0E770B10C00A8800A0276E /* InspectorFrontendHost.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorFrontendHost.cpp; sourceTree = "<group>"; }; 11133 11139 7A0E770C10C00A8800A0276E /* InspectorFrontendHost.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorFrontendHost.h; sourceTree = "<group>"; }; … … 21261 21267 7C7941E31C56C29300A4C58E /* DataDetectorsCoreSoftLink.h */, 21262 21268 7C7941E21C56C29300A4C58E /* DataDetectorsCoreSoftLink.mm */, 21269 7A09CEF01F01D1F700E93BDB /* FileMonitorCocoa.mm */, 21263 21270 514B3F750C722055000530DF /* FileSystemCocoa.mm */, 21264 21271 A5C974CF11485FF10066F2AB /* KeyEventCocoa.h */, … … 24139 24146 5351D4AF1DF916AC008010CD /* FileHandle.h */, 24140 24147 4689F1AE1267BAE100E8D380 /* FileMetadata.h */, 24148 7A09CEEB1F01CC9300E93BDB /* FileMonitor.cpp */, 24149 7A09CEEC1F01CC9300E93BDB /* FileMonitor.h */, 24141 24150 2EF1BFE8121C9F4200C27627 /* FileStream.cpp */, 24142 24151 2EF1BFE9121C9F4200C27627 /* FileStream.h */, … … 26564 26573 76CDD2F31103DA6600680521 /* AccessibilityMenuList.h in Headers */, 26565 26574 76CDD2F71103DA6600680521 /* AccessibilityMenuListOption.h in Headers */, 26575 7A09CEF11F02069B00E93BDB /* FileMonitor.h in Headers */, 26566 26576 76CDD2F51103DA6600680521 /* AccessibilityMenuListPopup.h in Headers */, 26567 26577 29ACB212143E7128006BCA5F /* AccessibilityMockObject.h in Headers */, … … 30847 30857 0719427F1D088F21002AA51D /* AVFoundationMIMETypeCache.mm in Sources */, 30848 30858 070363E5181A1CDC00C074A5 /* AVMediaCaptureSource.mm in Sources */, 30859 7A32D7481F020EFF00162C44 /* FileMonitor.cpp in Sources */, 30849 30860 CD336F6117F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.mm in Sources */, 30850 30861 070363E7181A1CDC00C074A5 /* AVVideoCaptureSource.mm in Sources */, … … 33962 33973 8AA61CFF144D595B00F37350 /* WebKitCSSRegionRule.cpp in Sources */, 33963 33974 3FFFF9A8159D9A550020BBD5 /* WebKitCSSViewportRule.cpp in Sources */, 33975 7A32D7471F020EED00162C44 /* FileMonitorCocoa.mm in Sources */, 33964 33976 1A1414B513A0F0500019996C /* WebKitFontFamilyNames.cpp in Sources */, 33965 33977 2D0621441DA639B600A7FB26 /* WebKitMediaKeyMessageEvent.cpp in Sources */, -
trunk/Source/WebCore/loader/ResourceLoadStatisticsStore.cpp
r218865 r218901 159 159 ASSERT(!isMainThread()); 160 160 clearInMemory(); 161 if (m_ writePersistentStoreHandler)162 m_ writePersistentStoreHandler();161 if (m_deletePersistentStoreHandler) 162 m_deletePersistentStoreHandler(); 163 163 if (m_grandfatherExistingWebsiteDataHandler) 164 164 m_grandfatherExistingWebsiteDataHandler(); … … 221 221 { 222 222 m_grandfatherExistingWebsiteDataHandler = WTFMove(handler); 223 } 224 225 void ResourceLoadStatisticsStore::setDeletePersistentStoreCallback(WTF::Function<void()>&& handler) 226 { 227 m_deletePersistentStoreHandler = WTFMove(handler); 223 228 } 224 229 -
trunk/Source/WebCore/loader/ResourceLoadStatisticsStore.h
r218865 r218901 85 85 WEBCORE_EXPORT void setShouldPartitionCookiesCallback(WTF::Function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst)>&&); 86 86 WEBCORE_EXPORT void setWritePersistentStoreCallback(WTF::Function<void()>&&); 87 WEBCORE_EXPORT void setDeletePersistentStoreCallback(WTF::Function<void()>&&); 87 88 WEBCORE_EXPORT void setGrandfatherExistingWebsiteDataCallback(WTF::Function<void()>&&); 88 89 WEBCORE_EXPORT void setFireTelemetryCallback(WTF::Function<void()>&& handler); … … 120 121 WTF::Function<void()> m_writePersistentStoreHandler; 121 122 WTF::Function<void()> m_grandfatherExistingWebsiteDataHandler; 123 WTF::Function<void()> m_deletePersistentStoreHandler; 122 124 WTF::Function<void()> m_fireTelemetryHandler; 123 125 -
trunk/Source/WebCore/platform/FileSystem.h
r218160 r218901 29 29 */ 30 30 31 #ifndef FileSystem_h 32 #define FileSystem_h 31 #pragma once 33 32 34 33 #include <time.h> … … 72 71 enum FileOpenMode { 73 72 OpenForRead = 0, 74 OpenForWrite 73 OpenForWrite, 74 #if OS(DARWIN) 75 OpenForEventsOnly 76 #endif 75 77 }; 76 78 … … 132 134 WEBCORE_EXPORT int writeToFile(PlatformFileHandle, const char* data, int length); 133 135 // Returns number of bytes actually written if successful, -1 otherwise. 134 int readFromFile(PlatformFileHandle, char* data, int length);136 WEBCORE_EXPORT int readFromFile(PlatformFileHandle, char* data, int length); 135 137 136 138 // Appends the contents of the file found at 'path' to the open PlatformFileHandle. … … 142 144 143 145 #if USE(FILE_LOCK) 144 bool lockFile(PlatformFileHandle, FileLockMode);145 bool unlockFile(PlatformFileHandle);146 WEBCORE_EXPORT bool lockFile(PlatformFileHandle, FileLockMode); 147 WEBCORE_EXPORT bool unlockFile(PlatformFileHandle); 146 148 #endif 147 149 … … 199 201 } // namespace WebCore 200 202 201 #endif // FileSystem_h -
trunk/Source/WebCore/platform/Logging.h
r218615 r218901 1 1 /* 2 * Copyright (C) 2003 , 2006, 2013, 2015, 2016Apple Inc. All rights reserved.2 * Copyright (C) 2003-2017 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 77 77 M(ResourceLoading) \ 78 78 M(ResourceLoadObserver) \ 79 M(ResourceLoadStatistics) \ 79 80 M(Scrolling) \ 80 81 M(Services) \ -
trunk/Source/WebCore/platform/posix/FileSystemPOSIX.cpp
r212484 r218901 84 84 else if (mode == OpenForWrite) 85 85 platformFlag |= (O_WRONLY | O_CREAT | O_TRUNC); 86 #if OS(DARWIN) 87 else if (mode == OpenForEventsOnly) 88 platformFlag |= O_EVTONLY; 89 #endif 90 86 91 return open(fsRep.data(), platformFlag, 0666); 87 92 } -
trunk/Source/WebKit2/ChangeLog
r218899 r218901 1 2017-06-28 Brent Fulgham <bfulgham@apple.com> 2 3 Teach ResourceLoadStatistics to recognize changes in the file system 4 https://bugs.webkit.org/show_bug.cgi?id=173800 5 <rdar://problem/32937842> 6 7 Reviewed by Chris Dumez. 8 9 We want to support the case where multiple UI processes choose to share the same 10 statistics file. To support this, update the ResourceLoadStatistics logic to be aware 11 that the statistics data file might change underneath it, and to take appropriate 12 action when it does. 13 14 * UIProcess/WebResourceLoadStatisticsStore.cpp: 15 (WebKit::WebResourceLoadStatisticsStore::setResourceLoadStatisticsEnabled): When we enable 16 the statistics, read in the data and then watch for changes. 17 (WebKit::WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver): Add a 18 'delete data' handler to remove the file on disk, not just write an empty store. 19 (WebKit::WebResourceLoadStatisticsStore::readDataFromDiskIfNeeded): Use ASCIILiteral. 20 (WebKit::WebResourceLoadStatisticsStore::refreshFromDisk): Convenience function. 21 (WebKit::WebResourceLoadStatisticsStore::writeStoreToDisk): Sync with any on-disk 22 storage before writing out. 23 (WebKit::openAndLockFile): Convenience function. 24 (WebKit::closeAndUnlockFile): Ditto. 25 (WebKit::WebResourceLoadStatisticsStore::writeEncoderToDisk): Revise to lock file (on 26 platforms that support it) before writing to disk. 27 (WebKit::WebResourceLoadStatisticsStore::deleteStoreFromDisk): Added convenience function. 28 (WebKit::WebResourceLoadStatisticsStore::clearInMemoryData): Ditto. 29 (WebKit::WebResourceLoadStatisticsStore::startMonitoringStatisticsStorage): Create a 30 file system monitor to watch for file changes. 31 (WebKit::WebResourceLoadStatisticsStore::syncWithExistingStatisticsStorageIfNeeded): Added 32 convenience function. 33 (WebKit::WebResourceLoadStatisticsStore::createDecoderFromDisk): Revise to read data 34 directly so we can control file locking. 35 * UIProcess/WebResourceLoadStatisticsStore.h: 36 1 37 2017-06-28 Wenson Hsieh <wenson_hsieh@apple.com> 2 38 -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheData.h
r218457 r218901 1 1 /* 2 * Copyright (C) 2015 Apple Inc. All rights reserved.2 * Copyright (C) 2015-2017 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 34 34 #include <wtf/text/WTFString.h> 35 35 36 #if PLATFORM(COCOA) 37 #include <wtf/DispatchPtr.h> 38 #endif 39 36 40 #if USE(SOUP) 37 41 #include <WebCore/GRefPtrSoup.h> … … 43 47 44 48 namespace NetworkCache { 45 46 #if PLATFORM(COCOA)47 template <typename T> class DispatchPtr;48 template <typename T> DispatchPtr<T> adoptDispatch(T dispatchObject);49 50 // FIXME: Use OSObjectPtr instead when it works with dispatch_data_t on all platforms.51 template<typename T> class DispatchPtr {52 public:53 DispatchPtr()54 : m_ptr(nullptr)55 {56 }57 explicit DispatchPtr(T ptr)58 : m_ptr(ptr)59 {60 if (m_ptr)61 dispatch_retain(m_ptr);62 }63 DispatchPtr(const DispatchPtr& other)64 : m_ptr(other.m_ptr)65 {66 if (m_ptr)67 dispatch_retain(m_ptr);68 }69 ~DispatchPtr()70 {71 if (m_ptr)72 dispatch_release(m_ptr);73 }74 75 DispatchPtr& operator=(const DispatchPtr& other)76 {77 auto copy = other;78 std::swap(m_ptr, copy.m_ptr);79 return *this;80 }81 82 T get() const { return m_ptr; }83 explicit operator bool() const { return m_ptr; }84 85 friend DispatchPtr adoptDispatch<T>(T);86 87 private:88 struct Adopt { };89 DispatchPtr(Adopt, T data)90 : m_ptr(data)91 {92 }93 94 T m_ptr;95 };96 97 template <typename T> DispatchPtr<T> adoptDispatch(T dispatchObject)98 {99 return DispatchPtr<T>(typename DispatchPtr<T>::Adopt { }, dispatchObject);100 }101 #endif102 49 103 50 class Data { -
trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp
r218841 r218901 27 27 #include "WebResourceLoadStatisticsStore.h" 28 28 29 #include "Logging.h" 29 30 #include "WebProcessMessages.h" 30 31 #include "WebProcessPool.h" … … 34 35 #include "WebsiteDataFetchOption.h" 35 36 #include "WebsiteDataType.h" 37 #include <WebCore/FileMonitor.h> 38 #include <WebCore/FileSystem.h> 36 39 #include <WebCore/KeyedCoding.h> 37 40 #include <WebCore/ResourceLoadObserver.h> … … 43 46 #include <wtf/Seconds.h> 44 47 #include <wtf/threads/BinarySemaphore.h> 48 49 #if PLATFORM(COCOA) 50 #define ENABLE_MULTIPROCESS_ACCESS_TO_STATISTICS_STORE 1 51 #endif 45 52 46 53 using namespace WebCore; … … 151 158 }); 152 159 } 153 160 161 stopMonitoringStatisticsStorage(); 162 154 163 writeStoreToDisk(); 164 165 startMonitoringStatisticsStorage(); 155 166 }); 156 167 } … … 167 178 void WebResourceLoadStatisticsStore::setResourceLoadStatisticsEnabled(bool enabled) 168 179 { 180 ASSERT(RunLoop::isMain()); 181 169 182 if (enabled == m_resourceLoadStatisticsEnabled) 170 183 return; … … 172 185 m_resourceLoadStatisticsEnabled = enabled; 173 186 174 readDataFromDiskIfNeeded(); 187 if (m_resourceLoadStatisticsEnabled) { 188 readDataFromDiskIfNeeded(); 189 m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] () { 190 startMonitoringStatisticsStorage(); 191 }); 192 } else 193 m_statisticsQueue->dispatch([statisticsStorageMonitor = WTFMove(m_statisticsStorageMonitor)] { }); 175 194 } 176 195 … … 198 217 m_resourceLoadStatisticsStore->setGrandfatherExistingWebsiteDataCallback([this, protectedThis = makeRef(*this)]() { 199 218 grandfatherExistingWebsiteData(); 219 }); 220 m_resourceLoadStatisticsStore->setDeletePersistentStoreCallback([this, protectedThis = makeRef(*this)] { 221 m_statisticsQueue->dispatch([this, protectedThis = protectedThis.copyRef()] { 222 deleteStoreFromDisk(); 223 }); 200 224 }); 201 225 m_resourceLoadStatisticsStore->setFireTelemetryCallback([this, protectedThis = makeRef(*this)]() { … … 240 264 241 265 m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] { 242 auto decoder = createDecoderFromDisk( "full_browsing_session");266 auto decoder = createDecoderFromDisk(ASCIILiteral("full_browsing_session")); 243 267 if (!decoder) { 244 268 grandfatherExistingWebsiteData(); … … 254 278 }); 255 279 } 256 280 281 void WebResourceLoadStatisticsStore::refreshFromDisk() 282 { 283 ASSERT(!RunLoop::isMain()); 284 auto decoder = createDecoderFromDisk(ASCIILiteral("full_browsing_session")); 285 if (!decoder) 286 return; 287 288 auto locker = holdLock(coreStore().statisticsLock()); 289 coreStore().readDataFromDecoder(*decoder); 290 } 291 257 292 void WebResourceLoadStatisticsStore::processWillOpenConnection(WebProcessProxy&, IPC::Connection& connection) 258 293 { … … 288 323 ASSERT(!RunLoop::isMain()); 289 324 325 syncWithExistingStatisticsStorageIfNeeded(); 326 290 327 auto encoder = coreStore().createEncoderFromData(); 291 328 writeEncoderToDisk(*encoder.get(), "full_browsing_session"); 329 } 330 331 static PlatformFileHandle openAndLockFile(const String& path, FileOpenMode mode) 332 { 333 ASSERT(!RunLoop::isMain()); 334 auto handle = openFile(path, mode); 335 if (handle == invalidPlatformFileHandle) 336 return invalidPlatformFileHandle; 337 338 #if ENABLE(MULTIPROCESS_ACCESS_TO_STATISTICS_STORE) 339 bool locked = lockFile(handle, WebCore::LockExclusive); 340 ASSERT_UNUSED(locked, locked); 341 #endif 342 343 return handle; 344 } 345 346 static void closeAndUnlockFile(PlatformFileHandle handle) 347 { 348 ASSERT(!RunLoop::isMain()); 349 #if ENABLE(MULTIPROCESS_ACCESS_TO_STATISTICS_STORE) 350 bool unlocked = unlockFile(handle); 351 ASSERT_UNUSED(unlocked, unlocked); 352 #endif 353 closeFile(handle); 292 354 } 293 355 … … 309 371 } 310 372 311 auto handle = open File(resourceLog, OpenForWrite);312 if ( !handle)373 auto handle = openAndLockFile(resourceLog, OpenForWrite); 374 if (handle == invalidPlatformFileHandle) 313 375 return; 314 376 315 377 int64_t writtenBytes = writeToFile(handle, rawData->data(), rawData->size()); 316 close File(handle);378 closeAndUnlockFile(handle); 317 379 318 380 if (writtenBytes != static_cast<int64_t>(rawData->size())) 319 WTFLogAlways("WebResourceLoadStatisticsStore: We only wrote %d out of %d bytes to disk", static_cast<unsigned>(writtenBytes), rawData->size()); 320 } 321 381 RELEASE_LOG_ERROR(ResourceLoadStatistics, "WebResourceLoadStatisticsStore: We only wrote %d out of %d bytes to disk", static_cast<unsigned>(writtenBytes), rawData->size()); 382 } 383 384 void WebResourceLoadStatisticsStore::deleteStoreFromDisk() 385 { 386 ASSERT(!RunLoop::isMain()); 387 String resourceLogPath = persistentStoragePath(ASCIILiteral("full_browsing_session")); 388 if (resourceLogPath.isEmpty()) 389 return; 390 391 stopMonitoringStatisticsStorage(); 392 393 if (!deleteFile(resourceLogPath)) 394 RELEASE_LOG_ERROR(ResourceLoadStatistics, "Unable to delete statistics file: %s", resourceLogPath.utf8().data()); 395 } 396 397 void WebResourceLoadStatisticsStore::clearInMemoryData() 398 { 399 auto locker = holdLock(coreStore().statisticsLock()); 400 coreStore().clearInMemory(); 401 } 402 403 void WebResourceLoadStatisticsStore::startMonitoringStatisticsStorage() 404 { 405 ASSERT(!RunLoop::isMain()); 406 if (m_statisticsStorageMonitor) 407 return; 408 409 String resourceLogPath = persistentStoragePath(ASCIILiteral("full_browsing_session")); 410 if (resourceLogPath.isEmpty()) 411 return; 412 413 m_statisticsStorageMonitor = FileMonitor::create(resourceLogPath, m_statisticsQueue.copyRef(), [this] (FileMonitor::FileChangeType type) { 414 ASSERT(!RunLoop::isMain()); 415 switch (type) { 416 case FileMonitor::FileChangeType::Modification: 417 refreshFromDisk(); 418 break; 419 case FileMonitor::FileChangeType::Removal: 420 clearInMemoryData(); 421 m_statisticsStorageMonitor = nullptr; 422 break; 423 } 424 }); 425 426 m_statisticsStorageMonitor->startMonitoring(); 427 } 428 429 void WebResourceLoadStatisticsStore::stopMonitoringStatisticsStorage() 430 { 431 ASSERT(!RunLoop::isMain()); 432 if (!m_statisticsStorageMonitor) 433 return; 434 435 m_statisticsStorageMonitor = nullptr; 436 } 437 438 void WebResourceLoadStatisticsStore::syncWithExistingStatisticsStorageIfNeeded() 439 { 440 ASSERT(!RunLoop::isMain()); 441 if (m_statisticsStorageMonitor) 442 return; 443 444 refreshFromDisk(); 445 446 startMonitoringStatisticsStorage(); 447 } 448 449 322 450 #if !PLATFORM(COCOA) 323 451 void WebResourceLoadStatisticsStore::platformExcludeFromBackup() const … … 329 457 std::unique_ptr<KeyedDecoder> WebResourceLoadStatisticsStore::createDecoderFromDisk(const String& label) const 330 458 { 459 ASSERT(!RunLoop::isMain()); 331 460 String resourceLog = persistentStoragePath(label); 332 461 if (resourceLog.isEmpty()) 333 462 return nullptr; 334 463 335 RefPtr<SharedBuffer> rawData = SharedBuffer::createWithContentsOfFile(resourceLog);336 if ( !rawData)464 auto handle = openAndLockFile(resourceLog, OpenForRead); 465 if (handle == invalidPlatformFileHandle) 337 466 return nullptr; 338 339 return KeyedDecoder::decoder(reinterpret_cast<const uint8_t*>(rawData->data()), rawData->size()); 467 468 long long fileSize = 0; 469 if (!getFileSize(handle, fileSize)) { 470 closeAndUnlockFile(handle); 471 return nullptr; 472 } 473 474 size_t bytesToRead; 475 if (!WTF::convertSafely(fileSize, bytesToRead)) { 476 closeAndUnlockFile(handle); 477 return nullptr; 478 } 479 480 Vector<char> buffer(bytesToRead); 481 size_t totalBytesRead = readFromFile(handle, buffer.data(), buffer.size()); 482 483 closeAndUnlockFile(handle); 484 485 if (totalBytesRead != bytesToRead) 486 return nullptr; 487 488 return KeyedDecoder::decoder(reinterpret_cast<const uint8_t*>(buffer.data()), buffer.size()); 340 489 } 341 490 -
trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.h
r218865 r218901 47 47 class KeyedDecoder; 48 48 class KeyedEncoder; 49 class FileMonitor; 49 50 struct ResourceLoadStatistics; 50 51 } … … 86 87 void classifyResource(WebCore::ResourceLoadStatistics&); 87 88 void removeDataRecords(); 89 void startMonitoringStatisticsStorage(); 90 void stopMonitoringStatisticsStorage(); 88 91 89 92 String persistentStoragePath(const String& label) const; … … 98 101 std::unique_ptr<WebCore::KeyedDecoder> createDecoderFromDisk(const String& label) const; 99 102 void platformExcludeFromBackup() const; 100 103 void deleteStoreFromDisk(); 104 void clearInMemoryData(); 105 void syncWithExistingStatisticsStorageIfNeeded(); 106 void refreshFromDisk(); 101 107 void telemetryTimerFired(); 102 108 … … 108 114 #endif 109 115 Ref<WTF::WorkQueue> m_statisticsQueue; 116 RefPtr<WebCore::FileMonitor> m_statisticsStorageMonitor; 110 117 String m_statisticsStoragePath; 111 118 bool m_resourceLoadStatisticsEnabled { false }; -
trunk/Tools/ChangeLog
r218896 r218901 1 2017-06-28 Brent Fulgham <bfulgham@apple.com> 2 3 Teach ResourceLoadStatistics to recognize changes in the file system 4 https://bugs.webkit.org/show_bug.cgi?id=173800 5 <rdar://problem/32937842> 6 7 Reviewed by Chris Dumez. 8 9 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 10 * TestWebKitAPI/Tests/WebCore/FileMonitor.cpp: Added. 11 (TestWebKitAPI::FileMonitorTest::tempFilePath): 12 (TestWebKitAPI::handleFileModification): 13 (TestWebKitAPI::handleFileDeletion): 14 (TestWebKitAPI::resetTestState): 15 (TestWebKitAPI::TEST_F): 16 1 17 2017-06-28 Brady Eidson <beidson@apple.com> 2 18 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r218855 r218901 232 232 7A010BCD1D877C0D00EDE72A /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7A010BCC1D877C0D00EDE72A /* QuartzCore.framework */; }; 233 233 7A1458FC1AD5C07000E06772 /* mouse-button-listener.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7A1458FB1AD5C03500E06772 /* mouse-button-listener.html */; }; 234 7A32D74A1F02151500162C44 /* FileMonitor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A32D7491F02151500162C44 /* FileMonitor.cpp */; }; 234 235 7A66BDB61EAF14EF00CCC924 /* LimitTitleSize.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A66BDB51EAF14D000CCC924 /* LimitTitleSize.cpp */; }; 235 236 7A66BDB81EAF18D500CCC924 /* set-long-title.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7A66BDB71EAF150100CCC924 /* set-long-title.html */; }; … … 1261 1262 7A010BCC1D877C0D00EDE72A /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; 1262 1263 7A1458FB1AD5C03500E06772 /* mouse-button-listener.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "mouse-button-listener.html"; sourceTree = "<group>"; }; 1264 7A32D7491F02151500162C44 /* FileMonitor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FileMonitor.cpp; sourceTree = "<group>"; }; 1263 1265 7A38D7E51C752D5F004F157D /* HashCountedSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HashCountedSet.cpp; sourceTree = "<group>"; }; 1264 1266 7A5623101AD5AF3E0096B920 /* MenuTypesForMouseEvents.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MenuTypesForMouseEvents.cpp; sourceTree = "<group>"; }; … … 1930 1932 26F6E1EF1ADC749B00DE696B /* DFAMinimizer.cpp */, 1931 1933 3151180F1DB1ADD500176304 /* ExtendedColor.cpp */, 1934 7A32D7491F02151500162C44 /* FileMonitor.cpp */, 1932 1935 41973B5A1AF2286A006C7B36 /* FileSystem.cpp */, 1933 1936 7A909A701D877475007E10F8 /* FloatPoint.cpp */, … … 3025 3028 CD78E11D1DB7EA660014A2DE /* FullscreenDelegate.mm in Sources */, 3026 3029 7C83E0BD1D0A650C00FEBCF3 /* FullscreenTopContentInset.mm in Sources */, 3030 7A32D74A1F02151500162C44 /* FileMonitor.cpp in Sources */, 3027 3031 CDBFCC451A9FF45300A7B691 /* FullscreenZoomInitialFrame.mm in Sources */, 3028 3032 7CCE7EF81A411AE600447C4C /* Geolocation.cpp in Sources */,
Note: See TracChangeset
for help on using the changeset viewer.