| OLD | NEW |
| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include <locale> | 9 #include <locale> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 CHECK(io_thread.StartWithOptions( | 201 CHECK(io_thread.StartWithOptions( |
| 202 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 202 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 203 | 203 |
| 204 base::MessageLoop cmd_loop; | 204 base::MessageLoop cmd_loop; |
| 205 base::RunLoop cmd_run_loop; | 205 base::RunLoop cmd_run_loop; |
| 206 HttpHandler handler(cmd_run_loop.QuitClosure(), io_thread.task_runner(), | 206 HttpHandler handler(cmd_run_loop.QuitClosure(), io_thread.task_runner(), |
| 207 url_base, adb_port, std::move(port_server)); | 207 url_base, adb_port, std::move(port_server)); |
| 208 HttpRequestHandlerFunc handle_request_func = | 208 HttpRequestHandlerFunc handle_request_func = |
| 209 base::Bind(&HandleRequestOnCmdThread, &handler, whitelisted_ips); | 209 base::Bind(&HandleRequestOnCmdThread, &handler, whitelisted_ips); |
| 210 | 210 |
| 211 io_thread.message_loop()->task_runner()->PostTask( | 211 io_thread.task_runner()->PostTask( |
| 212 FROM_HERE, | 212 FROM_HERE, |
| 213 base::Bind(&StartServerOnIOThread, port, allow_remote, | 213 base::Bind(&StartServerOnIOThread, port, allow_remote, |
| 214 base::Bind(&HandleRequestOnIOThread, cmd_loop.task_runner(), | 214 base::Bind(&HandleRequestOnIOThread, cmd_loop.task_runner(), |
| 215 handle_request_func))); | 215 handle_request_func))); |
| 216 // Run the command loop. This loop is quit after the response for a shutdown | 216 // Run the command loop. This loop is quit after the response for a shutdown |
| 217 // request is posted to the IO loop. After the command loop quits, a task | 217 // request is posted to the IO loop. After the command loop quits, a task |
| 218 // is posted to the IO loop to stop the server. Lastly, the IO thread is | 218 // is posted to the IO loop to stop the server. Lastly, the IO thread is |
| 219 // destroyed, which waits until all pending tasks have been completed. | 219 // destroyed, which waits until all pending tasks have been completed. |
| 220 // This assumes the response is sent synchronously as part of the IO task. | 220 // This assumes the response is sent synchronously as part of the IO task. |
| 221 cmd_run_loop.Run(); | 221 cmd_run_loop.Run(); |
| 222 io_thread.message_loop()->task_runner()->PostTask( | 222 io_thread.task_runner()->PostTask(FROM_HERE, |
| 223 FROM_HERE, base::Bind(&StopServerOnIOThread)); | 223 base::Bind(&StopServerOnIOThread)); |
| 224 } | 224 } |
| 225 | 225 |
| 226 } // namespace | 226 } // namespace |
| 227 | 227 |
| 228 int main(int argc, char *argv[]) { | 228 int main(int argc, char *argv[]) { |
| 229 base::CommandLine::Init(argc, argv); | 229 base::CommandLine::Init(argc, argv); |
| 230 | 230 |
| 231 base::AtExitManager at_exit; | 231 base::AtExitManager at_exit; |
| 232 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 232 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 233 | 233 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 } | 331 } |
| 332 | 332 |
| 333 if (!InitLogging()) { | 333 if (!InitLogging()) { |
| 334 printf("Unable to initialize logging. Exiting...\n"); | 334 printf("Unable to initialize logging. Exiting...\n"); |
| 335 return 1; | 335 return 1; |
| 336 } | 336 } |
| 337 RunServer(port, allow_remote, whitelisted_ips, url_base, adb_port, | 337 RunServer(port, allow_remote, whitelisted_ips, url_base, adb_port, |
| 338 std::move(port_server)); | 338 std::move(port_server)); |
| 339 return 0; | 339 return 0; |
| 340 } | 340 } |
| OLD | NEW |