Title: [169955] trunk/Source/WebCore
Revision
169955
Author
ander...@apple.com
Date
2014-06-13 16:01:31 -0700 (Fri, 13 Jun 2014)

Log Message

Use the callOnMainThread version that takes an std::function in BlobResourceHandle::start()
https://bugs.webkit.org/show_bug.cgi?id=133886

Reviewed by Andreas Kling.

Also replace a couple of NSAutoreleasePools with @autoreleasepool and an OwnPtr with an std::unique_ptr.

* page/scrolling/mac/ScrollingThreadMac.mm:
(WebCore::ScrollingThread::threadRunLoopSourceCallback):
* platform/mac/SharedTimerMac.mm:
(WebCore::PowerObserver::PowerObserver):
(WebCore::timerFired):
(WebCore::setSharedTimerFireInterval):
(WebCore::PowerObserver::create): Deleted.
(WebCore::PowerObserver::didReceiveSystemPowerNotification): Deleted.
* platform/network/BlobResourceHandle.cpp:
(WebCore::BlobResourceHandle::start):
(WebCore::delayedStartBlobResourceHandle): Deleted.
* platform/network/BlobResourceHandle.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (169954 => 169955)


--- trunk/Source/WebCore/ChangeLog	2014-06-13 22:52:50 UTC (rev 169954)
+++ trunk/Source/WebCore/ChangeLog	2014-06-13 23:01:31 UTC (rev 169955)
@@ -1,3 +1,25 @@
+2014-06-13  Anders Carlsson  <ander...@apple.com>
+
+        Use the callOnMainThread version that takes an std::function in BlobResourceHandle::start()
+        https://bugs.webkit.org/show_bug.cgi?id=133886
+
+        Reviewed by Andreas Kling.
+
+        Also replace a couple of NSAutoreleasePools with @autoreleasepool and an OwnPtr with an std::unique_ptr.
+
+        * page/scrolling/mac/ScrollingThreadMac.mm:
+        (WebCore::ScrollingThread::threadRunLoopSourceCallback):
+        * platform/mac/SharedTimerMac.mm:
+        (WebCore::PowerObserver::PowerObserver):
+        (WebCore::timerFired):
+        (WebCore::setSharedTimerFireInterval):
+        (WebCore::PowerObserver::create): Deleted.
+        (WebCore::PowerObserver::didReceiveSystemPowerNotification): Deleted.
+        * platform/network/BlobResourceHandle.cpp:
+        (WebCore::BlobResourceHandle::start):
+        (WebCore::delayedStartBlobResourceHandle): Deleted.
+        * platform/network/BlobResourceHandle.h:
+
 2014-06-12  Sam Weinig  <s...@webkit.org>
 
         Constructors should eagerly reify their properties too

Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingThreadMac.mm (169954 => 169955)


