OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/net/crn_http_protocol_handler_proxy_with_client_thread.h" | 5 #import "ios/net/crn_http_protocol_handler_proxy_with_client_thread.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #import "ios/net/protocol_handler_util.h" | 12 #import "ios/net/protocol_handler_util.h" |
13 #include "net/base/auth.h" | 13 #include "net/base/auth.h" |
14 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
15 | 15 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." |
| 18 #endif |
| 19 |
16 // When the protocol is invalidated, no synchronization (lock) is needed: | 20 // When the protocol is invalidated, no synchronization (lock) is needed: |
17 // - The actual calls to the protocol and its invalidation are all done on | 21 // - The actual calls to the protocol and its invalidation are all done on |
18 // clientThread_ and thus are serialized. | 22 // clientThread_ and thus are serialized. |
19 // - When a proxy method is called, the protocol is compared to nil. There may | 23 // - When a proxy method is called, the protocol is compared to nil. There may |
20 // be a conflict at this point, in the case the protocol is being invalidated | 24 // be a conflict at this point, in the case the protocol is being invalidated |
21 // during this comparison. However, in such a case, the actual value of the | 25 // during this comparison. However, in such a case, the actual value of the |
22 // pointer does not matter: an invalid pointer will behave as a valid one and | 26 // pointer does not matter: an invalid pointer will behave as a valid one and |
23 // post a task on the clientThread_, and that task will be handled correctly, | 27 // post a task on the clientThread_, and that task will be handled correctly, |
24 // as described by the item above. | 28 // as described by the item above. |
25 | 29 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 DCHECK(clientThread); | 70 DCHECK(clientThread); |
67 if ((self = [super init])) { | 71 if ((self = [super init])) { |
68 _protocol = protocol; | 72 _protocol = protocol; |
69 _url.reset([[[[protocol request] URL] absoluteString] copy]); | 73 _url.reset([[[[protocol request] URL] absoluteString] copy]); |
70 _creationTime = base::Time::Now(); | 74 _creationTime = base::Time::Now(); |
71 _clientThread = clientThread; | 75 _clientThread = clientThread; |
72 // Use the common run loop mode in addition to the client thread mode, in | 76 // Use the common run loop mode in addition to the client thread mode, in |
73 // hope that our tasks are executed even if the client thread changes mode | 77 // hope that our tasks are executed even if the client thread changes mode |
74 // later on. | 78 // later on. |
75 if ([mode isEqualToString:NSRunLoopCommonModes]) | 79 if ([mode isEqualToString:NSRunLoopCommonModes]) |
76 _runLoopModes.reset([@[ NSRunLoopCommonModes ] retain]); | 80 _runLoopModes.reset(@[ NSRunLoopCommonModes ]); |
77 else | 81 else |
78 _runLoopModes.reset([@[ mode, NSRunLoopCommonModes ] retain]); | 82 _runLoopModes.reset(@[ mode, NSRunLoopCommonModes ]); |
79 _queuedInvocations.reset([[NSMutableArray alloc] init]); | 83 _queuedInvocations.reset([[NSMutableArray alloc] init]); |
80 } | 84 } |
81 return self; | 85 return self; |
82 } | 86 } |
83 | 87 |
84 - (void)invalidate { | 88 - (void)invalidate { |
85 DCHECK([NSThread currentThread] == _clientThread); | 89 DCHECK([NSThread currentThread] == _clientThread); |
86 _protocol = nil; | 90 _protocol = nil; |
87 _requestComplete = YES; | 91 _requestComplete = YES; |
88 // Note that there may still be queued invocations here, if the chrome network | 92 // Note that there may still be queued invocations here, if the chrome network |
(...skipping 30 matching lines...) Expand all Loading... |
119 NSMethodSignature* sig = [self methodSignatureForSelector:aSelector]; | 123 NSMethodSignature* sig = [self methodSignatureForSelector:aSelector]; |
120 DCHECK(sig != nil); | 124 DCHECK(sig != nil); |
121 NSInvocation* inv = [NSInvocation invocationWithMethodSignature:sig]; | 125 NSInvocation* inv = [NSInvocation invocationWithMethodSignature:sig]; |
122 [inv setTarget:self]; | 126 [inv setTarget:self]; |
123 [inv setSelector:aSelector]; | 127 [inv setSelector:aSelector]; |
124 [inv retainArguments]; | 128 [inv retainArguments]; |
125 | 129 |
126 size_t arg_index = 2; | 130 size_t arg_index = 2; |
127 va_list args; | 131 va_list args; |
128 va_start(args, aSelector); | 132 va_start(args, aSelector); |
129 NSObject* arg = va_arg(args, NSObject*); | 133 __unsafe_unretained NSObject* arg = va_arg(args, NSObject*); |
130 while (arg != nil) { | 134 while (arg != nil) { |
131 [inv setArgument:&arg atIndex:arg_index]; | 135 [inv setArgument:&arg atIndex:arg_index]; |
132 arg = va_arg(args, NSObject*); | 136 arg = va_arg(args, NSObject*); |
133 arg_index++; | 137 arg_index++; |
134 } | 138 } |
135 va_end(args); | 139 va_end(args); |
136 | 140 |
137 DCHECK(arg_index == sig.numberOfArguments); | 141 DCHECK(arg_index == sig.numberOfArguments); |
138 [self performSelector:@selector(invokeOnClientThread:) | 142 [self performSelector:@selector(invokeOnClientThread:) |
139 onThread:_clientThread | 143 onThread:_clientThread |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 } | 261 } |
258 | 262 |
259 - (void)resume { | 263 - (void)resume { |
260 DCHECK([NSThread currentThread] == _clientThread); | 264 DCHECK([NSThread currentThread] == _clientThread); |
261 DCHECK(!_requestComplete || !_protocol); | 265 DCHECK(!_requestComplete || !_protocol); |
262 _paused = NO; | 266 _paused = NO; |
263 [self runInvocationQueueOnClientThread]; | 267 [self runInvocationQueueOnClientThread]; |
264 } | 268 } |
265 | 269 |
266 @end | 270 @end |
OLD | NEW |