[AW] Change prefetch exception boundary interface
Instead of creating boundary interface for each value type of the PrefetchExceptions, we can just use an enum and pass any necessary information in the onFailure and let AndroidX create this exception based on the data passed. This should be the clean and optimized way of handling it. Bug: 355430425 Change-Id: I186c3a443ecb24955442116ad49bb84a81b7f581 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6309156 Reviewed-by: Richard (Torne) Coles <torne@chromium.org> Commit-Queue: Sayed Elabady <elabadysayed@chromium.org> Cr-Commit-Position: refs/heads/main@{#1427142}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
ddafe310f9
commit
0434289fcb
@ -51,9 +51,6 @@ android_library("glue_java") {
|
||||
"java/src/com/android/webview/chromium/GraphicsUtils.java",
|
||||
"java/src/com/android/webview/chromium/NoVarySearchData.java",
|
||||
"java/src/com/android/webview/chromium/PacProcessorImpl.java",
|
||||
"java/src/com/android/webview/chromium/PrefetchDuplicateException.java",
|
||||
"java/src/com/android/webview/chromium/PrefetchException.java",
|
||||
"java/src/com/android/webview/chromium/PrefetchNetworkException.java",
|
||||
"java/src/com/android/webview/chromium/PrefetchOperationCallback.java",
|
||||
"java/src/com/android/webview/chromium/PrefetchOperationResult.java",
|
||||
"java/src/com/android/webview/chromium/PrefetchOperationStatusCode.java",
|
||||
|
@ -1,15 +0,0 @@
|
||||
// Copyright 2025 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package com.android.webview.chromium;
|
||||
|
||||
import org.chromium.android_webview.common.Lifetime;
|
||||
|
||||
/** A variation of {@link PrefetchException} for duplicate prefetch requests. */
|
||||
@Lifetime.Temporary
|
||||
public class PrefetchDuplicateException extends PrefetchException {
|
||||
public PrefetchDuplicateException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package com.android.webview.chromium;
|
||||
|
||||
import org.chromium.android_webview.common.Lifetime;
|
||||
|
||||
/** A generic class for the prefetch exception. */
|
||||
@Lifetime.Temporary
|
||||
public class PrefetchException extends Exception {
|
||||
|
||||
public PrefetchException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public PrefetchException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package com.android.webview.chromium;
|
||||
|
||||
import org.chromium.android_webview.common.Lifetime;
|
||||
|
||||
/** A variation of {@link PrefetchException} for the network operation. */
|
||||
@Lifetime.Temporary
|
||||
public class PrefetchNetworkException extends PrefetchException {
|
||||
private final int mHttpResponseStatusCode;
|
||||
|
||||
public PrefetchNetworkException(String error, int httpResponseStatusCode) {
|
||||
super(error);
|
||||
mHttpResponseStatusCode = httpResponseStatusCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* HttpResponseStatusCode is based on <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status">MDN web response codes</a>.
|
||||
*/
|
||||
public int getHttpResponseStatusCode() {
|
||||
return mHttpResponseStatusCode;
|
||||
}
|
||||
}
|
@ -10,5 +10,5 @@ import org.chromium.android_webview.common.Lifetime;
|
||||
public interface PrefetchOperationCallback {
|
||||
void onSuccess();
|
||||
|
||||
void onError(PrefetchException prefetchException);
|
||||
void onError(@PrefetchOperationStatusCode int errorCode, String message, int networkErrorCode);
|
||||
}
|
||||
|
@ -32,29 +32,29 @@ public class ProfileWebViewPrefetchCallback implements AwPrefetchCallback {
|
||||
if (operationResult.statusCode == PrefetchOperationStatusCode.SUCCESS) {
|
||||
mCallbackExecutor.execute(mCallback::onSuccess);
|
||||
} else {
|
||||
resolvePrefetchErrorCallback(errorFromOperationResult(operationResult));
|
||||
resolvePrefetchErrorCallback(operationResult);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
resolvePrefetchErrorCallback(new PrefetchException(e));
|
||||
mCallback.onError(PrefetchOperationStatusCode.FAILURE, e.getMessage(), 0);
|
||||
}
|
||||
|
||||
private PrefetchException errorFromOperationResult(PrefetchOperationResult operationResult) {
|
||||
private void resolvePrefetchErrorCallback(PrefetchOperationResult operationResult) {
|
||||
assert operationResult.statusCode != PrefetchOperationStatusCode.SUCCESS;
|
||||
return switch (operationResult.statusCode) {
|
||||
case PrefetchOperationStatusCode.FAILURE -> new PrefetchException(
|
||||
"Prefetch request failed");
|
||||
case PrefetchOperationStatusCode.SERVER_FAILURE -> new PrefetchNetworkException(
|
||||
"Server error", operationResult.httpResponseStatusCode);
|
||||
case PrefetchOperationStatusCode.DUPLICATE_REQUEST -> new PrefetchDuplicateException(
|
||||
"Duplicate prefetch request");
|
||||
default -> new PrefetchException("Unexpected error occurred.");
|
||||
};
|
||||
}
|
||||
|
||||
private void resolvePrefetchErrorCallback(PrefetchException e) {
|
||||
mCallbackExecutor.execute(() -> mCallback.onError(e));
|
||||
int errorCode = 0;
|
||||
String message;
|
||||
switch (operationResult.statusCode) {
|
||||
case PrefetchOperationStatusCode.FAILURE -> message = "Prefetch request failed";
|
||||
case PrefetchOperationStatusCode.SERVER_FAILURE -> {
|
||||
message = "Server error";
|
||||
errorCode = operationResult.httpResponseStatusCode;
|
||||
}
|
||||
case PrefetchOperationStatusCode.DUPLICATE_REQUEST -> message =
|
||||
"Duplicate prefetch request";
|
||||
default -> message = "Unexpected error occurred.";
|
||||
}
|
||||
mCallback.onError(operationResult.statusCode, message, errorCode);
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,6 @@ android_library("support_lib_glue_java") {
|
||||
"java/src/org/chromium/support_lib_glue/IsomorphicAdapter.java",
|
||||
"java/src/org/chromium/support_lib_glue/SupportLibDropDataContentProviderAdapter.java",
|
||||
"java/src/org/chromium/support_lib_glue/SupportLibJsReplyProxyAdapter.java",
|
||||
"java/src/org/chromium/support_lib_glue/SupportLibPrefetchDuplicateException.java",
|
||||
"java/src/org/chromium/support_lib_glue/SupportLibPrefetchException.java",
|
||||
"java/src/org/chromium/support_lib_glue/SupportLibPrefetchNetworkException.java",
|
||||
"java/src/org/chromium/support_lib_glue/SupportLibProfile.java",
|
||||
"java/src/org/chromium/support_lib_glue/SupportLibProfileStore.java",
|
||||
"java/src/org/chromium/support_lib_glue/SupportLibProxyControllerAdapter.java",
|
||||
|
@ -13,9 +13,6 @@ android_library("boundary_interface_java") {
|
||||
"src/org/chromium/support_lib_boundary/IsomorphicObjectBoundaryInterface.java",
|
||||
"src/org/chromium/support_lib_boundary/JsReplyProxyBoundaryInterface.java",
|
||||
"src/org/chromium/support_lib_boundary/NoVarySearchDataBoundaryInterface.java",
|
||||
"src/org/chromium/support_lib_boundary/PrefetchDuplicateExceptionBoundaryInterface.java",
|
||||
"src/org/chromium/support_lib_boundary/PrefetchExceptionBoundaryInterface.java",
|
||||
"src/org/chromium/support_lib_boundary/PrefetchNetworkExceptionBoundaryInterface.java",
|
||||
"src/org/chromium/support_lib_boundary/PrefetchOperationCallbackBoundaryInterface.java",
|
||||
"src/org/chromium/support_lib_boundary/ProcessGlobalConfigConstants.java",
|
||||
"src/org/chromium/support_lib_boundary/ProfileBoundaryInterface.java",
|
||||
|
@ -1,11 +0,0 @@
|
||||
// Copyright 2025 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package org.chromium.support_lib_boundary;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public interface PrefetchDuplicateExceptionBoundaryInterface
|
||||
extends PrefetchExceptionBoundaryInterface {}
|
@ -1,16 +0,0 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package org.chromium.support_lib_boundary;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
@NullMarked
|
||||
public interface PrefetchExceptionBoundaryInterface {
|
||||
|
||||
@Nullable String getMessage();
|
||||
|
||||
@Nullable Throwable getCause();
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package org.chromium.support_lib_boundary;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public interface PrefetchNetworkExceptionBoundaryInterface
|
||||
extends PrefetchExceptionBoundaryInterface {
|
||||
|
||||
int getHttpResponseStatusCode();
|
||||
}
|
@ -4,14 +4,29 @@
|
||||
|
||||
package org.chromium.support_lib_boundary;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@NullMarked
|
||||
public interface PrefetchOperationCallbackBoundaryInterface {
|
||||
@IntDef({
|
||||
PrefetchExceptionTypeBoundaryInterface.GENERIC,
|
||||
PrefetchExceptionTypeBoundaryInterface.NETWORK,
|
||||
PrefetchExceptionTypeBoundaryInterface.DUPLICATE
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@interface PrefetchExceptionTypeBoundaryInterface {
|
||||
int GENERIC = 0;
|
||||
int NETWORK = 1;
|
||||
int DUPLICATE = 2;
|
||||
}
|
||||
|
||||
void onSuccess();
|
||||
|
||||
void onFailure(/* PrefetchException */ InvocationHandler failure);
|
||||
void onFailure(
|
||||
@PrefetchExceptionTypeBoundaryInterface int type, String message, int networkErrorCode);
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ public class Features {
|
||||
|
||||
// Profile.prefetchUrl
|
||||
// Profile.clearPrefetch
|
||||
public static final String PREFETCH_WITH_URL = "PREFETCH_URL_V3";
|
||||
public static final String PREFETCH_WITH_URL = "PREFETCH_URL_V4";
|
||||
|
||||
// WebviewCompat.setDefaultTrafficStatsTag
|
||||
// WebviewCompat.setDefaultTrafficStatsUid
|
||||
|
@ -1,30 +0,0 @@
|
||||
// Copyright 2025 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package org.chromium.support_lib_glue;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.webview.chromium.PrefetchDuplicateException;
|
||||
|
||||
import org.chromium.support_lib_boundary.PrefetchDuplicateExceptionBoundaryInterface;
|
||||
|
||||
public class SupportLibPrefetchDuplicateException
|
||||
implements PrefetchDuplicateExceptionBoundaryInterface {
|
||||
PrefetchDuplicateException mException;
|
||||
|
||||
public SupportLibPrefetchDuplicateException(@NonNull PrefetchDuplicateException exception) {
|
||||
mException = exception;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return mException.getMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Throwable getCause() {
|
||||
return mException.getCause();
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package org.chromium.support_lib_glue;
|
||||
|
||||
import com.android.webview.chromium.PrefetchException;
|
||||
|
||||
import org.chromium.support_lib_boundary.PrefetchExceptionBoundaryInterface;
|
||||
|
||||
public class SupportLibPrefetchException implements PrefetchExceptionBoundaryInterface {
|
||||
PrefetchException mException;
|
||||
|
||||
public SupportLibPrefetchException(PrefetchException exception) {
|
||||
mException = exception;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return mException.getMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Throwable getCause() {
|
||||
return mException.getCause();
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package org.chromium.support_lib_glue;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.webview.chromium.PrefetchNetworkException;
|
||||
|
||||
import org.chromium.support_lib_boundary.PrefetchNetworkExceptionBoundaryInterface;
|
||||
|
||||
public class SupportLibPrefetchNetworkException
|
||||
implements PrefetchNetworkExceptionBoundaryInterface {
|
||||
PrefetchNetworkException mException;
|
||||
|
||||
public SupportLibPrefetchNetworkException(@NonNull PrefetchNetworkException exception) {
|
||||
mException = exception;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return mException.getMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Throwable getCause() {
|
||||
return mException.getCause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHttpResponseStatusCode() {
|
||||
return mException.getHttpResponseStatusCode();
|
||||
}
|
||||
}
|
@ -15,15 +15,12 @@ import android.webkit.WebStorage;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.webview.chromium.PrefetchDuplicateException;
|
||||
import com.android.webview.chromium.PrefetchException;
|
||||
import com.android.webview.chromium.PrefetchNetworkException;
|
||||
import com.android.webview.chromium.PrefetchOperationCallback;
|
||||
import com.android.webview.chromium.PrefetchOperationStatusCode;
|
||||
import com.android.webview.chromium.Profile;
|
||||
import com.android.webview.chromium.SpeculativeLoadingConfig;
|
||||
|
||||
import org.chromium.android_webview.common.Lifetime;
|
||||
import org.chromium.support_lib_boundary.PrefetchExceptionBoundaryInterface;
|
||||
import org.chromium.support_lib_boundary.PrefetchOperationCallbackBoundaryInterface;
|
||||
import org.chromium.support_lib_boundary.ProfileBoundaryInterface;
|
||||
import org.chromium.support_lib_boundary.SpeculativeLoadingConfigBoundaryInterface;
|
||||
@ -158,22 +155,31 @@ public class SupportLibProfile implements ProfileBoundaryInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(PrefetchException prefetchException) {
|
||||
operationCallback.onFailure(
|
||||
BoundaryInterfaceReflectionUtil.createInvocationHandlerFor(
|
||||
mapPrefetchException(prefetchException)));
|
||||
public void onError(
|
||||
@PrefetchOperationStatusCode int errorCode,
|
||||
String message,
|
||||
int networkErrorCode) {
|
||||
mapFailure(operationCallback, errorCode, message, networkErrorCode);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private PrefetchExceptionBoundaryInterface mapPrefetchException(
|
||||
PrefetchException preMappedException) {
|
||||
if (preMappedException instanceof PrefetchNetworkException networkException) {
|
||||
return new SupportLibPrefetchNetworkException(networkException);
|
||||
} else if (preMappedException instanceof PrefetchDuplicateException duplicateException) {
|
||||
return new SupportLibPrefetchDuplicateException(duplicateException);
|
||||
} else {
|
||||
return new SupportLibPrefetchException(preMappedException);
|
||||
}
|
||||
private void mapFailure(
|
||||
PrefetchOperationCallbackBoundaryInterface callback,
|
||||
@PrefetchOperationStatusCode int errorCode,
|
||||
String message,
|
||||
int networkErrorCode) {
|
||||
int type =
|
||||
switch (errorCode) {
|
||||
case PrefetchOperationStatusCode
|
||||
.SERVER_FAILURE -> PrefetchOperationCallbackBoundaryInterface
|
||||
.PrefetchExceptionTypeBoundaryInterface.NETWORK;
|
||||
case PrefetchOperationStatusCode
|
||||
.DUPLICATE_REQUEST -> PrefetchOperationCallbackBoundaryInterface
|
||||
.PrefetchExceptionTypeBoundaryInterface.DUPLICATE;
|
||||
default -> PrefetchOperationCallbackBoundaryInterface
|
||||
.PrefetchExceptionTypeBoundaryInterface.GENERIC;
|
||||
};
|
||||
callback.onFailure(type, message, networkErrorCode);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user