| 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 org.chromium.base.CalledByNative; |
| 10 import org.chromium.base.JNINamespace; |
| 11 |
| 12 /** |
| 13 * Class to watch for Sdch dictionary events. The native implementation |
| 14 * unregisters itself when an event happens. Therefore, an instance of this |
| 15 * class is only able to receive a notification of the earliest event. |
| 16 * Currently, implemented events include {@link #onDictionaryAdded}. |
| 17 */ |
| 18 @JNINamespace("cronet") |
| 19 public class SdchObserver { |
| 20 protected boolean mDictionaryAlreadyPresent = false; |
| 21 private final ConditionVariable mAddBlock = new ConditionVariable(); |
| 22 |
| 23 /** |
| 24 * Constructor. |
| 25 * @param targetUrl the target url on which sdch encoding will be used. |
| 26 * @param contextAdapter the native context adapter to register the observer
. |
| 27 * @param isLegacyApi whether legacy api is used. |
| 28 */ |
| 29 public SdchObserver(String targetUrl, long contextAdapter, boolean isLegacyA
PI) { |
| 30 if (isLegacyAPI) { |
| 31 nativeAddSdchObserverLegacyAPI(targetUrl, contextAdapter); |
| 32 } else { |
| 33 nativeAddSdchObserver(targetUrl, contextAdapter); |
| 34 } |
| 35 mAddBlock.block(); |
| 36 mAddBlock.close(); |
| 37 } |
| 38 |
| 39 /** |
| 40 * Called when a dictionary is added to the SdchManager for the target url. |
| 41 * Override this method if caller would like to get notified. |
| 42 */ |
| 43 @CalledByNative |
| 44 public void onDictionaryAdded() { |
| 45 // Left blank; |
| 46 } |
| 47 |
| 48 @CalledByNative |
| 49 private void onAddSdchObserverCompleted() { |
| 50 mAddBlock.open(); |
| 51 } |
| 52 |
| 53 @CalledByNative |
| 54 private void onDictionarySetAlreadyPresent() { |
| 55 mDictionaryAlreadyPresent = true; |
| 56 mAddBlock.open(); |
| 57 } |
| 58 |
| 59 private native void nativeAddSdchObserver(String targetUrl, long contextAdap
ter); |
| 60 private native void nativeAddSdchObserverLegacyAPI(String targetUrl, long co
ntextAdapter); |
| 61 } |
| OLD | NEW |