Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / cronet / android / test / src / org / chromium / net / SdchObserver.java
blob1d55cd72511577b37e33b494f26565befe9dfd3c
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.
5 package org.chromium.net;
7 import android.os.ConditionVariable;
9 import org.chromium.base.annotations.CalledByNative;
10 import org.chromium.base.annotations.JNINamespace;
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}.
18 @JNINamespace("cronet")
19 public class SdchObserver {
20 protected boolean mDictionaryAlreadyPresent = false;
21 private final ConditionVariable mAddBlock = new ConditionVariable();
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.
29 public SdchObserver(String targetUrl, long contextAdapter, boolean isLegacyAPI) {
30 if (isLegacyAPI) {
31 nativeAddSdchObserverLegacyAPI(targetUrl, contextAdapter);
32 } else {
33 nativeAddSdchObserver(targetUrl, contextAdapter);
35 mAddBlock.block();
36 mAddBlock.close();
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.
43 @CalledByNative
44 public void onDictionaryAdded() {
45 // Left blank;
48 @CalledByNative
49 private void onAddSdchObserverCompleted() {
50 mAddBlock.open();
53 @CalledByNative
54 private void onDictionarySetAlreadyPresent() {
55 mDictionaryAlreadyPresent = true;
56 mAddBlock.open();
59 private native void nativeAddSdchObserver(String targetUrl, long contextAdapter);
60 private native void nativeAddSdchObserverLegacyAPI(String targetUrl, long contextAdapter);