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

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

Issue 1412243012: Initial implementation of CronetBidirectionalStream. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync Created 5 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_CRONET_ANDROID_CRONET_BIDIRECTIONAL_STREAM_H_
6 #define COMPONENTS_CRONET_ANDROID_CRONET_BIDIRECTIONAL_STREAM_H_
7
8 #include <jni.h>
9 #include <string>
10
11 #include "base/android/jni_android.h"
12 #include "base/android/jni_array.h"
13 #include "base/android/jni_string.h"
14 #include "base/android/scoped_java_ref.h"
15 #include "base/callback.h"
xunjieli 2015/12/18 19:11:11 nit: not used?
mef 2015/12/29 20:36:54 Done.
16 #include "base/location.h"
xunjieli 2015/12/18 19:11:11 nit: not used?
mef 2015/12/29 20:36:54 Done.
17 #include "base/macros.h"
18 #include "base/memory/ref_counted.h"
19 #include "base/memory/scoped_ptr.h"
20 #include "net/base/request_priority.h"
21 #include "net/http/bidirectional_stream.h"
22 #include "url/gurl.h"
23
24 namespace net {
25 class BidirectionalStreamRequestInfo;
26 class SpdyHeaderBlock;
27 } // namespace net
28
29 namespace cronet {
30
31 class CronetURLRequestContextAdapter;
32
33 bool CronetBidirectionalStreamRegisterJni(JNIEnv* env);
34
35 // An adapter from Java BidirectionalStream object to net::BidirectionalStream.
36 // Created and configured from a Java thread. Start, ReadData, and Destroy are
37 // posted to network thread and all callbacks into the Java BidirectionalStream
38 // are done on the network thread. Java BidirectionalStream is expected to
39 // initiate the next step like ReadData or Destroy. Public methods can be called
40 // on any thread except Get* methods, which can only be called on the network
41 // thread.
42 class CronetBidirectionalStream : public net::BidirectionalStream::Delegate {
xunjieli 2015/12/18 19:49:25 I think this should be named CronetBidirectionalSt
mef 2015/12/29 20:36:54 Acknowledged. Sounds like a good idea, will do in
43 public:
44 CronetBidirectionalStream(CronetURLRequestContextAdapter* context,
45 JNIEnv* env,
46 jobject jbidi_stream);
47 ~CronetBidirectionalStream() override;
48
49 // Starts the request.
50 jint Start(JNIEnv* env,
51 jobject jcaller,
52 jstring jurl,
53 jstring jmethod,
54 jobjectArray jheaders,
55 jboolean jend_of_stream);
56
57 // Reads more data.
58 jboolean ReadData(JNIEnv* env,
59 jobject jcaller,
60 jobject jbyte_buffer,
61 jint jposition,
62 jint jcapacity);
63
64 // Writes more data.
65 jboolean WriteData(JNIEnv* env,
66 jobject jcaller,
67 jobject jbyte_buffer,
68 jint jposition,
69 jint jcapacity,
70 jboolean jend_of_stream);
71
72 // Releases all resources for the request and deletes the object itself.
73 // |jsend_on_canceled| indicates if Java onCanceled callback should be
74 // issued to indicate when no more callbacks will be issued.
xunjieli 2015/12/18 19:49:25 nit: s/indicate when/indicate that
mef 2015/12/29 20:36:54 Done.
75 void Destroy(JNIEnv* env, jobject jcaller, jboolean jsend_on_canceled);
76
77 // Gets NPN or ALPN Negotiated Protocol (if any) from HttpResponseInfo.
78 // Can only be called on the network thread.
79 base::android::ScopedJavaLocalRef<jstring> GetNegotiatedProtocol(
80 JNIEnv* env,
81 jobject jcaller) const;
82
83 // net::BidirectionalStream::Delegate implementations:
84
85 // Called when the request headers have been sent.
xunjieli 2015/12/18 19:49:25 nit: override methods do not need documentation. T
mef 2015/12/29 20:36:54 Done.
86 void OnHeadersSent() override;
87
88 // Called when response headers are received.
89 void OnHeadersReceived(const net::SpdyHeaderBlock& response_headers) override;
90
91 // Called when read is completed asynchronously. |bytes_read| specifies how
92 // much data is available.
93 void OnDataRead(int bytes_read) override;
94
95 // Called when the entire buffer passed through SendData is sent.
96 void OnDataSent() override;
97
98 // Called when trailers are received.
99 void OnTrailersReceived(const net::SpdyHeaderBlock& trailers) override;
100
101 // Called when the stream is closed with error. No other delegate functions
102 // will be called after this.
103 void OnFailed(int error) override;
104
105 private:
106 class IOBufferWithByteBuffer;
107
108 void StartOnNetworkThread(
109 scoped_ptr<net::BidirectionalStreamRequestInfo> request_info);
110 // Gets headers as Java array.
111 base::android::ScopedJavaLocalRef<jobjectArray> GetHeadersArray(
112 JNIEnv* env,
113 const net::SpdyHeaderBlock& header_block);
114 void ReadDataOnNetworkThread(
115 scoped_refptr<IOBufferWithByteBuffer> read_buffer,
116 int buffer_size);
117 void WriteDataOnNetworkThread(
118 scoped_refptr<IOBufferWithByteBuffer> read_buffer,
119 int buffer_size,
120 bool end_of_stream);
121 void DestroyOnNetworkThread(bool send_on_canceled);
122
123 CronetURLRequestContextAdapter* context_;
124
125 // Java object that owns this CronetBidirectionalStream.
126 base::android::ScopedJavaGlobalRef<jobject> owner_;
127
128 scoped_refptr<IOBufferWithByteBuffer> read_buffer_;
129 scoped_refptr<IOBufferWithByteBuffer> write_buffer_;
130 scoped_ptr<net::BidirectionalStream> bidi_stream_;
131
132 DISALLOW_COPY_AND_ASSIGN(CronetBidirectionalStream);
133 };
134
135 } // namespace cronet
136
137 #endif // COMPONENTS_CRONET_ANDROID_CRONET_BIDIRECTIONAL_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698