Changeset 224982 in webkit
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r224977 r224982 1 2017-11-17 Alex Christensen <achristensen@webkit.org> 2 3 Use RunLoop and Mode from NetworkingContext if they are given 4 https://bugs.webkit.org/show_bug.cgi?id=179800 5 <rdar://problem/35519421> 6 7 Reviewed by Brady Eidson. 8 9 * platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm: 10 (callOnMainThreadOrSchedule): 11 (-[WebCoreResourceHandleAsOperationQueueDelegate connection:willSendRequest:redirectResponse:]): 12 (-[WebCoreResourceHandleAsOperationQueueDelegate connection:didReceiveAuthenticationChallenge:]): 13 (-[WebCoreResourceHandleAsOperationQueueDelegate connection:canAuthenticateAgainstProtectionSpace:]): 14 (-[WebCoreResourceHandleAsOperationQueueDelegate connection:didReceiveResponse:]): 15 (-[WebCoreResourceHandleAsOperationQueueDelegate connection:didReceiveData:lengthReceived:]): 16 (-[WebCoreResourceHandleAsOperationQueueDelegate connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:]): 17 (-[WebCoreResourceHandleAsOperationQueueDelegate connectionDidFinishLoading:]): 18 (-[WebCoreResourceHandleAsOperationQueueDelegate connection:didFailWithError:]): 19 (-[WebCoreResourceHandleAsOperationQueueDelegate connection:willCacheResponse:]): 20 1 21 2017-11-17 Simon Fraser <simon.fraser@apple.com> 2 22 -
trunk/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm
r224969 r224982 38 38 #import "WebCoreURLResponse.h" 39 39 #import <pal/spi/cf/CFNetworkSPI.h> 40 #import <wtf/BlockPtr.h> 40 41 #import <wtf/MainThread.h> 41 42 42 43 using namespace WebCore; 43 44 44 static SchedulePairHashSet* scheduledRunLoopPairs(ResourceHandle* handle) 45 { 46 if (!handle) 47 return nullptr; 48 if (!handle->context()) 49 return nullptr; 50 return handle->context()->scheduledRunLoopPairs(); 45 static bool scheduledWithCustomRunLoopMode(SchedulePairHashSet* pairs) 46 { 47 if (!pairs) 48 return false; 49 for (auto& pair : *pairs) { 50 auto mode = pair->mode(); 51 if (mode != kCFRunLoopCommonModes && mode != kCFRunLoopDefaultMode) 52 return true; 53 } 54 return false; 51 55 } 52 56 53 57 @implementation WebCoreResourceHandleAsOperationQueueDelegate 58 59 - (void)callFunctionOnMainThread:(Function<void()>&&)function 60 { 61 // Sync xhr uses the message queue. 62 if (m_messageQueue) 63 return m_messageQueue->append(std::make_unique<Function<void()>>(WTFMove(function))); 64 65 // This is the common case. 66 SchedulePairHashSet* pairs = m_handle && m_handle->context() ? m_handle->context()->scheduledRunLoopPairs() : nullptr; 67 if (!scheduledWithCustomRunLoopMode(pairs)) 68 return callOnMainThread(WTFMove(function)); 69 70 // If we have been scheduled in a custom run loop mode, schedule a block in that mode. 71 auto block = BlockPtr<void()>::fromCallable([alreadyCalled = false, function = WTFMove(function)] () mutable { 72 if (alreadyCalled) 73 return; 74 alreadyCalled = true; 75 function(); 76 function = nullptr; 77 }); 78 for (auto& pair : *pairs) 79 CFRunLoopPerformBlock(pair->runLoop(), pair->mode(), block.get()); 80 } 54 81 55 82 - (id)initWithHandle:(ResourceHandle*)handle messageQueue:(MessageQueue<Function<void()>>*)messageQueue … … 117 144 #endif 118 145 119 auto work = [self = self, protectedSelf = RetainPtr<id>(self), newRequest = RetainPtr<NSURLRequest>(newRequest), redirectResponse = RetainPtr<NSURLResponse>(redirectResponse)] () mutable {146 auto work = [self = self, protectedSelf = retainPtr(self), newRequest = retainPtr(newRequest), redirectResponse = retainPtr(redirectResponse)] () mutable { 120 147 if (!m_handle) { 121 148 m_requestResult = nullptr; … … 130 157 }; 131 158 132 if (m_messageQueue) 133 m_messageQueue->append(std::make_unique<Function<void()>>(WTFMove(work))); 134 else 135 callOnMainThread(WTFMove(work), scheduledRunLoopPairs(m_handle)); 136 159 [self callFunctionOnMainThread:WTFMove(work)]; 137 160 dispatch_semaphore_wait(m_semaphore, DISPATCH_TIME_FOREVER); 138 161 return m_requestResult.get(); … … 146 169 LOG(Network, "Handle %p delegate connection:%p didReceiveAuthenticationChallenge:%p", m_handle, connection, challenge); 147 170 148 auto work = [self, protectedSelf = RetainPtr<id>(self), challenge = RetainPtr<NSURLAuthenticationChallenge>(challenge)] () mutable {171 auto work = [self, protectedSelf = retainPtr(self), challenge = retainPtr(challenge)] () mutable { 149 172 if (!m_handle) { 150 173 [[challenge sender] cancelAuthenticationChallenge:challenge.get()]; … … 154 177 }; 155 178 156 if (m_messageQueue) 157 m_messageQueue->append(std::make_unique<Function<void()>>(WTFMove(work))); 158 else 159 callOnMainThread(WTFMove(work), scheduledRunLoopPairs(m_handle)); 179 [self callFunctionOnMainThread:WTFMove(work)]; 160 180 } 161 181 … … 167 187 LOG(Network, "Handle %p delegate connection:%p canAuthenticateAgainstProtectionSpace:%@://%@:%u realm:%@ method:%@ %@%@", m_handle, connection, [protectionSpace protocol], [protectionSpace host], [protectionSpace port], [protectionSpace realm], [protectionSpace authenticationMethod], [protectionSpace isProxy] ? @"proxy:" : @"", [protectionSpace isProxy] ? [protectionSpace proxyType] : @""); 168 188 169 auto work = [self = self, protectedSelf = RetainPtr<id>(self), protectionSpace = RetainPtr<NSURLProtectionSpace>(protectionSpace)] () mutable {189 auto work = [self = self, protectedSelf = retainPtr(self), protectionSpace = retainPtr(protectionSpace)] () mutable { 170 190 if (!m_handle) { 171 191 m_boolResult = NO; … … 176 196 }; 177 197 178 if (m_messageQueue) 179 m_messageQueue->append(std::make_unique<Function<void()>>(WTFMove(work))); 180 else 181 callOnMainThread(WTFMove(work), scheduledRunLoopPairs(m_handle)); 182 198 [self callFunctionOnMainThread:WTFMove(work)]; 183 199 dispatch_semaphore_wait(m_semaphore, DISPATCH_TIME_FOREVER); 184 200 return m_boolResult; … … 191 207 LOG(Network, "Handle %p delegate connection:%p didReceiveResponse:%p (HTTP status %d, reported MIMEType '%s')", m_handle, connection, r, [r respondsToSelector:@selector(statusCode)] ? [(id)r statusCode] : 0, [[r MIMEType] UTF8String]); 192 208 193 auto work = [self = self, protectedSelf = RetainPtr<id>(self), r = RetainPtr<NSURLResponse>(r), connection = RetainPtr<NSURLConnection>(connection)] () mutable {209 auto work = [self = self, protectedSelf = retainPtr(self), r = retainPtr(r), connection = retainPtr(connection)] () mutable { 194 210 RefPtr<ResourceHandle> protectedHandle(m_handle); 195 211 if (!m_handle || !m_handle->client()) { … … 215 231 }; 216 232 217 if (m_messageQueue) 218 m_messageQueue->append(std::make_unique<Function<void()>>(WTFMove(work))); 219 else 220 callOnMainThread(WTFMove(work), scheduledRunLoopPairs(m_handle)); 221 233 [self callFunctionOnMainThread:WTFMove(work)]; 222 234 dispatch_semaphore_wait(m_semaphore, DISPATCH_TIME_FOREVER); 223 235 } … … 231 243 LOG(Network, "Handle %p delegate connection:%p didReceiveData:%p lengthReceived:%lld", m_handle, connection, data, lengthReceived); 232 244 233 auto work = [self = self, protectedSelf = RetainPtr<id>(self), data = RetainPtr<NSData>(data)] () mutable {245 auto work = [self = self, protectedSelf = retainPtr(self), data = retainPtr(data)] () mutable { 234 246 if (!m_handle || !m_handle->client()) 235 247 return; … … 244 256 }; 245 257 246 if (m_messageQueue) 247 m_messageQueue->append(std::make_unique<Function<void()>>(WTFMove(work))); 248 else 249 callOnMainThread(WTFMove(work), scheduledRunLoopPairs(m_handle)); 258 [self callFunctionOnMainThread:WTFMove(work)]; 250 259 } 251 260 … … 258 267 LOG(Network, "Handle %p delegate connection:%p didSendBodyData:%d totalBytesWritten:%d totalBytesExpectedToWrite:%d", m_handle, connection, bytesWritten, totalBytesWritten, totalBytesExpectedToWrite); 259 268 260 auto work = [self = self, protectedSelf = RetainPtr<id>(self), totalBytesWritten = totalBytesWritten, totalBytesExpectedToWrite = totalBytesExpectedToWrite] () mutable {269 auto work = [self = self, protectedSelf = retainPtr(self), totalBytesWritten = totalBytesWritten, totalBytesExpectedToWrite = totalBytesExpectedToWrite] () mutable { 261 270 if (!m_handle || !m_handle->client()) 262 271 return; … … 264 273 }; 265 274 266 if (m_messageQueue) 267 m_messageQueue->append(std::make_unique<Function<void()>>(WTFMove(work))); 268 else 269 callOnMainThread(WTFMove(work), scheduledRunLoopPairs(m_handle)); 275 [self callFunctionOnMainThread:WTFMove(work)]; 270 276 } 271 277 … … 277 283 LOG(Network, "Handle %p delegate connectionDidFinishLoading:%p", m_handle, connection); 278 284 279 auto work = [self = self, protectedSelf = RetainPtr<id>(self)] () mutable {285 auto work = [self = self, protectedSelf = retainPtr(self)] () mutable { 280 286 if (!m_handle || !m_handle->client()) 281 287 return; … … 288 294 }; 289 295 290 if (m_messageQueue) 291 m_messageQueue->append(std::make_unique<Function<void()>>(WTFMove(work))); 292 else 293 callOnMainThread(WTFMove(work), scheduledRunLoopPairs(m_handle)); 296 [self callFunctionOnMainThread:WTFMove(work)]; 294 297 } 295 298 … … 301 304 LOG(Network, "Handle %p delegate connection:%p didFailWithError:%@", m_handle, connection, error); 302 305 303 auto work = [self = self, protectedSelf = RetainPtr<id>(self), error = RetainPtr<NSError>(error)] () mutable {306 auto work = [self = self, protectedSelf = retainPtr(self), error = retainPtr(error)] () mutable { 304 307 if (!m_handle || !m_handle->client()) 305 308 return; … … 312 315 }; 313 316 314 if (m_messageQueue) 315 m_messageQueue->append(std::make_unique<Function<void()>>(WTFMove(work))); 316 else 317 callOnMainThread(WTFMove(work), scheduledRunLoopPairs(m_handle)); 317 [self callFunctionOnMainThread:WTFMove(work)]; 318 318 } 319 319 … … 326 326 LOG(Network, "Handle %p delegate connection:%p willCacheResponse:%p", m_handle, connection, cachedResponse); 327 327 328 auto work = [self = self, protectedSelf = RetainPtr<id>(self), cachedResponse = RetainPtr<NSCachedURLResponse>(cachedResponse)] () mutable {328 auto work = [self = self, protectedSelf = retainPtr(self), cachedResponse = retainPtr(cachedResponse)] () mutable { 329 329 if (!m_handle || !m_handle->client()) { 330 330 m_cachedResponseResult = nullptr; … … 336 336 }; 337 337 338 if (m_messageQueue) 339 m_messageQueue->append(std::make_unique<Function<void()>>(WTFMove(work))); 340 else 341 callOnMainThread(WTFMove(work), scheduledRunLoopPairs(m_handle)); 342 338 [self callFunctionOnMainThread:WTFMove(work)]; 343 339 dispatch_semaphore_wait(m_semaphore, DISPATCH_TIME_FOREVER); 344 340 return m_cachedResponseResult.get(); -
trunk/Tools/TestWebKitAPI/Tests/mac/WebViewScheduleInRunLoop.mm
r224896 r224982 64 64 65 65 while (loadsFinished < webViewCount) 66 CFRunLoopRunInMode(CFSTR("TestRunLoopMode"), std::numeric_limits<double>::max(), true);66 CFRunLoopRunInMode(CFSTR("TestRunLoopMode"), .001, true); 67 67 } 68 68
Note:
See TracChangeset
for help on using the changeset viewer.