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 #ifndef COMPONENTS_CRONET_ANDROID_WRAPPED_CHANNEL_UPLOAD_ELEMENT_READER_H_ | 5 #ifndef COMPONENTS_CRONET_ANDROID_WRAPPED_CHANNEL_UPLOAD_ELEMENT_READER_H_ |
6 #define COMPONENTS_CRONET_ANDROID_WRAPPED_CHANNEL_UPLOAD_ELEMENT_READER_H_ | 6 #define COMPONENTS_CRONET_ANDROID_WRAPPED_CHANNEL_UPLOAD_ELEMENT_READER_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "components/cronet/android/url_request_peer.h" |
12 #include "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
13 #include "net/base/upload_element_reader.h" | 14 #include "net/base/upload_element_reader.h" |
14 | 15 |
15 namespace net { | 16 namespace net { |
16 class IOBuffer; | 17 class IOBuffer; |
17 } // namespace net | 18 } // namespace net |
18 | 19 |
19 namespace cronet { | 20 namespace cronet { |
20 | 21 |
21 bool WrappedChannelRegisterJni(JNIEnv* env); | |
22 | |
23 // An UploadElementReader implementation for | 22 // An UploadElementReader implementation for |
24 // java.nio.channels.ReadableByteChannel. | 23 // java.nio.channels.ReadableByteChannel. |
25 // |channel_| should outlive this class because this class does not take the | 24 // |channel_| should outlive this class because this class does not take the |
26 // ownership of the data. | 25 // ownership of the data. |
27 class WrappedChannelElementReader : public net::UploadElementReader { | 26 class WrappedChannelElementReader : public net::UploadElementReader { |
28 public: | 27 public: |
29 WrappedChannelElementReader(JNIEnv* env, jobject channel, uint64 length); | 28 WrappedChannelElementReader( |
| 29 JNIEnv* env, |
| 30 scoped_refptr<URLRequestPeer::URLRequestPeerDelegate> delegate, |
| 31 uint64 length); |
30 virtual ~WrappedChannelElementReader(); | 32 virtual ~WrappedChannelElementReader(); |
31 | 33 |
32 // UploadElementReader overrides: | 34 // UploadElementReader overrides: |
33 virtual int Init(const net::CompletionCallback& callback) OVERRIDE; | 35 virtual int Init(const net::CompletionCallback& callback) OVERRIDE; |
34 virtual uint64 GetContentLength() const OVERRIDE; | 36 virtual uint64 GetContentLength() const OVERRIDE; |
35 virtual uint64 BytesRemaining() const OVERRIDE; | 37 virtual uint64 BytesRemaining() const OVERRIDE; |
36 virtual bool IsInMemory() const OVERRIDE; | 38 virtual bool IsInMemory() const OVERRIDE; |
37 virtual int Read(net::IOBuffer* buf, | 39 virtual int Read(net::IOBuffer* buf, |
38 int buf_length, | 40 int buf_length, |
39 const net::CompletionCallback& callback) OVERRIDE; | 41 const net::CompletionCallback& callback) OVERRIDE; |
40 | 42 |
41 private: | 43 private: |
42 const uint64 length_; | 44 const uint64 length_; |
43 uint64 offset_; | 45 uint64 offset_; |
44 jobject channel_; | 46 scoped_refptr<URLRequestPeer::URLRequestPeerDelegate> delegate_; |
45 | 47 |
46 DISALLOW_COPY_AND_ASSIGN(WrappedChannelElementReader); | 48 DISALLOW_COPY_AND_ASSIGN(WrappedChannelElementReader); |
47 }; | 49 }; |
48 | 50 |
49 } // namespace cronet | 51 } // namespace cronet |
50 | 52 |
51 #endif // COMPONENTS_CRONET_ANDROID_WRAPPED_CHANNEL_UPLOAD_ELEMENT_READER_H_ | 53 #endif // COMPONENTS_CRONET_ANDROID_WRAPPED_CHANNEL_UPLOAD_ELEMENT_READER_H_ |
OLD | NEW |