OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.net; | 5 package org.chromium.net; |
6 | 6 |
7 import android.os.ConditionVariable; | 7 import android.os.ConditionVariable; |
8 | 8 |
9 import org.chromium.base.annotations.CalledByNative; | 9 import org.chromium.base.annotations.CalledByNative; |
10 import org.chromium.base.annotations.JNINamespace; | 10 import org.chromium.base.annotations.JNINamespace; |
| 11 import org.chromium.net.impl.CronetUrlRequestContext; |
11 | 12 |
12 /** | 13 /** |
13 * Class to watch for Sdch dictionary events. The native implementation | 14 * Class to watch for Sdch dictionary events. The native implementation |
14 * unregisters itself when an event happens. Therefore, an instance of this | 15 * 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 * class is only able to receive a notification of the earliest event. |
16 * Currently, implemented events include {@link #onDictionaryAdded}. | 17 * Currently, implemented events include {@link #onDictionaryAdded}. |
17 */ | 18 */ |
18 @JNINamespace("cronet") | 19 @JNINamespace("cronet") |
19 public class SdchObserver { | 20 public class SdchObserver { |
20 protected boolean mDictionaryAlreadyPresent = false; | 21 protected boolean mDictionaryAlreadyPresent = false; |
21 private final ConditionVariable mAddBlock = new ConditionVariable(); | 22 private final ConditionVariable mAddBlock = new ConditionVariable(); |
22 | 23 |
23 /** | 24 /** |
24 * Constructor. | 25 * Constructor. |
25 * @param targetUrl the target url on which sdch encoding will be used. | 26 * @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 contextAdapter the native context adapter to register the observer
. |
27 */ | 28 */ |
28 public SdchObserver(String targetUrl, long contextAdapter) { | 29 public SdchObserver(final String targetUrl, final CronetUrlRequestContext en
gine) { |
29 nativeAddSdchObserver(targetUrl, contextAdapter); | 30 CronetTestUtil.postToNetworkThread(engine, new Runnable() { |
| 31 @Override |
| 32 public void run() { |
| 33 nativeAddSdchObserverOnNetworkThread( |
| 34 targetUrl, engine.getUrlRequestContextForTesting()); |
| 35 } |
| 36 }); |
30 mAddBlock.block(); | 37 mAddBlock.block(); |
31 mAddBlock.close(); | 38 mAddBlock.close(); |
32 } | 39 } |
33 | 40 |
34 /** | 41 /** |
35 * Called when a dictionary is added to the SdchManager for the target url. | 42 * Called when a dictionary is added to the SdchManager for the target url. |
36 * Override this method if caller would like to get notified. | 43 * Override this method if caller would like to get notified. |
37 */ | 44 */ |
38 @CalledByNative | 45 @CalledByNative |
39 public void onDictionaryAdded() { | 46 public void onDictionaryAdded() { |
40 // Left blank; | 47 // Left blank; |
41 } | 48 } |
42 | 49 |
43 @CalledByNative | 50 @CalledByNative |
44 private void onAddSdchObserverCompleted() { | 51 private void onAddSdchObserverCompleted() { |
45 mAddBlock.open(); | 52 mAddBlock.open(); |
46 } | 53 } |
47 | 54 |
48 @CalledByNative | 55 @CalledByNative |
49 private void onDictionarySetAlreadyPresent() { | 56 private void onDictionarySetAlreadyPresent() { |
50 mDictionaryAlreadyPresent = true; | 57 mDictionaryAlreadyPresent = true; |
51 mAddBlock.open(); | 58 mAddBlock.open(); |
52 } | 59 } |
53 | 60 |
54 private native void nativeAddSdchObserver(String targetUrl, long contextAdap
ter); | 61 private native void nativeAddSdchObserverOnNetworkThread(String targetUrl, l
ong context); |
55 } | 62 } |
OLD | NEW |