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 #include "quic_test_server.h" | 5 #include "quic_test_server.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread()); | 49 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread()); |
50 g_quic_server->Shutdown(); | 50 g_quic_server->Shutdown(); |
51 delete g_quic_server; | 51 delete g_quic_server; |
52 } | 52 } |
53 | 53 |
54 } // namespace | 54 } // namespace |
55 | 55 |
56 // Quic server is currently hardcoded to run on port 6121 of the localhost on | 56 // Quic server is currently hardcoded to run on port 6121 of the localhost on |
57 // the device. | 57 // the device. |
58 void StartQuicTestServer(JNIEnv* env, | 58 void StartQuicTestServer(JNIEnv* env, |
59 jclass /*jcaller*/, | 59 const JavaParamRef<jclass>& /*jcaller*/, |
60 jstring jtest_files_root) { | 60 const JavaParamRef<jstring>& jtest_files_root) { |
61 DCHECK(!g_quic_server_thread); | 61 DCHECK(!g_quic_server_thread); |
62 g_quic_server_thread = new base::Thread("quic server thread"); | 62 g_quic_server_thread = new base::Thread("quic server thread"); |
63 base::Thread::Options thread_options; | 63 base::Thread::Options thread_options; |
64 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; | 64 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; |
65 bool started = g_quic_server_thread->StartWithOptions(thread_options); | 65 bool started = g_quic_server_thread->StartWithOptions(thread_options); |
66 DCHECK(started); | 66 DCHECK(started); |
67 base::FilePath test_files_root( | 67 base::FilePath test_files_root( |
68 base::android::ConvertJavaStringToUTF8(env, jtest_files_root)); | 68 base::android::ConvertJavaStringToUTF8(env, jtest_files_root)); |
69 g_quic_server_thread->task_runner()->PostTask( | 69 g_quic_server_thread->task_runner()->PostTask( |
70 FROM_HERE, base::Bind(&ServeFilesFromDirectory, test_files_root)); | 70 FROM_HERE, base::Bind(&ServeFilesFromDirectory, test_files_root)); |
71 } | 71 } |
72 | 72 |
73 void ShutdownQuicTestServer(JNIEnv* env, jclass /*jcaller*/) { | 73 void ShutdownQuicTestServer(JNIEnv* env, |
| 74 const JavaParamRef<jclass>& /*jcaller*/) { |
74 DCHECK(!g_quic_server_thread->task_runner()->BelongsToCurrentThread()); | 75 DCHECK(!g_quic_server_thread->task_runner()->BelongsToCurrentThread()); |
75 g_quic_server_thread->task_runner()->PostTask( | 76 g_quic_server_thread->task_runner()->PostTask( |
76 FROM_HERE, base::Bind(&ShutdownOnServerThread)); | 77 FROM_HERE, base::Bind(&ShutdownOnServerThread)); |
77 delete g_quic_server_thread; | 78 delete g_quic_server_thread; |
78 } | 79 } |
79 | 80 |
80 ScopedJavaLocalRef<jstring> GetServerHost(JNIEnv* env, jclass /*jcaller*/) { | 81 ScopedJavaLocalRef<jstring> GetServerHost( |
| 82 JNIEnv* env, |
| 83 const JavaParamRef<jclass>& /*jcaller*/) { |
81 return base::android::ConvertUTF8ToJavaString(env, kServerHost); | 84 return base::android::ConvertUTF8ToJavaString(env, kServerHost); |
82 } | 85 } |
83 | 86 |
84 int GetServerPort(JNIEnv* env, jclass /*jcaller*/) { | 87 int GetServerPort(JNIEnv* env, const JavaParamRef<jclass>& /*jcaller*/) { |
85 return kServerPort; | 88 return kServerPort; |
86 } | 89 } |
87 | 90 |
88 bool RegisterQuicTestServer(JNIEnv* env) { | 91 bool RegisterQuicTestServer(JNIEnv* env) { |
89 return RegisterNativesImpl(env); | 92 return RegisterNativesImpl(env); |
90 } | 93 } |
91 | 94 |
92 } // namespace cronet | 95 } // namespace cronet |
OLD | NEW |