Commit 4d000d1b authored by kapishnikov's avatar kapishnikov Committed by Commit bot

Cronet iOS: Delete CRNPauseableHTTPProtocolHandler

BUG=711783
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.android:android_cronet_tester

Review-Url: https://codereview.chromium.org/2856693002
Cr-Commit-Position: refs/heads/master@{#468639}
parent 18323acb
......@@ -260,7 +260,7 @@ class CronetHttpProtocolHandlerDelegate
[NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]];
// Register the chrome http protocol handler to replace the default one.
BOOL success =
[NSURLProtocol registerClass:[CRNPauseableHTTPProtocolHandler class]];
[NSURLProtocol registerClass:[CRNHTTPProtocolHandler class]];
DCHECK(success);
}
......@@ -270,11 +270,11 @@ class CronetHttpProtocolHandlerDelegate
[NSURLCache setSharedURLCache:gPreservedSharedURLCache];
gPreservedSharedURLCache = nil;
}
[NSURLProtocol unregisterClass:[CRNPauseableHTTPProtocolHandler class]];
[NSURLProtocol unregisterClass:[CRNHTTPProtocolHandler class]];
}
+ (void)installIntoSessionConfiguration:(NSURLSessionConfiguration*)config {
config.protocolClasses = @[ [CRNPauseableHTTPProtocolHandler class] ];
config.protocolClasses = @[ [CRNHTTPProtocolHandler class] ];
}
+ (NSString*)getNetLogPathForFile:(NSString*)fileName {
......
......@@ -311,7 +311,7 @@ void CrNetEnvironment::Install() {
void CrNetEnvironment::InstallIntoSessionConfiguration(
NSURLSessionConfiguration* config) {
config.protocolClasses = @[ [CRNPauseableHTTPProtocolHandler class] ];
config.protocolClasses = @[ [CRNHTTPProtocolHandler class] ];
}
CrNetEnvironment::~CrNetEnvironment() {
......@@ -328,14 +328,14 @@ void CrNetEnvironment::SetHTTPProtocolHandlerRegistered(bool registered) {
[NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]];
// Register the chrome http protocol handler to replace the default one.
BOOL success =
[NSURLProtocol registerClass:[CRNPauseableHTTPProtocolHandler class]];
[NSURLProtocol registerClass:[CRNHTTPProtocolHandler class]];
DCHECK(success);
} else {
// Set up an empty default cache, with default size.
// TODO(droger): If the NSURLCache is to be used, its size should most
// likely be changed. On an iPod2 with iOS4, the default size is 512k.
[NSURLCache setSharedURLCache:[[[NSURLCache alloc] init] autorelease]];
[NSURLProtocol unregisterClass:[CRNPauseableHTTPProtocolHandler class]];
[NSURLProtocol unregisterClass:[CRNHTTPProtocolHandler class]];
}
}
......
......@@ -40,13 +40,4 @@ class HTTPProtocolHandlerDelegate {
@interface CRNHTTPProtocolHandler : NSURLProtocol
@end
// Custom NSURLProtocol handling HTTP and HTTPS requests.
// The HttpProtocolHandler is registered as a NSURLProtocol in the iOS system.
// This protocol is called for each NSURLRequest. This allows handling the
// requests issued by UIWebView using our own network stack. This protocol
// handler implements iOS 8 NSURLProtocol pause/resume semantics, in which
// |startLoading| means "start or resume" and |stopLoading| means "pause".
@interface CRNPauseableHTTPProtocolHandler : CRNHTTPProtocolHandler
@end
#endif // IOS_NET_CRN_HTTP_PROTOCOL_HANDLER_H_
......@@ -965,77 +965,3 @@ void HttpProtocolHandlerCore::StripPostSpecificHeaders(
}
@end
#pragma mark -
#pragma mark PauseableHttpProtocolHandler
// The HttpProtocolHandler is called by the iOS system to handle the
// NSURLRequest. This HttpProtocolHandler conforms to the observed semantics of
// NSURLProtocol when used with NSURLSession on iOS 8 - i.e., |-startLoading|
// means "start or resume request" and |-stopLoading| means "pause request".
// Since there is no way to actually pause a request in the network stack, this
// is implemented using a subclass of CRNHTTPProtocolHandlerProxy that knows how
// to defer callbacks.
//
// Note that this class conforms to somewhat complex threading rules:
// 1) |initWithRequest:cachedResponse:client:| and |dealloc| can be called on
// any thread.
// 2) |startLoading| and |stopLoading| are always called on the client thread.
// 3) |stopLoading| is called before |dealloc| is called.
//
// The main wrinkle is that |dealloc|, which may be called on any thread, needs
// to clean up a running network request. To do this, |dealloc| needs to run
// |cancelRequest|, which needs to be run on the client thread. Since it is
// guaranteed that |startLoading| is called before |dealloc| is called, the
// |startLoading| method stores a pointer to the client thread, then |dealloc|
// asks that client thread to perform the |cancelRequest| selector via
// |scheduleCancelRequest|.
//
// Some of the above logic is implemented in the parent class
// (CRNHTTPProtocolHandler) because it is convenient.
@implementation CRNPauseableHTTPProtocolHandler {
BOOL _started;
dispatch_queue_t _queue;
}
#pragma mark NSURLProtocol methods
- (void)dealloc {
[self scheduleCancelRequest];
}
#pragma mark NSURLProtocol overrides.
- (void)startLoading {
if (_started) {
[[self getProtocolHandlerProxy] resume];
return;
}
_started = YES;
[super startLoading];
}
- (void)stopLoading {
[[self getProtocolHandlerProxy] pause];
}
// This method has unusual concurrency properties. It can be called on any
// thread, but it must be called from |-dealloc|, which guarantees that no other
// method of this object is running concurrently (since |-dealloc| is only
// called when the last reference to the object drops).
//
// This method takes a reference to _core to ensure that _core lives long enough
// to have the request cleanly cancelled.
- (void)scheduleCancelRequest {
DeferredCancellation* cancellation =
[[DeferredCancellation alloc] initWithCore:[self getCore]];
NSArray* modes = @[ [[NSRunLoop currentRunLoop] currentMode] ];
[cancellation performSelector:@selector(cancel)
onThread:[self getClientThread]
withObject:nil
waitUntilDone:NO
modes:modes];
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment