Changeset 259610 in webkit


Ignore:
Timestamp:
Apr 6, 2020 4:25:58 PM (4 years ago)
Author:
Chris Dumez
Message:

[iOS] Transition most process assertions to RunningBoard
https://bugs.webkit.org/show_bug.cgi?id=210065
<rdar://problem/61354901>

Reviewed by Geoffrey Garen.

Transition most process assertions to RunningBoard, instead of legacy BKSProcessAssertion.
The only assertion that still uses BKSProcessAssertion is the MediaPlayback once because
we do not have a RunningBoard equivalent for this one yet (see <rdar://problem/61263147>).

  • UIProcess/ProcessAssertion.h:
  • UIProcess/ios/ProcessAssertionIOS.mm:

(-[WKRBSAssertionDelegate assertionWillInvalidate:]):
(-[WKRBSAssertionDelegate assertion:didInvalidateWithError:]):
(WebKit::runningBoardNameForAssertionType):
(WebKit::ProcessAssertion::ProcessAssertion):
(WebKit::ProcessAssertion::~ProcessAssertion):
(WebKit::ProcessAssertion::processAssertionWasInvalidated):

Location:
trunk/Source/WebKit
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r259606 r259610  
     12020-04-06  Chris Dumez  <cdumez@apple.com>
     2
     3        [iOS] Transition most process assertions to RunningBoard
     4        https://bugs.webkit.org/show_bug.cgi?id=210065
     5        <rdar://problem/61354901>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Transition most process assertions to RunningBoard, instead of legacy BKSProcessAssertion.
     10        The only assertion that still uses BKSProcessAssertion is the MediaPlayback once because
     11        we do not have a RunningBoard equivalent for this one yet (see <rdar://problem/61263147>).
     12
     13        * UIProcess/ProcessAssertion.h:
     14        * UIProcess/ios/ProcessAssertionIOS.mm:
     15        (-[WKRBSAssertionDelegate assertionWillInvalidate:]):
     16        (-[WKRBSAssertionDelegate assertion:didInvalidateWithError:]):
     17        (WebKit::runningBoardNameForAssertionType):
     18        (WebKit::ProcessAssertion::ProcessAssertion):
     19        (WebKit::ProcessAssertion::~ProcessAssertion):
     20        (WebKit::ProcessAssertion::processAssertionWasInvalidated):
     21
    1222020-04-06  Ross Kirsling  <ross.kirsling@sony.com>
    223
  • trunk/Source/WebKit/Platform/spi/ios/RunningBoardServicesSPI.h

    r259414 r259610  
    4343@end
    4444
    45 @interface RBSAssertion : NSObject
    46 - (instancetype)initWithExplanation:(NSString *)explanation target:(RBSTarget *)target attributes:(NSArray <RBSAttribute *> *)attributes;
    47 - (BOOL)acquireWithError:(NSError **)error;
    48 - (void)invalidate;
    49 @end
    50 
    5145@protocol RBSAssertionObserving <NSObject>
    5246- (void)assertionWillInvalidate:(RBSAssertion *)assertion;
     
    5448@end
    5549
     50@interface RBSAssertion : NSObject
     51- (instancetype)initWithExplanation:(NSString *)explanation target:(RBSTarget *)target attributes:(NSArray <RBSAttribute *> *)attributes;
     52- (BOOL)acquireWithError:(NSError **)error;
     53- (void)invalidate;
     54- (void)addObserver:(id <RBSAssertionObserving>)observer;
     55- (void)removeObserver:(id <RBSAssertionObserving>)observer;
     56@end
     57
    5658#endif
  • trunk/Source/WebKit/UIProcess/ProcessAssertion.h

    r259579 r259610  
    3737#if PLATFORM(IOS_FAMILY)
    3838#include <wtf/RetainPtr.h>
     39
     40OBJC_CLASS RBSAssertion;
     41OBJC_CLASS WKRBSAssertionDelegate;
    3942OBJC_CLASS BKSProcessAssertion;
    40 #endif
     43#endif // PLATFORM(IOS_FAMILY)
    4144
    4245namespace WebKit {
     
    7679
    7780private:
     81    const ProcessAssertionType m_assertionType;
    7882#if PLATFORM(IOS_FAMILY)
    79     RetainPtr<BKSProcessAssertion> m_assertion;
     83    const ProcessID m_pid;
     84    RetainPtr<RBSAssertion> m_rbsAssertion;
     85    RetainPtr<WKRBSAssertionDelegate> m_delegate;
     86    RetainPtr<BKSProcessAssertion> m_bksAssertion; // Legacy.
    8087    Validity m_validity { Validity::Unset };
    8188#endif
    82     const ProcessAssertionType m_assertionType;
    8389    Client* m_client { nullptr };
    8490};
  • trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm

    r259579 r259610  
    266266@end
    267267
     268typedef void(^RBSAssertionInvalidationCallbackType)();
     269
     270@interface WKRBSAssertionDelegate : NSObject<RBSAssertionObserving>
     271@property (copy) RBSAssertionInvalidationCallbackType invalidationCallback;
     272@end
     273
     274@implementation WKRBSAssertionDelegate
     275- (void)assertionWillInvalidate:(RBSAssertion *)assertion
     276{
     277    RELEASE_LOG(ProcessSuspension, "%p - WKRBSAssertionDelegate: assertionWillInvalidate", self);
     278}
     279
     280- (void)assertion:(RBSAssertion *)assertion didInvalidateWithError:(NSError *)error
     281{
     282    RELEASE_LOG(ProcessSuspension, "%p - WKRBSAssertionDelegate: assertion was invalidated, error: %{public}@", error, self);
     283    dispatch_async(dispatch_get_main_queue(), ^{
     284        if (_invalidationCallback)
     285            _invalidationCallback();
     286    });
     287}
     288@end
     289
    268290namespace WebKit {
     291
     292static NSString *runningBoardNameForAssertionType(ProcessAssertionType assertionType)
     293{
     294#if HAVE(RUNNINGBOARD_WEBKIT_ASSERTIONS)
     295    switch (assertionType) {
     296    case ProcessAssertionType::Suspended:
     297        return @"Suspended";
     298    case ProcessAssertionType::Background:
     299        return @"Background";
     300    case ProcessAssertionType::UnboundedNetworking:
     301        return @"UnboundedNetworking";
     302    case ProcessAssertionType::Foreground:
     303        return @"Foreground";
     304    case ProcessAssertionType::MediaPlayback:
     305        return nil; // FIXME: Name to be defined in <rdar://problem/61263147>.
     306    }
     307#else
     308    UNUSED_PARAM(assertionType);
     309    return nil;
     310#endif
     311}
    269312
    270313const BKSProcessAssertionFlags suspendedTabFlags = (BKSProcessAssertionAllowIdleSleep);
     
    302345ProcessAssertion::ProcessAssertion(pid_t pid, ASCIILiteral reason, ProcessAssertionType assertionType)
    303346    : m_assertionType(assertionType)
     347    , m_pid(pid)
    304348{
    305349    auto weakThis = makeWeakPtr(*this);
    306     BKSProcessAssertionAcquisitionHandler handler = ^(BOOL acquired) {
    307         if (!acquired) {
    308             RELEASE_LOG_ERROR(ProcessSuspension, " %p - ProcessAssertion() PID %d Unable to acquire assertion for process with PID %d", this, getpid(), pid);
     350    NSString *nsReason = [NSString stringWithCString:reason.characters() encoding:NSASCIIStringEncoding];
     351    NSString *runningBoardAssertionName = runningBoardNameForAssertionType(assertionType);
     352    if (runningBoardAssertionName) {
     353        RBSTarget *target = [RBSTarget targetWithPid:pid];
     354        RBSDomainAttribute *domainAttribute = [RBSDomainAttribute attributeWithDomain:@"com.apple.webkit" name:runningBoardAssertionName];
     355        m_rbsAssertion = adoptNS([[RBSAssertion alloc] initWithExplanation:nsReason target:target attributes:@[domainAttribute]]);
     356
     357        m_delegate = adoptNS([[WKRBSAssertionDelegate alloc] init]);
     358        [m_rbsAssertion addObserver:m_delegate.get()];
     359        m_delegate.get().invalidationCallback = ^{
     360            RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() RBS %{public}@ assertion for process with PID %d was invalidated", this, runningBoardAssertionName, pid);
     361            processAssertionWasInvalidated();
     362        };
     363
     364        NSError *acquisitionError = nil;
     365        if (![m_rbsAssertion acquireWithError:&acquisitionError]) {
     366            RELEASE_LOG_ERROR(ProcessSuspension, "%p - ProcessAssertion: Failed to acquire RBS %{public}@ assertion '%{public}s' for process with PID %d, error: %{public}@", this, runningBoardAssertionName, reason.characters(), pid, acquisitionError);
    309367            dispatch_async(dispatch_get_main_queue(), ^{
    310368                if (weakThis)
    311369                    processAssertionWasInvalidated();
    312370            });
    313         }
    314     };
    315     RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() PID %d acquiring assertion for process with PID %d, name '%s'", this, getpid(), pid, reason.characters());
    316    
    317     NSString *nsReason = [NSString stringWithCString:reason.characters() encoding:NSASCIIStringEncoding];
    318     m_assertion = adoptNS([[BKSProcessAssertion alloc] initWithPID:pid flags:flagsForAssertionType(assertionType) reason:toBKSProcessAssertionReason(assertionType) name:nsReason withHandler:handler]);
    319 
    320     m_assertion.get().invalidationHandler = ^() {
    321         dispatch_async(dispatch_get_main_queue(), ^{
    322             RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() Process assertion for process with PID %d was invalidated", this, pid);
    323             if (weakThis)
    324                 processAssertionWasInvalidated();
    325         });
    326     };
     371        } else
     372            RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion: Successfully took RBS %{public}@ assertion '%{public}s' for process with PID %d", this, runningBoardAssertionName, reason.characters(), pid);
     373    } else {
     374        // Legacy code path.
     375        BKSProcessAssertionAcquisitionHandler handler = ^(BOOL acquired) {
     376            if (!acquired) {
     377                RELEASE_LOG_ERROR(ProcessSuspension, " %p - ProcessAssertion() PID %d Unable to acquire BKS assertion for process with PID %d", this, getpid(), pid);
     378                dispatch_async(dispatch_get_main_queue(), ^{
     379                    if (weakThis)
     380                        processAssertionWasInvalidated();
     381                });
     382            }
     383        };
     384        RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() PID %d acquiring BKS assertion for process with PID %d, name '%s'", this, getpid(), pid, reason.characters());
     385
     386        m_bksAssertion = adoptNS([[BKSProcessAssertion alloc] initWithPID:pid flags:flagsForAssertionType(assertionType) reason:toBKSProcessAssertionReason(assertionType) name:nsReason withHandler:handler]);
     387
     388        m_bksAssertion.get().invalidationHandler = ^() {
     389            dispatch_async(dispatch_get_main_queue(), ^{
     390                RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() BKS Process assertion for process with PID %d was invalidated", this, pid);
     391                if (weakThis)
     392                    processAssertionWasInvalidated();
     393            });
     394        };
     395    }
     396    ASSERT(m_rbsAssertion || m_bksAssertion);
    327397}
    328398
    329399ProcessAssertion::~ProcessAssertion()
    330400{
    331     m_assertion.get().invalidationHandler = nil;
    332 
    333     RELEASE_LOG(ProcessSuspension, "%p - ~ProcessAssertion() Releasing process assertion", this);
    334     [m_assertion invalidate];
     401    RELEASE_LOG(ProcessSuspension, "%p - ~ProcessAssertion() Releasing process assertion for process with PID %d", this, m_pid);
     402
     403    if (m_rbsAssertion) {
     404        [m_rbsAssertion removeObserver:m_delegate.get()];
     405        [m_rbsAssertion invalidate];
     406    } else {
     407        m_bksAssertion.get().invalidationHandler = nil;
     408        [m_bksAssertion invalidate];
     409    }
    335410}
    336411
     
    338413{
    339414    ASSERT(RunLoop::isMain());
    340     RELEASE_LOG_ERROR(ProcessSuspension, "%p - ProcessAssertion::processAssertionWasInvalidated()", this);
     415    RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion::processAssertionWasInvalidated() PID: %d", this, m_pid);
    341416
    342417    m_validity = Validity::No;
Note: See TracChangeset for help on using the changeset viewer.