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.content.Context; | 7 import android.content.Context; |
8 import android.os.ConditionVariable; | 8 import android.os.ConditionVariable; |
9 | 9 |
10 import org.chromium.base.CalledByNative; | 10 import org.chromium.base.CalledByNative; |
11 import org.chromium.base.JNINamespace; | 11 import org.chromium.base.JNINamespace; |
| 12 import org.chromium.base.Log; |
12 | 13 |
13 /** | 14 /** |
14 * Wrapper class to start a Quic test server. | 15 * Wrapper class to start a Quic test server. |
15 */ | 16 */ |
16 @JNINamespace("cronet") | 17 @JNINamespace("cronet") |
17 public final class QuicTestServer { | 18 public final class QuicTestServer { |
18 private static final ConditionVariable sBlock = new ConditionVariable(); | 19 private static final ConditionVariable sBlock = new ConditionVariable(); |
| 20 private static final String TAG = Log.makeTag("QuicTestServer"); |
19 | 21 |
20 public static void startQuicTestServer(Context context) { | 22 public static void startQuicTestServer(Context context) { |
| 23 TestFilesInstaller.installIfNeeded(context); |
21 nativeStartQuicTestServer(TestFilesInstaller.getInstalledPath(context)); | 24 nativeStartQuicTestServer(TestFilesInstaller.getInstalledPath(context)); |
22 sBlock.block(); | 25 sBlock.block(); |
23 } | 26 } |
24 | 27 |
25 public static void shutdownQuicTestServer() { | 28 public static void shutdownQuicTestServer() { |
26 nativeShutdownQuicTestServer(); | 29 nativeShutdownQuicTestServer(); |
27 sBlock.close(); | 30 sBlock.close(); |
28 } | 31 } |
29 | 32 |
30 public static String getServerURL() { | 33 public static String getServerURL() { |
31 return "http://" + getServerHost() + ":" + getServerPort(); | 34 return "http://" + getServerHost() + ":" + getServerPort(); |
32 } | 35 } |
33 | 36 |
34 public static String getServerHost() { | 37 public static String getServerHost() { |
35 return nativeGetServerHost(); | 38 return nativeGetServerHost(); |
36 } | 39 } |
37 | 40 |
38 public static int getServerPort() { | 41 public static int getServerPort() { |
39 return nativeGetServerPort(); | 42 return nativeGetServerPort(); |
40 } | 43 } |
41 | 44 |
42 @CalledByNative | 45 @CalledByNative |
43 private static void onServerStarted() { | 46 private static void onServerStarted() { |
| 47 Log.i(TAG, "Quic server started."); |
44 sBlock.open(); | 48 sBlock.open(); |
45 } | 49 } |
46 | 50 |
47 private static native void nativeStartQuicTestServer(String filePath); | 51 private static native void nativeStartQuicTestServer(String filePath); |
48 private static native void nativeShutdownQuicTestServer(); | 52 private static native void nativeShutdownQuicTestServer(); |
49 private static native String nativeGetServerHost(); | 53 private static native String nativeGetServerHost(); |
50 private static native int nativeGetServerPort(); | 54 private static native int nativeGetServerPort(); |
51 } | 55 } |
OLD | NEW |