Chromium Code Reviews| Index: components/cronet/android/test/quic_test_server.cc |
| diff --git a/components/cronet/android/test/quic_test_server.cc b/components/cronet/android/test/quic_test_server.cc |
| index cb6d926a991952d81ec9685ca90778a2cb6a9a17..6ec9ff0bb5c59c01330b8b2f69bf53b05c1e83ab 100644 |
| --- a/components/cronet/android/test/quic_test_server.cc |
| +++ b/components/cronet/android/test/quic_test_server.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/android/jni_android.h" |
| #include "base/android/jni_string.h" |
| +#include "base/android/path_utils.h" |
| #include "base/bind.h" |
| #include "base/files/file_path.h" |
| #include "base/files/file_util.h" |
| @@ -13,6 +14,8 @@ |
| #include "jni/QuicTestServer_jni.h" |
| #include "net/base/ip_endpoint.h" |
| #include "net/base/net_util.h" |
| +#include "net/base/test_data_directory.h" |
| +#include "net/quic/crypto/proof_source_chromium.h" |
| #include "net/tools/quic/quic_in_memory_cache.h" |
| #include "net/tools/quic/quic_simple_server.h" |
| @@ -20,17 +23,25 @@ namespace cronet { |
| namespace { |
| -static const char kServerHost[] = "127.0.0.1"; |
| +static const char kServerHost[] = "test.example.com"; |
| static const int kServerPort = 6121; |
| base::Thread* g_quic_server_thread = nullptr; |
| net::tools::QuicSimpleServer* g_quic_server = nullptr; |
| -void ServeFilesFromDirectory( |
| - const base::FilePath& directory) { |
| +net::ProofSource* CreateProofSource(const base::FilePath& cert_path, |
| + const base::FilePath& key_path) { |
|
pauljensen
2015/10/09 20:58:10
any particular reason you have a tiny function tha
xunjieli
2015/10/09 21:19:57
Done.
|
| + net::ProofSourceChromium* proof_source = new net::ProofSourceChromium(); |
| + CHECK(proof_source->Initialize(cert_path, key_path)); |
| + return proof_source; |
| +} |
| + |
| +void StartOnServerThread(const base::FilePath& test_files_root) { |
| DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread()); |
| DCHECK(!g_quic_server); |
| - base::FilePath file_dir = directory.Append("quic_data"); |
| + |
| + // Set up in-memory cache. |
| + base::FilePath file_dir = test_files_root.Append("quic_data"); |
| CHECK(base::PathExists(file_dir)) << "Quic data does not exist"; |
| net::tools::QuicInMemoryCache::GetInstance()->InitializeFromDirectory( |
| file_dir.value()); |
| @@ -39,6 +50,17 @@ void ServeFilesFromDirectory( |
| net::QuicConfig config; |
| g_quic_server = |
| new net::tools::QuicSimpleServer(config, net::QuicSupportedVersions()); |
| + |
| + // Set up server certs. |
| + base::FilePath directory; |
| + bool success = base::android::GetExternalStorageDirectory(&directory); |
|
pauljensen
2015/10/09 20:58:10
can we combine this and the next line into CHECK(b
xunjieli
2015/10/09 21:19:57
Done.
|
| + CHECK(success); |
| + directory = directory.Append("net/data/ssl/certificates"); |
| + g_quic_server->SetProofSource( |
| + CreateProofSource(directory.Append("quic_test.example.com.crt"), |
| + directory.Append("quic_test.example.com.key.pkcs8"))); |
| + |
| + // Start listening. |
| int rv = g_quic_server->Listen(net::IPEndPoint(ip, kServerPort)); |
| CHECK_GE(rv, 0) << "Quic server fails to start"; |
| JNIEnv* env = base::android::AttachCurrentThread(); |
| @@ -67,7 +89,7 @@ void StartQuicTestServer(JNIEnv* env, |
| base::FilePath test_files_root( |
| base::android::ConvertJavaStringToUTF8(env, jtest_files_root)); |
| g_quic_server_thread->task_runner()->PostTask( |
| - FROM_HERE, base::Bind(&ServeFilesFromDirectory, test_files_root)); |
| + FROM_HERE, base::Bind(&StartOnServerThread, test_files_root)); |
| } |
| void ShutdownQuicTestServer(JNIEnv* env, |