| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // or Destroy. Public methods can be called on any thread. | 64 // or Destroy. Public methods can be called on any thread. |
| 65 class CronetBidirectionalStreamAdapter | 65 class CronetBidirectionalStreamAdapter |
| 66 : public net::BidirectionalStream::Delegate { | 66 : public net::BidirectionalStream::Delegate { |
| 67 public: | 67 public: |
| 68 static bool RegisterJni(JNIEnv* env); | 68 static bool RegisterJni(JNIEnv* env); |
| 69 | 69 |
| 70 CronetBidirectionalStreamAdapter( | 70 CronetBidirectionalStreamAdapter( |
| 71 CronetURLRequestContextAdapter* context, | 71 CronetURLRequestContextAdapter* context, |
| 72 JNIEnv* env, | 72 JNIEnv* env, |
| 73 const base::android::JavaParamRef<jobject>& jbidi_stream, | 73 const base::android::JavaParamRef<jobject>& jbidi_stream, |
| 74 bool jdisable_auto_flush); | 74 bool jsend_request_headers_automatically); |
| 75 ~CronetBidirectionalStreamAdapter() override; | 75 ~CronetBidirectionalStreamAdapter() override; |
| 76 | 76 |
| 77 // Validates method and headers, initializes and starts the request. If | 77 // Validates method and headers, initializes and starts the request. If |
| 78 // |jend_of_stream| is true, then stream is half-closed after sending header | 78 // |jend_of_stream| is true, then stream is half-closed after sending header |
| 79 // frame and no data is expected to be written. | 79 // frame and no data is expected to be written. |
| 80 // Returns 0 if request is valid and started successfully, | 80 // Returns 0 if request is valid and started successfully, |
| 81 // Returns -1 if |jmethod| is not valid HTTP method name. | 81 // Returns -1 if |jmethod| is not valid HTTP method name. |
| 82 // Returns position of invalid header value in |jheaders| if header name is | 82 // Returns position of invalid header value in |jheaders| if header name is |
| 83 // not valid. | 83 // not valid. |
| 84 jint Start(JNIEnv* env, | 84 jint Start(JNIEnv* env, |
| 85 const base::android::JavaParamRef<jobject>& jcaller, | 85 const base::android::JavaParamRef<jobject>& jcaller, |
| 86 const base::android::JavaParamRef<jstring>& jurl, | 86 const base::android::JavaParamRef<jstring>& jurl, |
| 87 jint jpriority, | 87 jint jpriority, |
| 88 const base::android::JavaParamRef<jstring>& jmethod, | 88 const base::android::JavaParamRef<jstring>& jmethod, |
| 89 const base::android::JavaParamRef<jobjectArray>& jheaders, | 89 const base::android::JavaParamRef<jobjectArray>& jheaders, |
| 90 jboolean jend_of_stream); | 90 jboolean jend_of_stream); |
| 91 | 91 |
| 92 // Sends request headers to server. This is only required when |
| 93 // |send_request_headers_automatically| is false. |
| 94 // If |delay_headers_until_next_data| is true, headers will be sent |
| 95 // automatically by the stream when stream is negotiated successfully. |
| 96 void SendRequestHeaders(JNIEnv* env, |
| 97 const base::android::JavaParamRef<jobject>& jcaller); |
| 98 |
| 92 // Reads more data into |jbyte_buffer| starting at |jposition| and not | 99 // Reads more data into |jbyte_buffer| starting at |jposition| and not |
| 93 // exceeding |jlimit|. Arguments are preserved to ensure that |jbyte_buffer| | 100 // exceeding |jlimit|. Arguments are preserved to ensure that |jbyte_buffer| |
| 94 // is not modified by the application during read. | 101 // is not modified by the application during read. |
| 95 jboolean ReadData(JNIEnv* env, | 102 jboolean ReadData(JNIEnv* env, |
| 96 const base::android::JavaParamRef<jobject>& jcaller, | 103 const base::android::JavaParamRef<jobject>& jcaller, |
| 97 const base::android::JavaParamRef<jobject>& jbyte_buffer, | 104 const base::android::JavaParamRef<jobject>& jbyte_buffer, |
| 98 jint jposition, | 105 jint jposition, |
| 99 jint jlimit); | 106 jint jlimit); |
| 100 | 107 |
| 101 // Writes more data from |jbyte_buffers|. For the i_th buffer in | 108 // Writes more data from |jbyte_buffers|. For the i_th buffer in |
| (...skipping 12 matching lines...) Expand all Loading... |
| 114 | 121 |
| 115 // Releases all resources for the request and deletes the object itself. | 122 // Releases all resources for the request and deletes the object itself. |
| 116 // |jsend_on_canceled| indicates if Java onCanceled callback should be | 123 // |jsend_on_canceled| indicates if Java onCanceled callback should be |
| 117 // issued to indicate that no more callbacks will be issued. | 124 // issued to indicate that no more callbacks will be issued. |
| 118 void Destroy(JNIEnv* env, | 125 void Destroy(JNIEnv* env, |
| 119 const base::android::JavaParamRef<jobject>& jcaller, | 126 const base::android::JavaParamRef<jobject>& jcaller, |
| 120 jboolean jsend_on_canceled); | 127 jboolean jsend_on_canceled); |
| 121 | 128 |
| 122 private: | 129 private: |
| 123 // net::BidirectionalStream::Delegate implementations: | 130 // net::BidirectionalStream::Delegate implementations: |
| 124 void OnStreamReady() override; | 131 void OnStreamReady(bool request_headers_sent) override; |
| 125 void OnHeadersReceived(const net::SpdyHeaderBlock& response_headers) override; | 132 void OnHeadersReceived(const net::SpdyHeaderBlock& response_headers) override; |
| 126 void OnDataRead(int bytes_read) override; | 133 void OnDataRead(int bytes_read) override; |
| 127 void OnDataSent() override; | 134 void OnDataSent() override; |
| 128 void OnTrailersReceived(const net::SpdyHeaderBlock& trailers) override; | 135 void OnTrailersReceived(const net::SpdyHeaderBlock& trailers) override; |
| 129 void OnFailed(int error) override; | 136 void OnFailed(int error) override; |
| 130 | 137 |
| 131 void StartOnNetworkThread( | 138 void StartOnNetworkThread( |
| 132 std::unique_ptr<net::BidirectionalStreamRequestInfo> request_info); | 139 std::unique_ptr<net::BidirectionalStreamRequestInfo> request_info); |
| 140 void SendRequestHeadersOnNetworkThread(); |
| 133 void ReadDataOnNetworkThread( | 141 void ReadDataOnNetworkThread( |
| 134 scoped_refptr<IOBufferWithByteBuffer> read_buffer, | 142 scoped_refptr<IOBufferWithByteBuffer> read_buffer, |
| 135 int buffer_size); | 143 int buffer_size); |
| 136 void WritevDataOnNetworkThread( | 144 void WritevDataOnNetworkThread( |
| 137 std::unique_ptr<PendingWriteData> pending_write_data); | 145 std::unique_ptr<PendingWriteData> pending_write_data); |
| 138 void DestroyOnNetworkThread(bool send_on_canceled); | 146 void DestroyOnNetworkThread(bool send_on_canceled); |
| 139 // Gets headers as a Java array. | 147 // Gets headers as a Java array. |
| 140 base::android::ScopedJavaLocalRef<jobjectArray> GetHeadersArray( | 148 base::android::ScopedJavaLocalRef<jobjectArray> GetHeadersArray( |
| 141 JNIEnv* env, | 149 JNIEnv* env, |
| 142 const net::SpdyHeaderBlock& header_block); | 150 const net::SpdyHeaderBlock& header_block); |
| 143 | 151 |
| 144 CronetURLRequestContextAdapter* const context_; | 152 CronetURLRequestContextAdapter* const context_; |
| 145 | 153 |
| 146 // Java object that owns this CronetBidirectionalStreamAdapter. | 154 // Java object that owns this CronetBidirectionalStreamAdapter. |
| 147 base::android::ScopedJavaGlobalRef<jobject> owner_; | 155 base::android::ScopedJavaGlobalRef<jobject> owner_; |
| 148 const bool disable_auto_flush_; | 156 const bool send_request_headers_automatically_; |
| 149 | 157 |
| 150 scoped_refptr<IOBufferWithByteBuffer> read_buffer_; | 158 scoped_refptr<IOBufferWithByteBuffer> read_buffer_; |
| 151 std::unique_ptr<PendingWriteData> pending_write_data_; | 159 std::unique_ptr<PendingWriteData> pending_write_data_; |
| 152 std::unique_ptr<net::BidirectionalStream> bidi_stream_; | 160 std::unique_ptr<net::BidirectionalStream> bidi_stream_; |
| 153 | 161 |
| 154 // Whether BidirectionalStream::Delegate::OnFailed callback is invoked. | 162 // Whether BidirectionalStream::Delegate::OnFailed callback is invoked. |
| 155 bool stream_failed_; | 163 bool stream_failed_; |
| 156 | 164 |
| 157 DISALLOW_COPY_AND_ASSIGN(CronetBidirectionalStreamAdapter); | 165 DISALLOW_COPY_AND_ASSIGN(CronetBidirectionalStreamAdapter); |
| 158 }; | 166 }; |
| 159 | 167 |
| 160 } // namespace cronet | 168 } // namespace cronet |
| 161 | 169 |
| 162 #endif // COMPONENTS_CRONET_ANDROID_CRONET_BIDIRECTIONAL_STREAM_ADAPTER_H_ | 170 #endif // COMPONENTS_CRONET_ANDROID_CRONET_BIDIRECTIONAL_STREAM_ADAPTER_H_ |
| OLD | NEW |