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

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

Issue 2518063007: Pass QuicInMemoryCache directly instead of using a singleton. (Closed)
Patch Set: Fix Cronet compile error 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
« no previous file with comments | « no previous file | components/grpc_support/test/quic_test_server.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 13 matching lines...) Expand all
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::QuicSimpleServer* g_quic_server = nullptr; 35 net::QuicSimpleServer* g_quic_server = nullptr;
35 36
36 void StartOnServerThread(const base::FilePath& test_files_root, 37 void StartOnServerThread(const base::FilePath& test_files_root,
37 const base::FilePath& test_data_dir) { 38 const base::FilePath& test_data_dir) {
38 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread()); 39 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread());
39 DCHECK(!g_quic_server); 40 DCHECK(!g_quic_server);
40 41
41 // Set up in-memory cache. 42 // Set up in-memory cache.
42 base::FilePath file_dir = test_files_root.Append("quic_data"); 43 base::FilePath file_dir = test_files_root.Append("quic_data");
43 CHECK(base::PathExists(file_dir)) << "Quic data does not exist"; 44 CHECK(base::PathExists(file_dir)) << "Quic data does not exist";
44 net::QuicInMemoryCache::GetInstance()->InitializeFromDirectory( 45 g_quic_in_memory_cache = new net::QuicInMemoryCache();
45 file_dir.value()); 46 g_quic_in_memory_cache->InitializeFromDirectory(file_dir.value());
46 net::QuicConfig config; 47 net::QuicConfig config;
47 48
48 // Set up server certs. 49 // Set up server certs.
49 base::FilePath directory = test_data_dir.Append("net/data/ssl/certificates"); 50 base::FilePath directory = test_data_dir.Append("net/data/ssl/certificates");
50 std::unique_ptr<net::ProofSourceChromium> proof_source( 51 std::unique_ptr<net::ProofSourceChromium> proof_source(
51 new net::ProofSourceChromium()); 52 new net::ProofSourceChromium());
52 CHECK(proof_source->Initialize( 53 CHECK(proof_source->Initialize(
53 directory.Append("quic_test.example.com.crt"), 54 directory.Append("quic_test.example.com.crt"),
54 directory.Append("quic_test.example.com.key.pkcs8"), 55 directory.Append("quic_test.example.com.key.pkcs8"),
55 directory.Append("quic_test.example.com.key.sct"))); 56 directory.Append("quic_test.example.com.key.sct")));
56 g_quic_server = 57 g_quic_server = new net::QuicSimpleServer(
57 new net::QuicSimpleServer(std::move(proof_source), config, 58 std::move(proof_source), config,
58 net::QuicCryptoServerConfig::ConfigOptions(), 59 net::QuicCryptoServerConfig::ConfigOptions(), net::AllSupportedVersions(),
59 net::AllSupportedVersions()); 60 g_quic_in_memory_cache);
60 61
61 // Start listening. 62 // Start listening.
62 int rv = g_quic_server->Listen( 63 int rv = g_quic_server->Listen(
63 net::IPEndPoint(net::IPAddress::IPv4AllZeros(), kServerPort)); 64 net::IPEndPoint(net::IPAddress::IPv4AllZeros(), kServerPort));
64 CHECK_GE(rv, 0) << "Quic server fails to start"; 65 CHECK_GE(rv, 0) << "Quic server fails to start";
65 JNIEnv* env = base::android::AttachCurrentThread(); 66 JNIEnv* env = base::android::AttachCurrentThread();
66 Java_QuicTestServer_onServerStarted(env); 67 Java_QuicTestServer_onServerStarted(env);
67 } 68 }
68 69
69 void ShutdownOnServerThread() { 70 void ShutdownOnServerThread() {
70 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread()); 71 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread());
71 g_quic_server->Shutdown(); 72 g_quic_server->Shutdown();
72 delete g_quic_server; 73 delete g_quic_server;
74 delete g_quic_in_memory_cache;
73 } 75 }
74 76
75 } // namespace 77 } // namespace
76 78
77 // 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
78 // the device. 80 // the device.
79 void StartQuicTestServer(JNIEnv* env, 81 void StartQuicTestServer(JNIEnv* env,
80 const JavaParamRef<jclass>& /*jcaller*/, 82 const JavaParamRef<jclass>& /*jcaller*/,
81 const JavaParamRef<jstring>& jtest_files_root, 83 const JavaParamRef<jstring>& jtest_files_root,
82 const JavaParamRef<jstring>& jtest_data_dir) { 84 const JavaParamRef<jstring>& jtest_data_dir) {
(...skipping 24 matching lines...) Expand all
107 109
108 int GetServerPort(JNIEnv* env, const JavaParamRef<jclass>& /*jcaller*/) { 110 int GetServerPort(JNIEnv* env, const JavaParamRef<jclass>& /*jcaller*/) {
109 return kServerPort; 111 return kServerPort;
110 } 112 }
111 113
112 bool RegisterQuicTestServer(JNIEnv* env) { 114 bool RegisterQuicTestServer(JNIEnv* env) {
113 return RegisterNativesImpl(env); 115 return RegisterNativesImpl(env);
114 } 116 }
115 117
116 } // namespace cronet 118 } // namespace cronet
OLDNEW
« no previous file with comments | « no previous file | components/grpc_support/test/quic_test_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698