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

Side by Side Diff: components/cronet/android/cronet_url_request.cc

Issue 586143002: Initial implementation of Cronet Async API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "components/cronet/android/chromium_url_request.h" 5 #include "components/cronet/android/cronet_url_request.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "components/cronet/android/url_request_adapter.h" 10 #include "components/cronet/android/cronet_url_request_adapter.h"
11 #include "components/cronet/android/url_request_context_adapter.h" 11 #include "components/cronet/android/cronet_url_request_context_adapter.h"
12 #include "jni/ChromiumUrlRequest_jni.h" 12 #include "jni/CronetUrlRequest_jni.h"
13 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
14 #include "net/base/request_priority.h" 14 #include "net/base/request_priority.h"
15 #include "net/http/http_response_headers.h" 15 #include "net/http/http_response_headers.h"
16 16
17 using base::android::ConvertUTF8ToJavaString; 17 using base::android::ConvertUTF8ToJavaString;
18 18
19 namespace cronet { 19 namespace cronet {
20 namespace { 20 namespace {
21 21
22 net::RequestPriority ConvertRequestPriority(jint request_priority) { 22 net::RequestPriority ConvertRequestPriority(jint request_priority) {
23 switch (request_priority) { 23 switch (request_priority) {
24 case REQUEST_PRIORITY_IDLE: 24 case REQUEST_PRIORITY_IDLE:
25 return net::IDLE; 25 return net::IDLE;
26 case REQUEST_PRIORITY_LOWEST: 26 case REQUEST_PRIORITY_LOWEST:
27 return net::LOWEST; 27 return net::LOWEST;
28 case REQUEST_PRIORITY_LOW: 28 case REQUEST_PRIORITY_LOW:
29 return net::LOW; 29 return net::LOW;
30 case REQUEST_PRIORITY_MEDIUM: 30 case REQUEST_PRIORITY_MEDIUM:
31 return net::MEDIUM; 31 return net::MEDIUM;
32 case REQUEST_PRIORITY_HIGHEST: 32 case REQUEST_PRIORITY_HIGHEST:
33 return net::HIGHEST; 33 return net::HIGHEST;
34 default: 34 default:
35 return net::LOWEST; 35 return net::LOWEST;
36 } 36 }
37 } 37 }
38 38 // A delegate of CronetURLRequestAdapter that delivers callbacks to the Java
39 void SetPostContentType(JNIEnv* env, 39 // layer.
40 URLRequestAdapter* request, 40 class JniCronetURLRequestAdapterDelegate
41 jstring content_type) { 41 : public CronetURLRequestAdapter::CronetURLRequestAdapterDelegate {
42 DCHECK(request != NULL);
43
44 std::string method_post("POST");
45 request->SetMethod(method_post);
46
47 std::string content_type_header("Content-Type");
48 std::string content_type_string(
49 base::android::ConvertJavaStringToUTF8(env, content_type));
50
51 request->AddHeader(content_type_header, content_type_string);
52 }
53
54 // A delegate of URLRequestAdapter that delivers callbacks to the Java layer.
55 class JniURLRequestAdapterDelegate
56 : public URLRequestAdapter::URLRequestAdapterDelegate {
57 public: 42 public:
58 JniURLRequestAdapterDelegate(JNIEnv* env, jobject owner) { 43 JniCronetURLRequestAdapterDelegate(JNIEnv* env, jobject owner) {
59 owner_ = env->NewGlobalRef(owner); 44 owner_ = env->NewGlobalRef(owner);
60 } 45 }
61 46
62 virtual void OnResponseStarted(URLRequestAdapter* request) OVERRIDE { 47 virtual void OnRedirect(CronetURLRequestAdapter* request,
48 const GURL& newLocation) OVERRIDE {
63 JNIEnv* env = base::android::AttachCurrentThread(); 49 JNIEnv* env = base::android::AttachCurrentThread();
64 cronet::Java_ChromiumUrlRequest_onResponseStarted(env, owner_); 50 cronet::Java_CronetUrlRequest_onRedirect(
51 env,
52 owner_,
53 ConvertUTF8ToJavaString(env, newLocation.spec()).Release());
65 } 54 }
66 55
67 virtual void OnBytesRead(URLRequestAdapter* request) OVERRIDE { 56 virtual void OnResponseStarted(CronetURLRequestAdapter* request) OVERRIDE {
68 int bytes_read = request->bytes_read(); 57 JNIEnv* env = base::android::AttachCurrentThread();
69 if (bytes_read != 0) { 58 cronet::Java_CronetUrlRequest_onResponseStarted(env, owner_);
70 JNIEnv* env = base::android::AttachCurrentThread(); 59 }
60
61 virtual void OnBytesRead(CronetURLRequestAdapter* request,
62 int bytes_read) OVERRIDE {
63 JNIEnv* env = base::android::AttachCurrentThread();
64 if (bytes_read >= 0) {
71 base::android::ScopedJavaLocalRef<jobject> java_buffer( 65 base::android::ScopedJavaLocalRef<jobject> java_buffer(
72 env, env->NewDirectByteBuffer(request->Data(), bytes_read)); 66 env, env->NewDirectByteBuffer(request->Data(), bytes_read));
73 cronet::Java_ChromiumUrlRequest_onBytesRead( 67 cronet::Java_CronetUrlRequest_onDataReceived(
74 env, owner_, java_buffer.obj()); 68 env, owner_, java_buffer.obj());
69 } else {
70 cronet::Java_CronetUrlRequest_onError(env, owner_, request->error_code());
75 } 71 }
76 } 72 }
77 73
78 virtual void OnRequestFinished(URLRequestAdapter* request) OVERRIDE { 74 virtual void OnRequestFinished(CronetURLRequestAdapter* request) OVERRIDE {
79 JNIEnv* env = base::android::AttachCurrentThread(); 75 JNIEnv* env = base::android::AttachCurrentThread();
80 cronet::Java_ChromiumUrlRequest_finish(env, owner_); 76 cronet::Java_CronetUrlRequest_onComplete(env, owner_);
81 }
82
83 virtual int ReadFromUploadChannel(net::IOBuffer* buf,
84 int buf_length) OVERRIDE {
85 JNIEnv* env = base::android::AttachCurrentThread();
86 base::android::ScopedJavaLocalRef<jobject> java_buffer(
87 env, env->NewDirectByteBuffer(buf->data(), buf_length));
88 jint bytes_read = cronet::Java_ChromiumUrlRequest_readFromUploadChannel(
89 env, owner_, java_buffer.obj());
90 return bytes_read;
91 } 77 }
92 78
93 protected: 79 protected:
94 virtual ~JniURLRequestAdapterDelegate() { 80 virtual ~JniCronetURLRequestAdapterDelegate() {
95 JNIEnv* env = base::android::AttachCurrentThread(); 81 JNIEnv* env = base::android::AttachCurrentThread();
96 env->DeleteGlobalRef(owner_); 82 env->DeleteGlobalRef(owner_);
97 } 83 }
98 84
99 private: 85 private:
100 jobject owner_; 86 jobject owner_;
101 87
102 DISALLOW_COPY_AND_ASSIGN(JniURLRequestAdapterDelegate); 88 DISALLOW_COPY_AND_ASSIGN(JniCronetURLRequestAdapterDelegate);
103 }; 89 };
104 90
105 } // namespace 91 } // namespace
106 92
107 // Explicitly register static JNI functions. 93 // Explicitly register static JNI functions.
108 bool ChromiumUrlRequestRegisterJni(JNIEnv* env) { 94 bool CronetUrlRequestRegisterJni(JNIEnv* env) {
109 return RegisterNativesImpl(env); 95 return RegisterNativesImpl(env);
110 } 96 }
111 97
112 static jlong CreateRequestAdapter(JNIEnv* env, 98 static jlong CreateRequestAdapter(JNIEnv* env,
113 jobject object, 99 jobject object,
114 jlong urlRequestContextAdapter, 100 jlong urlRequestContextAdapter,
115 jstring url_string, 101 jstring url_string,
116 jint priority) { 102 jint priority) {
117 URLRequestContextAdapter* context = 103 CronetURLRequestContextAdapter* context =
118 reinterpret_cast<URLRequestContextAdapter*>(urlRequestContextAdapter); 104 reinterpret_cast<CronetURLRequestContextAdapter*>(
105 urlRequestContextAdapter);
119 DCHECK(context != NULL); 106 DCHECK(context != NULL);
120 107
121 GURL url(base::android::ConvertJavaStringToUTF8(env, url_string)); 108 GURL url(base::android::ConvertJavaStringToUTF8(env, url_string));
122 109
123 VLOG(1) << "New chromium network request: " << url.possibly_invalid_spec(); 110 VLOG(1) << "New chromium network request: " << url.possibly_invalid_spec();
124 111
125 URLRequestAdapter* adapter = 112 CronetURLRequestAdapter* adapter = new CronetURLRequestAdapter(
126 new URLRequestAdapter(context, 113 context,
127 new JniURLRequestAdapterDelegate(env, object), 114 new JniCronetURLRequestAdapterDelegate(env, object),
128 url, 115 url,
129 ConvertRequestPriority(priority)); 116 ConvertRequestPriority(priority));
130 117
131 return reinterpret_cast<jlong>(adapter); 118 return reinterpret_cast<jlong>(adapter);
132 } 119 }
133 120
134 // synchronized 121 // synchronized
135 static void AddHeader(JNIEnv* env, 122 static void AddHeader(JNIEnv* env,
136 jobject object, 123 jobject object,
137 jlong urlRequestAdapter, 124 jlong urlRequestAdapter,
138 jstring name, 125 jstring name,
139 jstring value) { 126 jstring value) {
140 URLRequestAdapter* request = 127 CronetURLRequestAdapter* request =
141 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); 128 reinterpret_cast<CronetURLRequestAdapter*>(urlRequestAdapter);
142 DCHECK(request); 129 DCHECK(request);
143 130
144 std::string name_string(base::android::ConvertJavaStringToUTF8(env, name)); 131 std::string name_string(base::android::ConvertJavaStringToUTF8(env, name));
145 std::string value_string(base::android::ConvertJavaStringToUTF8(env, value)); 132 std::string value_string(base::android::ConvertJavaStringToUTF8(env, value));
146 133
147 request->AddHeader(name_string, value_string); 134 request->AddHeader(name_string, value_string);
148 } 135 }
149 136
150 static void SetMethod(JNIEnv* env, 137 static void SetHttpMethod(JNIEnv* env,
151 jobject object, 138 jobject object,
152 jlong urlRequestAdapter, 139 jlong urlRequestAdapter,
153 jstring method) { 140 jstring method) {
154 URLRequestAdapter* request = 141 CronetURLRequestAdapter* request =
155 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); 142 reinterpret_cast<CronetURLRequestAdapter*>(urlRequestAdapter);
156 DCHECK(request); 143 DCHECK(request);
157 144
158 std::string method_string( 145 std::string method_string(
159 base::android::ConvertJavaStringToUTF8(env, method)); 146 base::android::ConvertJavaStringToUTF8(env, method));
160 147
161 request->SetMethod(method_string); 148 request->SetMethod(method_string);
162 } 149 }
163 150
164 static void SetUploadData(JNIEnv* env,
165 jobject object,
166 jlong urlRequestAdapter,
167 jstring content_type,
168 jbyteArray content) {
169 URLRequestAdapter* request =
170 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter);
171 SetPostContentType(env, request, content_type);
172
173 if (content != NULL) {
174 jsize size = env->GetArrayLength(content);
175 if (size > 0) {
176 jbyte* content_bytes = env->GetByteArrayElements(content, NULL);
177 request->SetUploadContent(reinterpret_cast<const char*>(content_bytes),
178 size);
179 env->ReleaseByteArrayElements(content, content_bytes, 0);
180 }
181 }
182 }
183
184 static void SetUploadChannel(JNIEnv* env,
185 jobject object,
186 jlong urlRequestAdapter,
187 jstring content_type,
188 jlong content_length) {
189 URLRequestAdapter* request =
190 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter);
191 SetPostContentType(env, request, content_type);
192
193 request->SetUploadChannel(env, content_length);
194 }
195
196 static void EnableChunkedUpload(JNIEnv* env,
197 jobject object,
198 jlong urlRequestAdapter,
199 jstring content_type) {
200 URLRequestAdapter* request =
201 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter);
202 SetPostContentType(env, request, content_type);
203
204 request->EnableChunkedUpload();
205 }
206
207 static void AppendChunk(JNIEnv* env,
208 jobject object,
209 jlong urlRequestAdapter,
210 jobject chunk_byte_buffer,
211 jint chunk_size,
212 jboolean is_last_chunk) {
213 URLRequestAdapter* request =
214 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter);
215 DCHECK(chunk_byte_buffer != NULL);
216
217 void* chunk = env->GetDirectBufferAddress(chunk_byte_buffer);
218 request->AppendChunk(
219 reinterpret_cast<const char*>(chunk), chunk_size, is_last_chunk);
220 }
221
222 /* synchronized */ 151 /* synchronized */
223 static void Start(JNIEnv* env, jobject object, jlong urlRequestAdapter) { 152 static void Start(JNIEnv* env, jobject object, jlong urlRequestAdapter) {
224 URLRequestAdapter* request = 153 CronetURLRequestAdapter* request =
225 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); 154 reinterpret_cast<CronetURLRequestAdapter*>(urlRequestAdapter);
226 if (request != NULL) { 155 if (request != NULL) {
227 request->Start(); 156 request->Start();
228 } 157 }
229 } 158 }
230 159
231 /* synchronized */ 160 /* synchronized */
232 static void DestroyRequestAdapter(JNIEnv* env, 161 static void DestroyRequestAdapter(JNIEnv* env,
233 jobject object, 162 jobject object,
234 jlong urlRequestAdapter) { 163 jlong urlRequestAdapter) {
235 URLRequestAdapter* request = 164 CronetURLRequestAdapter* request =
236 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); 165 reinterpret_cast<CronetURLRequestAdapter*>(urlRequestAdapter);
237 if (request != NULL) { 166 if (request != NULL) {
238 request->Destroy(); 167 request->Destroy();
239 } 168 }
240 } 169 }
241 170
242 /* synchronized */ 171 /* synchronized */
243 static void Cancel(JNIEnv* env, jobject object, jlong urlRequestAdapter) { 172 static void Cancel(JNIEnv* env, jobject object, jlong urlRequestAdapter) {
244 URLRequestAdapter* request = 173 CronetURLRequestAdapter* request =
245 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); 174 reinterpret_cast<CronetURLRequestAdapter*>(urlRequestAdapter);
246 if (request != NULL) { 175 if (request != NULL) {
247 request->Cancel(); 176 request->Cancel();
248 } 177 }
249 } 178 }
250 179
180 static void ReceiveData(JNIEnv* env, jobject jcaller, jlong urlRequestAdapter) {
181 CronetURLRequestAdapter* request =
182 reinterpret_cast<CronetURLRequestAdapter*>(urlRequestAdapter);
183 if (request != NULL) {
184 request->ReadData();
185 }
186 }
187
188 static void FollowDeferredRedirect(JNIEnv* env,
189 jobject jcaller,
190 jlong urlRequestAdapter) {
191 CronetURLRequestAdapter* request =
192 reinterpret_cast<CronetURLRequestAdapter*>(urlRequestAdapter);
193 if (request != NULL) {
194 request->FollowDeferredRedirect();
195 }
196 }
197
251 static jint GetErrorCode(JNIEnv* env, jobject object, jlong urlRequestAdapter) { 198 static jint GetErrorCode(JNIEnv* env, jobject object, jlong urlRequestAdapter) {
252 URLRequestAdapter* request = 199 CronetURLRequestAdapter* request =
253 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); 200 reinterpret_cast<CronetURLRequestAdapter*>(urlRequestAdapter);
254 int error_code = request->error_code(); 201 int error_code = request->error_code();
255 switch (error_code) { 202 switch (error_code) {
256 // TODO(mef): Investigate returning success on positive values, too, as 203 // TODO(mef): Investigate returning success on positive values, too, as
257 // they technically indicate success. 204 // they technically indicate success.
258 case net::OK: 205 case net::OK:
259 return REQUEST_ERROR_SUCCESS; 206 return REQUEST_ERROR_SUCCESS;
260 207
261 // TODO(mef): Investigate this. The fact is that Chrome does not do this, 208 // TODO(mef): Investigate this. The fact is that Chrome does not do this,
262 // and this library is not just being used for downloads. 209 // and this library is not just being used for downloads.
263 210
(...skipping 16 matching lines...) Expand all
280 227
281 case net::ERR_NAME_NOT_RESOLVED: 228 case net::ERR_NAME_NOT_RESOLVED:
282 return REQUEST_ERROR_UNKNOWN_HOST; 229 return REQUEST_ERROR_UNKNOWN_HOST;
283 } 230 }
284 return REQUEST_ERROR_UNKNOWN; 231 return REQUEST_ERROR_UNKNOWN;
285 } 232 }
286 233
287 static jstring GetErrorString(JNIEnv* env, 234 static jstring GetErrorString(JNIEnv* env,
288 jobject object, 235 jobject object,
289 jlong urlRequestAdapter) { 236 jlong urlRequestAdapter) {
290 URLRequestAdapter* request = 237 CronetURLRequestAdapter* request =
291 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); 238 reinterpret_cast<CronetURLRequestAdapter*>(urlRequestAdapter);
292 int error_code = request->error_code(); 239 int error_code = request->error_code();
293 char buffer[200]; 240 char buffer[200];
294 std::string error_string = net::ErrorToString(error_code); 241 std::string error_string = net::ErrorToString(error_code);
295 snprintf(buffer, 242 snprintf(buffer,
296 sizeof(buffer), 243 sizeof(buffer),
297 "System error: %s(%d)", 244 "System error: %s(%d)",
298 error_string.c_str(), 245 error_string.c_str(),
299 error_code); 246 error_code);
300 return ConvertUTF8ToJavaString(env, buffer).Release(); 247 return ConvertUTF8ToJavaString(env, buffer).Release();
301 } 248 }
302 249
303 static jint GetHttpStatusCode(JNIEnv* env, 250 static jint GetHttpStatusCode(JNIEnv* env,
304 jobject object, 251 jobject object,
305 jlong urlRequestAdapter) { 252 jlong urlRequestAdapter) {
306 URLRequestAdapter* request = 253 CronetURLRequestAdapter* request =
307 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); 254 reinterpret_cast<CronetURLRequestAdapter*>(urlRequestAdapter);
308 return request->http_status_code(); 255 return request->http_status_code();
309 } 256 }
310 257
311 static jstring GetContentType(JNIEnv* env, 258 static jstring GetContentType(JNIEnv* env,
312 jobject object, 259 jobject object,
313 jlong urlRequestAdapter) { 260 jlong urlRequestAdapter) {
314 URLRequestAdapter* request = 261 CronetURLRequestAdapter* request =
315 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); 262 reinterpret_cast<CronetURLRequestAdapter*>(urlRequestAdapter);
316 if (request == NULL) { 263 if (request == NULL) {
317 return NULL; 264 return NULL;
318 } 265 }
319 std::string type = request->content_type(); 266 std::string type = request->content_type();
320 if (!type.empty()) { 267 if (!type.empty()) {
321 return ConvertUTF8ToJavaString(env, type.c_str()).Release(); 268 return ConvertUTF8ToJavaString(env, type.c_str()).Release();
322 } else { 269 } else {
323 return NULL; 270 return NULL;
324 } 271 }
325 } 272 }
326 273
327 static jlong GetContentLength(JNIEnv* env, 274 static jlong GetContentLength(JNIEnv* env,
328 jobject object, 275 jobject object,
329 jlong urlRequestAdapter) { 276 jlong urlRequestAdapter) {
330 URLRequestAdapter* request = 277 CronetURLRequestAdapter* request =
331 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); 278 reinterpret_cast<CronetURLRequestAdapter*>(urlRequestAdapter);
332 if (request == NULL) { 279 if (request == NULL) {
333 return 0; 280 return 0;
334 } 281 }
335 return request->content_length(); 282 return request->content_length();
336 } 283 }
337 284
338 static jstring GetHeader(JNIEnv* env, 285 static jstring GetHeader(JNIEnv* env,
339 jobject object, 286 jobject object,
340 jlong urlRequestAdapter, 287 jlong urlRequestAdapter,
341 jstring name) { 288 jstring name) {
342 URLRequestAdapter* request = 289 CronetURLRequestAdapter* request =
343 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); 290 reinterpret_cast<CronetURLRequestAdapter*>(urlRequestAdapter);
344 if (request == NULL) { 291 if (request == NULL) {
345 return NULL; 292 return NULL;
346 } 293 }
347 294
348 std::string name_string = base::android::ConvertJavaStringToUTF8(env, name); 295 std::string name_string = base::android::ConvertJavaStringToUTF8(env, name);
349 std::string value = request->GetHeader(name_string); 296 std::string value = request->GetHeader(name_string);
350 if (!value.empty()) { 297 if (!value.empty()) {
351 return ConvertUTF8ToJavaString(env, value.c_str()).Release(); 298 return ConvertUTF8ToJavaString(env, value.c_str()).Release();
352 } else { 299 } else {
353 return NULL; 300 return NULL;
354 } 301 }
355 } 302 }
356 303
357 static void GetAllHeaders(JNIEnv* env, 304 static void GetAllHeaders(JNIEnv* env,
358 jobject object, 305 jobject object,
359 jlong urlRequestAdapter, 306 jlong urlRequestAdapter,
360 jobject headersMap) { 307 jobject headersMap) {
361 URLRequestAdapter* request = 308 CronetURLRequestAdapter* request =
362 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); 309 reinterpret_cast<CronetURLRequestAdapter*>(urlRequestAdapter);
363 if (request == NULL) 310 if (request == NULL)
364 return; 311 return;
365 312
366 net::HttpResponseHeaders* headers = request->GetResponseHeaders(); 313 net::HttpResponseHeaders* headers = request->GetResponseHeaders();
367 if (headers == NULL) 314 if (headers == NULL)
368 return; 315 return;
369 316
370 void* iter = NULL; 317 void* iter = NULL;
371 std::string header_name; 318 std::string header_name;
372 std::string header_value; 319 std::string header_value;
373 while (headers->EnumerateHeaderLines(&iter, &header_name, &header_value)) { 320 while (headers->EnumerateHeaderLines(&iter, &header_name, &header_value)) {
374 ScopedJavaLocalRef<jstring> name = 321 ScopedJavaLocalRef<jstring> name =
375 ConvertUTF8ToJavaString(env, header_name); 322 ConvertUTF8ToJavaString(env, header_name);
376 ScopedJavaLocalRef<jstring> value = 323 ScopedJavaLocalRef<jstring> value =
377 ConvertUTF8ToJavaString(env, header_value); 324 ConvertUTF8ToJavaString(env, header_value);
378 Java_ChromiumUrlRequest_onAppendResponseHeader( 325 Java_CronetUrlRequest_onAppendResponseHeader(
379 env, object, headersMap, name.Release(), value.Release()); 326 env, object, headersMap, name.Release(), value.Release());
380 } 327 }
381 328
382 // Some implementations (notably HttpURLConnection) include a mapping for the 329 // Some implementations (notably HttpURLConnection) include a mapping for the
383 // null key; in HTTP's case, this maps to the HTTP status line. 330 // null key; in HTTP's case, this maps to the HTTP status line.
384 ScopedJavaLocalRef<jstring> status_line = 331 ScopedJavaLocalRef<jstring> status_line =
385 ConvertUTF8ToJavaString(env, headers->GetStatusLine()); 332 ConvertUTF8ToJavaString(env, headers->GetStatusLine());
386 Java_ChromiumUrlRequest_onAppendResponseHeader( 333 Java_CronetUrlRequest_onAppendResponseHeader(
387 env, object, headersMap, NULL, status_line.Release()); 334 env, object, headersMap, NULL, status_line.Release());
388 } 335 }
389 336
390 static jstring GetNegotiatedProtocol(JNIEnv* env, 337 static jstring GetNegotiatedProtocol(JNIEnv* env,
391 jobject object, 338 jobject object,
392 jlong urlRequestAdapter) { 339 jlong urlRequestAdapter) {
393 URLRequestAdapter* request = 340 CronetURLRequestAdapter* request =
394 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); 341 reinterpret_cast<CronetURLRequestAdapter*>(urlRequestAdapter);
395 if (request == NULL) 342 if (request == NULL)
396 return ConvertUTF8ToJavaString(env, "").Release(); 343 return ConvertUTF8ToJavaString(env, "").Release();
397 344
398 std::string negotiated_protocol = request->GetNegotiatedProtocol(); 345 std::string negotiated_protocol = request->GetNegotiatedProtocol();
399 return ConvertUTF8ToJavaString(env, negotiated_protocol.c_str()).Release(); 346 return ConvertUTF8ToJavaString(env, negotiated_protocol.c_str()).Release();
400 } 347 }
401 348
402 } // namespace cronet 349 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698