Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: components/cronet/android/cronet_bidirectional_stream_adapter.h

Issue 1992953004: [Cronet] Make delaying sending request headers explicit in bidirectional stream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: correct a typo Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.
93 // When |send_request_headers_automatically_| is
94 // false and OnStreamReady() is invoked with request_headers_sent = false,
95 // headers will be combined with next WriteData/WritevData unless this
96 // method is called first, in which case headers will be sent separately
97 // without delay.
98 // (This method cannot be called when |send_request_headers_automatically_| is
99 // true nor when OnStreamReady() is invoked with request_headers_sent = true,
100 // since headers have been sent by the stream when stream is negotiated
101 // successfully.)
102 void SendRequestHeaders(JNIEnv* env,
103 const base::android::JavaParamRef<jobject>& jcaller);
104
92 // Reads more data into |jbyte_buffer| starting at |jposition| and not 105 // Reads more data into |jbyte_buffer| starting at |jposition| and not
93 // exceeding |jlimit|. Arguments are preserved to ensure that |jbyte_buffer| 106 // exceeding |jlimit|. Arguments are preserved to ensure that |jbyte_buffer|
94 // is not modified by the application during read. 107 // is not modified by the application during read.
95 jboolean ReadData(JNIEnv* env, 108 jboolean ReadData(JNIEnv* env,
96 const base::android::JavaParamRef<jobject>& jcaller, 109 const base::android::JavaParamRef<jobject>& jcaller,
97 const base::android::JavaParamRef<jobject>& jbyte_buffer, 110 const base::android::JavaParamRef<jobject>& jbyte_buffer,
98 jint jposition, 111 jint jposition,
99 jint jlimit); 112 jint jlimit);
100 113
101 // Writes more data from |jbyte_buffers|. For the i_th buffer in 114 // Writes more data from |jbyte_buffers|. For the i_th buffer in
(...skipping 12 matching lines...) Expand all
114 127
115 // Releases all resources for the request and deletes the object itself. 128 // Releases all resources for the request and deletes the object itself.
116 // |jsend_on_canceled| indicates if Java onCanceled callback should be 129 // |jsend_on_canceled| indicates if Java onCanceled callback should be
117 // issued to indicate that no more callbacks will be issued. 130 // issued to indicate that no more callbacks will be issued.
118 void Destroy(JNIEnv* env, 131 void Destroy(JNIEnv* env,
119 const base::android::JavaParamRef<jobject>& jcaller, 132 const base::android::JavaParamRef<jobject>& jcaller,
120 jboolean jsend_on_canceled); 133 jboolean jsend_on_canceled);
121 134
122 private: 135 private:
123 // net::BidirectionalStream::Delegate implementations: 136 // net::BidirectionalStream::Delegate implementations:
124 void OnStreamReady() override; 137 void OnStreamReady(bool request_headers_sent) override;
125 void OnHeadersReceived(const net::SpdyHeaderBlock& response_headers) override; 138 void OnHeadersReceived(const net::SpdyHeaderBlock& response_headers) override;
126 void OnDataRead(int bytes_read) override; 139 void OnDataRead(int bytes_read) override;
127 void OnDataSent() override; 140 void OnDataSent() override;
128 void OnTrailersReceived(const net::SpdyHeaderBlock& trailers) override; 141 void OnTrailersReceived(const net::SpdyHeaderBlock& trailers) override;
129 void OnFailed(int error) override; 142 void OnFailed(int error) override;
130 143
131 void StartOnNetworkThread( 144 void StartOnNetworkThread(
132 std::unique_ptr<net::BidirectionalStreamRequestInfo> request_info); 145 std::unique_ptr<net::BidirectionalStreamRequestInfo> request_info);
146 void SendRequestHeadersOnNetworkThread();
133 void ReadDataOnNetworkThread( 147 void ReadDataOnNetworkThread(
134 scoped_refptr<IOBufferWithByteBuffer> read_buffer, 148 scoped_refptr<IOBufferWithByteBuffer> read_buffer,
135 int buffer_size); 149 int buffer_size);
136 void WritevDataOnNetworkThread( 150 void WritevDataOnNetworkThread(
137 std::unique_ptr<PendingWriteData> pending_write_data); 151 std::unique_ptr<PendingWriteData> pending_write_data);
138 void DestroyOnNetworkThread(bool send_on_canceled); 152 void DestroyOnNetworkThread(bool send_on_canceled);
139 // Gets headers as a Java array. 153 // Gets headers as a Java array.
140 base::android::ScopedJavaLocalRef<jobjectArray> GetHeadersArray( 154 base::android::ScopedJavaLocalRef<jobjectArray> GetHeadersArray(
141 JNIEnv* env, 155 JNIEnv* env,
142 const net::SpdyHeaderBlock& header_block); 156 const net::SpdyHeaderBlock& header_block);
143 157
144 CronetURLRequestContextAdapter* const context_; 158 CronetURLRequestContextAdapter* const context_;
145 159
146 // Java object that owns this CronetBidirectionalStreamAdapter. 160 // Java object that owns this CronetBidirectionalStreamAdapter.
147 base::android::ScopedJavaGlobalRef<jobject> owner_; 161 base::android::ScopedJavaGlobalRef<jobject> owner_;
148 const bool disable_auto_flush_; 162 const bool send_request_headers_automatically_;
149 163
150 scoped_refptr<IOBufferWithByteBuffer> read_buffer_; 164 scoped_refptr<IOBufferWithByteBuffer> read_buffer_;
151 std::unique_ptr<PendingWriteData> pending_write_data_; 165 std::unique_ptr<PendingWriteData> pending_write_data_;
152 std::unique_ptr<net::BidirectionalStream> bidi_stream_; 166 std::unique_ptr<net::BidirectionalStream> bidi_stream_;
153 167
154 // Whether BidirectionalStream::Delegate::OnFailed callback is invoked. 168 // Whether BidirectionalStream::Delegate::OnFailed callback is invoked.
155 bool stream_failed_; 169 bool stream_failed_;
156 170
157 DISALLOW_COPY_AND_ASSIGN(CronetBidirectionalStreamAdapter); 171 DISALLOW_COPY_AND_ASSIGN(CronetBidirectionalStreamAdapter);
158 }; 172 };
159 173
160 } // namespace cronet 174 } // namespace cronet
161 175
162 #endif // COMPONENTS_CRONET_ANDROID_CRONET_BIDIRECTIONAL_STREAM_ADAPTER_H_ 176 #endif // COMPONENTS_CRONET_ANDROID_CRONET_BIDIRECTIONAL_STREAM_ADAPTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698