| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 uint64_t total_bytes_read = 0; | 527 uint64_t total_bytes_read = 0; |
| 528 while (bytes_read > 0) { | 528 while (bytes_read > 0) { |
| 529 base::scoped_nsobject<NSMutableData> data( | 529 base::scoped_nsobject<NSMutableData> data( |
| 530 [[NSMutableData alloc] initWithCapacity:bytes_read]); | 530 [[NSMutableData alloc] initWithCapacity:bytes_read]); |
| 531 // |bytes_read| should always be less or equal to |kClientMaxBufferSize|. | 531 // |bytes_read| should always be less or equal to |kClientMaxBufferSize|. |
| 532 // This is ensured by the fact that the max read buffer size (i.e. | 532 // This is ensured by the fact that the max read buffer size (i.e. |
| 533 // |kIOBufferSize|) is always smaller or equal to |kClientMaxBufferSize|. | 533 // |kIOBufferSize|) is always smaller or equal to |kClientMaxBufferSize|. |
| 534 while (bytes_read > 0 && | 534 while (bytes_read > 0 && |
| 535 [data length] + bytes_read <= kClientMaxBufferSize) { | 535 [data length] + bytes_read <= kClientMaxBufferSize) { |
| 536 total_bytes_read += bytes_read; | 536 total_bytes_read += bytes_read; |
| 537 NSUInteger data_length = [data length]; | 537 [data appendBytes:buffer_->data() length:bytes_read]; |
| 538 [data increaseLengthBy:bytes_read]; | |
| 539 memcpy(reinterpret_cast<char*>([data mutableBytes]) + data_length, | |
| 540 buffer_->data(), bytes_read); | |
| 541 bytes_read = request->Read(buffer_.get(), kIOBufferSize); | 538 bytes_read = request->Read(buffer_.get(), kIOBufferSize); |
| 542 } | 539 } |
| 543 | 540 |
| 544 if ([data length] > 0) { | 541 if ([data length] > 0) { |
| 545 // If the data is not encoded in UTF8, the NSString is nil. | 542 // If the data is not encoded in UTF8, the NSString is nil. |
| 546 DVLOG(3) << "To client:" << std::endl | 543 DVLOG(3) << "To client:" << std::endl |
| 547 << base::SysNSStringToUTF8([[NSString alloc] | 544 << base::SysNSStringToUTF8([[NSString alloc] |
| 548 initWithData:data | 545 initWithData:data |
| 549 encoding:NSUTF8StringEncoding]); | 546 encoding:NSUTF8StringEncoding]); |
| 550 [client_ didLoadData:data]; | 547 [client_ didLoadData:data]; |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 base::Bind(&net::HttpProtocolHandlerCore::Cancel, _core)); | 964 base::Bind(&net::HttpProtocolHandlerCore::Cancel, _core)); |
| 968 [_protocolProxy invalidate]; | 965 [_protocolProxy invalidate]; |
| 969 } | 966 } |
| 970 | 967 |
| 971 - (void)stopLoading { | 968 - (void)stopLoading { |
| 972 [self cancelRequest]; | 969 [self cancelRequest]; |
| 973 _protocolProxy.reset(); | 970 _protocolProxy.reset(); |
| 974 } | 971 } |
| 975 | 972 |
| 976 @end | 973 @end |
| OLD | NEW |