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

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

Issue 1856073002: Coalesce small buffers in net::BidirectionalStream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Andrei's comments Created 4 years, 8 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 #include <string> 9 #include <string>
10 10
(...skipping 10 matching lines...) Expand all
21 struct BidirectionalStreamRequestInfo; 21 struct BidirectionalStreamRequestInfo;
22 class SpdyHeaderBlock; 22 class SpdyHeaderBlock;
23 } // namespace net 23 } // namespace net
24 24
25 namespace cronet { 25 namespace cronet {
26 26
27 class CronetURLRequestContextAdapter; 27 class CronetURLRequestContextAdapter;
28 class IOBufferWithByteBuffer; 28 class IOBufferWithByteBuffer;
29 29
30 // An adapter from Java BidirectionalStream object to net::BidirectionalStream. 30 // An adapter from Java BidirectionalStream object to net::BidirectionalStream.
31 // Created and configured from a Java thread. Start, ReadData, WriteData and 31 // Created and configured from a Java thread. Start, ReadData, WritevData and
32 // Destroy can be called on any thread (including network thread), and post 32 // Destroy can be called on any thread (including network thread), and post
33 // calls to corresponding {Start|ReadData|WriteData|Destroy}OnNetworkThread to 33 // calls to corresponding {Start|ReadData|WritevData|Destroy}OnNetworkThread to
34 // the network thread. The object is always deleted on network thread. All 34 // the network thread. The object is always deleted on network thread. All
35 // callbacks into the Java BidirectionalStream are done on the network thread. 35 // callbacks into the Java BidirectionalStream are done on the network thread.
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,
57 const base::android::JavaParamRef<jobject>& jcaller, 58 const base::android::JavaParamRef<jobject>& jcaller,
58 const base::android::JavaParamRef<jstring>& jurl, 59 const base::android::JavaParamRef<jstring>& jurl,
59 jint jpriority, 60 jint jpriority,
60 const base::android::JavaParamRef<jstring>& jmethod, 61 const base::android::JavaParamRef<jstring>& jmethod,
61 const base::android::JavaParamRef<jobjectArray>& jheaders, 62 const base::android::JavaParamRef<jobjectArray>& jheaders,
62 jboolean jend_of_stream); 63 jboolean jend_of_stream);
63 64
64 // Reads more data into |jbyte_buffer| starting at |jposition| and not 65 // Reads more data into |jbyte_buffer| starting at |jposition| and not
65 // exceeding |jlimit|. Arguments are preserved to ensure that |jbyte_buffer| 66 // exceeding |jlimit|. Arguments are preserved to ensure that |jbyte_buffer|
66 // is not modified by the application during read. 67 // is not modified by the application during read.
67 jboolean ReadData(JNIEnv* env, 68 jboolean ReadData(JNIEnv* env,
68 const base::android::JavaParamRef<jobject>& jcaller, 69 const base::android::JavaParamRef<jobject>& jcaller,
69 const base::android::JavaParamRef<jobject>& jbyte_buffer, 70 const base::android::JavaParamRef<jobject>& jbyte_buffer,
70 jint jposition, 71 jint jposition,
71 jint jlimit); 72 jint jlimit);
72 73
73 // Writes more data from |jbyte_buffer| starting at |jposition| and ending at 74 jboolean WritevData(
74 // |jlimit|-1. Arguments are preserved to ensure that |jbyte_buffer| 75 JNIEnv* env,
75 // is not modified by the application during write. The |jend_of_stream| is 76 const base::android::JavaParamRef<jobject>& jcaller,
76 // passed to remote to indicate end of stream. 77 const base::android::JavaParamRef<jobjectArray>& jbyte_buffers,
77 jboolean WriteData(JNIEnv* env, 78 const base::android::JavaParamRef<jintArray>& jpositions,
78 const base::android::JavaParamRef<jobject>& jcaller, 79 const base::android::JavaParamRef<jintArray>& jlimits,
79 const base::android::JavaParamRef<jobject>& jbyte_buffer, 80 jboolean jend_of_stream);
80 jint jposition,
81 jint jlimit,
82 jboolean jend_of_stream);
83 81
84 // Releases all resources for the request and deletes the object itself. 82 // Releases all resources for the request and deletes the object itself.
85 // |jsend_on_canceled| indicates if Java onCanceled callback should be 83 // |jsend_on_canceled| indicates if Java onCanceled callback should be
86 // issued to indicate that no more callbacks will be issued. 84 // issued to indicate that no more callbacks will be issued.
87 void Destroy(JNIEnv* env, 85 void Destroy(JNIEnv* env,
88 const base::android::JavaParamRef<jobject>& jcaller, 86 const base::android::JavaParamRef<jobject>& jcaller,
89 jboolean jsend_on_canceled); 87 jboolean jsend_on_canceled);
90 88
91 private: 89 private:
90 typedef std::vector<scoped_refptr<IOBufferWithByteBuffer>> IOByteBufferList;
92 // net::BidirectionalStream::Delegate implementations: 91 // net::BidirectionalStream::Delegate implementations:
93 void OnHeadersSent() override; 92 void OnStreamReady() override;
94 void OnHeadersReceived(const net::SpdyHeaderBlock& response_headers) override; 93 void OnHeadersReceived(const net::SpdyHeaderBlock& response_headers) override;
95 void OnDataRead(int bytes_read) override; 94 void OnDataRead(int bytes_read) override;
96 void OnDataSent() override; 95 void OnDataSent() override;
97 void OnTrailersReceived(const net::SpdyHeaderBlock& trailers) override; 96 void OnTrailersReceived(const net::SpdyHeaderBlock& trailers) override;
98 void OnFailed(int error) override; 97 void OnFailed(int error) override;
99 98
100 void StartOnNetworkThread( 99 void StartOnNetworkThread(
101 scoped_ptr<net::BidirectionalStreamRequestInfo> request_info); 100 scoped_ptr<net::BidirectionalStreamRequestInfo> request_info);
102 void ReadDataOnNetworkThread( 101 void ReadDataOnNetworkThread(
103 scoped_refptr<IOBufferWithByteBuffer> read_buffer, 102 scoped_refptr<IOBufferWithByteBuffer> read_buffer,
104 int buffer_size); 103 int buffer_size);
105 void WriteDataOnNetworkThread( 104 void WritevDataOnNetworkThread(const IOByteBufferList& buffers,
106 scoped_refptr<IOBufferWithByteBuffer> read_buffer, 105 bool end_of_stream);
107 int buffer_size,
108 bool end_of_stream);
109 void DestroyOnNetworkThread(bool send_on_canceled); 106 void DestroyOnNetworkThread(bool send_on_canceled);
110 // Gets headers as a Java array. 107 // Gets headers as a Java array.
111 base::android::ScopedJavaLocalRef<jobjectArray> GetHeadersArray( 108 base::android::ScopedJavaLocalRef<jobjectArray> GetHeadersArray(
112 JNIEnv* env, 109 JNIEnv* env,
113 const net::SpdyHeaderBlock& header_block); 110 const net::SpdyHeaderBlock& header_block);
114 111
115 CronetURLRequestContextAdapter* const context_; 112 CronetURLRequestContextAdapter* const context_;
116 113
117 // Java object that owns this CronetBidirectionalStreamAdapter. 114 // Java object that owns this CronetBidirectionalStreamAdapter.
118 base::android::ScopedJavaGlobalRef<jobject> owner_; 115 base::android::ScopedJavaGlobalRef<jobject> owner_;
116 const bool disable_auto_flush_;
117 // Whether an end of stream flag is passed in through a write call.
118 // Not applicable to HTTP methods that do not send data.
119 bool write_end_of_stream_;
119 120
120 scoped_refptr<IOBufferWithByteBuffer> read_buffer_; 121 scoped_refptr<IOBufferWithByteBuffer> read_buffer_;
121 scoped_refptr<IOBufferWithByteBuffer> write_buffer_; 122 IOByteBufferList write_buffer_list_;
122 scoped_ptr<net::BidirectionalStream> bidi_stream_; 123 scoped_ptr<net::BidirectionalStream> bidi_stream_;
123 124
124 DISALLOW_COPY_AND_ASSIGN(CronetBidirectionalStreamAdapter); 125 DISALLOW_COPY_AND_ASSIGN(CronetBidirectionalStreamAdapter);
125 }; 126 };
126 127
127 } // namespace cronet 128 } // namespace cronet
128 129
129 #endif // COMPONENTS_CRONET_ANDROID_CRONET_BIDIRECTIONAL_STREAM_ADAPTER_H_ 130 #endif // COMPONENTS_CRONET_ANDROID_CRONET_BIDIRECTIONAL_STREAM_ADAPTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698