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

Unified Diff: components/cronet/android/cronet_url_request_adapter.cc

Issue 1393713005: [Cronet] Add error code and immediatelyRetryable() to UrlRequestException (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: components/cronet/android/cronet_url_request_adapter.cc
diff --git a/components/cronet/android/cronet_url_request_adapter.cc b/components/cronet/android/cronet_url_request_adapter.cc
index 14115e07d9d720799a2e1b438b6ca15f0b4b0e09..c867d996fce3da429ba5e90f177af8b265e4dc69 100644
--- a/components/cronet/android/cronet_url_request_adapter.cc
+++ b/components/cronet/android/cronet_url_request_adapter.cc
@@ -27,6 +27,53 @@ using base::android::ConvertUTF8ToJavaString;
namespace cronet {
+namespace {
+
+// Error codes for the most popular network stack error codes.
+// For descriptions see corresponding constants in UrlRequestException.java.
+// A Java counterpart will be generated for this enum.
+// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net
+enum UrlRequestError {
+ LISTENER_THREW,
+ HOSTNAME_NOT_RESOLVED,
+ INTERNET_DISCONNECTED,
+ NETWORK_CHANGED,
+ TIMED_OUT,
+ CONNECTION_CLOSED,
+ CONNECTION_TIMED_OUT,
+ CONNECTION_REFUSED,
+ CONNECTION_RESET,
+ ADDRESS_UNREACHABLE,
+ OTHER,
+};
+
+// Convert most popular net::ERR_* values to counterparts accessible in Java.
+UrlRequestError NetErrorToUrlRequestError(int net_error) {
+ switch (net_error) {
+ case net::ERR_NAME_NOT_RESOLVED:
+ return HOSTNAME_NOT_RESOLVED;
+ case net::ERR_INTERNET_DISCONNECTED:
+ return INTERNET_DISCONNECTED;
+ case net::ERR_NETWORK_CHANGED:
+ return NETWORK_CHANGED;
+ case net::ERR_TIMED_OUT:
+ return TIMED_OUT;
+ case net::ERR_CONNECTION_CLOSED:
+ return CONNECTION_CLOSED;
+ case net::ERR_CONNECTION_TIMED_OUT:
+ return CONNECTION_TIMED_OUT;
+ case net::ERR_CONNECTION_REFUSED:
+ return CONNECTION_REFUSED;
+ case net::ERR_CONNECTION_RESET:
+ return CONNECTION_RESET;
+ case net::ERR_ADDRESS_UNREACHABLE:
+ return ADDRESS_UNREACHABLE;
+ default:
+ return OTHER;
+ }
+}
+}
+
// Explicitly register static JNI functions.
bool CronetUrlRequestAdapterRegisterJni(JNIEnv* env) {
return RegisterNativesImpl(env);
@@ -282,7 +329,7 @@ void CronetURLRequestAdapter::OnSSLCertificateError(
int net_error = net::MapCertStatusToNetError(ssl_info.cert_status);
JNIEnv* env = base::android::AttachCurrentThread();
cronet::Java_CronetUrlRequest_onError(
- env, owner_.obj(), net_error,
+ env, owner_.obj(), NetErrorToUrlRequestError(net_error), net_error,
ConvertUTF8ToJavaString(env, net::ErrorToString(net_error)).obj());
}
@@ -379,7 +426,7 @@ bool CronetURLRequestAdapter::MaybeReportError(net::URLRequest* request) const {
<< " on chromium request: " << initial_url_.possibly_invalid_spec();
JNIEnv* env = base::android::AttachCurrentThread();
cronet::Java_CronetUrlRequest_onError(
- env, owner_.obj(), net_error,
+ env, owner_.obj(), NetErrorToUrlRequestError(net_error), net_error,
ConvertUTF8ToJavaString(env, net::ErrorToString(net_error)).obj());
return true;
}

Powered by Google App Engine
This is Rietveld 408576698