Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Unified Diff: components/cronet/android/test/src/org/chromium/net/SdchTestUtil.java

Issue 1133883002: [Cronet] Enable persistence mode for Sdch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@quic_server_remove_loop
Patch Set: Removed semicolon after override Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/cronet/android/test/src/org/chromium/net/SdchTestUtil.java
diff --git a/components/cronet/android/test/src/org/chromium/net/SdchTestUtil.java b/components/cronet/android/test/src/org/chromium/net/SdchTestUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..14a978cd70f11aeaf8c40e866fff440dc3d810e0
--- /dev/null
+++ b/components/cronet/android/test/src/org/chromium/net/SdchTestUtil.java
@@ -0,0 +1,78 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.net;
+
+import android.os.ConditionVariable;
+
+import static junit.framework.Assert.assertNull;
+
+import org.chromium.base.CalledByNative;
+import org.chromium.base.JNINamespace;
+
+/**
+ * Test utilities related to Sdch.
+ */
+@JNINamespace("cronet")
+public final class SdchTestUtil {
+ // Blocks until the native SdchObserver is added.
+ private static final ConditionVariable sAddBlock = new ConditionVariable();
mmenke 2015/05/26 19:34:40 Rather than use globals, could we just instantiate
xunjieli 2015/05/26 20:28:28 Done. I have moved this condition variable to be a
mmenke 2015/05/27 14:40:43 That's right. It's not the ability to have multip
+
+ /**
+ * Abstract class to listen for callbacks of the native SdchObserver.
+ */
+ public abstract static class SdchObserverCallback {
+ /**
+ * Called when a dictionary is added to the SdchManager.
+ * @param url the url of the dictionary added.
+ */
+ public abstract void onDictionaryAdded(String url);
+ }
+
+ private static SdchObserverCallback sCallback;
+ private static boolean sRegisterSdchObserverSucceeded = false;
mmenke 2015/05/26 19:34:40 We're generally putting variables before methods i
xunjieli 2015/05/26 20:28:28 Done.
+
+ /**
+ * Returns whether the native SdchObserver has been registered. The native
+ * SdchObserver will not be registered when dictionaries for the
+ * {@code targetUrl} are already loaded, for example.
+ */
+ public static boolean registerSdchObserverCallback(String targetUrl, long contextAdapter,
+ SdchObserverCallback callback, boolean isLegacyAPI) {
mmenke 2015/05/26 19:34:40 I thought we weren't adding legacy API support for
xunjieli 2015/05/26 20:28:28 We aren't adding legacy support for sdch meta data
+ assertNull(sCallback);
+ sCallback = callback;
+ if (isLegacyAPI) {
+ nativeAddSdchObserverLegacyAPI(targetUrl, contextAdapter);
+ } else {
+ nativeAddSdchObserver(targetUrl, contextAdapter);
+ }
+ sAddBlock.block();
+ sAddBlock.close();
+ return sRegisterSdchObserverSucceeded;
+ }
+
+ @CalledByNative
+ private static void onDictionaryAdded(String dictionaryURL) {
+ if (sCallback != null) {
+ sCallback.onDictionaryAdded(dictionaryURL);
+ sCallback = null;
+ }
+ }
+
+ @CalledByNative
+ private static void onAddSdchObserverCompleted() {
+ sRegisterSdchObserverSucceeded = true;
+ sAddBlock.open();
+ }
+
+ @CalledByNative
+ private static void onDictionaryAlreadyPresent() {
+ sAddBlock.open();
+ }
+
+
+ private static native void nativeAddSdchObserver(String targetUrl, long contextAdapter);
+ private static native void nativeAddSdchObserverLegacyAPI(
+ String targetUrl, long contextAdapter);
+}

Powered by Google App Engine
This is Rietveld 408576698