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

Side by Side Diff: chrome/test/chromedriver/net/test_http_server.cc

Issue 2021393004: Migrate WaitableEvent to enum-based constructor in chrome/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@WEvent_enums
Patch Set: Split out custom changes to thread_watcher_unittest.cc Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chrome/test/chromedriver/net/test_http_server.h" 5 #include "chrome/test/chromedriver/net/test_http_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/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "net/base/ip_endpoint.h" 16 #include "net/base/ip_endpoint.h"
17 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
18 #include "net/server/http_server_request_info.h" 18 #include "net/server/http_server_request_info.h"
19 #include "net/socket/tcp_server_socket.h" 19 #include "net/socket/tcp_server_socket.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 const int kBufferSize = 100 * 1024 * 1024; // 100 MB 22 const int kBufferSize = 100 * 1024 * 1024; // 100 MB
23 23
24 TestHttpServer::TestHttpServer() 24 TestHttpServer::TestHttpServer()
25 : thread_("ServerThread"), 25 : thread_("ServerThread"),
26 all_closed_event_(false, true), 26 all_closed_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
27 base::WaitableEvent::InitialState::SIGNALED),
27 request_action_(kAccept), 28 request_action_(kAccept),
28 message_action_(kEchoMessage) { 29 message_action_(kEchoMessage) {}
29 }
30 30
31 TestHttpServer::~TestHttpServer() { 31 TestHttpServer::~TestHttpServer() {
32 } 32 }
33 33
34 bool TestHttpServer::Start() { 34 bool TestHttpServer::Start() {
35 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); 35 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0);
36 bool thread_started = thread_.StartWithOptions(options); 36 bool thread_started = thread_.StartWithOptions(options);
37 EXPECT_TRUE(thread_started); 37 EXPECT_TRUE(thread_started);
38 if (!thread_started) 38 if (!thread_started)
39 return false; 39 return false;
40 bool success; 40 bool success;
41 base::WaitableEvent event(false, false); 41 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
42 base::WaitableEvent::InitialState::NOT_SIGNALED);
42 thread_.task_runner()->PostTask( 43 thread_.task_runner()->PostTask(
43 FROM_HERE, base::Bind(&TestHttpServer::StartOnServerThread, 44 FROM_HERE, base::Bind(&TestHttpServer::StartOnServerThread,
44 base::Unretained(this), &success, &event)); 45 base::Unretained(this), &success, &event));
45 event.Wait(); 46 event.Wait();
46 return success; 47 return success;
47 } 48 }
48 49
49 void TestHttpServer::Stop() { 50 void TestHttpServer::Stop() {
50 if (!thread_.IsRunning()) 51 if (!thread_.IsRunning())
51 return; 52 return;
52 base::WaitableEvent event(false, false); 53 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
54 base::WaitableEvent::InitialState::NOT_SIGNALED);
53 thread_.task_runner()->PostTask( 55 thread_.task_runner()->PostTask(
54 FROM_HERE, base::Bind(&TestHttpServer::StopOnServerThread, 56 FROM_HERE, base::Bind(&TestHttpServer::StopOnServerThread,
55 base::Unretained(this), &event)); 57 base::Unretained(this), &event));
56 event.Wait(); 58 event.Wait();
57 thread_.Stop(); 59 thread_.Stop();
58 } 60 }
59 61
60 bool TestHttpServer::WaitForConnectionsToClose() { 62 bool TestHttpServer::WaitForConnectionsToClose() {
61 return all_closed_event_.TimedWait(base::TimeDelta::FromSeconds(10)); 63 return all_closed_event_.TimedWait(base::TimeDelta::FromSeconds(10));
62 } 64 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 server_.reset(NULL); 157 server_.reset(NULL);
156 } 158 }
157 *success = server_.get(); 159 *success = server_.get();
158 event->Signal(); 160 event->Signal();
159 } 161 }
160 162
161 void TestHttpServer::StopOnServerThread(base::WaitableEvent* event) { 163 void TestHttpServer::StopOnServerThread(base::WaitableEvent* event) {
162 server_.reset(NULL); 164 server_.reset(NULL);
163 event->Signal(); 165 event->Signal();
164 } 166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698