| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 | 9 |
| 10 import org.chromium.base.annotations.CalledByNative; |
| 9 import org.chromium.base.annotations.JNINamespace; | 11 import org.chromium.base.annotations.JNINamespace; |
| 10 | 12 |
| 11 /** | 13 /** |
| 12 * Wrapper class to start an in-process native test server, and get URLs | 14 * Wrapper class to start an in-process native test server, and get URLs |
| 13 * needed to talk to it. | 15 * needed to talk to it. |
| 14 */ | 16 */ |
| 15 @JNINamespace("cronet") | 17 @JNINamespace("cronet") |
| 16 public final class NativeTestServer { | 18 public final class NativeTestServer { |
| 19 private static final ConditionVariable sHostResolverBlock = new ConditionVar
iable(); |
| 20 |
| 17 // This variable contains the response body of a request to getSuccessURL(). | 21 // This variable contains the response body of a request to getSuccessURL(). |
| 18 public static final String SUCCESS_BODY = "this is a text file\n"; | 22 public static final String SUCCESS_BODY = "this is a text file\n"; |
| 19 | 23 |
| 20 public static boolean startNativeTestServer(Context context) { | 24 public static boolean startNativeTestServer(Context context) { |
| 21 TestFilesInstaller.installIfNeeded(context); | 25 TestFilesInstaller.installIfNeeded(context); |
| 22 return nativeStartNativeTestServer( | 26 return nativeStartNativeTestServer( |
| 23 TestFilesInstaller.getInstalledPath(context)); | 27 TestFilesInstaller.getInstalledPath(context)); |
| 24 } | 28 } |
| 25 | 29 |
| 26 public static void shutdownNativeTestServer() { | 30 public static void shutdownNativeTestServer() { |
| 27 nativeShutdownNativeTestServer(); | 31 nativeShutdownNativeTestServer(); |
| 28 } | 32 } |
| 29 | 33 |
| 34 /** |
| 35 * Registers customized DNS mapping for {@link NativeTestServer}. |
| 36 * @param contextAdapter native context adapter object that this |
| 37 * mapping should apply to. |
| 38 * @param isLegacyAPI {@code true} if this context adapter is a part of the |
| 39 * old API. |
| 40 */ |
| 41 public static void registerHostResolverProc(long contextAdapter, boolean isL
egacyAPI) { |
| 42 nativeRegisterHostResolverProc(contextAdapter, isLegacyAPI); |
| 43 sHostResolverBlock.block(); |
| 44 sHostResolverBlock.close(); |
| 45 } |
| 46 |
| 30 public static String getEchoBodyURL() { | 47 public static String getEchoBodyURL() { |
| 31 return nativeGetEchoBodyURL(); | 48 return nativeGetEchoBodyURL(); |
| 32 } | 49 } |
| 33 | 50 |
| 34 public static String getEchoHeaderURL(String header) { | 51 public static String getEchoHeaderURL(String header) { |
| 35 return nativeGetEchoHeaderURL(header); | 52 return nativeGetEchoHeaderURL(header); |
| 36 } | 53 } |
| 37 | 54 |
| 38 public static String getEchoAllHeadersURL() { | 55 public static String getEchoAllHeadersURL() { |
| 39 return nativeGetEchoAllHeadersURL(); | 56 return nativeGetEchoAllHeadersURL(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 92 } |
| 76 | 93 |
| 77 public static String getHostPort() { | 94 public static String getHostPort() { |
| 78 return nativeGetHostPort(); | 95 return nativeGetHostPort(); |
| 79 } | 96 } |
| 80 | 97 |
| 81 public static boolean isDataReductionProxySupported() { | 98 public static boolean isDataReductionProxySupported() { |
| 82 return nativeIsDataReductionProxySupported(); | 99 return nativeIsDataReductionProxySupported(); |
| 83 } | 100 } |
| 84 | 101 |
| 102 @CalledByNative |
| 103 private static void onHostResolverProcRegistered() { |
| 104 sHostResolverBlock.open(); |
| 105 } |
| 106 |
| 85 private static native boolean nativeStartNativeTestServer(String filePath); | 107 private static native boolean nativeStartNativeTestServer(String filePath); |
| 86 private static native void nativeShutdownNativeTestServer(); | 108 private static native void nativeShutdownNativeTestServer(); |
| 109 private static native void nativeRegisterHostResolverProc( |
| 110 long contextAdapter, boolean isLegacyAPI); |
| 87 private static native String nativeGetEchoBodyURL(); | 111 private static native String nativeGetEchoBodyURL(); |
| 88 private static native String nativeGetEchoHeaderURL(String header); | 112 private static native String nativeGetEchoHeaderURL(String header); |
| 89 private static native String nativeGetEchoAllHeadersURL(); | 113 private static native String nativeGetEchoAllHeadersURL(); |
| 90 private static native String nativeGetEchoMethodURL(); | 114 private static native String nativeGetEchoMethodURL(); |
| 91 private static native String nativeGetRedirectToEchoBody(); | 115 private static native String nativeGetRedirectToEchoBody(); |
| 92 private static native String nativeGetFileURL(String filePath); | 116 private static native String nativeGetFileURL(String filePath); |
| 93 private static native String nativeGetSdchURL(); | 117 private static native String nativeGetSdchURL(); |
| 94 private static native String nativeGetHostPort(); | 118 private static native String nativeGetHostPort(); |
| 95 private static native boolean nativeIsDataReductionProxySupported(); | 119 private static native boolean nativeIsDataReductionProxySupported(); |
| 96 } | 120 } |
| OLD | NEW |