Changeset 259610 in webkit
- Timestamp:
- Apr 6, 2020 4:25:58 PM (4 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r259606 r259610 1 2020-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 1 22 2020-04-06 Ross Kirsling <ross.kirsling@sony.com> 2 23 -
trunk/Source/WebKit/Platform/spi/ios/RunningBoardServicesSPI.h
r259414 r259610 43 43 @end 44 44 45 @interface RBSAssertion : NSObject46 - (instancetype)initWithExplanation:(NSString *)explanation target:(RBSTarget *)target attributes:(NSArray <RBSAttribute *> *)attributes;47 - (BOOL)acquireWithError:(NSError **)error;48 - (void)invalidate;49 @end50 51 45 @protocol RBSAssertionObserving <NSObject> 52 46 - (void)assertionWillInvalidate:(RBSAssertion *)assertion; … … 54 48 @end 55 49 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 56 58 #endif -
trunk/Source/WebKit/UIProcess/ProcessAssertion.h
r259579 r259610 37 37 #if PLATFORM(IOS_FAMILY) 38 38 #include <wtf/RetainPtr.h> 39 40 OBJC_CLASS RBSAssertion; 41 OBJC_CLASS WKRBSAssertionDelegate; 39 42 OBJC_CLASS BKSProcessAssertion; 40 #endif 43 #endif // PLATFORM(IOS_FAMILY) 41 44 42 45 namespace WebKit { … … 76 79 77 80 private: 81 const ProcessAssertionType m_assertionType; 78 82 #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. 80 87 Validity m_validity { Validity::Unset }; 81 88 #endif 82 const ProcessAssertionType m_assertionType;83 89 Client* m_client { nullptr }; 84 90 }; -
trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm
r259579 r259610 266 266 @end 267 267 268 typedef 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 268 290 namespace WebKit { 291 292 static 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 } 269 312 270 313 const BKSProcessAssertionFlags suspendedTabFlags = (BKSProcessAssertionAllowIdleSleep); … … 302 345 ProcessAssertion::ProcessAssertion(pid_t pid, ASCIILiteral reason, ProcessAssertionType assertionType) 303 346 : m_assertionType(assertionType) 347 , m_pid(pid) 304 348 { 305 349 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); 309 367 dispatch_async(dispatch_get_main_queue(), ^{ 310 368 if (weakThis) 311 369 processAssertionWasInvalidated(); 312 370 }); 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); 327 397 } 328 398 329 399 ProcessAssertion::~ProcessAssertion() 330 400 { 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 } 335 410 } 336 411 … … 338 413 { 339 414 ASSERT(RunLoop::isMain()); 340 RELEASE_LOG _ERROR(ProcessSuspension, "%p - ProcessAssertion::processAssertionWasInvalidated()", this);415 RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion::processAssertionWasInvalidated() PID: %d", this, m_pid); 341 416 342 417 m_validity = Validity::No;
Note: See TracChangeset
for help on using the changeset viewer.