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 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 // Java BidirectionalStream is expected to initiate the next step like ReadData | 36 // Java BidirectionalStream is expected to initiate the next step like ReadData |
37 // or Destroy. Public methods can be called on any thread. | 37 // or Destroy. Public methods can be called on any thread. |
38 class CronetBidirectionalStreamAdapter | 38 class CronetBidirectionalStreamAdapter |
39 : public net::BidirectionalStream::Delegate { | 39 : public net::BidirectionalStream::Delegate { |
40 public: | 40 public: |
41 static bool RegisterJni(JNIEnv* env); | 41 static bool RegisterJni(JNIEnv* env); |
42 | 42 |
43 CronetBidirectionalStreamAdapter( | 43 CronetBidirectionalStreamAdapter( |
44 CronetURLRequestContextAdapter* context, | 44 CronetURLRequestContextAdapter* context, |
45 JNIEnv* env, | 45 JNIEnv* env, |
46 const base::android::JavaParamRef<jobject>& jbidi_stream); | 46 const base::android::JavaParamRef<jobject>& jbidi_stream, |
| 47 bool jdisable_auto_flush); |
47 ~CronetBidirectionalStreamAdapter() override; | 48 ~CronetBidirectionalStreamAdapter() override; |
48 | 49 |
49 // Validates method and headers, initializes and starts the request. If | 50 // Validates method and headers, initializes and starts the request. If |
50 // |jend_of_stream| is true, then stream is half-closed after sending header | 51 // |jend_of_stream| is true, then stream is half-closed after sending header |
51 // frame and no data is expected to be written. | 52 // frame and no data is expected to be written. |
52 // Returns 0 if request is valid and started successfully, | 53 // Returns 0 if request is valid and started successfully, |
53 // Returns -1 if |jmethod| is not valid HTTP method name. | 54 // Returns -1 if |jmethod| is not valid HTTP method name. |
54 // Returns position of invalid header value in |jheaders| if header name is | 55 // Returns position of invalid header value in |jheaders| if header name is |
55 // not valid. | 56 // not valid. |
56 jint Start(JNIEnv* env, | 57 jint Start(JNIEnv* env, |
(...skipping 17 matching lines...) Expand all Loading... |
74 // |jlimit|-1. Arguments are preserved to ensure that |jbyte_buffer| | 75 // |jlimit|-1. Arguments are preserved to ensure that |jbyte_buffer| |
75 // is not modified by the application during write. The |jend_of_stream| is | 76 // is not modified by the application during write. The |jend_of_stream| is |
76 // passed to remote to indicate end of stream. | 77 // passed to remote to indicate end of stream. |
77 jboolean WriteData(JNIEnv* env, | 78 jboolean WriteData(JNIEnv* env, |
78 const base::android::JavaParamRef<jobject>& jcaller, | 79 const base::android::JavaParamRef<jobject>& jcaller, |
79 const base::android::JavaParamRef<jobject>& jbyte_buffer, | 80 const base::android::JavaParamRef<jobject>& jbyte_buffer, |
80 jint jposition, | 81 jint jposition, |
81 jint jlimit, | 82 jint jlimit, |
82 jboolean jend_of_stream); | 83 jboolean jend_of_stream); |
83 | 84 |
| 85 jboolean WritevData( |
| 86 JNIEnv* env, |
| 87 const base::android::JavaParamRef<jobject>& jcaller, |
| 88 const base::android::JavaParamRef<jobjectArray>& jbyte_buffers, |
| 89 const base::android::JavaParamRef<jintArray>& jpositions, |
| 90 const base::android::JavaParamRef<jintArray>& jlimits, |
| 91 jboolean jend_of_stream); |
| 92 |
84 // Releases all resources for the request and deletes the object itself. | 93 // Releases all resources for the request and deletes the object itself. |
85 // |jsend_on_canceled| indicates if Java onCanceled callback should be | 94 // |jsend_on_canceled| indicates if Java onCanceled callback should be |
86 // issued to indicate that no more callbacks will be issued. | 95 // issued to indicate that no more callbacks will be issued. |
87 void Destroy(JNIEnv* env, | 96 void Destroy(JNIEnv* env, |
88 const base::android::JavaParamRef<jobject>& jcaller, | 97 const base::android::JavaParamRef<jobject>& jcaller, |
89 jboolean jsend_on_canceled); | 98 jboolean jsend_on_canceled); |
90 | 99 |
91 private: | 100 private: |
| 101 typedef std::vector<scoped_refptr<IOBufferWithByteBuffer>> IOByteBufferList; |
92 // net::BidirectionalStream::Delegate implementations: | 102 // net::BidirectionalStream::Delegate implementations: |
93 void OnHeadersSent() override; | 103 void OnStreamReady() override; |
94 void OnHeadersReceived(const net::SpdyHeaderBlock& response_headers) override; | 104 void OnHeadersReceived(const net::SpdyHeaderBlock& response_headers) override; |
95 void OnDataRead(int bytes_read) override; | 105 void OnDataRead(int bytes_read) override; |
96 void OnDataSent() override; | 106 void OnDataSent() override; |
97 void OnTrailersReceived(const net::SpdyHeaderBlock& trailers) override; | 107 void OnTrailersReceived(const net::SpdyHeaderBlock& trailers) override; |
98 void OnFailed(int error) override; | 108 void OnFailed(int error) override; |
99 | 109 |
100 void StartOnNetworkThread( | 110 void StartOnNetworkThread( |
101 scoped_ptr<net::BidirectionalStreamRequestInfo> request_info); | 111 scoped_ptr<net::BidirectionalStreamRequestInfo> request_info); |
102 void ReadDataOnNetworkThread( | 112 void ReadDataOnNetworkThread( |
103 scoped_refptr<IOBufferWithByteBuffer> read_buffer, | 113 scoped_refptr<IOBufferWithByteBuffer> read_buffer, |
104 int buffer_size); | 114 int buffer_size); |
105 void WriteDataOnNetworkThread( | 115 void WriteDataOnNetworkThread( |
106 scoped_refptr<IOBufferWithByteBuffer> read_buffer, | 116 scoped_refptr<IOBufferWithByteBuffer> read_buffer, |
107 int buffer_size, | |
108 bool end_of_stream); | 117 bool end_of_stream); |
| 118 void WritevDataOnNetworkThread(const IOByteBufferList& buffers, |
| 119 bool end_of_stream); |
109 void DestroyOnNetworkThread(bool send_on_canceled); | 120 void DestroyOnNetworkThread(bool send_on_canceled); |
110 // Gets headers as a Java array. | 121 // Gets headers as a Java array. |
111 base::android::ScopedJavaLocalRef<jobjectArray> GetHeadersArray( | 122 base::android::ScopedJavaLocalRef<jobjectArray> GetHeadersArray( |
112 JNIEnv* env, | 123 JNIEnv* env, |
113 const net::SpdyHeaderBlock& header_block); | 124 const net::SpdyHeaderBlock& header_block); |
114 | 125 |
115 CronetURLRequestContextAdapter* const context_; | 126 CronetURLRequestContextAdapter* const context_; |
116 | 127 |
117 // Java object that owns this CronetBidirectionalStreamAdapter. | 128 // Java object that owns this CronetBidirectionalStreamAdapter. |
118 base::android::ScopedJavaGlobalRef<jobject> owner_; | 129 base::android::ScopedJavaGlobalRef<jobject> owner_; |
| 130 const bool disable_auto_flush_; |
| 131 // Whether an end of stream flag is passed in through a write call. |
| 132 // Not applicable to HTTP methods that do not send data. |
| 133 bool write_end_of_stream_; |
119 | 134 |
120 scoped_refptr<IOBufferWithByteBuffer> read_buffer_; | 135 scoped_refptr<IOBufferWithByteBuffer> read_buffer_; |
121 scoped_refptr<IOBufferWithByteBuffer> write_buffer_; | 136 scoped_refptr<IOBufferWithByteBuffer> write_buffer_; |
| 137 IOByteBufferList write_buffer_list_; |
122 scoped_ptr<net::BidirectionalStream> bidi_stream_; | 138 scoped_ptr<net::BidirectionalStream> bidi_stream_; |
123 | 139 |
124 DISALLOW_COPY_AND_ASSIGN(CronetBidirectionalStreamAdapter); | 140 DISALLOW_COPY_AND_ASSIGN(CronetBidirectionalStreamAdapter); |
125 }; | 141 }; |
126 | 142 |
127 } // namespace cronet | 143 } // namespace cronet |
128 | 144 |
129 #endif // COMPONENTS_CRONET_ANDROID_CRONET_BIDIRECTIONAL_STREAM_ADAPTER_H_ | 145 #endif // COMPONENTS_CRONET_ANDROID_CRONET_BIDIRECTIONAL_STREAM_ADAPTER_H_ |
OLD | NEW |