Goktug Gokdogan has submitted this change and it was merged.
Change subject: Adds a module to revert GWT.runAsync to do immediate
callbacks in consecutive calls.
......................................................................
Adds a module to revert GWT.runAsync to do immediate callbacks in
consecutive calls.
This is for backward compatibility until a major release. It introduces a
module
that can be inherited by user module to revert back GWT.runAsync to old
behavior.
Change-Id: If3a54663d6d857ca294c99a1a99084328748996d
---
A user/src/com/google/gwt/core/SynchronousFragmentLoadCallback.gwt.xml
M user/src/com/google/gwt/core/client/impl/AsyncFragmentLoader.java
A user/src/com/google/gwt/core/client/impl/OnSuccessExecutor.java
A user/src/com/google/gwt/core/client/impl/SynchronousOnSuccessExecutor.java
M user/test/com/google/gwt/core/client/impl/AsyncFragmentLoaderTest.java
5 files changed, 114 insertions(+), 30 deletions(-)
Approvals:
Roberto Lublinerman: Looks good to me, approved
Leeroy Jenkins: Verified
diff --git
a/user/src/com/google/gwt/core/SynchronousFragmentLoadCallback.gwt.xml
b/user/src/com/google/gwt/core/SynchronousFragmentLoadCallback.gwt.xml
new file mode 100644
index 0000000..1a37fb2
--- /dev/null
+++ b/user/src/com/google/gwt/core/SynchronousFragmentLoadCallback.gwt.xml
@@ -0,0 +1,24 @@
+<!--
-->
+<!-- Copyright 2013 Google
Inc. -->
+<!-- Licensed under the Apache License, Version 2.0 (the "License");
you -->
+<!-- may not use this file except in compliance with the License. You
may -->
+<!-- may obtain a copy of the License
at -->
+<!--
-->
+<!--
http://www.apache.org/licenses/LICENSE-2.0 -->
+<!--
-->
+<!-- Unless required by applicable law or agreed to in writing,
software -->
+<!-- distributed under the License is distributed on an "AS IS"
BASIS, -->
+<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or -->
+<!-- implied. License for the specific language governing permissions
and -->
+<!-- limitations under the
License. -->
+
+<!-- Inheriting this module makes callback executed immediately
if -->
+<!-- GWT.runAsync is called against already loaded
fragment. -->
+
+<!-- TODO(goktug): remove after 2.6 is
released -->
+
+<module>
+ <replace-with
class="com.google.gwt.core.client.impl.SynchronousOnSuccessExecutor">
+ <when-type-is
class="com.google.gwt.core.client.impl.OnSuccessExecutor"/>
+ </replace-with>
+</module>
\ No newline at end of file
diff --git
a/user/src/com/google/gwt/core/client/impl/AsyncFragmentLoader.java
b/user/src/com/google/gwt/core/client/impl/AsyncFragmentLoader.java
index 77ab67f..d6ac682 100644
--- a/user/src/com/google/gwt/core/client/impl/AsyncFragmentLoader.java
+++ b/user/src/com/google/gwt/core/client/impl/AsyncFragmentLoader.java
@@ -18,8 +18,6 @@
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.RunAsyncCallback;
-import com.google.gwt.core.client.Scheduler;
-import com.google.gwt.core.client.Scheduler.ScheduledCommand;
/**
* <p>
@@ -57,7 +55,7 @@
* been installed, so that {@link AsyncFragmentLoader} can distinguish
* successful from unsuccessful downloads.
*/
- public static interface LoadTerminatedHandler {
+ public interface LoadTerminatedHandler {
void loadTerminated(Throwable reason);
}
@@ -297,12 +295,15 @@
*/
private static AsyncFragmentLoader makeBrowserLoader(int numFragments,
int initialLoad[]) {
if (GWT.isClient()) {
- return new AsyncFragmentLoader(numFragments, initialLoad,
(LoadingStrategy) GWT
- .create(LoadingStrategy.class), (Logger)
GWT.create(Logger.class));
+ return new AsyncFragmentLoader(numFragments, initialLoad,
+ (LoadingStrategy) GWT.create(LoadingStrategy.class), (Logger)
GWT.create(Logger.class),
+ (OnSuccessExecutor) GWT.create(OnSuccessExecutor.class));
} else {
return null;
}
}
+
+ private final OnSuccessExecutor onSuccessExecutor;
/**
* Callbacks indexed by fragment number.
@@ -371,11 +372,12 @@
private final BoundedIntQueue requestedExclusives;
public AsyncFragmentLoader(int numEntries, int[] initialLoadSequence,
- LoadingStrategy loadingStrategy, Logger logger) {
+ LoadingStrategy loadingStrategy, Logger logger, OnSuccessExecutor
executor) {
this.numEntries = numEntries;
this.initialLoadSequence = initialLoadSequence;
this.loadingStrategy = loadingStrategy;
this.logger = logger;
+ this.onSuccessExecutor = executor;
int numEntriesPlusOne = numEntries + 1;
this.allCallbacks = new Object[numEntriesPlusOne][];
this.requestedExclusives = new BoundedIntQueue(numEntriesPlusOne);
@@ -589,7 +591,7 @@
private void runAsyncImpl(final int fragment, RunAsyncCallback callback)
{
if (isLoaded[fragment]) {
assert allCallbacks[fragment] == null;
- executeOnSuccessAsynchronously(callback);
+ this.onSuccessExecutor.execute(this, callback);
return;
}
@@ -617,18 +619,7 @@
}
}
- /**
- * Executes onSuccess asynchronously.
- */
- private void executeOnSuccessAsynchronously(final RunAsyncCallback
callback) {
- Scheduler.get().scheduleDeferred(new ScheduledCommand() {
- @Override public void execute() {
- executeOnSuccess(callback);
- }
- });
- }
-
- private void executeOnSuccess(RunAsyncCallback callback) {
+ void executeOnSuccess0(RunAsyncCallback callback) {
/*
* Calls on {@link RunAsyncCallback#onSuccess} from {@link
AsyncFragmentLoader} is special
* treated (See RescueVisitor in ControlFlowAnalyzer) so that code
splitter will not follow them
diff --git
a/user/src/com/google/gwt/core/client/impl/OnSuccessExecutor.java
b/user/src/com/google/gwt/core/client/impl/OnSuccessExecutor.java
new file mode 100644
index 0000000..883cd2c
--- /dev/null
+++ b/user/src/com/google/gwt/core/client/impl/OnSuccessExecutor.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.core.client.impl;
+
+import com.google.gwt.core.client.RunAsyncCallback;
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.core.client.Scheduler.ScheduledCommand;
+
+/**
+ * An asynchronous {@link RunAsyncCallback#onSuccess()} executor using a
deferred command.
+ */
+class OnSuccessExecutor {
+
+ /**
+ * Executes onSuccess asynchronously.
+ */
+ void execute(final AsyncFragmentLoader fragmentLoader, final
RunAsyncCallback callback) {
+ Scheduler.get().scheduleDeferred(new ScheduledCommand() {
+ @Override
+ public void execute() {
+ fragmentLoader.executeOnSuccess0(callback);
+ }
+ });
+ }
+}
diff --git
a/user/src/com/google/gwt/core/client/impl/SynchronousOnSuccessExecutor.java
b/user/src/com/google/gwt/core/client/impl/SynchronousOnSuccessExecutor.java
new file mode 100644
index 0000000..6c16465
--- /dev/null
+++
b/user/src/com/google/gwt/core/client/impl/SynchronousOnSuccessExecutor.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.core.client.impl;
+
+import com.google.gwt.core.client.RunAsyncCallback;
+
+/**
+ * An synchronous {@link RunAsyncCallback#onSuccess()} executor that
immediately calls onSuccess.
+ */
+class SynchronousOnSuccessExecutor extends OnSuccessExecutor {
+
+ /**
+ * Executes onSuccess synchronously.
+ */
+ void execute(final AsyncFragmentLoader fragmentLoader, final
RunAsyncCallback callback) {
+ fragmentLoader.executeOnSuccess0(callback);
+ }
+}
diff --git
a/user/test/com/google/gwt/core/client/impl/AsyncFragmentLoaderTest.java
b/user/test/com/google/gwt/core/client/impl/AsyncFragmentLoaderTest.java
index cac5944..d1ebd8e 100644
--- a/user/test/com/google/gwt/core/client/impl/AsyncFragmentLoaderTest.java
+++ b/user/test/com/google/gwt/core/client/impl/AsyncFragmentLoaderTest.java
@@ -152,7 +152,7 @@
MockProgressLogger progress = new MockProgressLogger();
int numEntries = 5;
AsyncFragmentLoader loader = new AsyncFragmentLoader(numEntries,
- new int[] {}, reqs, progress);
+ new int[] {}, reqs, progress, null);
loader.inject(1, NULL_ERROR_HANDLER);
reqs.assertFragmentsRequested(numEntries);
@@ -184,7 +184,7 @@
MockProgressLogger progress = new MockProgressLogger();
int numEntries = 10;
AsyncFragmentLoader loader = new AsyncFragmentLoader(numEntries, new
int[] {
- 1, 2, 3}, reqs, progress);
+ 1, 2, 3}, reqs, progress, null);
// request fragment 1
MockErrorHandler error1try1 = new MockErrorHandler();
@@ -298,7 +298,7 @@
MockProgressLogger progress = new MockProgressLogger();
int numEntries = 6;
AsyncFragmentLoader loader = new AsyncFragmentLoader(numEntries,
- new int[] {}, reqs, progress);
+ new int[] {}, reqs, progress, null);
// Load fragment 1
loader.inject(1, NULL_ERROR_HANDLER);
@@ -337,7 +337,7 @@
MockProgressLogger progress = new MockProgressLogger();
int numEntries = 6;
AsyncFragmentLoader loader = new AsyncFragmentLoader(numEntries,
- new int[] {}, reqs, progress);
+ new int[] {}, reqs, progress, null);
// Request 1
loader.inject(1, NULL_ERROR_HANDLER);
@@ -377,7 +377,7 @@
MockProgressLogger progress = new MockProgressLogger();
int numEntries = 6;
AsyncFragmentLoader loader = new AsyncFragmentLoader(numEntries, new
int[] {
- 1, 2, 3}, reqs, progress);
+ 1, 2, 3}, reqs, progress, null);
loader.inject(1, NULL_ERROR_HANDLER);
reqs.assertFragmentsRequested(1);
@@ -431,7 +431,7 @@
MockProgressLogger progress = new MockProgressLogger();
int numEntries = 6;
AsyncFragmentLoader loader = new AsyncFragmentLoader(numEntries, new
int[] {
- 1, 2, 3}, reqs, progress);
+ 1, 2, 3}, reqs, progress, null);
/*
* Repeatedly queue up extra downloads waiting on an initial and then
fail.
@@ -453,7 +453,7 @@
MockProgressLogger progress = new MockProgressLogger();
int numEntries = 20;
AsyncFragmentLoader loader = new AsyncFragmentLoader(numEntries, new
int[] {
- 1, 2, 3}, reqs, progress);
+ 1, 2, 3}, reqs, progress, null);
loader.startPrefetching();
// request a prefetch of something in the initial load sequence
loader.setPrefetchQueue(2);
@@ -542,7 +542,7 @@
MockProgressLogger progress = new MockProgressLogger();
int numEntries = 20;
AsyncFragmentLoader loader = new AsyncFragmentLoader(numEntries, new
int[] {
- 1, 2, 3}, reqs, progress);
+ 1, 2, 3}, reqs, progress, null);
loader.startPrefetching();
// request a prefetch of something in the initial load sequence
loader.setPrefetchQueue(3, 2, 1);
@@ -588,7 +588,7 @@
MockProgressLogger progress = new MockProgressLogger();
int numEntries = 20;
AsyncFragmentLoader loader = new AsyncFragmentLoader(numEntries,
- new int[] {}, reqs, progress);
+ new int[] {}, reqs, progress, null);
loader.stopPrefetching();
// Prefetch 1, but leave prefetching off
loader.setPrefetchQueue(1);
@@ -630,7 +630,7 @@
MockProgressLogger progress = new MockProgressLogger();
int numEntries = 20;
AsyncFragmentLoader loader = new AsyncFragmentLoader(numEntries,
- new int[] {}, reqs, progress);
+ new int[] {}, reqs, progress, null);
loader.startPrefetching();
// Load the leftovers and one fragment
@@ -678,7 +678,7 @@
MockProgressLogger progress = new MockProgressLogger();
int numEntries = 6;
AsyncFragmentLoader loader = new AsyncFragmentLoader(numEntries, new
int[] {
- 1, 2, 3}, reqs, progress);
+ 1, 2, 3}, reqs, progress, null);
loader.inject(1, NULL_ERROR_HANDLER);
reqs.assertFragmentsRequested(1);
--
To view, visit https://gwt-review.googlesource.com/3310
To unsubscribe, visit https://gwt-review.googlesource.com/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If3a54663d6d857ca294c99a1a99084328748996d
Gerrit-PatchSet: 1
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Goktug Gokdogan <[email protected]>
Gerrit-Reviewer: Brian Slesinsky <[email protected]>
Gerrit-Reviewer: Goktug Gokdogan <[email protected]>
Gerrit-Reviewer: Leeroy Jenkins <[email protected]>
Gerrit-Reviewer: Roberto Lublinerman <[email protected]>
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
---
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.