Bug 1468048 - Make GeckoSession.saveState() return a GeckoResult r=droeh,esawin

MozReview-Commit-ID: Ck6EZcaUeV2
This commit is contained in:
James Willcox 2018-06-09 20:24:46 -05:00
Родитель 68a96de0af
Коммит aad0d2a7f6
1 изменённых файлов: 20 добавлений и 13 удалений

Просмотреть файл

@ -100,6 +100,18 @@ public class GeckoSession extends LayerSession
private String mId = UUID.randomUUID().toString().replace("-", ""); private String mId = UUID.randomUUID().toString().replace("-", "");
/* package */ String getId() { return mId; } /* package */ String getId() { return mId; }
private static abstract class CallbackResult<T> extends GeckoResult<T> 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<ContentDelegate> mContentHandler = private final GeckoSessionHandler<ContentDelegate> mContentHandler =
new GeckoSessionHandler<ContentDelegate>( new GeckoSessionHandler<ContentDelegate>(
"GeckoViewContent", this, "GeckoViewContent", this,
@ -1147,22 +1159,17 @@ public class GeckoSession extends LayerSession
* but does not include information pertaining to the GeckoSession itself (for example, * but does not include information pertaining to the GeckoSession itself (for example,
* this does not include settings on the GeckoSession). * 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 * @return A {@link GeckoResult} containing the {@link SessionState}
* saved. Can be null if we fail to save the state for any reason.
*/ */
public void saveState(final GeckoResponse<SessionState> response) { public @NonNull GeckoResult<SessionState> saveState() {
mEventDispatcher.dispatch("GeckoView:SaveState", null, new EventCallback() { CallbackResult<SessionState> result = new CallbackResult<SessionState>() {
@Override @Override
public void sendSuccess(final Object result) { public void sendSuccess(final Object value) {
response.respond(new SessionState((String) result)); complete(new SessionState((String)value));
} }
};
@Override mEventDispatcher.dispatch("GeckoView:SaveState", null, result);
public void sendError(final Object result) { return result;
Log.w(LOGTAG, "Failed to save state, as another save is already in progress.");
response.respond(null);
}
});
} }
/** /**