Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.net; | |
| 6 | |
| 7 import android.os.ConditionVariable; | |
| 8 | |
| 9 import static junit.framework.Assert.assertNull; | |
| 10 | |
| 11 import org.chromium.base.CalledByNative; | |
| 12 import org.chromium.base.JNINamespace; | |
| 13 | |
| 14 /** | |
| 15 * Test utilities related to Sdch. | |
| 16 */ | |
| 17 @JNINamespace("cronet") | |
| 18 public final class SdchTestUtil { | |
| 19 // Blocks until the native SdchObserver is added. | |
| 20 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
| |
| 21 | |
| 22 /** | |
| 23 * Abstract class to listen for callbacks of the native SdchObserver. | |
| 24 */ | |
| 25 public abstract static class SdchObserverCallback { | |
| 26 /** | |
| 27 * Called when a dictionary is added to the SdchManager. | |
| 28 * @param url the url of the dictionary added. | |
| 29 */ | |
| 30 public abstract void onDictionaryAdded(String url); | |
| 31 } | |
| 32 | |
| 33 private static SdchObserverCallback sCallback; | |
| 34 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.
| |
| 35 | |
| 36 /** | |
| 37 * Returns whether the native SdchObserver has been registered. The native | |
| 38 * SdchObserver will not be registered when dictionaries for the | |
| 39 * {@code targetUrl} are already loaded, for example. | |
| 40 */ | |
| 41 public static boolean registerSdchObserverCallback(String targetUrl, long co ntextAdapter, | |
| 42 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
| |
| 43 assertNull(sCallback); | |
| 44 sCallback = callback; | |
| 45 if (isLegacyAPI) { | |
| 46 nativeAddSdchObserverLegacyAPI(targetUrl, contextAdapter); | |
| 47 } else { | |
| 48 nativeAddSdchObserver(targetUrl, contextAdapter); | |
| 49 } | |
| 50 sAddBlock.block(); | |
| 51 sAddBlock.close(); | |
| 52 return sRegisterSdchObserverSucceeded; | |
| 53 } | |
| 54 | |
| 55 @CalledByNative | |
| 56 private static void onDictionaryAdded(String dictionaryURL) { | |
| 57 if (sCallback != null) { | |
| 58 sCallback.onDictionaryAdded(dictionaryURL); | |
| 59 sCallback = null; | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 @CalledByNative | |
| 64 private static void onAddSdchObserverCompleted() { | |
| 65 sRegisterSdchObserverSucceeded = true; | |
| 66 sAddBlock.open(); | |
| 67 } | |
| 68 | |
| 69 @CalledByNative | |
| 70 private static void onDictionaryAlreadyPresent() { | |
| 71 sAddBlock.open(); | |
| 72 } | |
| 73 | |
| 74 | |
| 75 private static native void nativeAddSdchObserver(String targetUrl, long cont extAdapter); | |
| 76 private static native void nativeAddSdchObserverLegacyAPI( | |
| 77 String targetUrl, long contextAdapter); | |
| 78 } | |
| OLD | NEW |