| 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" |
| 11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "net/url_request/url_request_context_getter.h" | 13 #include "net/url_request/url_request_context_getter.h" |
| 14 #include "remoting/host/setup/host_starter.h" | 14 #include "remoting/host/setup/host_starter.h" |
| 15 #include "remoting/host/setup/oauth_helper.h" |
| 15 #include "remoting/host/setup/pin_validator.h" | 16 #include "remoting/host/setup/pin_validator.h" |
| 16 #include "remoting/host/url_request_context.h" | 17 #include "remoting/host/url_request_context.h" |
| 17 | 18 |
| 18 // A simple command-line app that registers and starts a host. | 19 // A simple command-line app that registers and starts a host. |
| 19 | 20 |
| 20 using remoting::HostStarter; | 21 using remoting::HostStarter; |
| 21 | 22 |
| 22 // True if the host was started successfully. | 23 // True if the host was started successfully. |
| 23 bool g_started = false; | 24 bool g_started = false; |
| 24 | 25 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 86 } |
| 86 | 87 |
| 87 int main(int argc, char** argv) { | 88 int main(int argc, char** argv) { |
| 88 // google_apis::GetOAuth2ClientID/Secret need a static CommandLine. | 89 // google_apis::GetOAuth2ClientID/Secret need a static CommandLine. |
| 89 CommandLine::Init(argc, argv); | 90 CommandLine::Init(argc, argv); |
| 90 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 91 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 91 | 92 |
| 92 std::string host_name = command_line->GetSwitchValueASCII("name"); | 93 std::string host_name = command_line->GetSwitchValueASCII("name"); |
| 93 std::string host_pin = command_line->GetSwitchValueASCII("pin"); | 94 std::string host_pin = command_line->GetSwitchValueASCII("pin"); |
| 94 std::string auth_code = command_line->GetSwitchValueASCII("code"); | 95 std::string auth_code = command_line->GetSwitchValueASCII("code"); |
| 96 std::string redirect_url = command_line->GetSwitchValueASCII("redirect-url"); |
| 95 | 97 |
| 96 if (host_name.empty()) { | 98 if (host_name.empty()) { |
| 97 fprintf(stderr, | 99 fprintf(stderr, |
| 98 "Usage: %s --name=<hostname> [--code=<auth-code>] [--pin=<PIN>]\n", | 100 "Usage: %s --name=<hostname> [--code=<auth-code>] [--pin=<PIN>] " |
| 101 "[--redirect-url=<redirectURL>]\n", |
| 99 argv[0]); | 102 argv[0]); |
| 100 return 1; | 103 return 1; |
| 101 } | 104 } |
| 102 | 105 |
| 103 if (host_pin.empty()) { | 106 if (host_pin.empty()) { |
| 104 while (true) { | 107 while (true) { |
| 105 fprintf(stdout, "Enter a six-digit PIN: "); | 108 fprintf(stdout, "Enter a six-digit PIN: "); |
| 106 fflush(stdout); | 109 fflush(stdout); |
| 107 host_pin = ReadString(true); | 110 host_pin = ReadString(true); |
| 108 if (!remoting::IsPinValid(host_pin)) { | 111 if (!remoting::IsPinValid(host_pin)) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 io_thread.StartWithOptions(io_thread_options); | 150 io_thread.StartWithOptions(io_thread_options); |
| 148 | 151 |
| 149 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter( | 152 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter( |
| 150 new remoting::URLRequestContextGetter( | 153 new remoting::URLRequestContextGetter( |
| 151 g_message_loop->message_loop_proxy(), | 154 g_message_loop->message_loop_proxy(), |
| 152 io_thread.message_loop_proxy())); | 155 io_thread.message_loop_proxy())); |
| 153 | 156 |
| 154 // Start the host. | 157 // Start the host. |
| 155 scoped_ptr<HostStarter> host_starter( | 158 scoped_ptr<HostStarter> host_starter( |
| 156 HostStarter::Create(url_request_context_getter)); | 159 HostStarter::Create(url_request_context_getter)); |
| 157 host_starter->StartHost(host_name, host_pin, true, auth_code, | 160 if (redirect_url.empty()) { |
| 161 redirect_url = remoting::GetDefaultOauthRedirectUrl(); |
| 162 } |
| 163 host_starter->StartHost(host_name, host_pin, true, auth_code, redirect_url, |
| 158 base::Bind(&OnDone)); | 164 base::Bind(&OnDone)); |
| 159 | 165 |
| 160 // Run the message loop until the StartHost completion callback. | 166 // Run the message loop until the StartHost completion callback. |
| 161 base::RunLoop run_loop; | 167 base::RunLoop run_loop; |
| 162 run_loop.Run(); | 168 run_loop.Run(); |
| 163 | 169 |
| 164 g_message_loop = NULL; | 170 g_message_loop = NULL; |
| 165 | 171 |
| 166 // Destroy the HostStarter and URLRequestContextGetter before stopping the | 172 // Destroy the HostStarter and URLRequestContextGetter before stopping the |
| 167 // IO thread. | 173 // IO thread. |
| 168 host_starter.reset(); | 174 host_starter.reset(); |
| 169 url_request_context_getter = NULL; | 175 url_request_context_getter = NULL; |
| 170 | 176 |
| 171 io_thread.Stop(); | 177 io_thread.Stop(); |
| 172 | 178 |
| 173 return g_started ? 0 : 1; | 179 return g_started ? 0 : 1; |
| 174 } | 180 } |
| OLD | NEW |