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/network_context.h" | 10 #include "mojo/services/network/network_context.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 } | 59 } |
60 | 60 |
61 // Reads the request body upload data from a DataPipe. | 61 // Reads the request body upload data from a DataPipe. |
62 class UploadDataPipeElementReader : public net::UploadElementReader { | 62 class UploadDataPipeElementReader : public net::UploadElementReader { |
63 public: | 63 public: |
64 UploadDataPipeElementReader(ScopedDataPipeConsumerHandle pipe) | 64 UploadDataPipeElementReader(ScopedDataPipeConsumerHandle pipe) |
65 : pipe_(pipe.Pass()), num_bytes_(0) {} | 65 : pipe_(pipe.Pass()), num_bytes_(0) {} |
66 virtual ~UploadDataPipeElementReader() {} | 66 virtual ~UploadDataPipeElementReader() {} |
67 | 67 |
68 // UploadElementReader overrides: | 68 // UploadElementReader overrides: |
69 virtual int Init(const net::CompletionCallback& callback) OVERRIDE { | 69 virtual int Init(const net::CompletionCallback& callback) override { |
70 offset_ = 0; | 70 offset_ = 0; |
71 ReadDataRaw(pipe_.get(), NULL, &num_bytes_, MOJO_READ_DATA_FLAG_QUERY); | 71 ReadDataRaw(pipe_.get(), NULL, &num_bytes_, MOJO_READ_DATA_FLAG_QUERY); |
72 return net::OK; | 72 return net::OK; |
73 } | 73 } |
74 virtual uint64 GetContentLength() const OVERRIDE { | 74 virtual uint64 GetContentLength() const override { |
75 return num_bytes_; | 75 return num_bytes_; |
76 } | 76 } |
77 virtual uint64 BytesRemaining() const OVERRIDE { | 77 virtual uint64 BytesRemaining() const override { |
78 return num_bytes_ - offset_; | 78 return num_bytes_ - offset_; |
79 } | 79 } |
80 virtual bool IsInMemory() const OVERRIDE { | 80 virtual bool IsInMemory() const override { |
81 return false; | 81 return false; |
82 } | 82 } |
83 virtual int Read(net::IOBuffer* buf, | 83 virtual int Read(net::IOBuffer* buf, |
84 int buf_length, | 84 int buf_length, |
85 const net::CompletionCallback& callback) OVERRIDE { | 85 const net::CompletionCallback& callback) override { |
86 uint32_t bytes_read = | 86 uint32_t bytes_read = |
87 std::min(static_cast<uint32_t>(BytesRemaining()), | 87 std::min(static_cast<uint32_t>(BytesRemaining()), |
88 static_cast<uint32_t>(buf_length)); | 88 static_cast<uint32_t>(buf_length)); |
89 if (bytes_read > 0) { | 89 if (bytes_read > 0) { |
90 ReadDataRaw(pipe_.get(), buf->data(), &bytes_read, | 90 ReadDataRaw(pipe_.get(), buf->data(), &bytes_read, |
91 MOJO_READ_DATA_FLAG_NONE); | 91 MOJO_READ_DATA_FLAG_NONE); |
92 } | 92 } |
93 | 93 |
94 offset_ += bytes_read; | 94 offset_ += bytes_read; |
95 return bytes_read; | 95 return bytes_read; |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 if (completed_synchronously) { | 375 if (completed_synchronously) { |
376 base::MessageLoop::current()->PostTask( | 376 base::MessageLoop::current()->PostTask( |
377 FROM_HERE, | 377 FROM_HERE, |
378 base::Bind(&URLLoaderImpl::ReadMore, weak_ptr_factory_.GetWeakPtr())); | 378 base::Bind(&URLLoaderImpl::ReadMore, weak_ptr_factory_.GetWeakPtr())); |
379 } else { | 379 } else { |
380 ReadMore(); | 380 ReadMore(); |
381 } | 381 } |
382 } | 382 } |
383 | 383 |
384 } // namespace mojo | 384 } // namespace mojo |
OLD | NEW |