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.h" | 5 #import "ios/net/crn_http_protocol_handler.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/mac/bind_objc_block.h" | 9 #include "base/mac/bind_objc_block.h" |
10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 // NSURLProtocol client, and the following clients are ordered such as the | 186 // NSURLProtocol client, and the following clients are ordered such as the |
187 // ith client is responsible for managing the (i-1)th client. | 187 // ith client is responsible for managing the (i-1)th client. |
188 base::scoped_nsobject<NSMutableArray> clients_; | 188 base::scoped_nsobject<NSMutableArray> clients_; |
189 // Weak. This is the last client in |clients_|. | 189 // Weak. This is the last client in |clients_|. |
190 id<CRNNetworkClientProtocol> top_level_client_; | 190 id<CRNNetworkClientProtocol> top_level_client_; |
191 scoped_refptr<IOBuffer> buffer_; | 191 scoped_refptr<IOBuffer> buffer_; |
192 base::scoped_nsobject<NSMutableURLRequest> request_; | 192 base::scoped_nsobject<NSMutableURLRequest> request_; |
193 // Stream delegate to read the HTTPBodyStream. | 193 // Stream delegate to read the HTTPBodyStream. |
194 base::scoped_nsobject<CRWHTTPStreamDelegate> stream_delegate_; | 194 base::scoped_nsobject<CRWHTTPStreamDelegate> stream_delegate_; |
195 // Vector of readers used to accumulate a POST data stream. | 195 // Vector of readers used to accumulate a POST data stream. |
196 ScopedVector<UploadElementReader> post_data_readers_; | 196 std::vector<scoped_ptr<UploadElementReader>> post_data_readers_; |
mmenke
2015/11/24 17:25:08
include <vector>, scoped_ptr
| |
197 | 197 |
198 // This cannot be a scoped pointer because it must be deleted on the IO | 198 // This cannot be a scoped pointer because it must be deleted on the IO |
199 // thread. | 199 // thread. |
200 URLRequest* net_request_; | 200 URLRequest* net_request_; |
201 | 201 |
202 base::WeakPtr<RequestTracker> tracker_; | 202 base::WeakPtr<RequestTracker> tracker_; |
203 | 203 |
204 DISALLOW_COPY_AND_ASSIGN(HttpProtocolHandlerCore); | 204 DISALLOW_COPY_AND_ASSIGN(HttpProtocolHandlerCore); |
205 }; | 205 }; |
206 | 206 |
(...skipping 24 matching lines...) Expand all Loading... | |
231 << base::SysNSStringToUTF8([[stream streamError] description]); | 231 << base::SysNSStringToUTF8([[stream streamError] description]); |
232 StopListeningStream(stream); | 232 StopListeningStream(stream); |
233 StopRequestWithError(NSURLErrorUnknown, ERR_UNEXPECTED); | 233 StopRequestWithError(NSURLErrorUnknown, ERR_UNEXPECTED); |
234 break; | 234 break; |
235 case NSStreamEventEndEncountered: | 235 case NSStreamEventEndEncountered: |
236 StopListeningStream(stream); | 236 StopListeningStream(stream); |
237 if (!post_data_readers_.empty()) { | 237 if (!post_data_readers_.empty()) { |
238 // NOTE: This call will result in |post_data_readers_| being cleared, | 238 // NOTE: This call will result in |post_data_readers_| being cleared, |
239 // which is the desired behavior. | 239 // which is the desired behavior. |
240 net_request_->set_upload(make_scoped_ptr( | 240 net_request_->set_upload(make_scoped_ptr( |
241 new ElementsUploadDataStream(post_data_readers_.Pass(), 0))); | 241 new ElementsUploadDataStream(std::move(post_data_readers_), 0))); |
242 DCHECK(post_data_readers_.empty()); | 242 DCHECK(post_data_readers_.empty()); |
243 } | 243 } |
244 net_request_->Start(); | 244 net_request_->Start(); |
245 if (tracker_) | 245 if (tracker_) |
246 tracker_->StartRequest(net_request_); | 246 tracker_->StartRequest(net_request_); |
247 break; | 247 break; |
248 case NSStreamEventHasBytesAvailable: { | 248 case NSStreamEventHasBytesAvailable: { |
249 NSUInteger length; | 249 NSUInteger length; |
250 DCHECK([stream isKindOfClass:[NSInputStream class]]); | 250 DCHECK([stream isKindOfClass:[NSInputStream class]]); |
251 length = [(NSInputStream*)stream read:(unsigned char*)buffer_->data() | 251 length = [(NSInputStream*)stream read:(unsigned char*)buffer_->data() |
252 maxLength:kIOBufferSize]; | 252 maxLength:kIOBufferSize]; |
253 if (length) { | 253 if (length) { |
254 std::vector<char> owned_data(buffer_->data(), buffer_->data() + length); | 254 std::vector<char> owned_data(buffer_->data(), buffer_->data() + length); |
255 post_data_readers_.push_back( | 255 post_data_readers_.push_back( |
256 new UploadOwnedBytesElementReader(&owned_data)); | 256 make_scoped_ptr(new UploadOwnedBytesElementReader(&owned_data))); |
257 } | 257 } |
258 break; | 258 break; |
259 } | 259 } |
260 case NSStreamEventNone: | 260 case NSStreamEventNone: |
261 case NSStreamEventOpenCompleted: | 261 case NSStreamEventOpenCompleted: |
262 case NSStreamEventHasSpaceAvailable: | 262 case NSStreamEventHasSpaceAvailable: |
263 break; | 263 break; |
264 default: | 264 default: |
265 NOTREACHED() << "Unexpected stream event: " << event; | 265 NOTREACHED() << "Unexpected stream event: " << event; |
266 break; | 266 break; |
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1089 [[DeferredCancellation alloc] initWithCore:[self getCore]]; | 1089 [[DeferredCancellation alloc] initWithCore:[self getCore]]; |
1090 NSArray* modes = @[ [[NSRunLoop currentRunLoop] currentMode] ]; | 1090 NSArray* modes = @[ [[NSRunLoop currentRunLoop] currentMode] ]; |
1091 [cancellation performSelector:@selector(cancel) | 1091 [cancellation performSelector:@selector(cancel) |
1092 onThread:[self getClientThread] | 1092 onThread:[self getClientThread] |
1093 withObject:nil | 1093 withObject:nil |
1094 waitUntilDone:NO | 1094 waitUntilDone:NO |
1095 modes:modes]; | 1095 modes:modes]; |
1096 } | 1096 } |
1097 | 1097 |
1098 @end | 1098 @end |
OLD | NEW |