Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "cronet_url_request_adapter.h" | 5 #include "cronet_url_request_adapter.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "net/http/http_status_code.h" | 21 #include "net/http/http_status_code.h" |
| 22 #include "net/http/http_util.h" | 22 #include "net/http/http_util.h" |
| 23 #include "net/ssl/ssl_info.h" | 23 #include "net/ssl/ssl_info.h" |
| 24 #include "net/url_request/redirect_info.h" | 24 #include "net/url_request/redirect_info.h" |
| 25 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
| 26 | 26 |
| 27 using base::android::ConvertUTF8ToJavaString; | 27 using base::android::ConvertUTF8ToJavaString; |
| 28 | 28 |
| 29 namespace cronet { | 29 namespace cronet { |
| 30 | 30 |
| 31 namespace { | |
| 32 | |
| 33 // Error codes for the most popular network stack error codes. | |
| 34 // For descriptions see corresponding constants in UrlRequestException.java. | |
| 35 // A Java counterpart will be generated for this enum. | |
| 36 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net | |
| 37 enum UrlRequestError { | |
| 38 LISTENER_THREW, | |
| 39 HOSTNAME_NOT_RESOLVED, | |
| 40 INTERNET_DISCONNECTED, | |
| 41 NETWORK_CHANGED, | |
| 42 TIMED_OUT, | |
| 43 CONNECTION_CLOSED, | |
| 44 CONNECTION_TIMED_OUT, | |
| 45 CONNECTION_REFUSED, | |
| 46 CONNECTION_RESET, | |
| 47 ADDRESS_UNREACHABLE, | |
| 48 OTHER, | |
| 49 }; | |
| 50 | |
| 51 // Convert most popular net::ERR_* values to counterparts accessible in Java. | |
|
xunjieli
2015/11/06 15:23:22
nit: Convert -> Converts
pauljensen
2016/01/25 01:43:51
Done.
| |
| 52 UrlRequestError NetErrorToUrlRequestError(int net_error) { | |
| 53 switch (net_error) { | |
| 54 case net::ERR_NAME_NOT_RESOLVED: | |
| 55 return HOSTNAME_NOT_RESOLVED; | |
| 56 case net::ERR_INTERNET_DISCONNECTED: | |
| 57 return INTERNET_DISCONNECTED; | |
| 58 case net::ERR_NETWORK_CHANGED: | |
| 59 return NETWORK_CHANGED; | |
| 60 case net::ERR_TIMED_OUT: | |
| 61 return TIMED_OUT; | |
| 62 case net::ERR_CONNECTION_CLOSED: | |
| 63 return CONNECTION_CLOSED; | |
| 64 case net::ERR_CONNECTION_TIMED_OUT: | |
| 65 return CONNECTION_TIMED_OUT; | |
| 66 case net::ERR_CONNECTION_REFUSED: | |
| 67 return CONNECTION_REFUSED; | |
| 68 case net::ERR_CONNECTION_RESET: | |
| 69 return CONNECTION_RESET; | |
| 70 case net::ERR_ADDRESS_UNREACHABLE: | |
| 71 return ADDRESS_UNREACHABLE; | |
| 72 default: | |
| 73 return OTHER; | |
| 74 } | |
| 75 } | |
| 76 } | |
| 77 | |
| 31 // Explicitly register static JNI functions. | 78 // Explicitly register static JNI functions. |
| 32 bool CronetUrlRequestAdapterRegisterJni(JNIEnv* env) { | 79 bool CronetUrlRequestAdapterRegisterJni(JNIEnv* env) { |
| 33 return RegisterNativesImpl(env); | 80 return RegisterNativesImpl(env); |
| 34 } | 81 } |
| 35 | 82 |
| 36 static jlong CreateRequestAdapter(JNIEnv* env, | 83 static jlong CreateRequestAdapter(JNIEnv* env, |
| 37 const JavaParamRef<jobject>& jurl_request, | 84 const JavaParamRef<jobject>& jurl_request, |
| 38 jlong jurl_request_context_adapter, | 85 jlong jurl_request_context_adapter, |
| 39 const JavaParamRef<jstring>& jurl_string, | 86 const JavaParamRef<jstring>& jurl_string, |
| 40 jint jpriority) { | 87 jint jpriority) { |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 | 306 |
| 260 void CronetURLRequestAdapter::OnSSLCertificateError( | 307 void CronetURLRequestAdapter::OnSSLCertificateError( |
| 261 net::URLRequest* request, | 308 net::URLRequest* request, |
| 262 const net::SSLInfo& ssl_info, | 309 const net::SSLInfo& ssl_info, |
| 263 bool fatal) { | 310 bool fatal) { |
| 264 DCHECK(context_->IsOnNetworkThread()); | 311 DCHECK(context_->IsOnNetworkThread()); |
| 265 request->Cancel(); | 312 request->Cancel(); |
| 266 int net_error = net::MapCertStatusToNetError(ssl_info.cert_status); | 313 int net_error = net::MapCertStatusToNetError(ssl_info.cert_status); |
| 267 JNIEnv* env = base::android::AttachCurrentThread(); | 314 JNIEnv* env = base::android::AttachCurrentThread(); |
| 268 cronet::Java_CronetUrlRequest_onError( | 315 cronet::Java_CronetUrlRequest_onError( |
| 269 env, owner_.obj(), net_error, | 316 env, owner_.obj(), NetErrorToUrlRequestError(net_error), net_error, |
| 270 ConvertUTF8ToJavaString(env, net::ErrorToString(net_error)).obj(), | 317 ConvertUTF8ToJavaString(env, net::ErrorToString(net_error)).obj(), |
| 271 request->GetTotalReceivedBytes()); | 318 request->GetTotalReceivedBytes()); |
| 272 } | 319 } |
| 273 | 320 |
| 274 void CronetURLRequestAdapter::OnResponseStarted(net::URLRequest* request) { | 321 void CronetURLRequestAdapter::OnResponseStarted(net::URLRequest* request) { |
| 275 DCHECK(context_->IsOnNetworkThread()); | 322 DCHECK(context_->IsOnNetworkThread()); |
| 276 if (MaybeReportError(request)) | 323 if (MaybeReportError(request)) |
| 277 return; | 324 return; |
| 278 JNIEnv* env = base::android::AttachCurrentThread(); | 325 JNIEnv* env = base::android::AttachCurrentThread(); |
| 279 cronet::Java_CronetUrlRequest_onResponseStarted( | 326 cronet::Java_CronetUrlRequest_onResponseStarted( |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 bool CronetURLRequestAdapter::MaybeReportError(net::URLRequest* request) const { | 428 bool CronetURLRequestAdapter::MaybeReportError(net::URLRequest* request) const { |
| 382 DCHECK_NE(net::URLRequestStatus::IO_PENDING, url_request_->status().status()); | 429 DCHECK_NE(net::URLRequestStatus::IO_PENDING, url_request_->status().status()); |
| 383 DCHECK_EQ(request, url_request_); | 430 DCHECK_EQ(request, url_request_); |
| 384 if (url_request_->status().is_success()) | 431 if (url_request_->status().is_success()) |
| 385 return false; | 432 return false; |
| 386 int net_error = url_request_->status().error(); | 433 int net_error = url_request_->status().error(); |
| 387 VLOG(1) << "Error " << net::ErrorToString(net_error) | 434 VLOG(1) << "Error " << net::ErrorToString(net_error) |
| 388 << " on chromium request: " << initial_url_.possibly_invalid_spec(); | 435 << " on chromium request: " << initial_url_.possibly_invalid_spec(); |
| 389 JNIEnv* env = base::android::AttachCurrentThread(); | 436 JNIEnv* env = base::android::AttachCurrentThread(); |
| 390 cronet::Java_CronetUrlRequest_onError( | 437 cronet::Java_CronetUrlRequest_onError( |
| 391 env, owner_.obj(), net_error, | 438 env, owner_.obj(), NetErrorToUrlRequestError(net_error), net_error, |
| 392 ConvertUTF8ToJavaString(env, net::ErrorToString(net_error)).obj(), | 439 ConvertUTF8ToJavaString(env, net::ErrorToString(net_error)).obj(), |
| 393 request->GetTotalReceivedBytes()); | 440 request->GetTotalReceivedBytes()); |
| 394 return true; | 441 return true; |
| 395 } | 442 } |
| 396 | 443 |
| 397 } // namespace cronet | 444 } // namespace cronet |
| OLD | NEW |