Changeset 247103 in webkit


Ignore:
Timestamp:
Jul 3, 2019 2:01:50 PM (5 years ago)
Author:
commit-queue@webkit.org
Message:

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

Patch by Alex Christensen <achristensen@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.

Location:
trunk/Source/WebKit
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r247102 r247103  
     12019-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
    1202019-07-03  Sam Weinig  <weinig@apple.com>
    221
  • trunk/Source/WebKit/NetworkProcess/Downloads/Download.h

    r245901 r247103  
    3838#include <wtf/Noncopyable.h>
    3939#include <wtf/RetainPtr.h>
     40#include <wtf/WeakPtr.h>
    4041
    4142#if PLATFORM(COCOA)
     
    6566class WebPage;
    6667
    67 class Download : public IPC::MessageSender {
     68class Download : public IPC::MessageSender, public CanMakeWeakPtr<Download> {
    6869    WTF_MAKE_NONCOPYABLE(Download); WTF_MAKE_FAST_ALLOCATED;
    6970public:
  • trunk/Source/WebKit/NetworkProcess/Downloads/cocoa/DownloadCocoa.mm

    r246551 r247103  
    112112        return;
    113113
    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]);
    115115#if USE(NSPROGRESS_PUBLISHING_SPI)
    116116    [m_progress _publish];
  • trunk/Source/WebKit/NetworkProcess/Downloads/cocoa/WKDownloadProgress.h

    r242339 r247103  
    4040@interface WKDownloadProgress : NSProgress
    4141
    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;
    4343
    4444@end
  • trunk/Source/WebKit/NetworkProcess/Downloads/cocoa/WKDownloadProgress.mm

    r246568 r247103  
    4040@implementation WKDownloadProgress {
    4141    RetainPtr<NSURLSessionDownloadTask> m_task;
    42     WebKit::Download* m_download;
     42    WeakPtr<WebKit::Download> m_download;
    4343    RefPtr<WebKit::SandboxExtension> m_sandboxExtension;
    44     std::once_flag m_progressCancelOnce;
    4544}
    4645
     
    4948    if (m_download)
    5049        m_download->cancel();
     50    m_download = nullptr;
    5151}
    5252
    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
    6654{
    6755    if (!(self = [self initWithParent:nil userInfo:nil]))
     
    6957
    7058    m_task = task;
    71     m_download = download;
     59    m_download = makeWeakPtr(download);
    7260
    7361    [task addObserver:self forKeyPath:countOfBytesExpectedToReceiveKeyPath options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial context:WKDownloadProgressBytesExpectedToReceiveCountContext];
     
    8573
    8674    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];
    8983    }).get();
    9084
Note: See TracChangeset for help on using the changeset viewer.