| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "mojo/services/network/url_loader_impl.h" | 5 #include "mojo/services/network/url_loader_impl.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "mojo/common/common_type_converters.h" | 9 #include "mojo/common/common_type_converters.h" |
| 10 #include "mojo/services/network/net_adapters.h" | 10 #include "mojo/services/network/net_adapters.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 response->charset = charset; | 48 response->charset = charset; |
| 49 | 49 |
| 50 return response.Pass(); | 50 return response.Pass(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Reads the request body upload data from a DataPipe. | 53 // Reads the request body upload data from a DataPipe. |
| 54 class UploadDataPipeElementReader : public net::UploadElementReader { | 54 class UploadDataPipeElementReader : public net::UploadElementReader { |
| 55 public: | 55 public: |
| 56 UploadDataPipeElementReader(ScopedDataPipeConsumerHandle pipe) | 56 UploadDataPipeElementReader(ScopedDataPipeConsumerHandle pipe) |
| 57 : pipe_(pipe.Pass()), num_bytes_(0) {} | 57 : pipe_(pipe.Pass()), num_bytes_(0) {} |
| 58 virtual ~UploadDataPipeElementReader() {} | 58 ~UploadDataPipeElementReader() override {} |
| 59 | 59 |
| 60 // UploadElementReader overrides: | 60 // UploadElementReader overrides: |
| 61 virtual int Init(const net::CompletionCallback& callback) override { | 61 int Init(const net::CompletionCallback& callback) override { |
| 62 offset_ = 0; | 62 offset_ = 0; |
| 63 ReadDataRaw(pipe_.get(), NULL, &num_bytes_, MOJO_READ_DATA_FLAG_QUERY); | 63 ReadDataRaw(pipe_.get(), NULL, &num_bytes_, MOJO_READ_DATA_FLAG_QUERY); |
| 64 return net::OK; | 64 return net::OK; |
| 65 } | 65 } |
| 66 virtual uint64 GetContentLength() const override { | 66 uint64 GetContentLength() const override { return num_bytes_; } |
| 67 return num_bytes_; | 67 uint64 BytesRemaining() const override { return num_bytes_ - offset_; } |
| 68 } | 68 bool IsInMemory() const override { return false; } |
| 69 virtual uint64 BytesRemaining() const override { | 69 int Read(net::IOBuffer* buf, |
| 70 return num_bytes_ - offset_; | 70 int buf_length, |
| 71 } | 71 const net::CompletionCallback& callback) override { |
| 72 virtual bool IsInMemory() const override { | |
| 73 return false; | |
| 74 } | |
| 75 virtual int Read(net::IOBuffer* buf, | |
| 76 int buf_length, | |
| 77 const net::CompletionCallback& callback) override { | |
| 78 uint32_t bytes_read = | 72 uint32_t bytes_read = |
| 79 std::min(static_cast<uint32_t>(BytesRemaining()), | 73 std::min(static_cast<uint32_t>(BytesRemaining()), |
| 80 static_cast<uint32_t>(buf_length)); | 74 static_cast<uint32_t>(buf_length)); |
| 81 if (bytes_read > 0) { | 75 if (bytes_read > 0) { |
| 82 ReadDataRaw(pipe_.get(), buf->data(), &bytes_read, | 76 ReadDataRaw(pipe_.get(), buf->data(), &bytes_read, |
| 83 MOJO_READ_DATA_FLAG_NONE); | 77 MOJO_READ_DATA_FLAG_NONE); |
| 84 } | 78 } |
| 85 | 79 |
| 86 offset_ += bytes_read; | 80 offset_ += bytes_read; |
| 87 return bytes_read; | 81 return bytes_read; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 if (completed_synchronously) { | 296 if (completed_synchronously) { |
| 303 base::MessageLoop::current()->PostTask( | 297 base::MessageLoop::current()->PostTask( |
| 304 FROM_HERE, | 298 FROM_HERE, |
| 305 base::Bind(&URLLoaderImpl::ReadMore, weak_ptr_factory_.GetWeakPtr())); | 299 base::Bind(&URLLoaderImpl::ReadMore, weak_ptr_factory_.GetWeakPtr())); |
| 306 } else { | 300 } else { |
| 307 ReadMore(); | 301 ReadMore(); |
| 308 } | 302 } |
| 309 } | 303 } |
| 310 | 304 |
| 311 } // namespace mojo | 305 } // namespace mojo |
| OLD | NEW |