Commit 709e3c43 authored by igsolla's avatar igsolla Committed by Commit bot

Revert of [WebView] Add unique visual state request ids. (patchset #4 id:60001...

Revert of [WebView] Add unique visual state request ids. (patchset #4 id:60001 of https://codereview.chromium.org/900303002/)

Reason for revert:
This is breaking some bots, see for example:
https://chromegw.corp.google.com/i/chromium.linux/builders/Android%20Arm64%20Builder%20(dbg)/builds/8923

https://chromegw.corp.google.com/i/chromium.linux/builders/Android%20Builder%20(dbg)/builds/73663

The reason is:
M D ST: Write to static field org.chromium.android_webview.AwContents.sNextVisualStateRequestId from instance method org.chromium.android_webview.AwContents.flushVisualState(AwContents$VisualStateFlushCallback)  At AwContents.java

Original issue's description:
> [WebView] Add unique visual state request ids.
>
> Each flushVisualState request returns a unique id
> that allows callers to match requests with callbacks.
> The reasoning behind is to potentially allow clients
> to reuse VisualStateFlushCallback objects to avoid
> additional java allocations.
>
> BUG=455651
>
> Committed: https://crrev.com/d011b93e7c8f966ba068b0c77c8a1400bdedee88
> Cr-Commit-Position: refs/heads/master@{#315304}

TBR=boliu@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=455651

Review URL: https://codereview.chromium.org/907723004

Cr-Commit-Position: refs/heads/master@{#315321}
parent 9dcc0401
......@@ -183,18 +183,13 @@ public class AwContents implements SmartClipProvider {
/**
* Callback used when flushing the visual state, see {@link #flushVisualState}.
*
* <p>The {@code requestId} is the unique request id returned by
* {@link AwContents#flushVisualState} which can be used to match callbacks with requests.
*/
@VisibleForTesting
public abstract static class VisualStateFlushCallback {
public abstract void onComplete(long requestId);
public abstract void onFailure(long requestId);
public abstract void onComplete();
public abstract void onFailure();
}
private static long sNextVisualStateRequestId = 1;
private long mNativeAwContents;
private final AwBrowserContext mBrowserContext;
private ViewGroup mContainerView;
......@@ -2054,14 +2049,9 @@ public class AwContents implements SmartClipProvider {
* 1. The DOM tree is committed becoming the pending tree - see ThreadProxy::BeginMainFrame
* 2. The pending tree is activated becoming the active tree
* 3. A frame swap happens that draws the active tree into the screen
*
* @return an unique id that identifies this request. It can be used to match this request
* to the corresponding callback to allow reuse of {@link VisualStateFlushCallback} objects.
*/
public long flushVisualState(VisualStateFlushCallback callback) {
long requestId = sNextVisualStateRequestId++;
nativeFlushVisualState(mNativeAwContents, callback, requestId);
return requestId;
public void flushVisualState(VisualStateFlushCallback callback) {
nativeFlushVisualState(mNativeAwContents, callback);
}
//--------------------------------------------------------------------------------------------
......@@ -2174,16 +2164,16 @@ public class AwContents implements SmartClipProvider {
*/
@CalledByNative
public void flushVisualStateCallback(
final VisualStateFlushCallback callback, final long requestId, final boolean result) {
final VisualStateFlushCallback callback, final boolean result) {
// Posting avoids invoking the callback inside invoking_composite_
// (see synchronous_compositor_impl.cc and crbug/452530).
mContainerView.getHandler().post(new Runnable() {
@Override
public void run() {
if (result) {
callback.onComplete(requestId);
callback.onComplete();
} else {
callback.onFailure(requestId);
callback.onFailure();
}
}
});
......@@ -2746,7 +2736,7 @@ public class AwContents implements SmartClipProvider {
private native long nativeCapturePicture(long nativeAwContents, int width, int height);
private native void nativeEnableOnNewPicture(long nativeAwContents, boolean enabled);
private native void nativeFlushVisualState(
long nativeAwContents, VisualStateFlushCallback callback, long requestId);
long nativeAwContents, VisualStateFlushCallback callback);
private native void nativeClearView(long nativeAwContents);
private native void nativeSetExtraHeadersForUrl(long nativeAwContents,
String url, String extraHeaders);
......
......@@ -18,6 +18,7 @@ import org.chromium.content_public.browser.LoadUrlParams;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
/**
* Visual state related tests.
......@@ -25,8 +26,6 @@ import java.util.concurrent.TimeUnit;
public class VisualStateTest extends AwTestBase {
private TestAwContentsClient mContentsClient = new TestAwContentsClient();
private long mExpectedFlushRequestId = -1;
private AwContents mAwContents;
@Feature({"AndroidWebView"})
@SmallTest
......@@ -40,16 +39,14 @@ public class VisualStateTest extends AwTestBase {
runTestOnUiThread(new Runnable() {
@Override
public void run() {
mExpectedFlushRequestId =
awContents.flushVisualState(new AwContents.VisualStateFlushCallback() {
@Override
public void onComplete(long requestId) {
assertEquals(mExpectedFlushRequestId, requestId);
public void onComplete() {
ch.notifyCalled();
}
@Override
public void onFailure(long requestId) {
public void onFailure() {
fail("onFailure received");
}
});
......@@ -68,24 +65,22 @@ public class VisualStateTest extends AwTestBase {
final LoadUrlParams bluePageUrl = createTestPageUrl("blue");
final CountDownLatch testFinishedSignal = new CountDownLatch(1);
final AtomicReference<AwContents> awContentsRef = new AtomicReference<>();
final AwTestContainerView testView =
createAwTestContainerViewOnMainSync(new TestAwContentsClient() {
@Override
public void onPageFinished(String url) {
if (bluePageUrl.getUrl().equals(url)) {
mExpectedFlushRequestId =
mAwContents.flushVisualState(new VisualStateFlushCallback() {
awContentsRef.get().flushVisualState(new VisualStateFlushCallback() {
@Override
public void onFailure(long requestId) {
public void onFailure() {
fail("onFailure received");
}
@Override
public void onComplete(long requestId) {
assertEquals(mExpectedFlushRequestId, requestId);
Bitmap blueScreenshot =
GraphicsTestUtils.drawAwContents(
mAwContents, 1, 1);
public void onComplete() {
Bitmap blueScreenshot = GraphicsTestUtils.drawAwContents(
awContentsRef.get(), 1, 1);
assertEquals(Color.BLUE, blueScreenshot.getPixel(0, 0));
testFinishedSignal.countDown();
}
......@@ -93,19 +88,21 @@ public class VisualStateTest extends AwTestBase {
}
}
});
mAwContents = testView.getAwContents();
final AwContents awContents = testView.getAwContents();
awContentsRef.set(awContents);
runTestOnUiThread(new Runnable() {
@Override
public void run() {
mAwContents.setBackgroundColor(Color.RED);
mAwContents.loadUrl(bluePageUrl);
awContents.setBackgroundColor(Color.RED);
awContents.loadUrl(bluePageUrl);
// We have just loaded the blue page, but the graphics pipeline is asynchronous
// so at this point the WebView still draws red, ie. the View background color.
// Only when the flush callback is received will we know for certain that the
// blue page contents are on screen.
Bitmap redScreenshot = GraphicsTestUtils.drawAwContents(mAwContents, 1, 1);
Bitmap redScreenshot = GraphicsTestUtils.drawAwContents(
awContentsRef.get(), 1, 1);
assertEquals(Color.RED, redScreenshot.getPixel(0, 0));
}
});
......
......@@ -1037,27 +1037,22 @@ void AwContents::EnableOnNewPicture(JNIEnv* env,
namespace {
void FlushVisualStateCallback(const JavaObjectWeakGlobalRef& java_ref,
ScopedJavaGlobalRef<jobject>* callback,
int64 request_id,
bool result) {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref.get(env);
if (obj.is_null())
return;
Java_AwContents_flushVisualStateCallback(env, obj.obj(), callback->obj(),
request_id, result);
Java_AwContents_flushVisualStateCallback(
env, obj.obj(), callback->obj(), result);
}
} // namespace
void AwContents::FlushVisualState(JNIEnv* env,
jobject obj,
jobject callback,
int64 request_id) {
void AwContents::FlushVisualState(JNIEnv* env, jobject obj, jobject callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
ScopedJavaGlobalRef<jobject>* j_callback = new ScopedJavaGlobalRef<jobject>();
j_callback->Reset(env, callback);
web_contents_->GetMainFrame()->FlushVisualState(
base::Bind(&FlushVisualStateCallback, java_ref_, base::Owned(j_callback),
request_id));
web_contents_->GetMainFrame()->FlushVisualState(base::Bind(
&FlushVisualStateCallback, java_ref_, base::Owned(j_callback)));
}
void AwContents::ClearView(JNIEnv* env, jobject obj) {
......
......@@ -129,10 +129,7 @@ class AwContents : public FindHelper::Listener,
jlong GetAwDrawGLViewContext(JNIEnv* env, jobject obj);
jlong CapturePicture(JNIEnv* env, jobject obj, int width, int height);
void EnableOnNewPicture(JNIEnv* env, jobject obj, jboolean enabled);
void FlushVisualState(JNIEnv* env,
jobject obj,
jobject callback,
int64 request_id);
void FlushVisualState(JNIEnv* env, jobject obj, jobject callback);
void ClearView(JNIEnv* env, jobject obj);
void SetExtraHeadersForUrl(JNIEnv* env, jobject obj,
jstring url, jstring extra_headers);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment