From aad0d2a7f669a5f98467054ada52e2ad31c8e9f4 Mon Sep 17 00:00:00 2001 From: James Willcox Date: Sat, 9 Jun 2018 20:24:46 -0500 Subject: [PATCH] Bug 1468048 - Make GeckoSession.saveState() return a GeckoResult r=droeh,esawin MozReview-Commit-ID: Ck6EZcaUeV2 --- .../org/mozilla/geckoview/GeckoSession.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java index c01327377273..891f6fc99255 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java @@ -100,6 +100,18 @@ public class GeckoSession extends LayerSession private String mId = UUID.randomUUID().toString().replace("-", ""); /* package */ String getId() { return mId; } + private static abstract class CallbackResult extends GeckoResult implements EventCallback { + @Override + public abstract void sendSuccess(Object response); + + @Override + public void sendError(Object response) { + completeExceptionally(response != null ? + new Exception(response.toString()) : + new UnknownError()); + } + } + private final GeckoSessionHandler mContentHandler = new GeckoSessionHandler( "GeckoViewContent", this, @@ -1147,22 +1159,17 @@ public class GeckoSession extends LayerSession * but does not include information pertaining to the GeckoSession itself (for example, * this does not include settings on the GeckoSession). * - * @param response This is a response which will be called with the state once it has been - * saved. Can be null if we fail to save the state for any reason. + * @return A {@link GeckoResult} containing the {@link SessionState} */ - public void saveState(final GeckoResponse response) { - mEventDispatcher.dispatch("GeckoView:SaveState", null, new EventCallback() { + public @NonNull GeckoResult saveState() { + CallbackResult result = new CallbackResult() { @Override - public void sendSuccess(final Object result) { - response.respond(new SessionState((String) result)); + public void sendSuccess(final Object value) { + complete(new SessionState((String)value)); } - - @Override - public void sendError(final Object result) { - Log.w(LOGTAG, "Failed to save state, as another save is already in progress."); - response.respond(null); - } - }); + }; + mEventDispatcher.dispatch("GeckoView:SaveState", null, result); + return result; } /**