Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handles better failure cases on Android Safe Browsing #19544

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;

/**
* Brave implementation of SafetyNetApiHandler for Safe Browsing
*/
public class BraveSafeBrowsingApiHandler implements SafetyNetApiHandler {
public static final long SAFE_BROWSING_INIT_INTERVAL_MS = 30000;
private static final long DEFAULT_CHECK_DELTA = 10;
private static final String SAFE_METADATA = "{}";
private static final String TAG = "BraveSafeBrowsingApiHandler";

/**
*This is a delegate that is implemented in the object where the handler is created
*/
public interface BraveSafeBrowsingApiHandlerDelegate {
default void turnSafeBrowsingOff() {}
default boolean isSafeBrowsingEnabled() {
Expand All @@ -39,16 +45,16 @@ default boolean isSafeBrowsingEnabled() {
private boolean mInitialized;
private int mTriesCount;
private BraveSafeBrowsingApiHandlerDelegate mBraveSafeBrowsingApiHandlerDelegate;
private static final Object lock = new Object();
private static BraveSafeBrowsingApiHandler instance;
private static final Object sLock = new Object();
private static BraveSafeBrowsingApiHandler sInstance;

public static BraveSafeBrowsingApiHandler getInstance() {
synchronized (lock) {
if (instance == null) {
instance = new BraveSafeBrowsingApiHandler();
synchronized (sLock) {
if (sInstance == null) {
sInstance = new BraveSafeBrowsingApiHandler();
}
}
return instance;
return sInstance;
}

public void setDelegate(String apiKey,
Expand Down Expand Up @@ -142,12 +148,17 @@ public void startUriLookup(final long callbackId, String uri, int[] threatsOfInt
== SafetyNetStatusCodes.SAFE_BROWSING_API_NOT_INITIALIZED) {
initSafeBrowsing();
startUriLookup(callbackId, uri, threatsOfInterest);
} else {
mObserver.onUrlCheckDone(callbackId, SafeBrowsingResult.TIMEOUT, "{}",
DEFAULT_CHECK_DELTA);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is DEFAULT_CHECK_DELTA in seconds?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// |check_delta| is the number of microseconds it took to look up the URL
// reputation from GmsCore.

}
} else {
// A different, unknown type of error occurred.
if (isDebuggable()) {
Log.d(TAG, "Error: " + e.getMessage());
}
mObserver.onUrlCheckDone(
callbackId, SafeBrowsingResult.TIMEOUT, "{}", DEFAULT_CHECK_DELTA);
}
mTriesCount = 0;
});
Expand Down