Changeset 219219 in webkit
- Timestamp:
- Jul 6, 2017 2:45:04 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r219218 r219219 1 2017-07-06 Chris Dumez <cdumez@apple.com> 2 3 FileMonitor should not be ref counted 4 https://bugs.webkit.org/show_bug.cgi?id=174166 5 6 Reviewed by Brent Fulgham. 7 8 Update FileMonitor to no longer be refcounted. It was previously easy to leak it 9 because the object would ref itself in various lambdas. The client would have to 10 explicitely call FileMonitor::stopMonitoring() which was fragile. 11 12 This patch also simplifies the code and API a bit since no longer actually 13 requires startMonitoring() / stopMonitoring() API. 14 15 No new tests, covered by API tests. 16 17 * platform/FileMonitor.cpp: 18 (WebCore::FileMonitor::FileMonitor): 19 (WebCore::FileMonitor::~FileMonitor): 20 (WebCore::FileMonitor::create): Deleted. 21 (WebCore::FileMonitor::startMonitoring): Deleted. 22 (WebCore::FileMonitor::stopMonitoring): Deleted. 23 * platform/FileMonitor.h: 24 * platform/cocoa/FileMonitorCocoa.mm: 25 (WebCore::FileMonitor::FileMonitor): 26 (WebCore::FileMonitor::~FileMonitor): 27 (WebCore::FileMonitor::startMonitoring): Deleted. 28 (WebCore::FileMonitor::stopMonitoring): Deleted. 29 1 30 2017-07-06 Matt Rajca <mrajca@apple.com> 2 31 -
trunk/Source/WebCore/platform/FileMonitor.cpp
r218901 r219219 29 29 namespace WebCore { 30 30 31 Ref<FileMonitor> FileMonitor::create(const String& path, Ref<WorkQueue>&& handlerQueue, WTF::Function<void(FileChangeType)>&& modificationHandler) 32 { 33 return adoptRef(*new FileMonitor(path, WTFMove(handlerQueue), WTFMove(modificationHandler))); 34 } 35 36 FileMonitor::FileMonitor(const String& path, Ref<WorkQueue>&& handlerQueue, WTF::Function<void(FileChangeType)>&& modificationHandler) 37 : m_path(path) 38 , m_modificationHandler(WTFMove(modificationHandler)) 39 , m_handlerQueue(WTFMove(handlerQueue)) 31 #if !PLATFORM(COCOA) 32 33 FileMonitor::FileMonitor(const String&, Ref<WorkQueue>&&, WTF::Function<void(FileChangeType)>&&) 40 34 { 41 35 } 42 36 43 37 FileMonitor::~FileMonitor() 44 38 { 45 stopMonitoring();46 }47 48 #if !PLATFORM(COCOA)49 void FileMonitor::startMonitoring()50 {51 // Do Nothing52 }53 54 void FileMonitor::stopMonitoring()55 {56 // Do Nothing57 39 } 58 40 -
trunk/Source/WebCore/platform/FileMonitor.h
r218901 r219219 27 27 28 28 #include <wtf/Function.h> 29 #include <wtf/ThreadSafeRefCounted.h>30 29 #include <wtf/WorkQueue.h> 31 30 #include <wtf/text/WTFString.h> … … 38 37 namespace WebCore { 39 38 40 class FileMonitor : public ThreadSafeRefCounted<FileMonitor>{39 class FileMonitor { 41 40 public: 42 41 enum class FileChangeType { … … 45 44 }; 46 45 47 WEBCORE_EXPORT static Ref<FileMonitor> create(const String&, Ref<WorkQueue>&& handlerQueue, WTF::Function<void(FileChangeType)>&& modificationHandler);46 WEBCORE_EXPORT FileMonitor(const String&, Ref<WorkQueue>&& handlerQueue, WTF::Function<void(FileChangeType)>&& modificationHandler); 48 47 WEBCORE_EXPORT ~FileMonitor(); 49 48 50 WEBCORE_EXPORT void startMonitoring();51 WEBCORE_EXPORT void stopMonitoring();52 53 49 private: 54 FileMonitor(const String&, Ref<WorkQueue>&& handlerQueue, WTF::Function<void(FileChangeType)>&& modificationHandler);55 56 String m_path;57 WTF::Function<void(FileChangeType)> m_modificationHandler;58 Ref<WTF::WorkQueue> m_handlerQueue;59 60 50 #if USE(COCOA_EVENT_LOOP) 61 51 DispatchPtr<dispatch_source_t> m_platformMonitor; -
trunk/Source/WebCore/platform/cocoa/FileMonitorCocoa.mm
r219144 r219219 29 29 #import "FileSystem.h" 30 30 #import "Logging.h" 31 #import <dispatch/dispatch.h> 32 #import <wtf/DispatchPtr.h> 31 #import <wtf/BlockPtr.h> 33 32 34 33 namespace WebCore { … … 37 36 constexpr unsigned fileUnavailableMask = DISPATCH_VNODE_DELETE | DISPATCH_VNODE_RENAME | DISPATCH_VNODE_REVOKE; 38 37 39 void FileMonitor::startMonitoring()38 FileMonitor::FileMonitor(const String& path, Ref<WorkQueue>&& handlerQueue, WTF::Function<void(FileChangeType)>&& modificationHandler) 40 39 { 41 if ( m_platformMonitor)40 if (path.isEmpty()) 42 41 return; 43 42 44 if ( m_path.isEmpty())43 if (!modificationHandler) 45 44 return; 46 45 47 if (!m_modificationHandler) 48 return; 49 50 auto handle = openFile(m_path, OpenForEventsOnly); 46 auto handle = openFile(path, OpenForEventsOnly); 51 47 if (handle == invalidPlatformFileHandle) { 52 RELEASE_LOG_ERROR(ResourceLoadStatistics, "Failed to open statistics file for monitoring: %s", m_path.utf8().data());48 RELEASE_LOG_ERROR(ResourceLoadStatistics, "Failed to open statistics file for monitoring: %s", path.utf8().data()); 53 49 return; 54 50 } 55 51 56 m_platformMonitor = adoptDispatch(dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, handle, monitorMask, m_handlerQueue->dispatchQueue())); 52 // The source (platformMonitor) retains the dispatch queue. 53 m_platformMonitor = adoptDispatch(dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, handle, monitorMask, handlerQueue->dispatchQueue())); 57 54 58 55 LOG(ResourceLoadStatistics, "Creating monitor %p", m_platformMonitor.get()); 59 56 60 dispatch_source_set_event_handler(m_platformMonitor.get(), [this, protectedThis = makeRefPtr(this), fileMonitor = m_platformMonitor.get()] () mutable{57 dispatch_source_set_event_handler(m_platformMonitor.get(), BlockPtr<void()>::fromCallable([modificationHandler = WTFMove(modificationHandler), fileMonitor = m_platformMonitor] { 61 58 // If this is getting called after the monitor was cancelled, just drop the notification. 62 if (dispatch_source_testcancel(fileMonitor ))59 if (dispatch_source_testcancel(fileMonitor.get())) 63 60 return; 64 61 65 unsigned flag = dispatch_source_get_data(fileMonitor );66 LOG(ResourceLoadStatistics, "File event %#X for monitor %p", flag, fileMonitor );62 unsigned flag = dispatch_source_get_data(fileMonitor.get()); 63 LOG(ResourceLoadStatistics, "File event %#X for monitor %p", flag, fileMonitor.get()); 67 64 if (flag & fileUnavailableMask) { 68 m _modificationHandler(FileChangeType::Removal);69 dispatch_source_cancel(fileMonitor );65 modificationHandler(FileChangeType::Removal); 66 dispatch_source_cancel(fileMonitor.get()); 70 67 } else { 71 68 ASSERT(flag & DISPATCH_VNODE_WRITE); 72 m _modificationHandler(FileChangeType::Modification);69 modificationHandler(FileChangeType::Modification); 73 70 } 74 }) ;71 }).get()); 75 72 76 dispatch_source_set_cancel_handler(m_platformMonitor.get(), [fileMonitor = m_platformMonitor.get()] { 77 auto handle = static_cast<PlatformFileHandle>(dispatch_source_get_handle(fileMonitor)); 73 dispatch_source_set_cancel_handler(m_platformMonitor.get(), [handle] () mutable { 78 74 closeFile(handle); 79 75 }); … … 81 77 dispatch_resume(m_platformMonitor.get()); 82 78 } 83 84 void FileMonitor::stopMonitoring()79 80 FileMonitor::~FileMonitor() 85 81 { 86 82 if (!m_platformMonitor) … … 90 86 91 87 dispatch_source_cancel(m_platformMonitor.get()); 92 m_platformMonitor = nullptr;93 88 } 94 89 -
trunk/Source/WebKit2/ChangeLog
r219218 r219219 1 2017-07-06 Chris Dumez <cdumez@apple.com> 2 3 FileMonitor should not be ref counted 4 https://bugs.webkit.org/show_bug.cgi?id=174166 5 6 Reviewed by Brent Fulgham. 7 8 Update code using FileMonitor to reflect API change. 9 10 * UIProcess/WebResourceLoadStatisticsStore.cpp: 11 (WebKit::WebResourceLoadStatisticsStore::startMonitoringStatisticsStorage): 12 (WebKit::WebResourceLoadStatisticsStore::stopMonitoringStatisticsStorage): 13 * UIProcess/WebResourceLoadStatisticsStore.h: 14 1 15 2017-07-06 Matt Rajca <mrajca@apple.com> 2 16 -
trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp
r219211 r219219 435 435 return; 436 436 437 m_statisticsStorageMonitor = FileMonitor::create(resourceLogPath, m_statisticsQueue.copyRef(), [this] (FileMonitor::FileChangeType type) {437 m_statisticsStorageMonitor = std::make_unique<FileMonitor>(resourceLogPath, m_statisticsQueue.copyRef(), [this] (FileMonitor::FileChangeType type) { 438 438 ASSERT(!RunLoop::isMain()); 439 439 switch (type) { … … 447 447 } 448 448 }); 449 450 m_statisticsStorageMonitor->startMonitoring();451 449 } 452 450 … … 454 452 { 455 453 ASSERT(!RunLoop::isMain()); 456 if (!m_statisticsStorageMonitor)457 return;458 459 // FIXME(174166): The FileMonitor captures itself, incrementing its refcount. Manually stopping the monitor shuts down the lambda holding the extra460 // reference, so the object will be cleaned up properly.461 m_statisticsStorageMonitor->stopMonitoring();462 454 m_statisticsStorageMonitor = nullptr; 463 455 } -
trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.h
r219211 r219219 146 146 #endif 147 147 Ref<WTF::WorkQueue> m_statisticsQueue; 148 RefPtr<WebCore::FileMonitor> m_statisticsStorageMonitor;148 std::unique_ptr<WebCore::FileMonitor> m_statisticsStorageMonitor; 149 149 const String m_statisticsStoragePath; 150 150 WTF::WallTime m_lastStatisticsFileSyncTime; -
trunk/Tools/ChangeLog
r219202 r219219 1 2017-07-06 Chris Dumez <cdumez@apple.com> 2 3 FileMonitor should not be ref counted 4 https://bugs.webkit.org/show_bug.cgi?id=174166 5 6 Reviewed by Brent Fulgham. 7 8 Update the API tests to reflect the API change. 9 10 * TestWebKitAPI/Tests/WebCore/FileMonitor.cpp: 11 (TestWebKitAPI::TEST_F): 12 1 13 2017-07-06 Commit Queue <commit-queue@webkit.org> 2 14 -
trunk/Tools/TestWebKitAPI/Tests/WebCore/FileMonitor.cpp
r218906 r219219 150 150 auto testQueue = WorkQueue::create("Test Work Queue"); 151 151 152 auto monitor = WebCore::FileMonitor::create(tempFilePath(), testQueue.copyRef(), [this] (WebCore::FileMonitor::FileChangeType type) {152 auto monitor = std::make_unique<FileMonitor>(tempFilePath(), testQueue.copyRef(), [this] (FileMonitor::FileChangeType type) { 153 153 ASSERT(!RunLoop::isMain()); 154 154 switch (type) { … … 161 161 } 162 162 }); 163 monitor->startMonitoring();164 163 165 164 testQueue->dispatch([this] () mutable { … … 193 192 auto testQueue = WorkQueue::create("Test Work Queue"); 194 193 195 auto monitor = WebCore::FileMonitor::create(tempFilePath(), testQueue.copyRef(), [this] (WebCore::FileMonitor::FileChangeType type) {194 auto monitor = std::make_unique<FileMonitor>(tempFilePath(), testQueue.copyRef(), [this] (FileMonitor::FileChangeType type) { 196 195 ASSERT(!RunLoop::isMain()); 197 196 switch (type) { … … 204 203 } 205 204 }); 206 monitor->startMonitoring();207 205 208 206 testQueue->dispatch([this] () mutable { … … 254 252 auto testQueue = WorkQueue::create("Test Work Queue"); 255 253 256 auto monitor = WebCore::FileMonitor::create(tempFilePath(), testQueue.copyRef(), [this] (WebCore::FileMonitor::FileChangeType type) {254 auto monitor = std::make_unique<FileMonitor>(tempFilePath(), testQueue.copyRef(), [this] (FileMonitor::FileChangeType type) { 257 255 ASSERT(!RunLoop::isMain()); 258 256 switch (type) { … … 265 263 } 266 264 }); 267 monitor->startMonitoring();268 265 269 266 testQueue->dispatch([this] () mutable { … … 294 291 auto testQueue = WorkQueue::create("Test Work Queue"); 295 292 296 auto monitor = WebCore::FileMonitor::create(tempFilePath(), testQueue.copyRef(), [this] (WebCore::FileMonitor::FileChangeType type) {293 auto monitor = std::make_unique<FileMonitor>(tempFilePath(), testQueue.copyRef(), [this] (FileMonitor::FileChangeType type) { 297 294 ASSERT(!RunLoop::isMain()); 298 295 switch (type) { … … 305 302 } 306 303 }); 307 monitor->startMonitoring();308 304 309 305 testQueue->dispatch([this] () mutable { … … 352 348 auto testQueue = WorkQueue::create("Test Work Queue"); 353 349 354 auto monitor = WebCore::FileMonitor::create(tempFilePath(), testQueue.copyRef(), [this] (WebCore::FileMonitor::FileChangeType type) {350 auto monitor = std::make_unique<FileMonitor>(tempFilePath(), testQueue.copyRef(), [this] (FileMonitor::FileChangeType type) { 355 351 ASSERT(!RunLoop::isMain()); 356 352 switch (type) { … … 363 359 } 364 360 }); 365 monitor->startMonitoring();366 361 367 362 testQueue->dispatch([this] () mutable {
Note: See TracChangeset
for help on using the changeset viewer.