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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 return std::string(); | 56 return std::string(); |
57 size_t newline_index = str.find('\n'); | 57 size_t newline_index = str.find('\n'); |
58 if (newline_index != std::string::npos) | 58 if (newline_index != std::string::npos) |
59 str[newline_index] = '\0'; | 59 str[newline_index] = '\0'; |
60 str.resize(strlen(&str[0])); | 60 str.resize(strlen(&str[0])); |
61 return str; | 61 return str; |
62 } | 62 } |
63 | 63 |
64 // Called when the HostStarter has finished. | 64 // Called when the HostStarter has finished. |
65 void OnDone(HostStarter::Result result) { | 65 void OnDone(HostStarter::Result result) { |
66 if (MessageLoop::current() != g_message_loop) { | 66 if (base::MessageLoop::current() != g_message_loop) { |
67 g_message_loop->PostTask(FROM_HERE, base::Bind(&OnDone, result)); | 67 g_message_loop->PostTask(FROM_HERE, base::Bind(&OnDone, result)); |
68 return; | 68 return; |
69 } | 69 } |
70 switch (result) { | 70 switch (result) { |
71 case HostStarter::START_COMPLETE: | 71 case HostStarter::START_COMPLETE: |
72 g_started = true; | 72 g_started = true; |
73 break; | 73 break; |
74 case HostStarter::NETWORK_ERROR: | 74 case HostStarter::NETWORK_ERROR: |
75 fprintf(stderr, "Couldn't start host: network error.\n"); | 75 fprintf(stderr, "Couldn't start host: network error.\n"); |
76 break; | 76 break; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 fprintf(stdout, "Enter an authorization code: "); | 136 fprintf(stdout, "Enter an authorization code: "); |
137 fflush(stdout); | 137 fflush(stdout); |
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 MessageLoop message_loop; | 146 base::MessageLoop message_loop; |
147 g_message_loop = &message_loop; | 147 g_message_loop = &message_loop; |
148 base::Thread io_thread("IO thread"); | 148 base::Thread io_thread("IO thread"); |
149 base::Thread::Options io_thread_options(MessageLoop::TYPE_IO, 0); | 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 | 151 |
152 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter( | 152 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter( |
153 new remoting::URLRequestContextGetter( | 153 new remoting::URLRequestContextGetter( |
154 g_message_loop->message_loop_proxy(), | 154 g_message_loop->message_loop_proxy(), |
155 io_thread.message_loop_proxy())); | 155 io_thread.message_loop_proxy())); |
156 | 156 |
157 if (remoting::ServiceUrls::GetInstance()->ignore_urlfetcher_cert_requests()) { | 157 if (remoting::ServiceUrls::GetInstance()->ignore_urlfetcher_cert_requests()) { |
158 net::URLFetcher::SetIgnoreCertificateRequests(true); | 158 net::URLFetcher::SetIgnoreCertificateRequests(true); |
159 } | 159 } |
(...skipping 18 matching lines...) Expand all Loading... |
178 | 178 |
179 // Destroy the HostStarter and URLRequestContextGetter before stopping the | 179 // Destroy the HostStarter and URLRequestContextGetter before stopping the |
180 // IO thread. | 180 // IO thread. |
181 host_starter.reset(); | 181 host_starter.reset(); |
182 url_request_context_getter = NULL; | 182 url_request_context_getter = NULL; |
183 | 183 |
184 io_thread.Stop(); | 184 io_thread.Stop(); |
185 | 185 |
186 return g_started ? 0 : 1; | 186 return g_started ? 0 : 1; |
187 } | 187 } |
OLD | NEW |