Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Side by Side Diff: components/cronet/android/test/quic_test_server.cc

Issue 2547583002: Landing Recent QUIC changes until Fri Nov 18 23:21:04 2016 +0000 (Closed)
Patch Set: Remove explicit HTTP/2 enum usage Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/test/test_support_android.h" 13 #include "base/test/test_support_android.h"
14 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
15 #include "components/cronet/android/test/cronet_test_util.h" 15 #include "components/cronet/android/test/cronet_test_util.h"
16 #include "jni/QuicTestServer_jni.h" 16 #include "jni/QuicTestServer_jni.h"
17 #include "net/base/ip_address.h" 17 #include "net/base/ip_address.h"
18 #include "net/base/ip_endpoint.h" 18 #include "net/base/ip_endpoint.h"
19 #include "net/quic/chromium/crypto/proof_source_chromium.h" 19 #include "net/quic/chromium/crypto/proof_source_chromium.h"
20 #include "net/test/test_data_directory.h" 20 #include "net/test/test_data_directory.h"
21 #include "net/tools/quic/quic_in_memory_cache.h" 21 #include "net/tools/quic/quic_http_response_cache.h"
22 #include "net/tools/quic/quic_simple_server.h" 22 #include "net/tools/quic/quic_simple_server.h"
23 23
24 using base::android::JavaParamRef; 24 using base::android::JavaParamRef;
25 using base::android::ScopedJavaLocalRef; 25 using base::android::ScopedJavaLocalRef;
26 26
27 namespace cronet { 27 namespace cronet {
28 28
29 namespace { 29 namespace {
30 30
31 static const int kServerPort = 6121; 31 static const int kServerPort = 6121;
32 32
33 base::Thread* g_quic_server_thread = nullptr; 33 base::Thread* g_quic_server_thread = nullptr;
34 net::QuicInMemoryCache* g_quic_in_memory_cache = nullptr; 34 net::QuicHttpResponseCache* g_quic_response_cache = nullptr;
35 net::QuicSimpleServer* g_quic_server = nullptr; 35 net::QuicSimpleServer* g_quic_server = nullptr;
36 36
37 void StartOnServerThread(const base::FilePath& test_files_root, 37 void StartOnServerThread(const base::FilePath& test_files_root,
38 const base::FilePath& test_data_dir) { 38 const base::FilePath& test_data_dir) {
39 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread()); 39 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread());
40 DCHECK(!g_quic_server); 40 DCHECK(!g_quic_server);
41 41
42 // Set up in-memory cache. 42 // Set up in-memory cache.
43 base::FilePath file_dir = test_files_root.Append("quic_data"); 43 base::FilePath file_dir = test_files_root.Append("quic_data");
44 CHECK(base::PathExists(file_dir)) << "Quic data does not exist"; 44 CHECK(base::PathExists(file_dir)) << "Quic data does not exist";
45 g_quic_in_memory_cache = new net::QuicInMemoryCache(); 45 g_quic_response_cache = new net::QuicHttpResponseCache();
46 g_quic_in_memory_cache->InitializeFromDirectory(file_dir.value()); 46 g_quic_response_cache->InitializeFromDirectory(file_dir.value());
47 net::QuicConfig config; 47 net::QuicConfig config;
48 48
49 // Set up server certs. 49 // Set up server certs.
50 base::FilePath directory = test_data_dir.Append("net/data/ssl/certificates"); 50 base::FilePath directory = test_data_dir.Append("net/data/ssl/certificates");
51 std::unique_ptr<net::ProofSourceChromium> proof_source( 51 std::unique_ptr<net::ProofSourceChromium> proof_source(
52 new net::ProofSourceChromium()); 52 new net::ProofSourceChromium());
53 CHECK(proof_source->Initialize( 53 CHECK(proof_source->Initialize(
54 directory.Append("quic_test.example.com.crt"), 54 directory.Append("quic_test.example.com.crt"),
55 directory.Append("quic_test.example.com.key.pkcs8"), 55 directory.Append("quic_test.example.com.key.pkcs8"),
56 directory.Append("quic_test.example.com.key.sct"))); 56 directory.Append("quic_test.example.com.key.sct")));
57 g_quic_server = new net::QuicSimpleServer( 57 g_quic_server = new net::QuicSimpleServer(
58 std::move(proof_source), config, 58 std::move(proof_source), config,
59 net::QuicCryptoServerConfig::ConfigOptions(), net::AllSupportedVersions(), 59 net::QuicCryptoServerConfig::ConfigOptions(), net::AllSupportedVersions(),
60 g_quic_in_memory_cache); 60 g_quic_response_cache);
61 61
62 // Start listening. 62 // Start listening.
63 int rv = g_quic_server->Listen( 63 int rv = g_quic_server->Listen(
64 net::IPEndPoint(net::IPAddress::IPv4AllZeros(), kServerPort)); 64 net::IPEndPoint(net::IPAddress::IPv4AllZeros(), kServerPort));
65 CHECK_GE(rv, 0) << "Quic server fails to start"; 65 CHECK_GE(rv, 0) << "Quic server fails to start";
66 JNIEnv* env = base::android::AttachCurrentThread(); 66 JNIEnv* env = base::android::AttachCurrentThread();
67 Java_QuicTestServer_onServerStarted(env); 67 Java_QuicTestServer_onServerStarted(env);
68 } 68 }
69 69
70 void ShutdownOnServerThread() { 70 void ShutdownOnServerThread() {
71 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread()); 71 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread());
72 g_quic_server->Shutdown(); 72 g_quic_server->Shutdown();
73 delete g_quic_server; 73 delete g_quic_server;
74 delete g_quic_in_memory_cache; 74 delete g_quic_response_cache;
75 } 75 }
76 76
77 } // namespace 77 } // namespace
78 78
79 // Quic server is currently hardcoded to run on port 6121 of the localhost on 79 // Quic server is currently hardcoded to run on port 6121 of the localhost on
80 // the device. 80 // the device.
81 void StartQuicTestServer(JNIEnv* env, 81 void StartQuicTestServer(JNIEnv* env,
82 const JavaParamRef<jclass>& /*jcaller*/, 82 const JavaParamRef<jclass>& /*jcaller*/,
83 const JavaParamRef<jstring>& jtest_files_root, 83 const JavaParamRef<jstring>& jtest_files_root,
84 const JavaParamRef<jstring>& jtest_data_dir) { 84 const JavaParamRef<jstring>& jtest_data_dir) {
(...skipping 24 matching lines...) Expand all
109 109
110 int GetServerPort(JNIEnv* env, const JavaParamRef<jclass>& /*jcaller*/) { 110 int GetServerPort(JNIEnv* env, const JavaParamRef<jclass>& /*jcaller*/) {
111 return kServerPort; 111 return kServerPort;
112 } 112 }
113 113
114 bool RegisterQuicTestServer(JNIEnv* env) { 114 bool RegisterQuicTestServer(JNIEnv* env) {
115 return RegisterNativesImpl(env); 115 return RegisterNativesImpl(env);
116 } 116 }
117 117
118 } // namespace cronet 118 } // namespace cronet
OLDNEW
« no previous file with comments | « components/cronet/android/cronet_url_request_adapter.cc ('k') | components/cronet/url_request_context_config.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698