Title: [247103] trunk/Source/WebKit
Revision
247103
Author
commit-qu...@webkit.org
Date
2019-07-03 14:01:50 -0700 (Wed, 03 Jul 2019)

Log Message

Use smarter pointers in WKDownloadProgress
https://bugs.webkit.org/show_bug.cgi?id=199456
<rdar://problem/51392926>

Patch by Alex Christensen <achristen...@webkit.org> on 2019-07-03
Reviewed by Chris Dumez.

There's still a problem related to our use of raw pointers.  Let's just not use raw pointers.

* NetworkProcess/Downloads/Download.h:
* NetworkProcess/Downloads/cocoa/DownloadCocoa.mm:
(WebKit::Download::publishProgress):
* NetworkProcess/Downloads/cocoa/WKDownloadProgress.h:
* NetworkProcess/Downloads/cocoa/WKDownloadProgress.mm:
(-[WKDownloadProgress performCancel]):
(-[WKDownloadProgress initWithDownloadTask:download:URL:sandboxExtension:]):
(-[WKDownloadProgress progressCancelled]): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (247102 => 247103)


--- trunk/Source/WebKit/ChangeLog	2019-07-03 20:46:41 UTC (rev 247102)
+++ trunk/Source/WebKit/ChangeLog	2019-07-03 21:01:50 UTC (rev 247103)
@@ -1,3 +1,22 @@
+2019-07-03  Alex Christensen  <achristen...@webkit.org>
+
+        Use smarter pointers in WKDownloadProgress
+        https://bugs.webkit.org/show_bug.cgi?id=199456
+        <rdar://problem/51392926>
+
+        Reviewed by Chris Dumez.
+
+        There's still a problem related to our use of raw pointers.  Let's just not use raw pointers.
+
+        * NetworkProcess/Downloads/Download.h:
+        * NetworkProcess/Downloads/cocoa/DownloadCocoa.mm:
+        (WebKit::Download::publishProgress):
+        * NetworkProcess/Downloads/cocoa/WKDownloadProgress.h:
+        * NetworkProcess/Downloads/cocoa/WKDownloadProgress.mm:
+        (-[WKDownloadProgress performCancel]):
+        (-[WKDownloadProgress initWithDownloadTask:download:URL:sandboxExtension:]):
+        (-[WKDownloadProgress progressCancelled]): Deleted.
+
 2019-07-03  Sam Weinig  <wei...@apple.com>
 
         Adopt simple structured bindings in more places

Modified: trunk/Source/WebKit/NetworkProcess/Downloads/Download.h (247102 => 247103)


--- trunk/Source/WebKit/NetworkProcess/Downloads/Download.h	2019-07-03 20:46:41 UTC (rev 247102)
+++ trunk/Source/WebKit/NetworkProcess/Downloads/Download.h	2019-07-03 21:01:50 UTC (rev 247103)
@@ -37,6 +37,7 @@
 #include <pal/SessionID.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/RetainPtr.h>
+#include <wtf/WeakPtr.h>
 
 #if PLATFORM(COCOA)
 OBJC_CLASS NSProgress;
@@ -64,7 +65,7 @@
 class NetworkSession;
 class WebPage;
 
