Changeset 279601 in webkit
- Timestamp:
- Jul 6, 2021, 12:01:27 PM (4 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r279600 r279601 1 2021-07-06 Chris Dumez <cdumez@apple.com> 2 3 [iOS] Have ProcessAssertion take the RunningBoard assertion asynchronously by default 4 https://bugs.webkit.org/show_bug.cgi?id=225324 5 <rdar://76972252> 6 7 Reviewed by Geoffrey Garen. 8 9 Have ProcessAssertion take the RunningBoard assertion asynchronously (on a background thread) by 10 default as we have evidence that doing so on the main thread is bad for performance and may 11 negatively impact launch time. 12 13 When constructing a ProcessAssertion, the caller can now indicate if it wants the assertion to be 14 taken asynchronously (default) or not. Bug 227552 is an example of a case where we still want to 15 take the assertion synchronously (because we're not on the main thread and we need to make sure 16 we have the assertion before proceeding). 17 18 The caller can also provide a completion handler that will get called once the RunningBoard is 19 taken. Note that the RunningBoard async API ([RBSAssertion acquireWithInvalidationHandler]) does 20 not provide a way for us to know when the assertion is taken. For this reason, ProcessAssertion 21 keeps using the RunningBoard sync API ([RBSAssertion acquireWithError:]) but calls in on a 22 background queue. 23 24 For the UIProcess's background task though, we don't need to know when the assertion is taken 25 so we can use the RunningBoard async API. 26 27 Note that the previous iteration of this patch had a bug where the ProcessThrottler would release 28 its previous assertion before the new one is taken (asynchronously) when changing the assertion 29 type (e.g. foreground to background). This is addressed in this patch. ProcessThrottler now passes 30 an acquisition handler when constructing the ProcessAssertion and only releases its previous 31 assertion once the acquisition handler for the new one is taken. 32 33 * NetworkProcess/Downloads/DownloadMap.cpp: 34 (WebKit::DownloadMap::add): 35 * NetworkProcess/Downloads/DownloadMap.h: 36 * Platform/IPC/cocoa/ConnectionCocoa.mm: 37 (IPC::ConnectionTerminationWatchdog::ConnectionTerminationWatchdog): 38 * UIProcess/Downloads/DownloadProxyMap.cpp: 39 (WebKit::DownloadProxyMap::createDownloadProxy): 40 * UIProcess/Downloads/DownloadProxyMap.h: 41 * UIProcess/Network/NetworkProcessProxy.cpp: 42 (WebKit::NetworkProcessProxy::setWebProcessHasUploads): 43 * UIProcess/Network/NetworkProcessProxy.h: 44 * UIProcess/ProcessAssertion.cpp: 45 (WebKit::ProcessAssertion::ProcessAssertion): 46 * UIProcess/ProcessAssertion.h: 47 (WebKit::ProcessAssertion::create): 48 * UIProcess/ProcessThrottler.cpp: 49 (WebKit::ProcessThrottler::setAssertionType): 50 * UIProcess/ProcessThrottler.h: 51 * UIProcess/WebProcessPool.cpp: 52 (WebKit::WebProcessPool::updateAudibleMediaAssertions): 53 * UIProcess/WebProcessPool.h: 54 * UIProcess/WebProcessProxy.cpp: 55 (WebKit::WebProcessProxy::updateAudibleMediaAssertions): 56 * UIProcess/WebProcessProxy.h: 57 * UIProcess/ios/ProcessAssertionIOS.mm: 58 (assertionsWorkQueue): 59 (-[WKProcessAssertionBackgroundTaskManager _updateBackgroundTask]): 60 (-[WKProcessAssertionBackgroundTaskManager assertion:didInvalidateWithError:]): 61 (WebKit::ProcessAssertion::ProcessAssertion): 62 (WebKit::ProcessAssertion::acquireAsync): 63 (WebKit::ProcessAssertion::acquireSync): 64 (WebKit::ProcessAssertion::~ProcessAssertion): 65 (WebKit::ProcessAssertion::processAssertionWasInvalidated): 66 (WebKit::ProcessAssertion::isValid const): 67 1 68 2021-07-06 Sihui Liu <sihui_liu@apple.com> 2 69 -
trunk/Source/WebKit/NetworkProcess/Downloads/DownloadMap.cpp
r268017 r279601 62 62 if (m_downloads.size() == 1) { 63 63 ASSERT(!m_downloadAssertion); 64 m_downloadAssertion = makeUnique<ProcessAssertion>(getpid(), "WebKit downloads"_s, ProcessAssertionType::UnboundedNetworking);64 m_downloadAssertion = ProcessAssertion::create(getpid(), "WebKit downloads"_s, ProcessAssertionType::UnboundedNetworking); 65 65 RELEASE_LOG(ProcessSuspension, "Took 'WebKit downloads' assertion in NetworkProcess"); 66 66 } -
trunk/Source/WebKit/NetworkProcess/Downloads/DownloadMap.h
r243110 r279601 54 54 private: 55 55 DownloadMapType m_downloads; 56 std::unique_ptr<ProcessAssertion> m_downloadAssertion;56 RefPtr<ProcessAssertion> m_downloadAssertion; 57 57 }; 58 58 -
trunk/Source/WebKit/NetworkProcess/NetworkProcess.h
r279514 r279601 578 578 #if PLATFORM(IOS_FAMILY) 579 579 WebSQLiteDatabaseTracker m_webSQLiteDatabaseTracker; 580 std::unique_ptr<ProcessAssertion> m_holdingLockedFileAssertion;580 RefPtr<ProcessAssertion> m_holdingLockedFileAssertion; 581 581 #endif 582 582 -
trunk/Source/WebKit/NetworkProcess/ios/NetworkProcessIOS.mm
r279526 r279601 113 113 // We synchronously take a process assertion when beginning a SQLite transaction so that we don't get suspended 114 114 // while holding a locked file. We would get killed if suspended while holding locked files. 115 m_holdingLockedFileAssertion = makeUnique<ProcessAssertion>(getCurrentProcessID(), "Network Process is holding locked files"_s, ProcessAssertionType::FinishTaskUninterruptable);115 m_holdingLockedFileAssertion = ProcessAssertion::create(getCurrentProcessID(), "Network Process is holding locked files"_s, ProcessAssertionType::FinishTaskUninterruptable, ProcessAssertion::Mode::Sync); 116 116 } 117 117 -
trunk/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm
r278338 r279601 90 90 , m_watchdogTimer(RunLoop::main(), this, &ConnectionTerminationWatchdog::watchdogTimerFired) 91 91 #if PLATFORM(IOS_FAMILY) 92 , m_assertion( makeUnique<WebKit::ProcessAndUIAssertion>(xpc_connection_get_pid(m_xpcConnection.get()), "ConnectionTerminationWatchdog"_s, WebKit::ProcessAssertionType::Background))92 , m_assertion(WebKit::ProcessAndUIAssertion::create(xpc_connection_get_pid(m_xpcConnection.get()), "ConnectionTerminationWatchdog"_s, WebKit::ProcessAssertionType::Background)) 93 93 #endif 94 94 { … … 105 105 RunLoop::Timer<ConnectionTerminationWatchdog> m_watchdogTimer; 106 106 #if PLATFORM(IOS_FAMILY) 107 std::unique_ptr<WebKit::ProcessAndUIAssertion> m_assertion;107 Ref<WebKit::ProcessAndUIAssertion> m_assertion; 108 108 #endif 109 109 }; -
trunk/Source/WebKit/Platform/spi/ios/RunningBoardServicesSPI.h
r279412 r279601 56 56 @end 57 57 58 @class RBSAssertion; 58 59 @protocol RBSAssertionObserving; 60 typedef void (^RBSAssertionInvalidationHandler)(RBSAssertion *assertion, NSError *error); 59 61 60 62 @interface RBSAssertion : NSObject 61 63 - (instancetype)initWithExplanation:(NSString *)explanation target:(RBSTarget *)target attributes:(NSArray <RBSAttribute *> *)attributes; 62 64 - (BOOL)acquireWithError:(NSError **)error; 65 - (void)acquireWithInvalidationHandler:(nullable RBSAssertionInvalidationHandler)handler; 63 66 - (void)invalidate; 64 67 - (void)addObserver:(id <RBSAssertionObserving>)observer; -
trunk/Source/WebKit/UIProcess/Downloads/DownloadProxyMap.cpp
r268485 r279601 91 91 if (m_downloads.size() == 1 && m_shouldTakeAssertion) { 92 92 ASSERT(!m_downloadUIAssertion); 93 m_downloadUIAssertion = makeUnique<ProcessAssertion>(getCurrentProcessID(), "WebKit downloads"_s, ProcessAssertionType::UnboundedNetworking);93 m_downloadUIAssertion = ProcessAssertion::create(getCurrentProcessID(), "WebKit downloads"_s, ProcessAssertionType::UnboundedNetworking); 94 94 95 95 ASSERT(!m_downloadNetworkingAssertion); 96 m_downloadNetworkingAssertion = makeUnique<ProcessAssertion>(m_process.processIdentifier(), "WebKit downloads"_s, ProcessAssertionType::UnboundedNetworking);96 m_downloadNetworkingAssertion = ProcessAssertion::create(m_process.processIdentifier(), "WebKit downloads"_s, ProcessAssertionType::UnboundedNetworking); 97 97 98 98 RELEASE_LOG(ProcessSuspension, "UIProcess took 'WebKit downloads' assertions for UIProcess and NetworkProcess"); -
trunk/Source/WebKit/UIProcess/Downloads/DownloadProxyMap.h
r267763 r279601 76 76 77 77 bool m_shouldTakeAssertion { false }; 78 std::unique_ptr<ProcessAssertion> m_downloadUIAssertion;79 std::unique_ptr<ProcessAssertion> m_downloadNetworkingAssertion;78 RefPtr<ProcessAssertion> m_downloadUIAssertion; 79 RefPtr<ProcessAssertion> m_downloadNetworkingAssertion; 80 80 81 81 #if PLATFORM(IOS_FAMILY) -
trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp
r279514 r279601 1443 1443 RELEASE_LOG(ProcessSuspension, "NetworkProcessProxy::setWebProcessHasUploads: The number of uploads in progress is now greater than 0. Taking Networking and UI process assertions."); 1444 1444 m_uploadActivity = UploadActivity { 1445 makeUnique<ProcessAssertion>(getCurrentProcessID(), "WebKit uploads"_s, ProcessAssertionType::UnboundedNetworking),1446 makeUnique<ProcessAssertion>(processIdentifier(), "WebKit uploads"_s, ProcessAssertionType::UnboundedNetworking),1447 HashMap<WebCore::ProcessIdentifier, std::unique_ptr<ProcessAssertion>>()1445 ProcessAssertion::create(getCurrentProcessID(), "WebKit uploads"_s, ProcessAssertionType::UnboundedNetworking), 1446 ProcessAssertion::create(processIdentifier(), "WebKit uploads"_s, ProcessAssertionType::UnboundedNetworking), 1447 HashMap<WebCore::ProcessIdentifier, RefPtr<ProcessAssertion>>() 1448 1448 }; 1449 1449 } … … 1451 1451 m_uploadActivity->webProcessAssertions.ensure(processID, [&] { 1452 1452 RELEASE_LOG(ProcessSuspension, "NetworkProcessProxy::setWebProcessHasUploads: Taking upload assertion on behalf of WebProcess with PID %d", process->processIdentifier()); 1453 return makeUnique<ProcessAssertion>(process->processIdentifier(), "WebKit uploads"_s, ProcessAssertionType::UnboundedNetworking);1453 return ProcessAssertion::create(process->processIdentifier(), "WebKit uploads"_s, ProcessAssertionType::UnboundedNetworking); 1454 1454 }); 1455 1455 } -
trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h
r279514 r279601 345 345 346 346 struct UploadActivity { 347 std::unique_ptr<ProcessAssertion> uiAssertion;348 std::unique_ptr<ProcessAssertion> networkAssertion;349 HashMap<WebCore::ProcessIdentifier, std::unique_ptr<ProcessAssertion>> webProcessAssertions;347 RefPtr<ProcessAssertion> uiAssertion; 348 RefPtr<ProcessAssertion> networkAssertion; 349 HashMap<WebCore::ProcessIdentifier, RefPtr<ProcessAssertion>> webProcessAssertions; 350 350 }; 351 351 std::optional<UploadActivity> m_uploadActivity; -
trunk/Source/WebKit/UIProcess/ProcessAssertion.cpp
r279514 r279601 47 47 } 48 48 49 void ProcessAssertion::acquireAsync(CompletionHandler<void()>&& completionHandler) 50 { 51 if (completionHandler) 52 RunLoop::main().dispatch(WTFMove(completionHandler)); 53 } 54 55 void ProcessAssertion::acquireSync() 56 { 57 } 58 49 59 ProcessAndUIAssertion::ProcessAndUIAssertion(ProcessID pid, const String& reason, ProcessAssertionType assertionType) 50 60 : ProcessAssertion(pid, reason, assertionType) -
trunk/Source/WebKit/UIProcess/ProcessAssertion.h
r279514 r279601 26 26 #pragma once 27 27 28 #include <wtf/CompletionHandler.h> 28 29 #include <wtf/Function.h> 29 30 #include <wtf/ProcessID.h> 31 #include <wtf/ThreadSafeRefCounted.h> 30 32 #include <wtf/WeakPtr.h> 31 33 #include <wtf/text/WTFString.h> … … 53 55 }; 54 56 55 class ProcessAssertion : public CanMakeWeakPtr<ProcessAssertion> {57 class ProcessAssertion : public ThreadSafeRefCounted<ProcessAssertion>, public CanMakeWeakPtr<ProcessAssertion> { 56 58 WTF_MAKE_FAST_ALLOCATED; 57 59 public: 58 ProcessAssertion(ProcessID, const String& reason, ProcessAssertionType); 60 enum class Mode : bool { Sync, Async }; 61 static Ref<ProcessAssertion> create(ProcessID pid, const String& reason, ProcessAssertionType type, Mode mode = Mode::Async, CompletionHandler<void()>&& acquisisionHandler = nullptr) 62 { 63 auto assertion = adoptRef(*new ProcessAssertion(pid, reason, type)); 64 if (mode == Mode::Async) 65 assertion->acquireAsync(WTFMove(acquisisionHandler)); 66 else { 67 assertion->acquireSync(); 68 if (acquisisionHandler) 69 acquisisionHandler(); 70 } 71 return assertion; 72 } 59 73 virtual ~ProcessAssertion(); 60 74 … … 66 80 bool isValid() const; 67 81 82 protected: 83 ProcessAssertion(ProcessID, const String& reason, ProcessAssertionType); 84 85 void acquireAsync(CompletionHandler<void()>&&); 86 void acquireSync(); 87 68 88 #if PLATFORM(IOS_FAMILY) 69 protected:70 89 virtual void processAssertionWasInvalidated(); 71 90 #endif … … 78 97 RetainPtr<RBSAssertion> m_rbsAssertion; 79 98 RetainPtr<WKRBSAssertionDelegate> m_delegate; 99 bool m_wasInvalidated { false }; 80 100 #endif 81 101 Function<void()> m_invalidationHandler; … … 84 104 class ProcessAndUIAssertion final : public ProcessAssertion { 85 105 public: 86 ProcessAndUIAssertion(ProcessID, const String& reason, ProcessAssertionType); 106 static Ref<ProcessAndUIAssertion> create(ProcessID pid, const String& reason, ProcessAssertionType type, Mode mode = Mode::Async, CompletionHandler<void()>&& acquisisionHandler = nullptr) 107 { 108 auto assertion = adoptRef(*new ProcessAndUIAssertion(pid, reason, type)); 109 if (mode == Mode::Async) 110 assertion->acquireAsync(WTFMove(acquisisionHandler)); 111 else { 112 assertion->acquireSync(); 113 if (acquisisionHandler) 114 acquisisionHandler(); 115 } 116 return assertion; 117 } 87 118 ~ProcessAndUIAssertion(); 88 119 … … 92 123 93 124 private: 125 ProcessAndUIAssertion(ProcessID, const String& reason, ProcessAssertionType); 126 94 127 #if PLATFORM(IOS_FAMILY) 95 128 void processAssertionWasInvalidated() final; -
trunk/Source/WebKit/UIProcess/ProcessThrottler.cpp
r279514 r279601 130 130 PROCESSTHROTTLER_RELEASE_LOG("setAssertionType: Updating process assertion type to %u (foregroundActivities=%u, backgroundActivities=%u)", newType, m_foregroundActivities.size(), m_backgroundActivities.size()); 131 131 132 // Keep the previous assertion around until after the new one has been created so that we always hold 133 // a process assertion for the process. 132 // Keep the previous assertion active until the new assertion is taken asynchronously. 134 133 auto previousAssertion = std::exchange(m_assertion, nullptr); 135 134 if (m_shouldTakeUIBackgroundAssertion) { 136 auto assertion = makeUnique<ProcessAndUIAssertion>(m_processIdentifier, assertionName(newType), newType); 137 assertion->setUIAssertionExpirationHandler([this] { 138 uiAssertionWillExpireImminently(); 135 auto assertion = ProcessAndUIAssertion::create(m_processIdentifier, assertionName(newType), newType, ProcessAssertion::Mode::Async, [previousAssertion = WTFMove(previousAssertion)] { }); 136 assertion->setUIAssertionExpirationHandler([weakThis = makeWeakPtr(*this)] { 137 if (weakThis) 138 weakThis->uiAssertionWillExpireImminently(); 139 139 }); 140 140 m_assertion = WTFMove(assertion); 141 141 } else 142 m_assertion = makeUnique<ProcessAssertion>(m_processIdentifier, assertionName(newType), newType); 143 144 m_assertion->setInvalidationHandler([this] { 145 assertionWasInvalidated(); 142 m_assertion = ProcessAssertion::create(m_processIdentifier, assertionName(newType), newType, ProcessAssertion::Mode::Async, [previousAssertion = WTFMove(previousAssertion)] { }); 143 144 m_assertion->setInvalidationHandler([weakThis = makeWeakPtr(*this)] { 145 if (weakThis) 146 weakThis->assertionWasInvalidated(); 146 147 }); 147 148 m_process.didSetAssertionType(newType); -
trunk/Source/WebKit/UIProcess/ProcessThrottler.h
r278253 r279601 150 150 ProcessThrottlerClient& m_process; 151 151 ProcessID m_processIdentifier { 0 }; 152 std::unique_ptr<ProcessAssertion> m_assertion;152 RefPtr<ProcessAssertion> m_assertion; 153 153 RunLoop::Timer<ProcessThrottler> m_prepareToSuspendTimeoutTimer; 154 154 HashSet<ForegroundActivity*> m_foregroundActivities; -
trunk/Source/WebKit/UIProcess/WebProcessPool.cpp
r279591 r279601 2033 2033 WEBPROCESSPOOL_RELEASE_LOG(ProcessSuspension, "updateAudibleMediaAssertions: The number of processes playing audible media is now greater than zero. Taking UI process assertion."); 2034 2034 m_audibleMediaActivity = AudibleMediaActivity { 2035 makeUniqueRef<ProcessAssertion>(getCurrentProcessID(), "WebKit Media Playback"_s, ProcessAssertionType::MediaPlayback)2035 ProcessAssertion::create(getCurrentProcessID(), "WebKit Media Playback"_s, ProcessAssertionType::MediaPlayback) 2036 2036 #if ENABLE(GPU_PROCESS) 2037 , gpuProcess() ? makeUnique<ProcessAssertion>(gpuProcess()->processIdentifier(), "WebKit Media Playback"_s, ProcessAssertionType::MediaPlayback): nullptr2037 , gpuProcess() ? RefPtr<ProcessAssertion> { ProcessAssertion::create(gpuProcess()->processIdentifier(), "WebKit Media Playback"_s, ProcessAssertionType::MediaPlayback) } : nullptr 2038 2038 #endif 2039 2039 }; -
trunk/Source/WebKit/UIProcess/WebProcessPool.h
r279591 r279601 772 772 773 773 struct AudibleMediaActivity { 774 UniqueRef<ProcessAssertion> uiProcessMediaPlaybackAssertion;774 Ref<ProcessAssertion> uiProcessMediaPlaybackAssertion; 775 775 #if ENABLE(GPU_PROCESS) 776 std::unique_ptr<ProcessAssertion> gpuProcessMediaPlaybackAssertion;776 RefPtr<ProcessAssertion> gpuProcessMediaPlaybackAssertion; 777 777 #endif 778 778 }; -
trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp
r279583 r279601 1489 1489 WEBPROCESSPROXY_RELEASE_LOG(ProcessSuspension, "updateAudibleMediaAssertions: Taking MediaPlayback assertion for WebProcess"); 1490 1490 m_audibleMediaActivity = AudibleMediaActivity { 1491 makeUniqueRef<ProcessAssertion>(processIdentifier(), "WebKit Media Playback"_s, ProcessAssertionType::MediaPlayback),1491 ProcessAssertion::create(processIdentifier(), "WebKit Media Playback"_s, ProcessAssertionType::MediaPlayback), 1492 1492 processPool().webProcessWithAudibleMediaToken() 1493 1493 }; -
trunk/Source/WebKit/UIProcess/WebProcessProxy.h
r279583 r279601 637 637 638 638 struct AudibleMediaActivity { 639 UniqueRef<ProcessAssertion> assertion;639 Ref<ProcessAssertion> assertion; 640 640 WebProcessWithAudibleMediaToken token; 641 641 }; -
trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm
r279514 r279601 42 42 using WebKit::ProcessAndUIAssertion; 43 43 44 static WorkQueue& assertionsWorkQueue() 45 { 46 static NeverDestroyed<Ref<WorkQueue>> workQueue(WorkQueue::create("ProcessAssertion Queue")); 47 return workQueue.get(); 48 } 49 44 50 // This gives some time to our child processes to process the ProcessWillSuspendImminently IPC but makes sure we release 45 51 // the background task before the UIKit timeout (We get killed if we do not release the background task within 5 seconds … … 65 71 { 66 72 RetainPtr<RBSAssertion> _backgroundTask; 73 std::atomic<bool> _backgroundTaskWasInvalidated; 67 74 WeakHashSet<ProcessAndUIAssertion> _assertionsNeedingBackgroundTask; 68 75 dispatch_block_t _pendingTaskReleaseTask; … … 161 168 - (void)_updateBackgroundTask 162 169 { 163 if (!_assertionsNeedingBackgroundTask.computesEmpty() && ![self _hasBackgroundTask]) {170 if (!_assertionsNeedingBackgroundTask.computesEmpty() && (![self _hasBackgroundTask] || _backgroundTaskWasInvalidated)) { 164 171 if (processHasActiveRunTimeLimitation()) { 165 172 RELEASE_LOG(ProcessSuspension, "%p - WKProcessAssertionBackgroundTaskManager: Ignored request to start a new background task because RunningBoard has already started the expiration timer", self); … … 172 179 [_backgroundTask addObserver:self]; 173 180 174 NSError *acquisitionError = nil; 175 if (![_backgroundTask acquireWithError:&acquisitionError]) 176 RELEASE_LOG_ERROR(ProcessSuspension, "WKProcessAssertionBackgroundTaskManager: Failed to acquire FinishTaskInterruptable assertion for own process, error: %{public}@", acquisitionError); 177 else 178 RELEASE_LOG(ProcessSuspension, "WKProcessAssertionBackgroundTaskManager: Successfully took a FinishTaskInterruptable assertion for own process"); 181 _backgroundTaskWasInvalidated = false; 182 [_backgroundTask acquireWithInvalidationHandler:nil]; 183 RELEASE_LOG(ProcessSuspension, "WKProcessAssertionBackgroundTaskManager: Took a FinishTaskInterruptable assertion for own process"); 179 184 } else if (_assertionsNeedingBackgroundTask.computesEmpty()) { 180 185 // Release the background task asynchronously because releasing the background task may destroy the ProcessThrottler and we don't … … 197 202 ASSERT(assertion == _backgroundTask.get()); 198 203 RELEASE_LOG_ERROR(ProcessSuspension, "WKProcessAssertionBackgroundTaskManager: FinishTaskInterruptable assertion was invalidated, error: %{public}@", error); 204 _backgroundTaskWasInvalidated = true; 199 205 } 200 206 … … 320 326 if (!pid) { 321 327 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()); 328 m_wasInvalidated = true; 322 329 return; 323 330 } … … 330 337 [m_rbsAssertion addObserver:m_delegate.get()]; 331 338 m_delegate.get().invalidationCallback = ^{ 332 RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion ()RBS %{public}@ assertion for process with PID=%d was invalidated", this, runningBoardAssertionName, pid);339 RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion: RBS %{public}@ assertion for process with PID=%d was invalidated", this, runningBoardAssertionName, pid); 333 340 processAssertionWasInvalidated(); 334 341 }; 335 342 } 343 344 void ProcessAssertion::acquireAsync(CompletionHandler<void()>&& completionHandler) 345 { 346 assertionsWorkQueue().dispatch([protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)]() mutable { 347 protectedThis->acquireSync(); 348 if (completionHandler) 349 RunLoop::main().dispatch(WTFMove(completionHandler)); 350 }); 351 } 352 353 void ProcessAssertion::acquireSync() 354 { 336 355 NSError *acquisitionError = nil; 337 356 if (![m_rbsAssertion acquireWithError:&acquisitionError]) { 338 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);357 RELEASE_LOG_ERROR(ProcessSuspension, "%p - ProcessAssertion: Failed to acquire RBS assertion '%{public}s' for process with PID=%d, error: %{public}@", this, m_reason.utf8().data(), m_pid, acquisitionError); 339 358 RunLoop::main().dispatch([weakThis = makeWeakPtr(*this)] { 340 359 if (weakThis) … … 342 361 }); 343 362 } else 344 RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion: Successfully took RBS %{public}@ assertion '%{public}s' for process with PID=%d", this, runningBoardAssertionName, reason.utf8().data(),pid);363 RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion: Successfully took RBS assertion '%{public}s' for process with PID=%d", this, m_reason.utf8().data(), m_pid); 345 364 } 346 365 347 366 ProcessAssertion::~ProcessAssertion() 348 367 { 349 RELEASE_LOG(ProcessSuspension, "%p - ~ProcessAssertion ()Releasing process assertion '%{public}s' for process with PID=%d", this, m_reason.utf8().data(), m_pid);368 RELEASE_LOG(ProcessSuspension, "%p - ~ProcessAssertion: Releasing process assertion '%{public}s' for process with PID=%d", this, m_reason.utf8().data(), m_pid); 350 369 351 370 if (m_rbsAssertion) { … … 362 381 RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion::processAssertionWasInvalidated() PID=%d", this, m_pid); 363 382 383 m_wasInvalidated = true; 364 384 if (m_invalidationHandler) 365 385 m_invalidationHandler(); … … 368 388 bool ProcessAssertion::isValid() const 369 389 { 370 return m_rbsAssertion && m_rbsAssertion.get().valid;390 return !m_wasInvalidated; 371 391 } 372 392
Note:
See TracChangeset
for help on using the changeset viewer.