Changeset 247103 in webkit
- Timestamp:
- Jul 3, 2019 2:01:50 PM (5 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r247102 r247103 1 2019-07-03 Alex Christensen <achristensen@webkit.org> 2 3 Use smarter pointers in WKDownloadProgress 4 https://bugs.webkit.org/show_bug.cgi?id=199456 5 <rdar://problem/51392926> 6 7 Reviewed by Chris Dumez. 8 9 There's still a problem related to our use of raw pointers. Let's just not use raw pointers. 10 11 * NetworkProcess/Downloads/Download.h: 12 * NetworkProcess/Downloads/cocoa/DownloadCocoa.mm: 13 (WebKit::Download::publishProgress): 14 * NetworkProcess/Downloads/cocoa/WKDownloadProgress.h: 15 * NetworkProcess/Downloads/cocoa/WKDownloadProgress.mm: 16 (-[WKDownloadProgress performCancel]): 17 (-[WKDownloadProgress initWithDownloadTask:download:URL:sandboxExtension:]): 18 (-[WKDownloadProgress progressCancelled]): Deleted. 19 1 20 2019-07-03 Sam Weinig <weinig@apple.com> 2 21 -
trunk/Source/WebKit/NetworkProcess/Downloads/Download.h
r245901 r247103 38 38 #include <wtf/Noncopyable.h> 39 39 #include <wtf/RetainPtr.h> 40 #include <wtf/WeakPtr.h> 40 41 41 42 #if PLATFORM(COCOA) … … 65 66 class WebPage; 66 67 67 class Download : public IPC::MessageSender {68 class Download : public IPC::MessageSender, public CanMakeWeakPtr<Download> { 68 69 WTF_MAKE_NONCOPYABLE(Download); WTF_MAKE_FAST_ALLOCATED; 69 70 public: -
trunk/Source/WebKit/NetworkProcess/Downloads/cocoa/DownloadCocoa.mm
r246551 r247103 112 112 return; 113 113 114 m_progress = adoptNS([[WKDownloadProgress alloc] initWithDownloadTask:m_downloadTask.get() download: this URL:(NSURL *)url sandboxExtension:sandboxExtension]);114 m_progress = adoptNS([[WKDownloadProgress alloc] initWithDownloadTask:m_downloadTask.get() download:*this URL:(NSURL *)url sandboxExtension:sandboxExtension]); 115 115 #if USE(NSPROGRESS_PUBLISHING_SPI) 116 116 [m_progress _publish]; -
trunk/Source/WebKit/NetworkProcess/Downloads/cocoa/WKDownloadProgress.h
r242339 r247103 40 40 @interface WKDownloadProgress : NSProgress 41 41 42 - (instancetype)initWithDownloadTask:(NSURLSessionDownloadTask *)task download:(WebKit::Download *)download URL:(NSURL *)fileURL sandboxExtension:(RefPtr<WebKit::SandboxExtension>)sandboxExtension;42 - (instancetype)initWithDownloadTask:(NSURLSessionDownloadTask *)task download:(WebKit::Download&)download URL:(NSURL *)fileURL sandboxExtension:(RefPtr<WebKit::SandboxExtension>)sandboxExtension; 43 43 44 44 @end -
trunk/Source/WebKit/NetworkProcess/Downloads/cocoa/WKDownloadProgress.mm
r246568 r247103 40 40 @implementation WKDownloadProgress { 41 41 RetainPtr<NSURLSessionDownloadTask> m_task; 42 We bKit::Download*m_download;42 WeakPtr<WebKit::Download> m_download; 43 43 RefPtr<WebKit::SandboxExtension> m_sandboxExtension; 44 std::once_flag m_progressCancelOnce;45 44 } 46 45 … … 49 48 if (m_download) 50 49 m_download->cancel(); 50 m_download = nullptr; 51 51 } 52 52 53 - (void)progressCancelled 54 { 55 std::call_once(m_progressCancelOnce, [self] { 56 if (!isMainThread()) { 57 [self performSelectorOnMainThread:@selector(performCancel) withObject:nil waitUntilDone:NO]; 58 return; 59 } 60 61 [self performCancel]; 62 }); 63 } 64 65 - (instancetype)initWithDownloadTask:(NSURLSessionDownloadTask *)task download:(WebKit::Download*)download URL:(NSURL *)fileURL sandboxExtension:(RefPtr<WebKit::SandboxExtension>)sandboxExtension 53 - (instancetype)initWithDownloadTask:(NSURLSessionDownloadTask *)task download:(WebKit::Download&)download URL:(NSURL *)fileURL sandboxExtension:(RefPtr<WebKit::SandboxExtension>)sandboxExtension 66 54 { 67 55 if (!(self = [self initWithParent:nil userInfo:nil])) … … 69 57 70 58 m_task = task; 71 m_download = download;59 m_download = makeWeakPtr(download); 72 60 73 61 [task addObserver:self forKeyPath:countOfBytesExpectedToReceiveKeyPath options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial context:WKDownloadProgressBytesExpectedToReceiveCountContext]; … … 85 73 86 74 self.cancellable = YES; 87 self.cancellationHandler = makeBlockPtr([weakSelf = WeakObjCPtr<WKDownloadProgress> { self }] { 88 [weakSelf.get() progressCancelled]; 75 self.cancellationHandler = makeBlockPtr([weakSelf = WeakObjCPtr<WKDownloadProgress> { self }] () mutable { 76 if (!RunLoop::isMain()) { 77 RunLoop::main().dispatch([weakSelf = WTFMove(weakSelf)] { 78 [weakSelf performCancel]; 79 }); 80 return; 81 } 82 [weakSelf performCancel]; 89 83 }).get(); 90 84
Note: See TracChangeset
for help on using the changeset viewer.