-class Download : public IPC::MessageSender {
+class Download : public IPC::MessageSender, public CanMakeWeakPtr<Download> {
     WTF_MAKE_NONCOPYABLE(Download); WTF_MAKE_FAST_ALLOCATED;
 public:
     Download(DownloadManager&, DownloadID, NetworkDataTask&, const PAL::SessionID& sessionID, const String& suggestedFilename = { });

Modified: trunk/Source/WebKit/NetworkProcess/Downloads/cocoa/DownloadCocoa.mm (247102 => 247103)


--- trunk/Source/WebKit/NetworkProcess/Downloads/cocoa/DownloadCocoa.mm	2019-07-03 20:46:41 UTC (rev 247102)
+++ trunk/Source/WebKit/NetworkProcess/Downloads/cocoa/DownloadCocoa.mm	2019-07-03 21:01:50 UTC (rev 247103)
@@ -111,7 +111,7 @@
     if (!sandboxExtension)
         return;
 
-    m_progress = adoptNS([[WKDownloadProgress alloc] initWithDownloadTask:m_downloadTask.get() download:this URL:(NSURL *)url sandboxExtension:sandboxExtension]);
+    m_progress = adoptNS([[WKDownloadProgress alloc] initWithDownloadTask:m_downloadTask.get() download:*this URL:(NSURL *)url sandboxExtension:sandboxExtension]);
 #if USE(NSPROGRESS_PUBLISHING_SPI)
     [m_progress _publish];
 #else

Modified: trunk/Source/WebKit/NetworkProcess/Downloads/cocoa/WKDownloadProgress.h (247102 => 247103)


--- trunk/Source/WebKit/NetworkProcess/Downloads/cocoa/WKDownloadProgress.h	2019-07-03 20:46:41 UTC (rev 247102)
+++ trunk/Source/WebKit/NetworkProcess/Downloads/cocoa/WKDownloadProgress.h	2019-07-03 21:01:50 UTC (rev 247103)
@@ -39,7 +39,7 @@
 
 @interface WKDownloadProgress : NSProgress
 
-- (instancetype)initWithDownloadTask:(NSURLSessionDownloadTask *)task download:(WebKit::Download*)download URL:(NSURL *)fileURL sandboxExtension:(RefPtr<WebKit::SandboxExtension>)sandboxExtension;
+- (instancetype)initWithDownloadTask:(NSURLSessionDownloadTask *)task download:(WebKit::Download&)download URL:(NSURL *)fileURL sandboxExtension:(RefPtr<WebKit::SandboxExtension>)sandboxExtension;
 
 @end
 

Modified: trunk/Source/WebKit/NetworkProcess/Downloads/cocoa/WKDownloadProgress.mm (247102 => 247103)


--- trunk/Source/WebKit/NetworkProcess/Downloads/cocoa/WKDownloadProgress.mm	2019-07-03 20:46:41 UTC (rev 247102)
+++ trunk/Source/WebKit/NetworkProcess/Downloads/cocoa/WKDownloadProgress.mm	2019-07-03 21:01:50 UTC (rev 247103)
@@ -39,9 +39,8 @@
 
 @implementation WKDownloadProgress {
     RetainPtr<NSURLSessionDownloadTask> m_task;
-    WebKit::Download* m_download;
+    WeakPtr<WebKit::Download> m_download;
     RefPtr<WebKit::SandboxExtension> m_sandboxExtension;
-    std::once_flag m_progressCancelOnce;
 }
 
 - (void)performCancel
@@ -48,27 +47,16 @@
 {
     if (m_download)
         m_download->cancel();
+    m_download = nullptr;
 }
 
-- (void)progressCancelled
+- (instancetype)initWithDownloadTask:(NSURLSessionDownloadTask *)task download:(WebKit::Download&)download URL:(NSURL *)fileURL sandboxExtension:(RefPtr<WebKit::SandboxExtension>)sandboxExtension
 {
-    std::call_once(m_progressCancelOnce, [self] {
-        if (!isMainThread()) {
-            [self performSelectorOnMainThread:@selector(performCancel) withObject:nil waitUntilDone:NO];
-            return;
-        }
-
-        [self performCancel];
-    });
-}
-
-- (instancetype)initWithDownloadTask:(NSURLSessionDownloadTask *)task download:(WebKit::Download*)download URL:(NSURL *)fileURL sandboxExtension:(RefPtr<WebKit::SandboxExtension>)sandboxExtension
-{
     if (!(self = [self initWithParent:nil userInfo:nil]))
         return nil;
 
     m_task = task;
-    m_download = download;
+    m_download = makeWeakPtr(download);
 
     [task addObserver:self forKeyPath:countOfBytesExpectedToReceiveKeyPath options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial context:WKDownloadProgressBytesExpectedToReceiveCountContext];
     [task addObserver:self forKeyPath:countOfBytesReceivedKeyPath options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial context:WKDownloadProgressBytesReceivedContext];
@@ -84,8 +72,14 @@
     m_sandboxExtension = sandboxExtension;
 
     self.cancellable = YES;
-    self.cancellationHandler = makeBlockPtr([weakSelf = WeakObjCPtr<WKDownloadProgress> { self }] {
-        [weakSelf.get() progressCancelled];
+    self.cancellationHandler = makeBlockPtr([weakSelf = WeakObjCPtr<WKDownloadProgress> { self }] () mutable {
+        if (!RunLoop::isMain()) {
+            RunLoop::main().dispatch([weakSelf = WTFMove(weakSelf)] {
+                [weakSelf performCancel];
+            });
+            return;
+        }
+        [weakSelf performCancel];
     }).get();
 
     return self;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to