Commit 54401ba9 authored by Laís Minchillo's avatar Laís Minchillo Committed by Commit Bot

[aw] Throw exception from AwProxyController

Throw IllegalArgumentException from AwProxyController instead of
throwing it in the support library glue. Update runBlockingFuture in
WebViewChromiumRunQueue to handle ExecutionException.

Bug: 1016285
Change-Id: Ic6a7903b2cfc6ca4f29e7a93ea1613434f5899da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872592
Commit-Queue: Laís Minchillo <laisminchillo@chromium.org>
Auto-Submit: Laís Minchillo <laisminchillo@chromium.org>
Reviewed-by: default avatarTobias Sargeant <tobiasjs@chromium.org>
Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712582}
parent 3b235277
...@@ -46,7 +46,7 @@ public class AwProxyController { ...@@ -46,7 +46,7 @@ public class AwProxyController {
public AwProxyController() {} public AwProxyController() {}
public String setProxyOverride( public void setProxyOverride(
String[][] proxyRules, String[] bypassRules, Runnable listener, Executor executor) { String[][] proxyRules, String[] bypassRules, Runnable listener, Executor executor) {
int length = (proxyRules == null ? 0 : proxyRules.length); int length = (proxyRules == null ? 0 : proxyRules.length);
String[] urlSchemes = new String[length]; String[] urlSchemes = new String[length];
...@@ -63,7 +63,7 @@ public class AwProxyController { ...@@ -63,7 +63,7 @@ public class AwProxyController {
// proxy URLs // proxy URLs
proxyUrls[i] = proxyRules[i][1]; proxyUrls[i] = proxyRules[i][1];
if (proxyUrls[i] == null) { if (proxyUrls[i] == null) {
return "Proxy rule " + i + " has a null url"; throw new IllegalArgumentException("Proxy rule " + i + " has a null url");
} }
// Check schemes for UMA // Check schemes for UMA
if (proxyRules[i][0].equals("http")) { if (proxyRules[i][0].equals("http")) {
...@@ -86,40 +86,41 @@ public class AwProxyController { ...@@ -86,40 +86,41 @@ public class AwProxyController {
length = (bypassRules == null ? 0 : bypassRules.length); length = (bypassRules == null ? 0 : bypassRules.length);
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
if (bypassRules[i] == null) { if (bypassRules[i] == null) {
return "Bypass rule " + i + " is null"; throw new IllegalArgumentException("Bypass rule " + i + " is null");
} }
} }
if (executor == null) { if (executor == null) {
return "Executor must not be null"; throw new IllegalArgumentException("Executor must not be null");
} }
String result = AwProxyControllerJni.get().setProxyOverride( String result = AwProxyControllerJni.get().setProxyOverride(
AwProxyController.this, urlSchemes, proxyUrls, bypassRules, listener, executor); AwProxyController.this, urlSchemes, proxyUrls, bypassRules, listener, executor);
if (result.equals("")) { if (!result.isEmpty()) {
// In case operation is successful, log UMA data on SetProxyOverride throw new IllegalArgumentException(result);
// Proxy scheme filter }
if (schemeHttp && schemeHttps) {
recordProxySchemeType(ProxySchemeType.ALL); // In case operation is successful, log UMA data on SetProxyOverride
} else if (schemeHttp) { // Proxy scheme filter
recordProxySchemeType(ProxySchemeType.HTTP); if (schemeHttp && schemeHttps) {
} else if (schemeHttps) { recordProxySchemeType(ProxySchemeType.ALL);
recordProxySchemeType(ProxySchemeType.HTTPS); } else if (schemeHttp) {
} recordProxySchemeType(ProxySchemeType.HTTP);
// Proxy url type } else if (schemeHttps) {
if (urlHttp) { recordProxySchemeType(ProxySchemeType.HTTPS);
recordProxyUrlType(ProxyUrlType.HTTP); }
} // Proxy url type
if (urlHttps) { if (urlHttp) {
recordProxyUrlType(ProxyUrlType.HTTPS); recordProxyUrlType(ProxyUrlType.HTTP);
} }
if (urlDirect) { if (urlHttps) {
recordProxyUrlType(ProxyUrlType.DIRECT); recordProxyUrlType(ProxyUrlType.HTTPS);
} }
// Bypass rules if (urlDirect) {
RecordHistogram.recordBooleanHistogram("Android.WebView.SetProxyOverride.BypassRules", recordProxyUrlType(ProxyUrlType.DIRECT);
bypassRules == null || bypassRules.length == 0 ? false : true);
} }
return result; // Bypass rules
RecordHistogram.recordBooleanHistogram("Android.WebView.SetProxyOverride.BypassRules",
bypassRules == null || bypassRules.length == 0 ? false : true);
} }
private static void recordProxySchemeType(@ProxySchemeType int proxySchemeType) { private static void recordProxySchemeType(@ProxySchemeType int proxySchemeType) {
...@@ -133,15 +134,14 @@ public class AwProxyController { ...@@ -133,15 +134,14 @@ public class AwProxyController {
proxyUrlType, ProxyUrlType.NUM_ENTRIES); proxyUrlType, ProxyUrlType.NUM_ENTRIES);
} }
public String clearProxyOverride(Runnable listener, Executor executor) { public void clearProxyOverride(Runnable listener, Executor executor) {
if (executor == null) { if (executor == null) {
return "Executor must not be null"; throw new IllegalArgumentException("Executor must not be null");
} }
AwProxyControllerJni.get().clearProxyOverride(AwProxyController.this, listener, executor); AwProxyControllerJni.get().clearProxyOverride(AwProxyController.this, listener, executor);
// Log UMA data on ClearProxyOverride // Log UMA data on ClearProxyOverride
RecordHistogram.recordBooleanHistogram("Android.WebView.ClearProxyOverride", true); RecordHistogram.recordBooleanHistogram("Android.WebView.ClearProxyOverride", true);
return "";
} }
@CalledByNativeUnchecked @CalledByNativeUnchecked
......
...@@ -21,6 +21,7 @@ import org.chromium.base.test.util.Feature; ...@@ -21,6 +21,7 @@ import org.chromium.base.test.util.Feature;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.test.util.TestWebServer; import org.chromium.net.test.util.TestWebServer;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
/** /**
...@@ -212,37 +213,42 @@ public class AwProxyControllerTest { ...@@ -212,37 +213,42 @@ public class AwProxyControllerTest {
throws Exception { throws Exception {
CallbackHelper ch = new CallbackHelper(); CallbackHelper ch = new CallbackHelper();
int callCount = ch.getCallCount(); int callCount = ch.getCallCount();
String result = TestThreadUtils.runOnUiThreadBlocking(() -> { runOnUiThreadBlocking(() -> {
return mAwProxyController.setProxyOverride(proxyRules, bypassRules, new Runnable() { mAwProxyController.setProxyOverride(proxyRules, bypassRules, new Runnable() {
@Override @Override
public void run() { public void run() {
ch.notifyCalled(); ch.notifyCalled();
} }
}, new SynchronousExecutor()); }, new SynchronousExecutor());
}); });
if (!result.isEmpty()) {
throw new IllegalArgumentException(result);
}
ch.waitForCallback(callCount); ch.waitForCallback(callCount);
} }
private void clearProxyOverrideSync() throws Exception { private void clearProxyOverrideSync() throws Exception {
CallbackHelper ch = new CallbackHelper(); CallbackHelper ch = new CallbackHelper();
int callCount = ch.getCallCount(); int callCount = ch.getCallCount();
String result = TestThreadUtils.runOnUiThreadBlocking(() -> { runOnUiThreadBlocking(() -> {
return mAwProxyController.clearProxyOverride(new Runnable() { mAwProxyController.clearProxyOverride(new Runnable() {
@Override @Override
public void run() { public void run() {
ch.notifyCalled(); ch.notifyCalled();
} }
}, new SynchronousExecutor()); }, new SynchronousExecutor());
}); });
if (!result.isEmpty()) {
throw new IllegalArgumentException(result);
}
ch.waitForCallback(callCount); ch.waitForCallback(callCount);
} }
private void runOnUiThreadBlocking(Runnable r) throws Exception {
try {
TestThreadUtils.runOnUiThreadBlocking(r);
} catch (RuntimeException e) {
Throwable cause = e.getCause();
if (cause instanceof ExecutionException) cause = cause.getCause();
if (cause instanceof IllegalArgumentException) throw (IllegalArgumentException) cause;
throw e;
}
}
static class SynchronousExecutor implements Executor { static class SynchronousExecutor implements Executor {
@Override @Override
public void execute(Runnable r) { public void execute(Runnable r) {
......
...@@ -9,6 +9,7 @@ import org.chromium.android_webview.WebViewChromiumRunQueue; ...@@ -9,6 +9,7 @@ import org.chromium.android_webview.WebViewChromiumRunQueue;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.support_lib_boundary.ProxyControllerBoundaryInterface; import org.chromium.support_lib_boundary.ProxyControllerBoundaryInterface;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
/** /**
...@@ -27,31 +28,44 @@ public class SupportLibProxyControllerAdapter implements ProxyControllerBoundary ...@@ -27,31 +28,44 @@ public class SupportLibProxyControllerAdapter implements ProxyControllerBoundary
@Override @Override
public void setProxyOverride( public void setProxyOverride(
String[][] proxyRules, String[] bypassRules, Runnable listener, Executor executor) { String[][] proxyRules, String[] bypassRules, Runnable listener, Executor executor) {
String result;
if (checkNeedsPost()) { if (checkNeedsPost()) {
result = mRunQueue.runOnUiThreadBlocking(() -> { RuntimeException exception = mRunQueue.runOnUiThreadBlocking(() -> {
return mProxyController.setProxyOverride( try {
proxyRules, bypassRules, listener, executor); mProxyController.setProxyOverride(proxyRules, bypassRules, listener, executor);
} catch (RuntimeException e) {
return e;
}
return null;
}); });
maybeThrowUnwrappedException(exception);
} else { } else {
result = mProxyController.setProxyOverride(proxyRules, bypassRules, listener, executor); mProxyController.setProxyOverride(proxyRules, bypassRules, listener, executor);
}
if (!result.isEmpty()) {
throw new IllegalArgumentException(result);
} }
} }
@Override @Override
public void clearProxyOverride(Runnable listener, Executor executor) { public void clearProxyOverride(Runnable listener, Executor executor) {
String result;
if (checkNeedsPost()) { if (checkNeedsPost()) {
result = mRunQueue.runOnUiThreadBlocking( RuntimeException exception = mRunQueue.runOnUiThreadBlocking(() -> {
() -> { return mProxyController.clearProxyOverride(listener, executor); }); try {
mProxyController.clearProxyOverride(listener, executor);
} catch (RuntimeException e) {
return e;
}
return null;
});
maybeThrowUnwrappedException(exception);
} else { } else {
result = mProxyController.clearProxyOverride(listener, executor); mProxyController.clearProxyOverride(listener, executor);
} }
if (!result.isEmpty()) { }
throw new IllegalArgumentException(result);
private void maybeThrowUnwrappedException(RuntimeException exception) {
if (exception != null) {
Throwable cause = exception.getCause();
if (cause instanceof ExecutionException) cause = cause.getCause();
if (cause instanceof RuntimeException) throw (RuntimeException) cause;
throw exception;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment