Changeset 260574 in webkit


Ignore:
Timestamp:
Apr 23, 2020 9:27:03 AM (4 years ago)
Author:
Chris Dumez
Message:

[iOS] Port MediaPlayback process assertion to RunningBoard
https://bugs.webkit.org/show_bug.cgi?id=210212
<rdar://problem/61476951>

Reviewed by Geoff Garen.

Port MediaPlayback process assertion to RunningBoard instead of the legacy BKSProcessAssertion.
We can now #ifdef out the legacy BKSProcessAssertion on recent iOS builds.

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

(WebKit::runningBoardNameForAssertionType):
(WebKit::ProcessAssertion::ProcessAssertion):
(WebKit::ProcessAssertion::~ProcessAssertion):

Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r260570 r260574  
     12020-04-23  Chris Dumez  <cdumez@apple.com>
     2
     3        [iOS] Port MediaPlayback process assertion to RunningBoard
     4        https://bugs.webkit.org/show_bug.cgi?id=210212
     5        <rdar://problem/61476951>
     6
     7        Reviewed by Geoff Garen.
     8
     9        Port MediaPlayback process assertion to RunningBoard instead of the legacy BKSProcessAssertion.
     10        We can now #ifdef out the legacy BKSProcessAssertion on recent iOS builds.
     11
     12        * UIProcess/ProcessAssertion.h:
     13        * UIProcess/ios/ProcessAssertionIOS.mm:
     14        (WebKit::runningBoardNameForAssertionType):
     15        (WebKit::ProcessAssertion::ProcessAssertion):
     16        (WebKit::ProcessAssertion::~ProcessAssertion):
     17
    1182020-04-23  John Frankish  <john.frankish@outlook.com>
    219
  • trunk/Source/WebKit/UIProcess/ProcessAssertion.h

    r260453 r260574  
    4040OBJC_CLASS RBSAssertion;
    4141OBJC_CLASS WKRBSAssertionDelegate;
     42#if !HAVE(RUNNINGBOARD_VISIBILITY_ASSERTIONS)
    4243OBJC_CLASS BKSProcessAssertion;
     44#endif
    4345#endif // PLATFORM(IOS_FAMILY)
    4446
     
    8688    RetainPtr<RBSAssertion> m_rbsAssertion;
    8789    RetainPtr<WKRBSAssertionDelegate> m_delegate;
     90#if !HAVE(RUNNINGBOARD_VISIBILITY_ASSERTIONS)
    8891    RetainPtr<BKSProcessAssertion> m_bksAssertion; // Legacy.
     92#endif
    8993    Validity m_validity { Validity::Unset };
    9094#endif
  • trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm

    r260569 r260574  
    2929#if PLATFORM(IOS_FAMILY)
    3030
    31 #import "AssertionServicesSPI.h"
    3231#import "Logging.h"
    3332#import "RunningBoardServicesSPI.h"
     
    3837#import <wtf/Vector.h>
    3938#import <wtf/WeakHashSet.h>
     39
     40#if !HAVE(RUNNINGBOARD_VISIBILITY_ASSERTIONS)
     41#import "AssertionServicesSPI.h"
     42#endif
    4043
    4144using WebKit::ProcessAndUIAssertion;
     
    314317        return @"DependentProcessLink";
    315318    case ProcessAssertionType::MediaPlayback:
    316         return nil; // FIXME: Name to be defined in <rdar://problem/61263147>.
     319        return @"MediaPlayback";
    317320    }
    318321#else
     
    322325#endif
    323326}
     327
     328#if !HAVE(RUNNINGBOARD_VISIBILITY_ASSERTIONS)
    324329
    325330const BKSProcessAssertionFlags suspendedTabFlags = (BKSProcessAssertionAllowIdleSleep);
     
    361366}
    362367
     368#endif // !HAVE(RUNNINGBOARD_VISIBILITY_ASSERTIONS)
     369
    363370ProcessAssertion::ProcessAssertion(pid_t pid, const String& reason, ProcessAssertionType assertionType)
    364371    : m_assertionType(assertionType)
     
    367374    auto weakThis = makeWeakPtr(*this);
    368375    NSString *runningBoardAssertionName = runningBoardNameForAssertionType(assertionType);
    369     if (runningBoardAssertionName) {
    370         if (!pid) {
    371             RELEASE_LOG_ERROR(ProcessSuspension, "%p - ProcessAssertion: Failed to acquire RBS %{public}@ assertion '%{public}s' for process because PID is invalid", this, runningBoardAssertionName, reason.utf8().data());
    372             return;
    373         }
    374 
    375         RBSTarget *target = [RBSTarget targetWithPid:pid];
    376         RBSDomainAttribute *domainAttribute = [RBSDomainAttribute attributeWithDomain:@"com.apple.webkit" name:runningBoardAssertionName];
    377         m_rbsAssertion = adoptNS([[RBSAssertion alloc] initWithExplanation:reason target:target attributes:@[domainAttribute]]);
    378 
    379         m_delegate = adoptNS([[WKRBSAssertionDelegate alloc] init]);
    380         [m_rbsAssertion addObserver:m_delegate.get()];
    381         m_delegate.get().invalidationCallback = ^{
    382             RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() RBS %{public}@ assertion for process with PID %d was invalidated", this, runningBoardAssertionName, pid);
    383             processAssertionWasInvalidated();
    384         };
    385 
    386         NSError *acquisitionError = nil;
    387         if (![m_rbsAssertion acquireWithError:&acquisitionError]) {
    388             RELEASE_LOG_ERROR(ProcessSuspension, "%p - ProcessAssertion: Failed to acquire RBS %{public}@ assertion '%{public}s' for process with PID %d, error: %{public}@", this, runningBoardAssertionName, reason.utf8().data(), pid, acquisitionError);
    389             dispatch_async(dispatch_get_main_queue(), ^{
    390                 if (weakThis)
    391                     processAssertionWasInvalidated();
    392             });
    393         } else
    394             RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion: Successfully took RBS %{public}@ assertion '%{public}s' for process with PID %d", this, runningBoardAssertionName, reason.utf8().data(), pid);
    395     } else {
     376
     377#if !HAVE(RUNNINGBOARD_VISIBILITY_ASSERTIONS)
     378    if (!runningBoardAssertionName) {
    396379        // Legacy code path.
    397380        BKSProcessAssertionAcquisitionHandler handler = ^(BOOL acquired) {
     
    415398            });
    416399        };
    417     }
     400        return;
     401    }
     402#endif // !HAVE(RUNNINGBOARD_VISIBILITY_ASSERTIONS)
     403
     404    ASSERT(runningBoardAssertionName);
     405    if (!pid) {
     406        RELEASE_LOG_ERROR(ProcessSuspension, "%p - ProcessAssertion: Failed to acquire RBS %{public}@ assertion '%{public}s' for process because PID is invalid", this, runningBoardAssertionName, reason.utf8().data());
     407        return;
     408    }
     409
     410    RBSTarget *target = [RBSTarget targetWithPid:pid];
     411    RBSDomainAttribute *domainAttribute = [RBSDomainAttribute attributeWithDomain:@"com.apple.webkit" name:runningBoardAssertionName];
     412    m_rbsAssertion = adoptNS([[RBSAssertion alloc] initWithExplanation:reason target:target attributes:@[domainAttribute]]);
     413
     414    m_delegate = adoptNS([[WKRBSAssertionDelegate alloc] init]);
     415    [m_rbsAssertion addObserver:m_delegate.get()];
     416    m_delegate.get().invalidationCallback = ^{
     417        RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() RBS %{public}@ assertion for process with PID %d was invalidated", this, runningBoardAssertionName, pid);
     418        processAssertionWasInvalidated();
     419    };
     420
     421    NSError *acquisitionError = nil;
     422    if (![m_rbsAssertion acquireWithError:&acquisitionError]) {
     423        RELEASE_LOG_ERROR(ProcessSuspension, "%p - ProcessAssertion: Failed to acquire RBS %{public}@ assertion '%{public}s' for process with PID %d, error: %{public}@", this, runningBoardAssertionName, reason.utf8().data(), pid, acquisitionError);
     424        dispatch_async(dispatch_get_main_queue(), ^{
     425            if (weakThis)
     426                processAssertionWasInvalidated();
     427        });
     428    } else
     429        RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion: Successfully took RBS %{public}@ assertion '%{public}s' for process with PID %d", this, runningBoardAssertionName, reason.utf8().data(), pid);
    418430}
    419431
     
    428440        [m_rbsAssertion removeObserver:m_delegate.get()];
    429441        [m_rbsAssertion invalidate];
    430     } else {
     442    }
     443
     444#if !HAVE(RUNNINGBOARD_VISIBILITY_ASSERTIONS)
     445    if (m_bksAssertion) {
    431446        m_bksAssertion.get().invalidationHandler = nil;
    432447        [m_bksAssertion invalidate];
    433448    }
     449#endif
    434450}
    435451
Note: See TracChangeset for help on using the changeset viewer.