| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <termios.h> | 6 #include <termios.h> |
| 7 | 7 |
| 8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 auth_code = ReadString(true); | 138 auth_code = ReadString(true); |
| 139 } | 139 } |
| 140 | 140 |
| 141 // This object instance is required by Chrome code (for example, | 141 // This object instance is required by Chrome code (for example, |
| 142 // FilePath, LazyInstance, MessageLoop). | 142 // FilePath, LazyInstance, MessageLoop). |
| 143 base::AtExitManager exit_manager; | 143 base::AtExitManager exit_manager; |
| 144 | 144 |
| 145 // Provide message loops and threads for the URLRequestContextGetter. | 145 // Provide message loops and threads for the URLRequestContextGetter. |
| 146 base::MessageLoop message_loop; | 146 base::MessageLoop message_loop; |
| 147 g_message_loop = &message_loop; | 147 g_message_loop = &message_loop; |
| 148 base::Thread::Options io_thread_options(base::MessageLoop::TYPE_IO, 0); |
| 148 base::Thread io_thread("IO thread"); | 149 base::Thread io_thread("IO thread"); |
| 149 base::Thread::Options io_thread_options(base::MessageLoop::TYPE_IO, 0); | |
| 150 io_thread.StartWithOptions(io_thread_options); | 150 io_thread.StartWithOptions(io_thread_options); |
| 151 base::Thread file_thread("file thread"); |
| 152 file_thread.StartWithOptions(io_thread_options); |
| 151 | 153 |
| 152 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter( | 154 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter( |
| 153 new remoting::URLRequestContextGetter(io_thread.message_loop_proxy())); | 155 new remoting::URLRequestContextGetter(io_thread.task_runner(), |
| 156 file_thread.task_runner())); |
| 154 | 157 |
| 155 net::URLFetcher::SetIgnoreCertificateRequests(true); | 158 net::URLFetcher::SetIgnoreCertificateRequests(true); |
| 156 | 159 |
| 157 // Start the host. | 160 // Start the host. |
| 158 scoped_ptr<HostStarter> host_starter(HostStarter::Create( | 161 scoped_ptr<HostStarter> host_starter(HostStarter::Create( |
| 159 remoting::ServiceUrls::GetInstance()->directory_hosts_url(), | 162 remoting::ServiceUrls::GetInstance()->directory_hosts_url(), |
| 160 url_request_context_getter.get())); | 163 url_request_context_getter.get())); |
| 161 if (redirect_url.empty()) { | 164 if (redirect_url.empty()) { |
| 162 redirect_url = remoting::GetDefaultOauthRedirectUrl(); | 165 redirect_url = remoting::GetDefaultOauthRedirectUrl(); |
| 163 } | 166 } |
| 164 host_starter->StartHost(host_name, host_pin, true, auth_code, redirect_url, | 167 host_starter->StartHost(host_name, host_pin, true, auth_code, redirect_url, |
| 165 base::Bind(&OnDone)); | 168 base::Bind(&OnDone)); |
| 166 | 169 |
| 167 // Run the message loop until the StartHost completion callback. | 170 // Run the message loop until the StartHost completion callback. |
| 168 base::RunLoop run_loop; | 171 base::RunLoop run_loop; |
| 169 run_loop.Run(); | 172 run_loop.Run(); |
| 170 | 173 |
| 171 g_message_loop = NULL; | 174 g_message_loop = NULL; |
| 172 | 175 |
| 173 // Destroy the HostStarter and URLRequestContextGetter before stopping the | 176 // Destroy the HostStarter and URLRequestContextGetter before stopping the |
| 174 // IO thread. | 177 // IO thread. |
| 175 host_starter.reset(); | 178 host_starter.reset(); |
| 176 url_request_context_getter = NULL; | 179 url_request_context_getter = NULL; |
| 177 | 180 |
| 178 io_thread.Stop(); | 181 io_thread.Stop(); |
| 179 | 182 |
| 180 return g_started ? 0 : 1; | 183 return g_started ? 0 : 1; |
| 181 } | 184 } |
| OLD | NEW |