| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/cronet/ios/test/quic_test_server.h" | 5 #include "components/cronet/ios/test/quic_test_server.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 base::Thread* g_quic_server_thread = nullptr; | 44 base::Thread* g_quic_server_thread = nullptr; |
| 45 net::QuicSimpleServer* g_quic_server = nullptr; | 45 net::QuicSimpleServer* g_quic_server = nullptr; |
| 46 | 46 |
| 47 void SetupQuicInMemoryCache() { | 47 void SetupQuicInMemoryCache() { |
| 48 static bool setup_done = false; | 48 static bool setup_done = false; |
| 49 if (setup_done) | 49 if (setup_done) |
| 50 return; | 50 return; |
| 51 setup_done = true; | 51 setup_done = true; |
| 52 net::SpdyHeaderBlock headers; | 52 net::SpdyHeaderBlock headers; |
| 53 headers.ReplaceOrAppendHeader(kHelloHeaderName, kHelloHeaderValue); | 53 headers.AppendValueOrAddHeader(kHelloHeaderName, kHelloHeaderValue); |
| 54 headers.ReplaceOrAppendHeader(kStatusHeader, kHelloStatus); | 54 headers.AppendValueOrAddHeader(kStatusHeader, kHelloStatus); |
| 55 net::SpdyHeaderBlock trailers; | 55 net::SpdyHeaderBlock trailers; |
| 56 trailers.ReplaceOrAppendHeader(kHelloTrailerName, kHelloTrailerValue); | 56 trailers.AppendValueOrAddHeader(kHelloTrailerName, kHelloTrailerValue); |
| 57 net::QuicInMemoryCache::GetInstance()->AddResponse( | 57 net::QuicInMemoryCache::GetInstance()->AddResponse( |
| 58 kTestServerHost, kHelloPath, std::move(headers), kHelloBodyValue, | 58 kTestServerHost, kHelloPath, std::move(headers), kHelloBodyValue, |
| 59 std::move(trailers)); | 59 std::move(trailers)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void StartQuicServerOnServerThread(const base::FilePath& test_files_root, | 62 void StartQuicServerOnServerThread(const base::FilePath& test_files_root, |
| 63 base::WaitableEvent* server_started_event) { | 63 base::WaitableEvent* server_started_event) { |
| 64 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread()); | 64 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread()); |
| 65 DCHECK(!g_quic_server); | 65 DCHECK(!g_quic_server); |
| 66 | 66 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 bool StartQuicTestServer() { | 101 bool StartQuicTestServer() { |
| 102 DCHECK(!g_quic_server_thread); | 102 DCHECK(!g_quic_server_thread); |
| 103 g_quic_server_thread = new base::Thread("quic server thread"); | 103 g_quic_server_thread = new base::Thread("quic server thread"); |
| 104 base::Thread::Options thread_options; | 104 base::Thread::Options thread_options; |
| 105 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; | 105 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 106 bool started = g_quic_server_thread->StartWithOptions(thread_options); | 106 bool started = g_quic_server_thread->StartWithOptions(thread_options); |
| 107 DCHECK(started); | 107 DCHECK(started); |
| 108 base::FilePath test_files_root; | 108 base::FilePath test_files_root; |
| 109 if (!PathService::Get(base::DIR_EXE, &test_files_root)) | 109 if (!PathService::Get(base::DIR_EXE, &test_files_root)) |
| 110 return false; | 110 return false; |
| 111 | |
| 112 base::WaitableEvent server_started_event( | 111 base::WaitableEvent server_started_event( |
| 113 base::WaitableEvent::ResetPolicy::MANUAL, | 112 base::WaitableEvent::ResetPolicy::MANUAL, |
| 114 base::WaitableEvent::InitialState::NOT_SIGNALED); | 113 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 115 g_quic_server_thread->task_runner()->PostTask( | 114 g_quic_server_thread->task_runner()->PostTask( |
| 116 FROM_HERE, base::Bind(&StartQuicServerOnServerThread, test_files_root, | 115 FROM_HERE, base::Bind(&StartQuicServerOnServerThread, |
| 116 test_files_root.Append("net/data/ssl/certificates"), |
| 117 &server_started_event)); | 117 &server_started_event)); |
| 118 server_started_event.Wait(); | 118 server_started_event.Wait(); |
| 119 return true; | 119 return true; |
| 120 } | 120 } |
| 121 | 121 |
| 122 void ShutdownQuicTestServer() { | 122 void ShutdownQuicTestServer() { |
| 123 if (!g_quic_server_thread) | 123 if (!g_quic_server_thread) |
| 124 return; | 124 return; |
| 125 DCHECK(!g_quic_server_thread->task_runner()->BelongsToCurrentThread()); | 125 DCHECK(!g_quic_server_thread->task_runner()->BelongsToCurrentThread()); |
| 126 base::WaitableEvent server_stopped_event( | 126 base::WaitableEvent server_stopped_event( |
| 127 base::WaitableEvent::ResetPolicy::MANUAL, | 127 base::WaitableEvent::ResetPolicy::MANUAL, |
| 128 base::WaitableEvent::InitialState::NOT_SIGNALED); | 128 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 129 g_quic_server_thread->task_runner()->PostTask( | 129 g_quic_server_thread->task_runner()->PostTask( |
| 130 FROM_HERE, base::Bind(&ShutdownOnServerThread, &server_stopped_event)); | 130 FROM_HERE, base::Bind(&ShutdownOnServerThread, &server_stopped_event)); |
| 131 server_stopped_event.Wait(); | 131 server_stopped_event.Wait(); |
| 132 delete g_quic_server_thread; | 132 delete g_quic_server_thread; |
| 133 g_quic_server_thread = nullptr; | 133 g_quic_server_thread = nullptr; |
| 134 } | 134 } |
| 135 | 135 |
| 136 } // namespace cronet | 136 } // namespace cronet |
| OLD | NEW |