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