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

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 feeback. Rebased. 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
« no previous file with comments | « remoting/host/heartbeat_sender_unittest.cc ('k') | remoting/host/simple_host_process.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/files/file_path_watcher.h" 19 #include "base/files/file_path_watcher.h"
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/memory/scoped_ptr.h" 21 #include "base/memory/scoped_ptr.h"
22 #include "base/message_loop.h" 22 #include "base/message_loop.h"
23 #include "base/threading/thread.h" 23 #include "base/threading/thread.h"
24 #include "build/build_config.h" 24 #include "build/build_config.h"
25 #include "crypto/nss_util.h" 25 #include "crypto/nss_util.h"
26 #include "net/base/network_change_notifier.h" 26 #include "net/base/network_change_notifier.h"
27 #include "remoting/base/constants.h" 27 #include "remoting/base/constants.h"
28 #include "remoting/host/branding.h" 28 #include "remoting/host/branding.h"
29 #include "remoting/host/constants.h"
29 #include "remoting/host/capturer.h" 30 #include "remoting/host/capturer.h"
30 #include "remoting/host/chromoting_host.h" 31 #include "remoting/host/chromoting_host.h"
31 #include "remoting/host/chromoting_host_context.h" 32 #include "remoting/host/chromoting_host_context.h"
32 #include "remoting/host/desktop_environment.h" 33 #include "remoting/host/desktop_environment.h"
33 #include "remoting/host/event_executor.h" 34 #include "remoting/host/event_executor.h"
34 #include "remoting/host/heartbeat_sender.h" 35 #include "remoting/host/heartbeat_sender.h"
35 #include "remoting/host/host_config.h" 36 #include "remoting/host/host_config.h"
36 #include "remoting/host/host_event_logger.h" 37 #include "remoting/host/host_event_logger.h"
37 #include "remoting/host/json_host_config.h" 38 #include "remoting/host/json_host_config.h"
38 #include "remoting/host/log_to_server.h" 39 #include "remoting/host/log_to_server.h"
39 #include "remoting/host/oauth_client.h" 40 #include "remoting/host/oauth_client.h"
40 #include "remoting/host/policy_hack/nat_policy.h" 41 #include "remoting/host/policy_hack/nat_policy.h"
41 #include "remoting/host/signaling_connector.h" 42 #include "remoting/host/signaling_connector.h"
42 #include "remoting/jingle_glue/xmpp_signal_strategy.h" 43 #include "remoting/jingle_glue/xmpp_signal_strategy.h"
43 #include "remoting/protocol/me2me_host_authenticator_factory.h" 44 #include "remoting/protocol/me2me_host_authenticator_factory.h"
44 45
45 #if defined(OS_MACOSX) 46 #if defined(OS_MACOSX)
46 #include "remoting/host/sighup_listener_mac.h" 47 #include "remoting/host/sighup_listener_mac.h"
47 #endif 48 #endif
48 #if defined(TOOLKIT_GTK) 49 #if defined(TOOLKIT_GTK)
49 #include "ui/gfx/gtk_util.h" 50 #include "ui/gfx/gtk_util.h"
50 #endif 51 #endif
51 52
52 namespace { 53 namespace {
53 54
54 const int kSuccessExitCode = 0;
55 const int kInvalidHostConfigurationExitCode = 1;
56
57 // This is used for tagging system event logs. 55 // This is used for tagging system event logs.
58 const char kApplicationName[] = "chromoting"; 56 const char kApplicationName[] = "chromoting";
59 57
60 // These are used for parsing the config-file locations from the command line, 58 // These are used for parsing the config-file locations from the command line,
61 // and for defining the default locations if the switches are not present. 59 // and for defining the default locations if the switches are not present.
62 const char kAuthConfigSwitchName[] = "auth-config"; 60 const char kAuthConfigSwitchName[] = "auth-config";
63 const char kHostConfigSwitchName[] = "host-config"; 61 const char kHostConfigSwitchName[] = "host-config";
64 62
65 const FilePath::CharType kDefaultAuthConfigFile[] = 63 const FilePath::CharType kDefaultAuthConfigFile[] =
66 FILE_PATH_LITERAL("auth.json"); 64 FILE_PATH_LITERAL("auth.json");
67 const FilePath::CharType kDefaultHostConfigFile[] = 65 const FilePath::CharType kDefaultHostConfigFile[] =
68 FILE_PATH_LITERAL("host.json"); 66 FILE_PATH_LITERAL("host.json");
69 67
70 const int kMinPortNumber = 12400; 68 const int kMinPortNumber = 12400;
71 const int kMaxPortNumber = 12409; 69 const int kMaxPortNumber = 12409;
72 70
73 } // namespace 71 } // namespace
74 72
75 namespace remoting { 73 namespace remoting {
76 74
77 class HostProcess : public OAuthClient::Delegate { 75 class HostProcess
76 : public OAuthClient::Delegate,
77 public HeartbeatSender::Listener {
78 public: 78 public:
79 HostProcess() 79 HostProcess()
80 : message_loop_(MessageLoop::TYPE_UI), 80 : message_loop_(MessageLoop::TYPE_UI),
81 allow_nat_traversal_(true), 81 allow_nat_traversal_(true),
82 restarting_(false) { 82 restarting_(false),
83 exit_code_(kSuccessExitCode) {
83 context_.reset( 84 context_.reset(
84 new ChromotingHostContext(message_loop_.message_loop_proxy())); 85 new ChromotingHostContext(message_loop_.message_loop_proxy()));
85 context_->Start(); 86 context_->Start();
86 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); 87 network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
87 config_updated_timer_.reset(new base::DelayTimer<HostProcess>( 88 config_updated_timer_.reset(new base::DelayTimer<HostProcess>(
88 FROM_HERE, base::TimeDelta::FromSeconds(2), this, 89 FROM_HERE, base::TimeDelta::FromSeconds(2), this,
89 &HostProcess::ConfigUpdated)); 90 &HostProcess::ConfigUpdated));
90 } 91 }
91 92
92 void InitWithCommandLine(const CommandLine* cmd_line) { 93 void InitWithCommandLine(const CommandLine* cmd_line) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 188 }
188 189
189 #if defined(OS_MACOSX) || defined(OS_WIN) 190 #if defined(OS_MACOSX) || defined(OS_WIN)
190 context_->file_message_loop()->PostTask( 191 context_->file_message_loop()->PostTask(
191 FROM_HERE, 192 FROM_HERE,
192 base::Bind(&HostProcess::ListenForConfigChanges, 193 base::Bind(&HostProcess::ListenForConfigChanges,
193 base::Unretained(this))); 194 base::Unretained(this)));
194 #endif 195 #endif
195 message_loop_.Run(); 196 message_loop_.Run();
196 197
197 return kSuccessExitCode; 198 return exit_code_;
198 } 199 }
199 200
200 // Overridden from OAuthClient::Delegate 201 // Overridden from OAuthClient::Delegate
201 virtual void OnRefreshTokenResponse(const std::string& access_token, 202 virtual void OnRefreshTokenResponse(const std::string& access_token,
202 int expires) OVERRIDE { 203 int expires) OVERRIDE {
203 xmpp_auth_token_ = access_token; 204 xmpp_auth_token_ = access_token;
204 // If there's already a signal strategy object, update it ready for the 205 // If there's already a signal strategy object, update it ready for the
205 // next time it calls Connect. If not, then this is the initial token 206 // next time it calls Connect. If not, then this is the initial token
206 // exchange, so proceed to the next stage of connection. 207 // exchange, so proceed to the next stage of connection.
207 if (signal_strategy_.get()) { 208 if (signal_strategy_.get()) {
208 context_->network_message_loop()->PostTask( 209 context_->network_message_loop()->PostTask(
209 FROM_HERE, base::Bind( 210 FROM_HERE, base::Bind(
210 &XmppSignalStrategy::SetAuthInfo, 211 &XmppSignalStrategy::SetAuthInfo,
211 base::Unretained(signal_strategy_.get()), 212 base::Unretained(signal_strategy_.get()),
212 xmpp_login_, xmpp_auth_token_, xmpp_auth_service_)); 213 xmpp_login_, xmpp_auth_token_, xmpp_auth_service_));
213 } else { 214 } else {
214 StartWatchingNatPolicy(); 215 StartWatchingNatPolicy();
215 } 216 }
216 } 217 }
217 218
218 virtual void OnOAuthError() OVERRIDE { 219 virtual void OnOAuthError() OVERRIDE {
219 LOG(ERROR) << "OAuth: invalid credentials."; 220 LOG(ERROR) << "OAuth: invalid credentials.";
221 Shutdown(kInvalidOauthCredentialsExitCode);
222 }
223
224 // Overridden from HeartbeatSender::Listener
225 virtual void OnUnknownHostIdError() OVERRIDE {
226 LOG(ERROR) << "Host ID not found.";
227 Shutdown(kInvalidHostIdExitCode);
220 } 228 }
221 229
222 private: 230 private:
223 void StartWatchingNatPolicy() { 231 void StartWatchingNatPolicy() {
224 nat_policy_.reset( 232 nat_policy_.reset(
225 policy_hack::NatPolicy::Create(context_->file_message_loop())); 233 policy_hack::NatPolicy::Create(context_->file_message_loop()));
226 nat_policy_->StartWatching( 234 nat_policy_->StartWatching(
227 base::Bind(&HostProcess::OnNatPolicyUpdate, base::Unretained(this))); 235 base::Bind(&HostProcess::OnNatPolicyUpdate, base::Unretained(this)));
228 } 236 }
229 237
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 protocol::NetworkSettings network_settings(allow_nat_traversal_); 336 protocol::NetworkSettings network_settings(allow_nat_traversal_);
329 if (!allow_nat_traversal_) { 337 if (!allow_nat_traversal_) {
330 network_settings.min_port = kMinPortNumber; 338 network_settings.min_port = kMinPortNumber;
331 network_settings.max_port = kMaxPortNumber; 339 network_settings.max_port = kMaxPortNumber;
332 } 340 }
333 341
334 host_ = new ChromotingHost( 342 host_ = new ChromotingHost(
335 context_.get(), signal_strategy_.get(), desktop_environment_.get(), 343 context_.get(), signal_strategy_.get(), desktop_environment_.get(),
336 network_settings); 344 network_settings);
337 345
338 heartbeat_sender_.reset( 346 heartbeat_sender_.reset(new HeartbeatSender(
339 new HeartbeatSender(host_id_, signal_strategy_.get(), &key_pair_)); 347 this, host_id_, signal_strategy_.get(), &key_pair_));
340 348
341 log_to_server_.reset( 349 log_to_server_.reset(
342 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); 350 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get()));
343 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); 351 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName);
344 352
345 host_->Start(); 353 host_->Start();
346 354
347 CreateAuthenticatorFactory(); 355 CreateAuthenticatorFactory();
348 } 356 }
349 357
(...skipping 14 matching lines...) Expand all
364 restarting_ = false; 372 restarting_ = false;
365 373
366 host_ = NULL; 374 host_ = NULL;
367 log_to_server_.reset(); 375 log_to_server_.reset();
368 host_event_logger_.reset(); 376 host_event_logger_.reset();
369 heartbeat_sender_.reset(); 377 heartbeat_sender_.reset();
370 378
371 StartHost(); 379 StartHost();
372 } 380 }
373 381
382 void Shutdown(int exit_code) {
383 exit_code_ = exit_code;
384 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure());
385 }
386
374 MessageLoop message_loop_; 387 MessageLoop message_loop_;
375 scoped_ptr<ChromotingHostContext> context_; 388 scoped_ptr<ChromotingHostContext> context_;
376 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; 389 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
377 390
378 FilePath auth_config_path_; 391 FilePath auth_config_path_;
379 FilePath host_config_path_; 392 FilePath host_config_path_;
380 393
381 std::string host_id_; 394 std::string host_id_;
382 HostKeyPair key_pair_; 395 HostKeyPair key_pair_;
383 protocol::SharedSecretHash host_secret_hash_; 396 protocol::SharedSecretHash host_secret_hash_;
(...skipping 11 matching lines...) Expand all
395 408
396 bool restarting_; 409 bool restarting_;
397 410
398 scoped_ptr<XmppSignalStrategy> signal_strategy_; 411 scoped_ptr<XmppSignalStrategy> signal_strategy_;
399 scoped_ptr<SignalingConnector> signaling_connector_; 412 scoped_ptr<SignalingConnector> signaling_connector_;
400 scoped_ptr<DesktopEnvironment> desktop_environment_; 413 scoped_ptr<DesktopEnvironment> desktop_environment_;
401 scoped_ptr<HeartbeatSender> heartbeat_sender_; 414 scoped_ptr<HeartbeatSender> heartbeat_sender_;
402 scoped_ptr<LogToServer> log_to_server_; 415 scoped_ptr<LogToServer> log_to_server_;
403 scoped_ptr<HostEventLogger> host_event_logger_; 416 scoped_ptr<HostEventLogger> host_event_logger_;
404 scoped_refptr<ChromotingHost> host_; 417 scoped_refptr<ChromotingHost> host_;
418
419 int exit_code_;
405 }; 420 };
406 421
407 } // namespace remoting 422 } // namespace remoting
408 423
409 int main(int argc, char** argv) { 424 int main(int argc, char** argv) {
410 CommandLine::Init(argc, argv); 425 CommandLine::Init(argc, argv);
411 426
412 // This object instance is required by Chrome code (for example, 427 // This object instance is required by Chrome code (for example,
413 // LazyInstance, MessageLoop). 428 // LazyInstance, MessageLoop).
414 base::AtExitManager exit_manager; 429 base::AtExitManager exit_manager;
(...skipping 29 matching lines...) Expand all
444 int CALLBACK WinMain(HINSTANCE instance, 459 int CALLBACK WinMain(HINSTANCE instance,
445 HINSTANCE previous_instance, 460 HINSTANCE previous_instance,
446 LPSTR command_line, 461 LPSTR command_line,
447 int show_command) { 462 int show_command) {
448 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting 463 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting
449 // the command line from GetCommandLineW(), so we can safely pass NULL here. 464 // the command line from GetCommandLineW(), so we can safely pass NULL here.
450 return main(0, NULL); 465 return main(0, NULL);
451 } 466 }
452 467
453 #endif 468 #endif
OLDNEW
« no previous file with comments | « remoting/host/heartbeat_sender_unittest.cc ('k') | remoting/host/simple_host_process.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698