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 "components/cronet/android/wrapped_channel_upload_element_reader.h" | 5 #include "components/cronet/android/wrapped_channel_upload_element_reader.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
11 | 11 |
12 namespace cronet { | 12 namespace cronet { |
13 | 13 |
14 WrappedChannelElementReader::WrappedChannelElementReader( | 14 WrappedChannelElementReader::WrappedChannelElementReader( |
15 scoped_refptr<URLRequestAdapter::URLRequestAdapterDelegate> delegate, | 15 scoped_refptr<URLRequestAdapter::URLRequestAdapterDelegate> delegate, |
16 uint64 length) | 16 uint64_t length) |
17 : length_(length), offset_(0), delegate_(delegate) { | 17 : length_(length), offset_(0), delegate_(delegate) {} |
18 } | |
19 | 18 |
20 WrappedChannelElementReader::~WrappedChannelElementReader() { | 19 WrappedChannelElementReader::~WrappedChannelElementReader() { |
21 } | 20 } |
22 | 21 |
23 int WrappedChannelElementReader::Init(const net::CompletionCallback& callback) { | 22 int WrappedChannelElementReader::Init(const net::CompletionCallback& callback) { |
24 if (offset_ != 0) | 23 if (offset_ != 0) |
25 return net::ERR_UPLOAD_STREAM_REWIND_NOT_SUPPORTED; | 24 return net::ERR_UPLOAD_STREAM_REWIND_NOT_SUPPORTED; |
26 return net::OK; | 25 return net::OK; |
27 } | 26 } |
28 | 27 |
29 uint64 WrappedChannelElementReader::GetContentLength() const { | 28 uint64_t WrappedChannelElementReader::GetContentLength() const { |
30 return length_; | 29 return length_; |
31 } | 30 } |
32 | 31 |
33 uint64 WrappedChannelElementReader::BytesRemaining() const { | 32 uint64_t WrappedChannelElementReader::BytesRemaining() const { |
34 return length_ - offset_; | 33 return length_ - offset_; |
35 } | 34 } |
36 | 35 |
37 bool WrappedChannelElementReader::IsInMemory() const { | 36 bool WrappedChannelElementReader::IsInMemory() const { |
38 return false; | 37 return false; |
39 } | 38 } |
40 | 39 |
41 int WrappedChannelElementReader::Read(net::IOBuffer* buf, | 40 int WrappedChannelElementReader::Read(net::IOBuffer* buf, |
42 int buf_length, | 41 int buf_length, |
43 const net::CompletionCallback& callback) { | 42 const net::CompletionCallback& callback) { |
44 DCHECK(!callback.is_null()); | 43 DCHECK(!callback.is_null()); |
45 DCHECK(delegate_.get()); | 44 DCHECK(delegate_.get()); |
46 // TODO(mef): Post the read to file thread. | 45 // TODO(mef): Post the read to file thread. |
47 int bytes_read = delegate_->ReadFromUploadChannel(buf, buf_length); | 46 int bytes_read = delegate_->ReadFromUploadChannel(buf, buf_length); |
48 if (bytes_read < 0) | 47 if (bytes_read < 0) |
49 return net::ERR_FAILED; | 48 return net::ERR_FAILED; |
50 offset_ += bytes_read; | 49 offset_ += bytes_read; |
51 return bytes_read; | 50 return bytes_read; |
52 } | 51 } |
53 | 52 |
54 } // namespace cronet | 53 } // namespace cronet |
55 | 54 |
OLD | NEW |