Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_CRONET_BIDIRECTIONAL_STREAM_ADAPTER_H_ | 5 #ifndef COMPONENTS_CRONET_ANDROID_CRONET_BIDIRECTIONAL_STREAM_ADAPTER_H_ |
| 6 #define COMPONENTS_CRONET_ANDROID_CRONET_BIDIRECTIONAL_STREAM_ADAPTER_H_ | 6 #define COMPONENTS_CRONET_ANDROID_CRONET_BIDIRECTIONAL_STREAM_ADAPTER_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 namespace net { | 21 namespace net { |
| 22 struct BidirectionalStreamRequestInfo; | 22 struct BidirectionalStreamRequestInfo; |
| 23 class SpdyHeaderBlock; | 23 class SpdyHeaderBlock; |
| 24 } // namespace net | 24 } // namespace net |
| 25 | 25 |
| 26 namespace cronet { | 26 namespace cronet { |
| 27 | 27 |
| 28 class CronetURLRequestContextAdapter; | 28 class CronetURLRequestContextAdapter; |
| 29 class IOBufferWithByteBuffer; | 29 class IOBufferWithByteBuffer; |
| 30 | 30 |
| 31 // Convenient wrapper to hold Java references and data to represent the pending | |
| 32 // data to be written. | |
| 33 struct PendingWriteData { | |
| 34 PendingWriteData(JNIEnv* env, | |
| 35 jobjectArray jwrite_buffer_list, | |
| 36 jintArray jwrite_buffer_pos_list, | |
| 37 jintArray jwrite_buffer_limit_list, | |
| 38 jboolean jwrite_end_of_stream); | |
| 39 ~PendingWriteData(); | |
| 40 | |
| 41 base::android::ScopedJavaGlobalRef<jobjectArray> jwrite_buffer_list; | |
| 42 base::android::ScopedJavaGlobalRef<jintArray> jwrite_buffer_pos_list; | |
| 43 base::android::ScopedJavaGlobalRef<jintArray> jwrite_buffer_limit_list; | |
| 44 jboolean jwrite_end_of_stream; | |
| 45 std::vector<scoped_refptr<net::IOBuffer>> write_buffer_list; | |
|
mef
2016/05/13 15:12:58
My concern about using net::IOBuffer insted of IOB
xunjieli
2016/05/13 15:35:22
But the Java ByteBuffer is not going to be destroy
mef
2016/05/16 13:54:18
Yeah, that's fine.
| |
| 46 std::vector<int> write_buffer_len_list; | |
| 47 | |
| 48 DISALLOW_COPY_AND_ASSIGN(PendingWriteData); | |
| 49 }; | |
| 50 | |
| 31 // An adapter from Java BidirectionalStream object to net::BidirectionalStream. | 51 // An adapter from Java BidirectionalStream object to net::BidirectionalStream. |
| 32 // Created and configured from a Java thread. Start, ReadData, WritevData and | 52 // Created and configured from a Java thread. Start, ReadData, WritevData and |
| 33 // Destroy can be called on any thread (including network thread), and post | 53 // Destroy can be called on any thread (including network thread), and post |
| 34 // calls to corresponding {Start|ReadData|WritevData|Destroy}OnNetworkThread to | 54 // calls to corresponding {Start|ReadData|WritevData|Destroy}OnNetworkThread to |
| 35 // the network thread. The object is always deleted on network thread. All | 55 // the network thread. The object is always deleted on network thread. All |
| 36 // callbacks into the Java BidirectionalStream are done on the network thread. | 56 // callbacks into the Java BidirectionalStream are done on the network thread. |
| 37 // Java BidirectionalStream is expected to initiate the next step like ReadData | 57 // Java BidirectionalStream is expected to initiate the next step like ReadData |
| 38 // or Destroy. Public methods can be called on any thread. | 58 // or Destroy. Public methods can be called on any thread. |
| 39 class CronetBidirectionalStreamAdapter | 59 class CronetBidirectionalStreamAdapter |
| 40 : public net::BidirectionalStream::Delegate { | 60 : public net::BidirectionalStream::Delegate { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 jboolean jend_of_stream); | 107 jboolean jend_of_stream); |
| 88 | 108 |
| 89 // Releases all resources for the request and deletes the object itself. | 109 // Releases all resources for the request and deletes the object itself. |
| 90 // |jsend_on_canceled| indicates if Java onCanceled callback should be | 110 // |jsend_on_canceled| indicates if Java onCanceled callback should be |
| 91 // issued to indicate that no more callbacks will be issued. | 111 // issued to indicate that no more callbacks will be issued. |
| 92 void Destroy(JNIEnv* env, | 112 void Destroy(JNIEnv* env, |
| 93 const base::android::JavaParamRef<jobject>& jcaller, | 113 const base::android::JavaParamRef<jobject>& jcaller, |
| 94 jboolean jsend_on_canceled); | 114 jboolean jsend_on_canceled); |
| 95 | 115 |
| 96 private: | 116 private: |
| 97 typedef std::vector<scoped_refptr<IOBufferWithByteBuffer>> | |
| 98 IOBufferWithByteBufferList; | |
| 99 // net::BidirectionalStream::Delegate implementations: | 117 // net::BidirectionalStream::Delegate implementations: |
| 100 void OnStreamReady() override; | 118 void OnStreamReady() override; |
| 101 void OnHeadersReceived(const net::SpdyHeaderBlock& response_headers) override; | 119 void OnHeadersReceived(const net::SpdyHeaderBlock& response_headers) override; |
| 102 void OnDataRead(int bytes_read) override; | 120 void OnDataRead(int bytes_read) override; |
| 103 void OnDataSent() override; | 121 void OnDataSent() override; |
| 104 void OnTrailersReceived(const net::SpdyHeaderBlock& trailers) override; | 122 void OnTrailersReceived(const net::SpdyHeaderBlock& trailers) override; |
| 105 void OnFailed(int error) override; | 123 void OnFailed(int error) override; |
| 106 | 124 |
| 107 void StartOnNetworkThread( | 125 void StartOnNetworkThread( |
| 108 std::unique_ptr<net::BidirectionalStreamRequestInfo> request_info); | 126 std::unique_ptr<net::BidirectionalStreamRequestInfo> request_info); |
| 109 void ReadDataOnNetworkThread( | 127 void ReadDataOnNetworkThread( |
| 110 scoped_refptr<IOBufferWithByteBuffer> read_buffer, | 128 scoped_refptr<IOBufferWithByteBuffer> read_buffer, |
| 111 int buffer_size); | 129 int buffer_size); |
| 112 void WritevDataOnNetworkThread(const IOBufferWithByteBufferList& buffers, | 130 void WritevDataOnNetworkThread( |
| 113 bool end_of_stream); | 131 std::unique_ptr<PendingWriteData> pending_write_data); |
| 114 void DestroyOnNetworkThread(bool send_on_canceled); | 132 void DestroyOnNetworkThread(bool send_on_canceled); |
| 115 // Gets headers as a Java array. | 133 // Gets headers as a Java array. |
| 116 base::android::ScopedJavaLocalRef<jobjectArray> GetHeadersArray( | 134 base::android::ScopedJavaLocalRef<jobjectArray> GetHeadersArray( |
| 117 JNIEnv* env, | 135 JNIEnv* env, |
| 118 const net::SpdyHeaderBlock& header_block); | 136 const net::SpdyHeaderBlock& header_block); |
| 119 | 137 |
| 120 CronetURLRequestContextAdapter* const context_; | 138 CronetURLRequestContextAdapter* const context_; |
| 121 | 139 |
| 122 // Java object that owns this CronetBidirectionalStreamAdapter. | 140 // Java object that owns this CronetBidirectionalStreamAdapter. |
| 123 base::android::ScopedJavaGlobalRef<jobject> owner_; | 141 base::android::ScopedJavaGlobalRef<jobject> owner_; |
| 124 const bool disable_auto_flush_; | 142 const bool disable_auto_flush_; |
| 125 // Whether an end of stream flag is passed in through a write call. | 143 // Whether an end of stream flag is passed in through a write call. |
| 126 // Not applicable to HTTP methods that do not send data. | 144 // Not applicable to HTTP methods that do not send data. |
| 127 bool write_end_of_stream_; | 145 bool write_end_of_stream_; |
| 128 | 146 |
| 129 scoped_refptr<IOBufferWithByteBuffer> read_buffer_; | 147 scoped_refptr<IOBufferWithByteBuffer> read_buffer_; |
| 130 IOBufferWithByteBufferList write_buffer_list_; | 148 std::unique_ptr<PendingWriteData> pending_write_data_; |
| 131 std::unique_ptr<net::BidirectionalStream> bidi_stream_; | 149 std::unique_ptr<net::BidirectionalStream> bidi_stream_; |
| 132 | 150 |
| 133 // Whether BidirectionalStream::Delegate::OnFailed callback is invoked. | 151 // Whether BidirectionalStream::Delegate::OnFailed callback is invoked. |
| 134 bool stream_failed_; | 152 bool stream_failed_; |
| 135 | 153 |
| 136 DISALLOW_COPY_AND_ASSIGN(CronetBidirectionalStreamAdapter); | 154 DISALLOW_COPY_AND_ASSIGN(CronetBidirectionalStreamAdapter); |
| 137 }; | 155 }; |
| 138 | 156 |
| 139 } // namespace cronet | 157 } // namespace cronet |
| 140 | 158 |
| 141 #endif // COMPONENTS_CRONET_ANDROID_CRONET_BIDIRECTIONAL_STREAM_ADAPTER_H_ | 159 #endif // COMPONENTS_CRONET_ANDROID_CRONET_BIDIRECTIONAL_STREAM_ADAPTER_H_ |
| OLD | NEW |