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

Unified Diff: components/cronet/ios/test/quic_test_server.cc

Issue 1858483002: Cronet for iOS with C API for GRPC support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@small
Patch Set: Address comments, bundle libboringssl.a into libcronet.a Created 4 years, 8 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/cronet/ios/test/quic_test_server.h ('k') | components/cronet/tools/cr_cronet.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cronet/ios/test/quic_test_server.cc
diff --git a/components/cronet/android/test/quic_test_server.cc b/components/cronet/ios/test/quic_test_server.cc
similarity index 62%
copy from components/cronet/android/test/quic_test_server.cc
copy to components/cronet/ios/test/quic_test_server.cc
index 8f21eae7b92cee88ea30248b7b6bd52892b6b51c..581d737b8a099434e443c23af0dcbbe160c8cb9c 100644
--- a/components/cronet/android/test/quic_test_server.cc
+++ b/components/cronet/ios/test/quic_test_server.cc
@@ -1,18 +1,15 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "quic_test_server.h"
-#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"
+#include "base/path_service.h"
+#include "base/synchronization/waitable_event.h"
#include "base/threading/thread.h"
-#include "components/cronet/android/test/cronet_test_util.h"
-#include "jni/QuicTestServer_jni.h"
#include "net/base/ip_endpoint.h"
#include "net/base/test_data_directory.h"
#include "net/quic/crypto/proof_source_chromium.h"
@@ -21,30 +18,35 @@
namespace cronet {
-namespace {
-
+// This must match the certificate used (quic_test.example.com.crt and
+// quic_test.example.com.key.pkcs8).
+const char kFakeQuicDomain[] = "test.example.com";
static const int kServerPort = 6121;
base::Thread* g_quic_server_thread = nullptr;
net::QuicSimpleServer* g_quic_server = nullptr;
-void StartOnServerThread(const base::FilePath& test_files_root) {
+void StartQuicServerOnServerThread(const base::FilePath& test_files_root,
+ base::WaitableEvent* server_started_event) {
DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread());
DCHECK(!g_quic_server);
// 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::QuicInMemoryCache::GetInstance()->InitializeFromDirectory(
file_dir.value());
+ */
net::IPAddressNumber ip;
net::ParseIPLiteralToNumber(kFakeQuicDomain, &ip);
net::QuicConfig config;
// Set up server certs.
base::FilePath directory;
- CHECK(base::android::GetExternalStorageDirectory(&directory));
- directory = directory.Append("net/data/ssl/certificates");
+ // CHECK(base::android::GetExternalStorageDirectory(&directory));
+ // directory = directory.Append("net/data/ssl/certificates");
+ directory = test_files_root;
// TODO(xunjieli): Use scoped_ptr when crbug.com/545474 is fixed.
net::ProofSourceChromium* proof_source = new net::ProofSourceChromium();
CHECK(proof_source->Initialize(
@@ -57,55 +59,46 @@ void StartOnServerThread(const base::FilePath& test_files_root) {
// 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();
- Java_QuicTestServer_onServerStarted(env);
+ server_started_event->Signal();
}
-void ShutdownOnServerThread() {
+void ShutdownOnServerThread(base::WaitableEvent* server_stopped_event) {
DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread());
g_quic_server->Shutdown();
delete g_quic_server;
+ g_quic_server = nullptr;
+ server_stopped_event->Signal();
}
-} // namespace
-
// Quic server is currently hardcoded to run on port 6121 of the localhost on
// the device.
-void StartQuicTestServer(JNIEnv* env,
- const JavaParamRef<jclass>& /*jcaller*/,
- const JavaParamRef<jstring>& jtest_files_root) {
+bool StartQuicTestServer() {
DCHECK(!g_quic_server_thread);
g_quic_server_thread = new base::Thread("quic server thread");
base::Thread::Options thread_options;
thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
bool started = g_quic_server_thread->StartWithOptions(thread_options);
DCHECK(started);
- base::FilePath test_files_root(
- base::android::ConvertJavaStringToUTF8(env, jtest_files_root));
+ base::FilePath test_files_root;
+ if (!PathService::Get(base::DIR_EXE, &test_files_root))
+ return false;
+
+ base::WaitableEvent server_started_event(true, false);
g_quic_server_thread->task_runner()->PostTask(
- FROM_HERE, base::Bind(&StartOnServerThread, test_files_root));
+ FROM_HERE, base::Bind(&StartQuicServerOnServerThread, test_files_root,
+ &server_started_event));
+ server_started_event.Wait();
+ return true;
}
-void ShutdownQuicTestServer(JNIEnv* env,
- const JavaParamRef<jclass>& /*jcaller*/) {
+void ShutdownQuicTestServer() {
DCHECK(!g_quic_server_thread->task_runner()->BelongsToCurrentThread());
+ base::WaitableEvent server_stopped_event(true, false);
g_quic_server_thread->task_runner()->PostTask(
- FROM_HERE, base::Bind(&ShutdownOnServerThread));
+ FROM_HERE, base::Bind(&ShutdownOnServerThread, &server_stopped_event));
+ server_stopped_event.Wait();
delete g_quic_server_thread;
-}
-
-ScopedJavaLocalRef<jstring> GetServerHost(
- JNIEnv* env,
- const JavaParamRef<jclass>& /*jcaller*/) {
- return base::android::ConvertUTF8ToJavaString(env, kFakeQuicDomain);
-}
-
-int GetServerPort(JNIEnv* env, const JavaParamRef<jclass>& /*jcaller*/) {
- return kServerPort;
-}
-
-bool RegisterQuicTestServer(JNIEnv* env) {
- return RegisterNativesImpl(env);
+ g_quic_server_thread = nullptr;
}
} // namespace cronet
« no previous file with comments | « components/cronet/ios/test/quic_test_server.h ('k') | components/cronet/tools/cr_cronet.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698