Changeset 259540 in webkit
- Timestamp:
- Apr 4, 2020 5:03:45 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r259539 r259540 1 2020-04-04 Chris Dumez <cdumez@apple.com> 2 3 [iOS] Simplify ProcessAssertion class in preparation for switch to RunningBoard 4 https://bugs.webkit.org/show_bug.cgi?id=209984 5 <rdar://problem/61273941> 6 7 Reviewed by Darin Adler. 8 9 Simplify ProcessAssertion class in preparation for switch to RunningBoard. There 10 is a slight mismatch between the way BKS and RunningBoard process assertion API. 11 This refactoring makes it so that we can use the same ProcessAssertion class in 12 WebKit to work with either BKS or RunningBoard. Support for RunningBoard will 13 come later. 14 15 In particular, the following changes were made: 16 - Replace AssertionState & AssertionReason enums with a single ProcessAssertionType 17 one since RunningBoard does not have 2 separate concepts. 18 - Drop ProcessAssertion::setState() since it is not possible to change the flags 19 on an existing RunningBoard assertion. Instead, we are expected to create a 20 brand new process assertion of the expected type. 21 22 * NetworkProcess/Downloads/DownloadMap.cpp: 23 (WebKit::DownloadMap::add): 24 * Platform/IPC/cocoa/ConnectionCocoa.mm: 25 (IPC::ConnectionTerminationWatchdog::ConnectionTerminationWatchdog): 26 * UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h: 27 * UIProcess/API/Cocoa/WKWebViewTesting.mm: 28 (-[WKWebView _setAssertionTypeForTesting:]): 29 (-[WKWebView _setAssertionStateForTesting:]): Deleted. 30 * UIProcess/Downloads/DownloadProxyMap.cpp: 31 (WebKit::DownloadProxyMap::createDownloadProxy): 32 * UIProcess/GPU/GPUProcessProxy.h: 33 * UIProcess/Network/NetworkProcessProxy.cpp: 34 (WebKit::NetworkProcessProxy::sendProcessDidResume): 35 (WebKit::NetworkProcessProxy::takeUploadAssertion): 36 (WebKit::NetworkProcessProxy::didSetAssertionState): Deleted. 37 * UIProcess/Network/NetworkProcessProxy.h: 38 * UIProcess/ProcessAssertion.cpp: 39 (WebKit::ProcessAssertion::ProcessAssertion): 40 (WebKit::ProcessAssertion::setState): Deleted. 41 * UIProcess/ProcessAssertion.h: 42 (WebKit::ProcessAssertion::type const): 43 (WebKit::ProcessAssertion::state const): Deleted. 44 * UIProcess/ProcessThrottler.cpp: 45 (WebKit::ProcessThrottler::expectedAssertionType): 46 (WebKit::ProcessThrottler::updateAssertionTypeNow): 47 (WebKit::ProcessThrottler::setAssertionType): 48 (WebKit::ProcessThrottler::updateAssertionIfNeeded): 49 (WebKit::ProcessThrottler::didConnectToProcess): 50 (WebKit::ProcessThrottler::prepareToSuspendTimeoutTimerFired): 51 (WebKit::ProcessThrottler::processReadyToSuspend): 52 (WebKit::ProcessThrottler::sendPrepareToSuspendIPC): 53 (WebKit::ProcessThrottler::expectedAssertionState): Deleted. 54 (WebKit::ProcessThrottler::updateAssertionStateNow): Deleted. 55 (WebKit::ProcessThrottler::setAssertionState): Deleted. 56 * UIProcess/ProcessThrottler.h: 57 * UIProcess/ProcessThrottlerClient.h: 58 (WebKit::ProcessThrottlerClient::didSetAssertionType): 59 * UIProcess/WebProcessPool.cpp: 60 (WebKit::WebProcessPool::setWebProcessHasUploads): 61 (WebKit::WebProcessPool::setWebProcessIsPlayingAudibleMedia): 62 * UIProcess/WebProcessProxy.cpp: 63 (WebKit::WebProcessProxy::didSetAssertionType): 64 (WebKit::WebProcessProxy::didSetAssertionState): Deleted. 65 * UIProcess/WebProcessProxy.h: 66 (WebKit::WebProcessProxy::setAssertionTypeForTesting): 67 (WebKit::WebProcessProxy::setAssertionStateForTesting): Deleted. 68 * UIProcess/ios/ProcessAssertionIOS.mm: 69 (WebKit::flagsForAssertionType): 70 (WebKit::toBKSProcessAssertionReason): 71 (WebKit::ProcessAssertion::ProcessAssertion): 72 (WebKit::ProcessAndUIAssertion::updateRunInBackgroundCount): 73 (WebKit::ProcessAndUIAssertion::ProcessAndUIAssertion): 74 (WebKit::flagsForState): Deleted. 75 (WebKit::reasonForState): Deleted. 76 (WebKit::ProcessAssertion::setState): Deleted. 77 (WebKit::ProcessAndUIAssertion::setState): Deleted. 78 1 79 2020-04-04 David Kilzer <ddkilzer@apple.com> 2 80 -
trunk/Source/WebKit/NetworkProcess/Downloads/DownloadMap.cpp
r248846 r259540 62 62 if (m_downloads.size() == 1) { 63 63 ASSERT(!m_downloadAssertion); 64 m_downloadAssertion = makeUnique<ProcessAssertion>(getpid(), "WebKit downloads"_s, AssertionState::UnboundedNetworking);64 m_downloadAssertion = makeUnique<ProcessAssertion>(getpid(), "WebKit downloads"_s, ProcessAssertionType::UnboundedNetworking); 65 65 RELEASE_LOG(ProcessSuspension, "Took 'WebKit downloads' assertion in NetworkProcess"); 66 66 } -
trunk/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm
r258369 r259540 87 87 , m_watchdogTimer(RunLoop::main(), this, &ConnectionTerminationWatchdog::watchdogTimerFired) 88 88 #if PLATFORM(IOS_FAMILY) 89 , m_assertion(makeUnique<WebKit::ProcessAndUIAssertion>(xpc_connection_get_pid(m_xpcConnection.get()), "ConnectionTerminationWatchdog"_s, WebKit:: AssertionState::Background))89 , m_assertion(makeUnique<WebKit::ProcessAndUIAssertion>(xpc_connection_get_pid(m_xpcConnection.get()), "ConnectionTerminationWatchdog"_s, WebKit::ProcessAssertionType::Background)) 90 90 #endif 91 91 { -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h
r259200 r259540 58 58 @property (nonatomic, readonly) BOOL _hasServiceWorkerBackgroundActivityForTesting; 59 59 @property (nonatomic, readonly) BOOL _hasServiceWorkerForegroundActivityForTesting; 60 - (void)_setAssertion StateForTesting:(int)state;60 - (void)_setAssertionTypeForTesting:(int)type; 61 61 62 62 - (void)_doAfterProcessingAllPendingMouseEvents:(dispatch_block_t)action; -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm
r259200 r259540 171 171 } 172 172 173 - (void)_setAssertion StateForTesting:(int)value173 - (void)_setAssertionTypeForTesting:(int)value 174 174 { 175 175 if (!_page) 176 176 return; 177 177 178 _page->process().setAssertion StateForTesting(static_cast<WebKit::AssertionState>(value));178 _page->process().setAssertionTypeForTesting(static_cast<WebKit::ProcessAssertionType>(value)); 179 179 } 180 180 -
trunk/Source/WebKit/UIProcess/Downloads/DownloadProxyMap.cpp
r255845 r259540 90 90 if (m_downloads.size() == 1 && m_shouldTakeAssertion) { 91 91 ASSERT(!m_downloadUIAssertion); 92 m_downloadUIAssertion = makeUnique<ProcessAssertion>(getCurrentProcessID(), "WebKit downloads"_s, AssertionState::UnboundedNetworking);92 m_downloadUIAssertion = makeUnique<ProcessAssertion>(getCurrentProcessID(), "WebKit downloads"_s, ProcessAssertionType::UnboundedNetworking); 93 93 94 94 ASSERT(!m_downloadNetworkingAssertion); 95 95 RELEASE_ASSERT(m_process); 96 m_downloadNetworkingAssertion = makeUnique<ProcessAssertion>(m_process->processIdentifier(), "WebKit downloads"_s, AssertionState::UnboundedNetworking);96 m_downloadNetworkingAssertion = makeUnique<ProcessAssertion>(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/GPU/GPUProcessProxy.h
r258322 r259540 93 93 // ProcessThrottlerClient 94 94 void sendPrepareToSuspend(IsSuspensionImminent, CompletionHandler<void()>&&) final { } 95 void didSetAssertionState(AssertionState) final { }96 95 97 96 // ProcessLauncher::Client -
trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp
r259521 r259540 1198 1198 send(Messages::NetworkProcess::ProcessDidResume(), 0); 1199 1199 } 1200 1201 void NetworkProcessProxy::didSetAssertionState(AssertionState)1202 {1203 }1204 1200 1205 1201 void NetworkProcessProxy::setIsHoldingLockedFiles(bool isHoldingLockedFiles) … … 1405 1401 { 1406 1402 ASSERT(!m_uploadAssertion); 1407 m_uploadAssertion = makeUnique<ProcessAssertion>(processIdentifier(), "WebKit uploads"_s, AssertionState::UnboundedNetworking);1403 m_uploadAssertion = makeUnique<ProcessAssertion>(processIdentifier(), "WebKit uploads"_s, ProcessAssertionType::UnboundedNetworking); 1408 1404 } 1409 1405 -
trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h
r259275 r259540 240 240 // ProcessThrottlerClient 241 241 void sendPrepareToSuspend(IsSuspensionImminent, CompletionHandler<void()>&&) final; 242 void didSetAssertionState(AssertionState) final;243 242 244 243 // IPC::Connection::Client -
trunk/Source/WebKit/UIProcess/ProcessAssertion.cpp
r244225 r259540 33 33 namespace WebKit { 34 34 35 ProcessAssertion::ProcessAssertion(ProcessID, const String&, AssertionState assertionState) 36 : m_assertionState(assertionState) 37 { 38 } 39 40 ProcessAssertion::ProcessAssertion(pid_t pid, const String& name, AssertionState assertionState, AssertionReason) 41 : m_assertionState(assertionState) 35 ProcessAssertion::ProcessAssertion(ProcessID, const String&, ProcessAssertionType assertionType) 36 : m_assertionType(assertionType) 42 37 { 43 38 } … … 45 40 ProcessAssertion::~ProcessAssertion() = default; 46 41 47 void ProcessAssertion::setState(AssertionState assertionState)48 {49 m_assertionState = assertionState;50 }51 52 42 } // namespace WebKit 53 43 -
trunk/Source/WebKit/UIProcess/ProcessAssertion.h
r245255 r259540 41 41 42 42 namespace WebKit { 43 44 enum class AssertionState {43 44 enum class ProcessAssertionType { 45 45 Suspended, 46 46 Background, 47 47 UnboundedNetworking, 48 48 Foreground, 49 };50 51 enum class AssertionReason {52 Extension,53 FinishTask,54 FinishTaskUnbounded,55 49 MediaPlayback, 56 50 }; … … 65 59 }; 66 60 67 ProcessAssertion(ProcessID, const String& reason, AssertionState); 68 ProcessAssertion(ProcessID, const String& reason, AssertionState, AssertionReason); 61 ProcessAssertion(ProcessID, const String& reason, ProcessAssertionType); 69 62 virtual ~ProcessAssertion(); 70 63 … … 72 65 Client* client() { return m_client; } 73 66 74 AssertionState state() const { return m_assertionState; } 75 virtual void setState(AssertionState); 67 ProcessAssertionType type() const { return m_assertionType; } 76 68 77 69 #if PLATFORM(IOS_FAMILY) … … 88 80 Validity m_validity { Validity::Unset }; 89 81 #endif 90 AssertionState m_assertionState;82 const ProcessAssertionType m_assertionType; 91 83 Client* m_client { nullptr }; 92 84 }; … … 96 88 class ProcessAndUIAssertion final : public ProcessAssertion { 97 89 public: 98 ProcessAndUIAssertion(ProcessID, const String& reason, AssertionState);90 ProcessAndUIAssertion(ProcessID, const String& reason, ProcessAssertionType); 99 91 ~ProcessAndUIAssertion(); 100 92 101 void setState(AssertionState) final;102 93 void uiAssertionWillExpireImminently(); 103 94 -
trunk/Source/WebKit/UIProcess/ProcessThrottler.cpp
r253980 r259540 87 87 } 88 88 89 AssertionState ProcessThrottler::expectedAssertionState()89 ProcessAssertionType ProcessThrottler::expectedAssertionType() 90 90 { 91 91 if (!m_foregroundActivities.isEmpty()) 92 return AssertionState::Foreground;92 return ProcessAssertionType::Foreground; 93 93 if (!m_backgroundActivities.isEmpty()) 94 return AssertionState::Background; 95 return AssertionState::Suspended; 96 } 97 98 void ProcessThrottler::updateAssertionStateNow() 99 { 100 setAssertionState(expectedAssertionState()); 101 } 102 103 void ProcessThrottler::setAssertionState(AssertionState newState) 104 { 105 RELEASE_ASSERT(m_assertion); 106 if (m_assertion->state() == newState) 94 return ProcessAssertionType::Background; 95 return ProcessAssertionType::Suspended; 96 } 97 98 void ProcessThrottler::updateAssertionTypeNow() 99 { 100 setAssertionType(expectedAssertionType()); 101 } 102 103 void ProcessThrottler::setAssertionType(ProcessAssertionType newType) 104 { 105 if (m_assertion && m_assertion->type() == newType) 107 106 return; 108 107 109 PROCESSTHROTTLER_RELEASE_LOG("setAssertionState: Updating process assertion state to %u (foregroundActivities: %u, backgroundActivities: %u)", newState, m_foregroundActivities.size(), m_backgroundActivities.size()); 110 m_assertion->setState(newState); 111 m_process.didSetAssertionState(newState); 108 PROCESSTHROTTLER_RELEASE_LOG("setAssertionType: Updating process assertion type to %u (foregroundActivities: %u, backgroundActivities: %u)", newType, m_foregroundActivities.size(), m_backgroundActivities.size()); 109 if (m_shouldTakeUIBackgroundAssertion) 110 m_assertion = makeUnique<ProcessAndUIAssertion>(m_processIdentifier, "Web content visibility"_s, newType); 111 else 112 m_assertion = makeUnique<ProcessAssertion>(m_processIdentifier, "Web content visibility"_s, newType); 113 m_process.didSetAssertionType(newType); 112 114 } 113 115 … … 118 120 119 121 if (shouldBeRunnable()) { 120 if (m_assertion-> state() == AssertionState::Suspended || m_pendingRequestToSuspendID) {121 if (m_assertion-> state() == AssertionState::Suspended)122 if (m_assertion->type() == ProcessAssertionType::Suspended || m_pendingRequestToSuspendID) { 123 if (m_assertion->type() == ProcessAssertionType::Suspended) 122 124 PROCESSTHROTTLER_RELEASE_LOG("updateAssertionIfNeeded: sending ProcessDidResume IPC because the process was suspended"); 123 125 else … … 130 132 // and clean up - move it to the background and send it a message to notify. Schedule a timeout so it can't stay running 131 133 // in the background for too long. 132 if (m_assertion-> state() != AssertionState::Suspended) {134 if (m_assertion->type() != ProcessAssertionType::Suspended) { 133 135 m_prepareToSuspendTimeoutTimer.startOneShot(processSuspensionTimeout); 134 136 sendPrepareToSuspendIPC(IsSuspensionImminent::No); … … 137 139 } 138 140 139 updateAssertion StateNow();141 updateAssertionTypeNow(); 140 142 } 141 143 … … 145 147 RELEASE_ASSERT(!m_assertion); 146 148 147 if (m_shouldTakeUIBackgroundAssertion)148 m_assertion = makeUnique<ProcessAndUIAssertion>(pid, "Web content visibility"_s, expectedAssertionState());149 else150 m_assertion = makeUnique<ProcessAssertion>(pid, "Web content visibility"_s, expectedAssertionState());151 152 149 m_processIdentifier = pid; 153 m_process.didSetAssertionState(expectedAssertionState()); 150 setAssertionType(expectedAssertionType()); 151 RELEASE_ASSERT(m_assertion); 154 152 m_assertion->setClient(*this); 155 153 } … … 159 157 PROCESSTHROTTLER_RELEASE_LOG("prepareToSuspendTimeoutTimerFired: Updating process assertion to allow suspension"); 160 158 RELEASE_ASSERT(m_pendingRequestToSuspendID); 161 updateAssertion StateNow();159 updateAssertionTypeNow(); 162 160 } 163 161 … … 169 167 clearPendingRequestToSuspend(); 170 168 171 if (m_assertion-> state() != AssertionState::Suspended)172 updateAssertion StateNow();169 if (m_assertion->type() != ProcessAssertionType::Suspended) 170 updateAssertionTypeNow(); 173 171 } 174 172 … … 195 193 } 196 194 197 setAssertion State(isSuspensionImminent == IsSuspensionImminent::Yes ? AssertionState::Suspended : AssertionState::Background);195 setAssertionType(isSuspensionImminent == IsSuspensionImminent::Yes ? ProcessAssertionType::Suspended : ProcessAssertionType::Background); 198 196 } 199 197 -
trunk/Source/WebKit/UIProcess/ProcessThrottler.h
r256745 r259540 108 108 109 109 private: 110 AssertionState expectedAssertionState();110 ProcessAssertionType expectedAssertionType(); 111 111 void updateAssertionIfNeeded(); 112 void updateAssertion StateNow();113 void setAssertion State(AssertionState);112 void updateAssertionTypeNow(); 113 void setAssertionType(ProcessAssertionType); 114 114 void prepareToSuspendTimeoutTimerFired(); 115 115 void sendPrepareToSuspendIPC(IsSuspensionImminent); -
trunk/Source/WebKit/UIProcess/ProcessThrottlerClient.h
r251599 r259540 39 39 virtual void sendPrepareToSuspend(IsSuspensionImminent, CompletionHandler<void()>&&) = 0; 40 40 virtual void sendProcessDidResume() = 0; 41 virtual void didSetAssertion State(AssertionState) = 0;41 virtual void didSetAssertionType(ProcessAssertionType) { }; 42 42 }; 43 43 -
trunk/Source/WebKit/UIProcess/WebProcessPool.cpp
r259516 r259540 2355 2355 2356 2356 ASSERT(!m_uiProcessUploadAssertion); 2357 m_uiProcessUploadAssertion = makeUnique<ProcessAssertion>(getCurrentProcessID(), "WebKit uploads"_s, AssertionState::UnboundedNetworking);2357 m_uiProcessUploadAssertion = makeUnique<ProcessAssertion>(getCurrentProcessID(), "WebKit uploads"_s, ProcessAssertionType::UnboundedNetworking); 2358 2358 } 2359 2359 2360 2360 auto result = m_processesWithUploads.add(processID, nullptr); 2361 2361 ASSERT(result.isNewEntry); 2362 result.iterator->value = makeUnique<ProcessAssertion>(process->processIdentifier(), "WebKit uploads"_s, AssertionState::UnboundedNetworking);2362 result.iterator->value = makeUnique<ProcessAssertion>(process->processIdentifier(), "WebKit uploads"_s, ProcessAssertionType::UnboundedNetworking); 2363 2363 } 2364 2364 … … 2397 2397 2398 2398 ASSERT(!m_uiProcessMediaPlaybackAssertion); 2399 m_uiProcessMediaPlaybackAssertion = makeUnique<ProcessAssertion>(getCurrentProcessID(), "WebKit Media Playback"_s, AssertionState::Foreground, AssertionReason::MediaPlayback);2399 m_uiProcessMediaPlaybackAssertion = makeUnique<ProcessAssertion>(getCurrentProcessID(), "WebKit Media Playback"_s, ProcessAssertionType::MediaPlayback); 2400 2400 #if ENABLE(GPU_PROCESS) 2401 2401 if (GPUProcessProxy::singletonIfCreated()) 2402 m_gpuProcessMediaPlaybackAssertion = makeUnique<ProcessAssertion>(GPUProcessProxy::singleton().processIdentifier(), "WebKit Media Playback"_s, AssertionState::Foreground, AssertionReason::MediaPlayback);2402 m_gpuProcessMediaPlaybackAssertion = makeUnique<ProcessAssertion>(GPUProcessProxy::singleton().processIdentifier(), "WebKit Media Playback"_s, ProcessAssertionType::MediaPlayback); 2403 2403 #endif 2404 2404 } … … 2406 2406 auto result = m_processesPlayingAudibleMedia.add(processID, nullptr); 2407 2407 ASSERT(result.isNewEntry); 2408 result.iterator->value = makeUnique<ProcessAssertion>(process->processIdentifier(), "WebKit Media Playback"_s, AssertionState::Foreground, AssertionReason::MediaPlayback);2408 result.iterator->value = makeUnique<ProcessAssertion>(process->processIdentifier(), "WebKit Media Playback"_s, ProcessAssertionType::MediaPlayback); 2409 2409 } 2410 2410 -
trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp
r259505 r259540 1326 1326 } 1327 1327 1328 void WebProcessProxy::didSetAssertion State(AssertionState state)1329 { 1330 RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertion State(%u)", this, state);1328 void WebProcessProxy::didSetAssertionType(ProcessAssertionType type) 1329 { 1330 RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionType(%u)", this, type); 1331 1331 1332 1332 if (isStandaloneServiceWorkerProcess()) { 1333 RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertion State() release all assertions for network process because this is a service worker process without page", this);1333 RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionType() release all assertions for network process because this is a service worker process without page", this); 1334 1334 m_foregroundToken = nullptr; 1335 1335 m_backgroundToken = nullptr; … … 1339 1339 ASSERT(!m_backgroundToken || !m_foregroundToken); 1340 1340 1341 switch ( state) {1342 case AssertionState::Suspended:1343 RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertion State(Suspended) release all assertions for network process", this);1341 switch (type) { 1342 case ProcessAssertionType::Suspended: 1343 RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionType(Suspended) release all assertions for network process", this); 1344 1344 m_foregroundToken = nullptr; 1345 1345 m_backgroundToken = nullptr; … … 1350 1350 break; 1351 1351 1352 case AssertionState::Background:1353 RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertion State(Background) taking background assertion for network process", this);1352 case ProcessAssertionType::Background: 1353 RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionType(Background) taking background assertion for network process", this); 1354 1354 m_backgroundToken = processPool().backgroundWebProcessToken(); 1355 1355 m_foregroundToken = nullptr; 1356 1356 break; 1357 1357 1358 case AssertionState::Foreground:1359 RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertion State(Foreground) taking foreground assertion for network process", this);1358 case ProcessAssertionType::Foreground: 1359 RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionType(Foreground) taking foreground assertion for network process", this); 1360 1360 m_foregroundToken = processPool().foregroundWebProcessToken(); 1361 1361 m_backgroundToken = nullptr; … … 1366 1366 break; 1367 1367 1368 case AssertionState::UnboundedNetworking: 1368 case ProcessAssertionType::MediaPlayback: 1369 case ProcessAssertionType::UnboundedNetworking: 1369 1370 ASSERT_NOT_REACHED(); 1370 1371 } -
trunk/Source/WebKit/UIProcess/WebProcessProxy.h
r259307 r259540 314 314 void sendPrepareToSuspend(IsSuspensionImminent, CompletionHandler<void()>&&) final; 315 315 void sendProcessDidResume() final; 316 void didSetAssertion State(AssertionState) final;316 void didSetAssertionType(ProcessAssertionType) final; 317 317 318 318 #if PLATFORM(COCOA) … … 361 361 bool hasServiceWorkerBackgroundActivityForTesting() const; 362 362 #endif 363 void setAssertion StateForTesting(AssertionState state) { didSetAssertionState(state); }363 void setAssertionTypeForTesting(ProcessAssertionType type) { didSetAssertionType(type); } 364 364 365 365 #if PLATFORM(COCOA) && ENABLE(MEDIA_STREAM) -
trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm
r259414 r259540 272 272 const BKSProcessAssertionFlags foregroundTabFlags = (BKSProcessAssertionPreventTaskSuspend | BKSProcessAssertionWantsForegroundResourcePriority | BKSProcessAssertionPreventTaskThrottleDown); 273 273 274 static BKSProcessAssertionFlags flagsFor State(AssertionState assertionState)275 { 276 switch (assertion State) {277 case AssertionState::Suspended:274 static BKSProcessAssertionFlags flagsForAssertionType(ProcessAssertionType assertionType) 275 { 276 switch (assertionType) { 277 case ProcessAssertionType::Suspended: 278 278 return suspendedTabFlags; 279 case AssertionState::Background:280 case AssertionState::UnboundedNetworking:279 case ProcessAssertionType::Background: 280 case ProcessAssertionType::UnboundedNetworking: 281 281 return backgroundTabFlags; 282 case AssertionState::Foreground: 282 case ProcessAssertionType::Foreground: 283 case ProcessAssertionType::MediaPlayback: 283 284 return foregroundTabFlags; 284 285 } 285 286 } 286 287 287 static AssertionReason reasonForState(AssertionState assertionState) 288 { 289 switch (assertionState) { 290 case AssertionState::UnboundedNetworking: 291 return AssertionReason::FinishTaskUnbounded; 292 case AssertionState::Suspended: 293 case AssertionState::Background: 294 case AssertionState::Foreground: 295 return AssertionReason::Extension; 296 } 297 } 298 299 static BKSProcessAssertionReason toBKSProcessAssertionReason(AssertionReason reason) 300 { 301 switch (reason) { 302 case AssertionReason::Extension: 288 static BKSProcessAssertionReason toBKSProcessAssertionReason(ProcessAssertionType assertionType) 289 { 290 switch (assertionType) { 291 case ProcessAssertionType::Suspended: 292 case ProcessAssertionType::Background: 293 case ProcessAssertionType::Foreground: 303 294 return BKSProcessAssertionReasonExtension; 304 case AssertionReason::FinishTask: 305 return BKSProcessAssertionReasonFinishTask; 306 case AssertionReason::FinishTaskUnbounded: 295 case ProcessAssertionType::UnboundedNetworking: 307 296 return BKSProcessAssertionReasonFinishTaskUnbounded; 308 case AssertionReason::MediaPlayback:297 case ProcessAssertionType::MediaPlayback: 309 298 return BKSProcessAssertionReasonMediaPlayback; 310 299 } 311 300 } 312 301 313 ProcessAssertion::ProcessAssertion(pid_t pid, const String& name, AssertionState assertionState) 314 : ProcessAssertion(pid, name, assertionState, reasonForState(assertionState)) 315 { 316 } 317 318 ProcessAssertion::ProcessAssertion(pid_t pid, const String& name, AssertionState assertionState, AssertionReason assertionReason) 319 : m_assertionState(assertionState) 302 ProcessAssertion::ProcessAssertion(pid_t pid, const String& name, ProcessAssertionType assertionType) 303 : m_assertionType(assertionType) 320 304 { 321 305 auto weakThis = makeWeakPtr(*this); … … 331 315 RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() PID %d acquiring assertion for process with PID %d, name '%s'", this, getpid(), pid, name.utf8().data()); 332 316 333 m_assertion = adoptNS([[BKSProcessAssertion alloc] initWithPID:pid flags:flagsFor State(assertionState) reason:toBKSProcessAssertionReason(assertionReason) name:(NSString *)name withHandler:handler]);317 m_assertion = adoptNS([[BKSProcessAssertion alloc] initWithPID:pid flags:flagsForAssertionType(assertionType) reason:toBKSProcessAssertionReason(assertionType) name:(NSString *)name withHandler:handler]); 334 318 m_assertion.get().invalidationHandler = ^() { 335 319 dispatch_async(dispatch_get_main_queue(), ^{ … … 357 341 } 358 342 359 void ProcessAssertion::setState(AssertionState assertionState)360 {361 if (m_assertionState == assertionState)362 return;363 364 RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion::setState(%u) previousState: %u", this, static_cast<unsigned>(assertionState), static_cast<unsigned>(m_assertionState));365 m_assertionState = assertionState;366 [m_assertion setFlags:flagsForState(assertionState)];367 }368 369 343 void ProcessAndUIAssertion::updateRunInBackgroundCount() 370 344 { 371 bool shouldHoldBackgroundTask = validity() != Validity::No && state() != AssertionState::Suspended;345 bool shouldHoldBackgroundTask = validity() != Validity::No && type() != ProcessAssertionType::Suspended; 372 346 if (m_isHoldingBackgroundTask == shouldHoldBackgroundTask) 373 347 return; … … 381 355 } 382 356 383 ProcessAndUIAssertion::ProcessAndUIAssertion(pid_t pid, const String& reason, AssertionState assertionState)384 : ProcessAssertion(pid, reason, assertion State)357 ProcessAndUIAssertion::ProcessAndUIAssertion(pid_t pid, const String& reason, ProcessAssertionType assertionType) 358 : ProcessAssertion(pid, reason, assertionType) 385 359 { 386 360 updateRunInBackgroundCount(); … … 393 367 } 394 368 395 void ProcessAndUIAssertion::setState(AssertionState assertionState)396 {397 ProcessAssertion::setState(assertionState);398 updateRunInBackgroundCount();399 }400 401 369 void ProcessAndUIAssertion::uiAssertionWillExpireImminently() 402 370 { -
trunk/Tools/ChangeLog
r259534 r259540 1 2020-04-04 Chris Dumez <cdumez@apple.com> 2 3 [iOS] Simplify ProcessAssertion class in preparation for switch to RunningBoard 4 https://bugs.webkit.org/show_bug.cgi?id=209984 5 <rdar://problem/61273941> 6 7 Reviewed by Darin Adler. 8 9 * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm: 10 1 11 2020-04-04 Wenson Hsieh <wenson_hsieh@apple.com> 2 12 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm
r257614 r259540 1666 1666 waitUntilServiceWorkerProcessCount(processPool, 1); 1667 1667 1668 [webView _setAssertion StateForTesting: 1];1668 [webView _setAssertionTypeForTesting: 1]; 1669 1669 waitUntilServiceWorkerProcessForegroundActivityState(webView.get(), false); 1670 1670 waitUntilServiceWorkerProcessBackgroundActivityState(webView.get(), true); 1671 1671 1672 [webView _setAssertion StateForTesting: 3];1672 [webView _setAssertionTypeForTesting: 3]; 1673 1673 waitUntilServiceWorkerProcessForegroundActivityState(webView.get(), true); 1674 1674 waitUntilServiceWorkerProcessBackgroundActivityState(webView.get(), false); 1675 1675 1676 [webView _setAssertion StateForTesting: 0];1676 [webView _setAssertionTypeForTesting: 0]; 1677 1677 waitUntilServiceWorkerProcessBackgroundActivityState(webView.get(), false); 1678 1678 waitUntilServiceWorkerProcessForegroundActivityState(webView.get(), false); … … 1686 1686 1687 1687 // The service worker process should take activity based on webView2 process. 1688 [webView2 _setAssertion StateForTesting: 1];1688 [webView2 _setAssertionTypeForTesting: 1]; 1689 1689 while (webView2.get()._hasServiceWorkerForegroundActivityForTesting || !webView2.get()._hasServiceWorkerBackgroundActivityForTesting) { 1690 [webView2 _setAssertion StateForTesting: 1];1690 [webView2 _setAssertionTypeForTesting: 1]; 1691 1691 TestWebKitAPI::Util::spinRunLoop(1); 1692 1692 } 1693 1693 1694 1694 while (!webView2.get()._hasServiceWorkerForegroundActivityForTesting || webView2.get()._hasServiceWorkerBackgroundActivityForTesting) { 1695 [webView2 _setAssertion StateForTesting: 3];1695 [webView2 _setAssertionTypeForTesting: 3]; 1696 1696 TestWebKitAPI::Util::spinRunLoop(1); 1697 1697 } 1698 1698 1699 1699 while (webView2.get()._hasServiceWorkerForegroundActivityForTesting || webView2.get()._hasServiceWorkerBackgroundActivityForTesting) { 1700 [webView2 _setAssertion StateForTesting: 0];1700 [webView2 _setAssertionTypeForTesting: 0]; 1701 1701 TestWebKitAPI::Util::spinRunLoop(1); 1702 1702 }
Note: See TracChangeset
for help on using the changeset viewer.