--- trunk/Source/WebCore/page/scrolling/mac/ScrollingThreadMac.mm	2014-06-13 22:52:50 UTC (rev 169954)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingThreadMac.mm	2014-06-13 23:01:31 UTC (rev 169955)
@@ -63,9 +63,9 @@
 
 void ScrollingThread::threadRunLoopSourceCallback()
 {
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-    dispatchFunctionsFromScrollingThread();
-    [pool drain];
+    @autoreleasepool {
+        dispatchFunctionsFromScrollingThread();
+    }
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/mac/SharedTimerMac.mm (169954 => 169955)


--- trunk/Source/WebCore/platform/mac/SharedTimerMac.mm	2014-06-13 22:52:50 UTC (rev 169954)
+++ trunk/Source/WebCore/platform/mac/SharedTimerMac.mm	2014-06-13 23:01:31 UTC (rev 169955)
@@ -43,16 +43,10 @@
     WTF_MAKE_NONCOPYABLE(PowerObserver);
     
 public:
-    static PassOwnPtr<PowerObserver> create()
-    {
-        return adoptPtr(new PowerObserver);
-    }
+    PowerObserver();
     ~PowerObserver();
 
 private:
-    PowerObserver();
-
-    static void didReceiveSystemPowerNotification(void* context, io_service_t, uint32_t messageType, void* messageArgument);
     void didReceiveSystemPowerNotification(io_service_t, uint32_t messageType, void* messageArgument);
 
     void restartSharedTimer();
@@ -65,11 +59,13 @@
 
 PowerObserver::PowerObserver()
     : m_powerConnection(0)
-    , m_notificationPort(0)
+    , m_notificationPort(nullptr)
     , m_notifierReference(0)
     , m_dispatchQueue(dispatch_queue_create("com.apple.WebKit.PowerObserver", 0))
 {
-    m_powerConnection = IORegisterForSystemPower(this, &m_notificationPort, didReceiveSystemPowerNotification, &m_notifierReference);
+    m_powerConnection = IORegisterForSystemPower(this, &m_notificationPort, [](void* context, io_service_t service, uint32_t messageType, void* messageArgument) {
+        static_cast<PowerObserver*>(context)->didReceiveSystemPowerNotification(service, messageType, messageArgument);
+    }, &m_notifierReference);
     if (!m_powerConnection)
         return;
 
@@ -88,11 +84,6 @@
     IONotificationPortDestroy(m_notificationPort);
 }
 
-void PowerObserver::didReceiveSystemPowerNotification(void* context, io_service_t service, uint32_t messageType, void* messageArgument)
-{
-    static_cast<PowerObserver*>(context)->didReceiveSystemPowerNotification(service, messageType, messageArgument);
-}
-
 void PowerObserver::didReceiveSystemPowerNotification(io_service_t, uint32_t messageType, void* messageArgument)
 {
     IOAllowPowerChange(m_powerConnection, reinterpret_cast<long>(messageArgument));
@@ -118,7 +109,7 @@
     timerFired(0, 0);
 }
 
-static PowerObserver* PowerObserver;
+static PowerObserver* powerObserver;
 
 void setSharedTimerFiredFunction(void (*f)())
 {
@@ -129,9 +120,9 @@
 
 static void timerFired(CFRunLoopTimerRef, void*)
 {
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-    sharedTimerFiredFunction();
-    [pool drain];
+    @autoreleasepool {
+        sharedTimerFiredFunction();
+    }
 }
 
 void setSharedTimerFireInterval(double interval)
@@ -147,8 +138,8 @@
     sharedTimer = CFRunLoopTimerCreate(0, fireDate, 0, 0, 0, timerFired, 0);
     CFRunLoopAddTimer(CFRunLoopGetCurrent(), sharedTimer, kCFRunLoopCommonModes);
     
-    if (!PowerObserver)
-        PowerObserver = PowerObserver::create().leakPtr();
+    if (!powerObserver)
+        powerObserver = std::make_unique<PowerObserver>().release();
 }
 
 void stopSharedTimer()

Modified: trunk/Source/WebCore/platform/network/BlobResourceHandle.cpp (169954 => 169955)


--- trunk/Source/WebCore/platform/network/BlobResourceHandle.cpp	2014-06-13 22:52:50 UTC (rev 169954)
+++ trunk/Source/WebCore/platform/network/BlobResourceHandle.cpp	2014-06-13 23:01:31 UTC (rev 169955)
@@ -205,24 +205,19 @@
     // BlobResourceHandle doesn't wait for didReceiveResponse, and it currently cannot be used for downloading.
 }
 
-void delayedStartBlobResourceHandle(void* context)
-{
-    RefPtr<BlobResourceHandle> handle = adoptRef(static_cast<BlobResourceHandle*>(context));
-    handle->doStart();
-}
-
 void BlobResourceHandle::start()
 {
-    if (m_async) {
-        // Keep BlobResourceHandle alive until delayedStartBlobResourceHandle runs.
-        ref();
-
-        // Finish this async call quickly and return.
-        callOnMainThread(delayedStartBlobResourceHandle, this);
+    if (!m_async) {
+        doStart();
         return;
     }
 
-    doStart();
+    RefPtr<BlobResourceHandle> handle(this);
+
+    // Finish this async call quickly and return.
+    callOnMainThread([handle] {
+        handle->doStart();
+    });
 }
 
 void BlobResourceHandle::doStart()

Modified: trunk/Source/WebCore/platform/network/BlobResourceHandle.h (169954 => 169955)


--- trunk/Source/WebCore/platform/network/BlobResourceHandle.h	2014-06-13 22:52:50 UTC (rev 169954)
+++ trunk/Source/WebCore/platform/network/BlobResourceHandle.h	2014-06-13 23:01:31 UTC (rev 169955)
@@ -58,8 +58,6 @@
     bool aborted() const { return m_aborted; }
 
 private:
-    friend void delayedStartBlobResourceHandle(void*);
-
     BlobResourceHandle(BlobData*, const ResourceRequest&, ResourceHandleClient*, bool async);
     virtual ~BlobResourceHandle();
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to