Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / components / cronet / android / wrapped_channel_upload_element_reader.cc
blob3027cbadab14600f46a5750c52bee900348b3e91
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
3 // found in the LICENSE file.
5 #include "components/cronet/android/wrapped_channel_upload_element_reader.h"
7 #include "base/android/jni_android.h"
8 #include "base/logging.h"
9 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h"
12 namespace cronet {
14 WrappedChannelElementReader::WrappedChannelElementReader(
15 scoped_refptr<URLRequestAdapter::URLRequestAdapterDelegate> delegate,
16 uint64 length)
17 : length_(length), offset_(0), delegate_(delegate) {
20 WrappedChannelElementReader::~WrappedChannelElementReader() {
23 int WrappedChannelElementReader::Init(const net::CompletionCallback& callback) {
24 offset_ = 0;
25 return net::OK;
28 uint64 WrappedChannelElementReader::GetContentLength() const {
29 return length_;
32 uint64 WrappedChannelElementReader::BytesRemaining() const {
33 return length_ - offset_;
36 bool WrappedChannelElementReader::IsInMemory() const {
37 return false;
40 int WrappedChannelElementReader::Read(net::IOBuffer* buf,
41 int buf_length,
42 const net::CompletionCallback& callback) {
43 DCHECK(!callback.is_null());
44 DCHECK(delegate_);
45 // TODO(mef): Post the read to file thread.
46 int bytes_read = delegate_->ReadFromUploadChannel(buf, buf_length);
47 if (bytes_read < 0)
48 return net::ERR_FAILED;
49 offset_ += bytes_read;
50 return bytes_read;
53 } // namespace cronet