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

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: Address Helen's comments Created 5 years, 1 month 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 46e789375ca562f321f3df9dc483e9576d5a46db..955cb5d29b446866860e9539fe8bc8d924ffee44 100644
--- a/components/cronet/android/cronet_url_request_adapter.cc
+++ b/components/cronet/android/cronet_url_request_adapter.cc
@@ -28,6 +28,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.
xunjieli 2015/11/06 15:23:22 nit: Convert -> Converts
pauljensen 2016/01/25 01:43:51 Done.
+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);
@@ -266,7 +313,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(),
request->GetTotalReceivedBytes());
}
@@ -388,7 +435,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(),
request->GetTotalReceivedBytes());
return true;

Powered by Google App Engine
This is Rietveld 408576698