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

Side by Side Diff: remoting/host/remoting_me2me_host.cc

Issue 10106013: Chromoting: stopping the service if the host ID is permanently not recognized by the could. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cr feedback. Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
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 // This file implements a standalone host process for Me2Me. 5 // This file implements a standalone host process for Me2Me.
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #endif 9 #endif
10 10
11 #include <string> 11 #include <string>
12 12
13 #include "base/at_exit.h" 13 #include "base/at_exit.h"
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/file_path.h" 17 #include "base/file_path.h"
18 #include "base/file_util.h" 18 #include "base/file_util.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/memory/scoped_ptr.h" 20 #include "base/memory/scoped_ptr.h"
21 #include "base/message_loop.h" 21 #include "base/message_loop.h"
22 #include "base/threading/thread.h" 22 #include "base/threading/thread.h"
23 #include "build/build_config.h" 23 #include "build/build_config.h"
24 #include "crypto/nss_util.h" 24 #include "crypto/nss_util.h"
25 #include "net/base/network_change_notifier.h" 25 #include "net/base/network_change_notifier.h"
26 #include "remoting/base/constants.h" 26 #include "remoting/base/constants.h"
27 #include "remoting/host/branding.h" 27 #include "remoting/host/branding.h"
28 #include "remoting/host/constants.h"
28 #include "remoting/host/capturer.h" 29 #include "remoting/host/capturer.h"
29 #include "remoting/host/chromoting_host.h" 30 #include "remoting/host/chromoting_host.h"
30 #include "remoting/host/chromoting_host_context.h" 31 #include "remoting/host/chromoting_host_context.h"
31 #include "remoting/host/desktop_environment.h" 32 #include "remoting/host/desktop_environment.h"
32 #include "remoting/host/event_executor.h" 33 #include "remoting/host/event_executor.h"
33 #include "remoting/host/heartbeat_sender.h" 34 #include "remoting/host/heartbeat_sender.h"
34 #include "remoting/host/host_config.h" 35 #include "remoting/host/host_config.h"
35 #include "remoting/host/host_event_logger.h" 36 #include "remoting/host/host_event_logger.h"
36 #include "remoting/host/json_host_config.h" 37 #include "remoting/host/json_host_config.h"
37 #include "remoting/host/log_to_server.h" 38 #include "remoting/host/log_to_server.h"
38 #include "remoting/host/oauth_client.h" 39 #include "remoting/host/oauth_client.h"
39 #include "remoting/host/policy_hack/nat_policy.h" 40 #include "remoting/host/policy_hack/nat_policy.h"
40 #include "remoting/host/signaling_connector.h" 41 #include "remoting/host/signaling_connector.h"
41 #include "remoting/jingle_glue/xmpp_signal_strategy.h" 42 #include "remoting/jingle_glue/xmpp_signal_strategy.h"
42 #include "remoting/protocol/me2me_host_authenticator_factory.h" 43 #include "remoting/protocol/me2me_host_authenticator_factory.h"
43 44
44 #if defined(OS_MACOSX) 45 #if defined(OS_MACOSX)
45 #include "remoting/host/sighup_listener_mac.h" 46 #include "remoting/host/sighup_listener_mac.h"
46 #endif 47 #endif
47 #if defined(TOOLKIT_GTK) 48 #if defined(TOOLKIT_GTK)
48 #include "ui/gfx/gtk_util.h" 49 #include "ui/gfx/gtk_util.h"
49 #endif 50 #endif
50 51
51 namespace { 52 namespace {
52 53
53 const int kSuccessExitCode = 0;
54 const int kInvalidHostConfigurationExitCode = 1;
55
56 // This is used for tagging system event logs. 54 // This is used for tagging system event logs.
57 const char kApplicationName[] = "chromoting"; 55 const char kApplicationName[] = "chromoting";
58 56
59 // These are used for parsing the config-file locations from the command line, 57 // These are used for parsing the config-file locations from the command line,
60 // and for defining the default locations if the switches are not present. 58 // and for defining the default locations if the switches are not present.
61 const char kAuthConfigSwitchName[] = "auth-config"; 59 const char kAuthConfigSwitchName[] = "auth-config";
62 const char kHostConfigSwitchName[] = "host-config"; 60 const char kHostConfigSwitchName[] = "host-config";
63 61
64 const FilePath::CharType kDefaultAuthConfigFile[] = 62 const FilePath::CharType kDefaultAuthConfigFile[] =
65 FILE_PATH_LITERAL("auth.json"); 63 FILE_PATH_LITERAL("auth.json");
66 const FilePath::CharType kDefaultHostConfigFile[] = 64 const FilePath::CharType kDefaultHostConfigFile[] =
67 FILE_PATH_LITERAL("host.json"); 65 FILE_PATH_LITERAL("host.json");
68 66
69 const int kMinPortNumber = 12400; 67 const int kMinPortNumber = 12400;
70 const int kMaxPortNumber = 12409; 68 const int kMaxPortNumber = 12409;
71 69
72 } // namespace 70 } // namespace
73 71
74 namespace remoting { 72 namespace remoting {
75 73
76 class HostProcess : public OAuthClient::Delegate { 74 class HostProcess
75 : public OAuthClient::Delegate,
76 public HeartbeatSender::Delegate {
77 public: 77 public:
78 HostProcess() 78 HostProcess()
79 : message_loop_(MessageLoop::TYPE_UI), 79 : message_loop_(MessageLoop::TYPE_UI),
80 file_io_thread_("FileIO"), 80 file_io_thread_("FileIO"),
81 allow_nat_traversal_(true), 81 allow_nat_traversal_(true),
82 restarting_(false) { 82 restarting_(false),
83 exit_code_(kSuccessExitCode) {
83 file_io_thread_.StartWithOptions( 84 file_io_thread_.StartWithOptions(
84 base::Thread::Options(MessageLoop::TYPE_IO, 0)); 85 base::Thread::Options(MessageLoop::TYPE_IO, 0));
85 86
86 context_.reset(new ChromotingHostContext( 87 context_.reset(new ChromotingHostContext(
87 file_io_thread_.message_loop_proxy(), 88 file_io_thread_.message_loop_proxy(),
88 message_loop_.message_loop_proxy())); 89 message_loop_.message_loop_proxy()));
89 context_->Start(); 90 context_->Start();
90 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); 91 network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
91 } 92 }
92 93
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 158 }
158 159
159 #if defined(OS_MACOSX) 160 #if defined(OS_MACOSX)
160 file_io_thread_.message_loop_proxy()->PostTask( 161 file_io_thread_.message_loop_proxy()->PostTask(
161 FROM_HERE, 162 FROM_HERE,
162 base::Bind(&HostProcess::ListenForConfigChanges, 163 base::Bind(&HostProcess::ListenForConfigChanges,
163 base::Unretained(this))); 164 base::Unretained(this)));
164 #endif 165 #endif
165 message_loop_.Run(); 166 message_loop_.Run();
166 167
167 return kSuccessExitCode; 168 return exit_code_;
168 } 169 }
169 170
170 // Overridden from OAuthClient::Delegate 171 // Overridden from OAuthClient::Delegate
171 virtual void OnRefreshTokenResponse(const std::string& access_token, 172 virtual void OnRefreshTokenResponse(const std::string& access_token,
172 int expires) OVERRIDE { 173 int expires) OVERRIDE {
173 xmpp_auth_token_ = access_token; 174 xmpp_auth_token_ = access_token;
174 // If there's already a signal strategy object, update it ready for the 175 // If there's already a signal strategy object, update it ready for the
175 // next time it calls Connect. If not, then this is the initial token 176 // next time it calls Connect. If not, then this is the initial token
176 // exchange, so proceed to the next stage of connection. 177 // exchange, so proceed to the next stage of connection.
177 if (signal_strategy_.get()) { 178 if (signal_strategy_.get()) {
178 context_->network_message_loop()->PostTask( 179 context_->network_message_loop()->PostTask(
179 FROM_HERE, base::Bind( 180 FROM_HERE, base::Bind(
180 &XmppSignalStrategy::SetAuthInfo, 181 &XmppSignalStrategy::SetAuthInfo,
181 base::Unretained(signal_strategy_.get()), 182 base::Unretained(signal_strategy_.get()),
182 xmpp_login_, xmpp_auth_token_, xmpp_auth_service_)); 183 xmpp_login_, xmpp_auth_token_, xmpp_auth_service_));
183 } else { 184 } else {
184 StartWatchingNatPolicy(); 185 StartWatchingNatPolicy();
185 } 186 }
186 } 187 }
187 188
188 virtual void OnOAuthError() OVERRIDE { 189 virtual void OnOAuthError() OVERRIDE {
189 LOG(ERROR) << "OAuth: invalid credentials."; 190 LOG(ERROR) << "OAuth: invalid credentials.";
191 Shutdown(kInvalidOauthCredentialsExitCode);
192 }
193
194 // Overridden from HeartbeatSender::Delegate
195 virtual void OnUnknownHostIdError() OVERRIDE {
196 LOG(ERROR) << "Host ID not found.";
197 Shutdown(kInvalidHostIdExitCode);
190 } 198 }
191 199
192 private: 200 private:
193 void StartWatchingNatPolicy() { 201 void StartWatchingNatPolicy() {
194 nat_policy_.reset( 202 nat_policy_.reset(
195 policy_hack::NatPolicy::Create(file_io_thread_.message_loop_proxy())); 203 policy_hack::NatPolicy::Create(file_io_thread_.message_loop_proxy()));
196 nat_policy_->StartWatching( 204 nat_policy_->StartWatching(
197 base::Bind(&HostProcess::OnNatPolicyUpdate, base::Unretained(this))); 205 base::Bind(&HostProcess::OnNatPolicyUpdate, base::Unretained(this)));
198 } 206 }
199 207
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 protocol::NetworkSettings network_settings(allow_nat_traversal_); 307 protocol::NetworkSettings network_settings(allow_nat_traversal_);
300 if (!allow_nat_traversal_) { 308 if (!allow_nat_traversal_) {
301 network_settings.min_port = kMinPortNumber; 309 network_settings.min_port = kMinPortNumber;
302 network_settings.max_port = kMaxPortNumber; 310 network_settings.max_port = kMaxPortNumber;
303 } 311 }
304 312
305 host_ = new ChromotingHost( 313 host_ = new ChromotingHost(
306 context_.get(), signal_strategy_.get(), desktop_environment_.get(), 314 context_.get(), signal_strategy_.get(), desktop_environment_.get(),
307 network_settings); 315 network_settings);
308 316
309 heartbeat_sender_.reset( 317 heartbeat_sender_.reset(new HeartbeatSender(
310 new HeartbeatSender(host_id_, signal_strategy_.get(), &key_pair_)); 318 this, host_id_, signal_strategy_.get(), &key_pair_));
311 319
312 log_to_server_.reset( 320 log_to_server_.reset(
313 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); 321 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get()));
314 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); 322 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName);
315 323
316 host_->Start(); 324 host_->Start();
317 325
318 CreateAuthenticatorFactory(); 326 CreateAuthenticatorFactory();
319 } 327 }
320 328
(...skipping 14 matching lines...) Expand all
335 restarting_ = false; 343 restarting_ = false;
336 344
337 host_ = NULL; 345 host_ = NULL;
338 log_to_server_.reset(); 346 log_to_server_.reset();
339 host_event_logger_.reset(); 347 host_event_logger_.reset();
340 heartbeat_sender_.reset(); 348 heartbeat_sender_.reset();
341 349
342 StartHost(); 350 StartHost();
343 } 351 }
344 352
353 void Shutdown(int exit_code) {
354 exit_code_ = exit_code;
355 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure());
356 }
357
345 MessageLoop message_loop_; 358 MessageLoop message_loop_;
346 base::Thread file_io_thread_; 359 base::Thread file_io_thread_;
347 scoped_ptr<ChromotingHostContext> context_; 360 scoped_ptr<ChromotingHostContext> context_;
348 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; 361 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
349 362
350 FilePath auth_config_path_; 363 FilePath auth_config_path_;
351 FilePath host_config_path_; 364 FilePath host_config_path_;
352 365
353 std::string host_id_; 366 std::string host_id_;
354 HostKeyPair key_pair_; 367 HostKeyPair key_pair_;
(...skipping 10 matching lines...) Expand all
365 378
366 bool restarting_; 379 bool restarting_;
367 380
368 scoped_ptr<XmppSignalStrategy> signal_strategy_; 381 scoped_ptr<XmppSignalStrategy> signal_strategy_;
369 scoped_ptr<SignalingConnector> signaling_connector_; 382 scoped_ptr<SignalingConnector> signaling_connector_;
370 scoped_ptr<DesktopEnvironment> desktop_environment_; 383 scoped_ptr<DesktopEnvironment> desktop_environment_;
371 scoped_ptr<HeartbeatSender> heartbeat_sender_; 384 scoped_ptr<HeartbeatSender> heartbeat_sender_;
372 scoped_ptr<LogToServer> log_to_server_; 385 scoped_ptr<LogToServer> log_to_server_;
373 scoped_ptr<HostEventLogger> host_event_logger_; 386 scoped_ptr<HostEventLogger> host_event_logger_;
374 scoped_refptr<ChromotingHost> host_; 387 scoped_refptr<ChromotingHost> host_;
388
389 int exit_code_;
375 }; 390 };
376 391
377 } // namespace remoting 392 } // namespace remoting
378 393
379 int main(int argc, char** argv) { 394 int main(int argc, char** argv) {
380 CommandLine::Init(argc, argv); 395 CommandLine::Init(argc, argv);
381 396
382 // This object instance is required by Chrome code (for example, 397 // This object instance is required by Chrome code (for example,
383 // LazyInstance, MessageLoop). 398 // LazyInstance, MessageLoop).
384 base::AtExitManager exit_manager; 399 base::AtExitManager exit_manager;
(...skipping 29 matching lines...) Expand all
414 int CALLBACK WinMain(HINSTANCE instance, 429 int CALLBACK WinMain(HINSTANCE instance,
415 HINSTANCE previous_instance, 430 HINSTANCE previous_instance,
416 LPSTR command_line, 431 LPSTR command_line,
417 int show_command) { 432 int show_command) {
418 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting 433 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting
419 // the command line from GetCommandLineW(), so we can safely pass NULL here. 434 // the command line from GetCommandLineW(), so we can safely pass NULL here.
420 return main(0, NULL); 435 return main(0, NULL);
421 } 436 }
422 437
423 #endif 438 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698