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

Side by Side Diff: chrome/test/chromedriver/server/chromedriver_server.cc

Issue 1167163002: chrome: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added some missing message_loop.h includes. Created 5 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 <stdio.h> 5 #include <stdio.h>
6 #include <locale> 6 #include <locale>
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/at_exit.h" 10 #include "base/at_exit.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
19 #include "base/run_loop.h" 19 #include "base/run_loop.h"
20 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/string_split.h" 21 #include "base/strings/string_split.h"
22 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
23 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
24 #include "base/synchronization/waitable_event.h" 24 #include "base/synchronization/waitable_event.h"
25 #include "base/thread_task_runner_handle.h"
25 #include "base/threading/thread.h" 26 #include "base/threading/thread.h"
26 #include "base/threading/thread_local.h" 27 #include "base/threading/thread_local.h"
27 #include "chrome/test/chromedriver/logging.h" 28 #include "chrome/test/chromedriver/logging.h"
28 #include "chrome/test/chromedriver/net/port_server.h" 29 #include "chrome/test/chromedriver/net/port_server.h"
29 #include "chrome/test/chromedriver/server/http_handler.h" 30 #include "chrome/test/chromedriver/server/http_handler.h"
30 #include "chrome/test/chromedriver/version.h" 31 #include "chrome/test/chromedriver/version.h"
31 #include "net/base/ip_endpoint.h" 32 #include "net/base/ip_endpoint.h"
32 #include "net/base/net_errors.h" 33 #include "net/base/net_errors.h"
33 #include "net/server/http_server.h" 34 #include "net/server/http_server.h"
34 #include "net/server/http_server_request_info.h" 35 #include "net/server/http_server_request_info.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 130
130 handler->Handle(request, send_response_func); 131 handler->Handle(request, send_response_func);
131 } 132 }
132 133
133 void HandleRequestOnIOThread( 134 void HandleRequestOnIOThread(
134 const scoped_refptr<base::SingleThreadTaskRunner>& cmd_task_runner, 135 const scoped_refptr<base::SingleThreadTaskRunner>& cmd_task_runner,
135 const HttpRequestHandlerFunc& handle_request_on_cmd_func, 136 const HttpRequestHandlerFunc& handle_request_on_cmd_func,
136 const net::HttpServerRequestInfo& request, 137 const net::HttpServerRequestInfo& request,
137 const HttpResponseSenderFunc& send_response_func) { 138 const HttpResponseSenderFunc& send_response_func) {
138 cmd_task_runner->PostTask( 139 cmd_task_runner->PostTask(
139 FROM_HERE, 140 FROM_HERE, base::Bind(handle_request_on_cmd_func, request,
140 base::Bind(handle_request_on_cmd_func, 141 base::Bind(&SendResponseOnCmdThread,
141 request, 142 base::ThreadTaskRunnerHandle::Get(),
142 base::Bind(&SendResponseOnCmdThread, 143 send_response_func)));
143 base::MessageLoopProxy::current(),
144 send_response_func)));
145 } 144 }
146 145
147 base::LazyInstance<base::ThreadLocalPointer<HttpServer> > 146 base::LazyInstance<base::ThreadLocalPointer<HttpServer> >
148 lazy_tls_server = LAZY_INSTANCE_INITIALIZER; 147 lazy_tls_server = LAZY_INSTANCE_INITIALIZER;
149 148
150 void StopServerOnIOThread() { 149 void StopServerOnIOThread() {
151 // Note, |server| may be NULL. 150 // Note, |server| may be NULL.
152 HttpServer* server = lazy_tls_server.Pointer()->Get(); 151 HttpServer* server = lazy_tls_server.Pointer()->Get();
153 lazy_tls_server.Pointer()->Set(NULL); 152 lazy_tls_server.Pointer()->Set(NULL);
154 delete server; 153 delete server;
(...skipping 15 matching lines...) Expand all
170 const std::vector<std::string>& whitelisted_ips, 169 const std::vector<std::string>& whitelisted_ips,
171 const std::string& url_base, 170 const std::string& url_base,
172 int adb_port, 171 int adb_port,
173 scoped_ptr<PortServer> port_server) { 172 scoped_ptr<PortServer> port_server) {
174 base::Thread io_thread("ChromeDriver IO"); 173 base::Thread io_thread("ChromeDriver IO");
175 CHECK(io_thread.StartWithOptions( 174 CHECK(io_thread.StartWithOptions(
176 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); 175 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
177 176
178 base::MessageLoop cmd_loop; 177 base::MessageLoop cmd_loop;
179 base::RunLoop cmd_run_loop; 178 base::RunLoop cmd_run_loop;
180 HttpHandler handler(cmd_run_loop.QuitClosure(), 179 HttpHandler handler(cmd_run_loop.QuitClosure(), io_thread.task_runner(),
181 io_thread.message_loop_proxy(), 180 url_base, adb_port, port_server.Pass());
182 url_base,
183 adb_port,
184 port_server.Pass());
185 HttpRequestHandlerFunc handle_request_func = 181 HttpRequestHandlerFunc handle_request_func =
186 base::Bind(&HandleRequestOnCmdThread, &handler, whitelisted_ips); 182 base::Bind(&HandleRequestOnCmdThread, &handler, whitelisted_ips);
187 183
188 io_thread.message_loop() 184 io_thread.message_loop()->PostTask(
189 ->PostTask(FROM_HERE, 185 FROM_HERE,
190 base::Bind(&StartServerOnIOThread, 186 base::Bind(&StartServerOnIOThread, port, allow_remote,
191 port, 187 base::Bind(&HandleRequestOnIOThread, cmd_loop.task_runner(),
192 allow_remote, 188 handle_request_func)));
193 base::Bind(&HandleRequestOnIOThread,
194 cmd_loop.message_loop_proxy(),
195 handle_request_func)));
196 // Run the command loop. This loop is quit after the response for a shutdown 189 // Run the command loop. This loop is quit after the response for a shutdown
197 // request is posted to the IO loop. After the command loop quits, a task 190 // request is posted to the IO loop. After the command loop quits, a task
198 // is posted to the IO loop to stop the server. Lastly, the IO thread is 191 // is posted to the IO loop to stop the server. Lastly, the IO thread is
199 // destroyed, which waits until all pending tasks have been completed. 192 // destroyed, which waits until all pending tasks have been completed.
200 // This assumes the response is sent synchronously as part of the IO task. 193 // This assumes the response is sent synchronously as part of the IO task.
201 cmd_run_loop.Run(); 194 cmd_run_loop.Run();
202 io_thread.message_loop() 195 io_thread.message_loop()
203 ->PostTask(FROM_HERE, base::Bind(&StopServerOnIOThread)); 196 ->PostTask(FROM_HERE, base::Bind(&StopServerOnIOThread));
204 } 197 }
205 198
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 } 303 }
311 304
312 if (!InitLogging()) { 305 if (!InitLogging()) {
313 printf("Unable to initialize logging. Exiting...\n"); 306 printf("Unable to initialize logging. Exiting...\n");
314 return 1; 307 return 1;
315 } 308 }
316 RunServer(port, allow_remote, whitelisted_ips, 309 RunServer(port, allow_remote, whitelisted_ips,
317 url_base, adb_port, port_server.Pass()); 310 url_base, adb_port, port_server.Pass());
318 return 0; 311 return 0;
319 } 312 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/net/websocket_unittest.cc ('k') | chrome/test/chromedriver/server/http_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698