Chromium Code Reviews| 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" |
| 11 #include "base/files/file_util.h" | |
| 11 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 12 #include "jni/QuicTestServer_jni.h" | 13 #include "jni/QuicTestServer_jni.h" |
| 13 #include "net/base/ip_endpoint.h" | 14 #include "net/base/ip_endpoint.h" |
| 14 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
| 15 #include "net/tools/quic/quic_in_memory_cache.h" | 16 #include "net/tools/quic/quic_in_memory_cache.h" |
| 16 #include "net/tools/quic/quic_simple_server.h" | 17 #include "net/tools/quic/quic_simple_server.h" |
| 17 | 18 |
| 18 namespace cronet { | 19 namespace cronet { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 static const char kServerHost[] = "127.0.0.1"; | 23 static const char kServerHost[] = "127.0.0.1"; |
| 23 static const int kServerPort = 6121; | 24 static const int kServerPort = 6121; |
| 24 | 25 |
| 25 base::Thread* g_quic_server_thread = nullptr; | 26 base::Thread* g_quic_server_thread = nullptr; |
| 26 net::tools::QuicSimpleServer* g_quic_server = nullptr; | 27 net::tools::QuicSimpleServer* g_quic_server = nullptr; |
| 27 | 28 |
| 28 void ServeFilesFromDirectory( | 29 void ServeFilesFromDirectory( |
| 29 const base::FilePath& directory) { | 30 const base::FilePath& directory) { |
| 30 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread()); | 31 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread()); |
| 31 DCHECK(!g_quic_server); | 32 DCHECK(!g_quic_server); |
| 32 base::FilePath file_dir = directory.Append("quic_data"); | 33 base::FilePath file_dir = directory.Append("quic_data"); |
| 34 bool file_exist = base::PathExists(file_dir); | |
| 35 CHECK(file_exist) << "Quic data does not exist"; | |
|
mef
2015/05/13 17:00:03
Do we need |file_exist| variable?
xunjieli
2015/05/13 17:06:16
Done. I don't think we do.
| |
| 33 net::tools::QuicInMemoryCache::GetInstance()->InitializeFromDirectory( | 36 net::tools::QuicInMemoryCache::GetInstance()->InitializeFromDirectory( |
| 34 file_dir.value()); | 37 file_dir.value()); |
| 35 net::IPAddressNumber ip; | 38 net::IPAddressNumber ip; |
| 36 net::ParseIPLiteralToNumber(kServerHost, &ip); | 39 net::ParseIPLiteralToNumber(kServerHost, &ip); |
| 37 net::QuicConfig config; | 40 net::QuicConfig config; |
| 38 g_quic_server = | 41 g_quic_server = |
| 39 new net::tools::QuicSimpleServer(config, net::QuicSupportedVersions()); | 42 new net::tools::QuicSimpleServer(config, net::QuicSupportedVersions()); |
| 40 int rv = g_quic_server->Listen(net::IPEndPoint(ip, kServerPort)); | 43 int rv = g_quic_server->Listen(net::IPEndPoint(ip, kServerPort)); |
| 41 CHECK_GE(rv, 0) << "Quic server fails to start"; | 44 CHECK_GE(rv, 0) << "Quic server fails to start"; |
| 42 JNIEnv* env = base::android::AttachCurrentThread(); | 45 JNIEnv* env = base::android::AttachCurrentThread(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 | 84 |
| 82 int GetServerPort(JNIEnv* env, jclass /*jcaller*/) { | 85 int GetServerPort(JNIEnv* env, jclass /*jcaller*/) { |
| 83 return kServerPort; | 86 return kServerPort; |
| 84 } | 87 } |
| 85 | 88 |
| 86 bool RegisterQuicTestServer(JNIEnv* env) { | 89 bool RegisterQuicTestServer(JNIEnv* env) { |
| 87 return RegisterNativesImpl(env); | 90 return RegisterNativesImpl(env); |
| 88 } | 91 } |
| 89 | 92 |
| 90 } // namespace cronet | 93 } // namespace cronet |
| OLD | NEW |