| 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/android/path_utils.h" | 9 #include "base/android/path_utils.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "components/cronet/android/test/cronet_test_util.h" | |
| 15 #include "jni/QuicTestServer_jni.h" | 14 #include "jni/QuicTestServer_jni.h" |
| 16 #include "net/base/ip_endpoint.h" | 15 #include "net/base/ip_endpoint.h" |
| 17 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
| 18 #include "net/base/test_data_directory.h" | 17 #include "net/base/test_data_directory.h" |
| 19 #include "net/quic/crypto/proof_source_chromium.h" | 18 #include "net/quic/crypto/proof_source_chromium.h" |
| 20 #include "net/tools/quic/quic_in_memory_cache.h" | 19 #include "net/tools/quic/quic_in_memory_cache.h" |
| 21 #include "net/tools/quic/quic_simple_server.h" | 20 #include "net/tools/quic/quic_simple_server.h" |
| 22 | 21 |
| 23 namespace cronet { | 22 namespace cronet { |
| 24 | 23 |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| 26 static const char kServerHost[] = "test.example.com"; |
| 27 static const int kServerPort = 6121; | 27 static const int kServerPort = 6121; |
| 28 | 28 |
| 29 base::Thread* g_quic_server_thread = nullptr; | 29 base::Thread* g_quic_server_thread = nullptr; |
| 30 net::tools::QuicSimpleServer* g_quic_server = nullptr; | 30 net::tools::QuicSimpleServer* g_quic_server = nullptr; |
| 31 | 31 |
| 32 void StartOnServerThread(const base::FilePath& test_files_root) { | 32 void StartOnServerThread(const base::FilePath& test_files_root) { |
| 33 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread()); | 33 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread()); |
| 34 DCHECK(!g_quic_server); | 34 DCHECK(!g_quic_server); |
| 35 | 35 |
| 36 // Set up in-memory cache. | 36 // Set up in-memory cache. |
| 37 base::FilePath file_dir = test_files_root.Append("quic_data"); | 37 base::FilePath file_dir = test_files_root.Append("quic_data"); |
| 38 CHECK(base::PathExists(file_dir)) << "Quic data does not exist"; | 38 CHECK(base::PathExists(file_dir)) << "Quic data does not exist"; |
| 39 net::tools::QuicInMemoryCache::GetInstance()->InitializeFromDirectory( | 39 net::tools::QuicInMemoryCache::GetInstance()->InitializeFromDirectory( |
| 40 file_dir.value()); | 40 file_dir.value()); |
| 41 net::IPAddressNumber ip; | 41 net::IPAddressNumber ip; |
| 42 net::ParseIPLiteralToNumber(kFakeQuicDomain, &ip); | 42 net::ParseIPLiteralToNumber(kServerHost, &ip); |
| 43 net::QuicConfig config; | 43 net::QuicConfig config; |
| 44 | 44 |
| 45 // Set up server certs. | 45 // Set up server certs. |
| 46 base::FilePath directory; | 46 base::FilePath directory; |
| 47 CHECK(base::android::GetExternalStorageDirectory(&directory)); | 47 CHECK(base::android::GetExternalStorageDirectory(&directory)); |
| 48 directory = directory.Append("net/data/ssl/certificates"); | 48 directory = directory.Append("net/data/ssl/certificates"); |
| 49 // TODO(xunjieli): Use scoped_ptr when crbug.com/545474 is fixed. | 49 // TODO(xunjieli): Use scoped_ptr when crbug.com/545474 is fixed. |
| 50 net::ProofSourceChromium* proof_source = new net::ProofSourceChromium(); | 50 net::ProofSourceChromium* proof_source = new net::ProofSourceChromium(); |
| 51 CHECK(proof_source->Initialize( | 51 CHECK(proof_source->Initialize( |
| 52 directory.Append("quic_test.example.com.crt"), | 52 directory.Append("quic_test.example.com.crt"), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 const JavaParamRef<jclass>& /*jcaller*/) { | 91 const JavaParamRef<jclass>& /*jcaller*/) { |
| 92 DCHECK(!g_quic_server_thread->task_runner()->BelongsToCurrentThread()); | 92 DCHECK(!g_quic_server_thread->task_runner()->BelongsToCurrentThread()); |
| 93 g_quic_server_thread->task_runner()->PostTask( | 93 g_quic_server_thread->task_runner()->PostTask( |
| 94 FROM_HERE, base::Bind(&ShutdownOnServerThread)); | 94 FROM_HERE, base::Bind(&ShutdownOnServerThread)); |
| 95 delete g_quic_server_thread; | 95 delete g_quic_server_thread; |
| 96 } | 96 } |
| 97 | 97 |
| 98 ScopedJavaLocalRef<jstring> GetServerHost( | 98 ScopedJavaLocalRef<jstring> GetServerHost( |
| 99 JNIEnv* env, | 99 JNIEnv* env, |
| 100 const JavaParamRef<jclass>& /*jcaller*/) { | 100 const JavaParamRef<jclass>& /*jcaller*/) { |
| 101 return base::android::ConvertUTF8ToJavaString(env, kFakeQuicDomain); | 101 return base::android::ConvertUTF8ToJavaString(env, kServerHost); |
| 102 } | 102 } |
| 103 | 103 |
| 104 int GetServerPort(JNIEnv* env, const JavaParamRef<jclass>& /*jcaller*/) { | 104 int GetServerPort(JNIEnv* env, const JavaParamRef<jclass>& /*jcaller*/) { |
| 105 return kServerPort; | 105 return kServerPort; |
| 106 } | 106 } |
| 107 | 107 |
| 108 bool RegisterQuicTestServer(JNIEnv* env) { | 108 bool RegisterQuicTestServer(JNIEnv* env) { |
| 109 return RegisterNativesImpl(env); | 109 return RegisterNativesImpl(env); |
| 110 } | 110 } |
| 111 | 111 |
| 112 } // namespace cronet | 112 } // namespace cronet |
| OLD | NEW |