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

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: Address Helen's comments. Created 4 years, 11 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
(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/macros.h"
16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h"
18 #include "net/base/request_priority.h"
19 #include "net/http/bidirectional_stream.h"
20 #include "url/gurl.h"
21
22 namespace net {
23 class BidirectionalStreamRequestInfo;
24 class SpdyHeaderBlock;
25 } // namespace net
26
27 namespace cronet {
28
29 class CronetURLRequestContextAdapter;
30
31 bool CronetBidirectionalStreamRegisterJni(JNIEnv* env);
32
33 // An adapter from Java BidirectionalStream object to net::BidirectionalStream.
34 // Created and configured from a Java thread. Start, ReadData, and Destroy are
35 // posted to network thread and all callbacks into the Java BidirectionalStream
36 // are done on the network thread. Java BidirectionalStream is expected to
37 // initiate the next step like ReadData or Destroy. Public methods can be called
38 // on any thread except Get* methods, which can only be called on the network
39 // thread.
40 class CronetBidirectionalStream : public net::BidirectionalStream::Delegate {
41 public:
42 CronetBidirectionalStream(CronetURLRequestContextAdapter* context,
43 JNIEnv* env,
44 jobject jbidi_stream);
45 ~CronetBidirectionalStream() override;
46
47 // Starts the request.
pauljensen 2016/01/06 17:18:33 This function needs more of a comment, esp WRT the
mef 2016/01/06 21:28:30 Done.
48 jint Start(JNIEnv* env,
49 jobject jcaller,
50 jstring jurl,
51 jint jpriority,
52 jstring jmethod,
53 jobjectArray jheaders,
54 jboolean jend_of_stream);
55
56 // Reads more data.
57 jboolean ReadData(JNIEnv* env,
58 jobject jcaller,
59 jobject jbyte_buffer,
60 jint jposition,
61 jint jcapacity);
62
63 // Writes more data.
64 jboolean WriteData(JNIEnv* env,
65 jobject jcaller,
66 jobject jbyte_buffer,
67 jint jposition,
68 jint jcapacity,
69 jboolean jend_of_stream);
70
71 // Releases all resources for the request and deletes the object itself.
72 // |jsend_on_canceled| indicates if Java onCanceled callback should be
73 // issued to indicate that no more callbacks will be issued.
74 void Destroy(JNIEnv* env, jobject jcaller, jboolean jsend_on_canceled);
75
76 // Gets NPN or ALPN Negotiated Protocol (if any) from HttpResponseInfo.
77 // Can only be called on the network thread.
78 base::android::ScopedJavaLocalRef<jstring> GetNegotiatedProtocol(
79 JNIEnv* env,
80 jobject jcaller) const;
81
82 // net::BidirectionalStream::Delegate implementations:
83 void OnHeadersSent() override;
84 void OnHeadersReceived(const net::SpdyHeaderBlock& response_headers) override;
85 void OnDataRead(int bytes_read) override;
86 void OnDataSent() override;
87 void OnTrailersReceived(const net::SpdyHeaderBlock& trailers) override;
88 void OnFailed(int error) override;
89
90 private:
91 class IOBufferWithByteBuffer;
92
93 void StartOnNetworkThread(
94 scoped_ptr<net::BidirectionalStreamRequestInfo> request_info);
95 // Gets headers as Java array.
96 base::android::ScopedJavaLocalRef<jobjectArray> GetHeadersArray(
97 JNIEnv* env,
98 const net::SpdyHeaderBlock& header_block);
99 void ReadDataOnNetworkThread(
100 scoped_refptr<IOBufferWithByteBuffer> read_buffer,
101 int buffer_size);
102 void WriteDataOnNetworkThread(
103 scoped_refptr<IOBufferWithByteBuffer> read_buffer,
104 int buffer_size,
105 bool end_of_stream);
106 void DestroyOnNetworkThread(bool send_on_canceled);
107
108 CronetURLRequestContextAdapter* context_;
109
110 // Java object that owns this CronetBidirectionalStream.
111 base::android::ScopedJavaGlobalRef<jobject> owner_;
112
113 scoped_refptr<IOBufferWithByteBuffer> read_buffer_;
114 scoped_refptr<IOBufferWithByteBuffer> write_buffer_;
115 scoped_ptr<net::BidirectionalStream> bidi_stream_;
116
117 DISALLOW_COPY_AND_ASSIGN(CronetBidirectionalStream);
118 };
119
120 } // namespace cronet
121
122 #endif // COMPONENTS_CRONET_ANDROID_CRONET_BIDIRECTIONAL_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698