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

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: Remove pref file support from legacy API 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..0559dbedfd4b1e4b8d0a096a042949afe4562470
--- /dev/null
+++ b/components/cronet/android/test/src/org/chromium/net/SdchTestUtil.java
@@ -0,0 +1,67 @@
+// 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();
+
+ /**
+ * 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;
+
+ /**
+ * 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) {
+ assertNull(sCallback);
+ sCallback = callback;
+ nativeAddSdchObserver(targetUrl, contextAdapter, isLegacyAPI);
+ 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(boolean succeeded) {
+ sRegisterSdchObserverSucceeded = succeeded;
+ sAddBlock.open();
+ }
+
+ private static native void nativeAddSdchObserver(
+ String targetUrl, long contextAdapter, boolean isLegacyAPI);
+}

Powered by Google App Engine
This is Rietveld 408576698