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 // This file implements a standalone host process for Me2Me. | 5 // This file implements a standalone host process for Me2Me. |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
22 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
23 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.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 "net/socket/ssl_server_socket.h" | 27 #include "net/socket/ssl_server_socket.h" |
28 #include "remoting/base/breakpad.h" | 28 #include "remoting/base/breakpad.h" |
29 #include "remoting/base/constants.h" | 29 #include "remoting/base/constants.h" |
30 #include "remoting/host/branding.h" | 30 #include "remoting/host/branding.h" |
31 #include "remoting/host/constants.h" | |
32 #include "remoting/host/video_frame_capturer.h" | |
33 #include "remoting/host/chromoting_host.h" | 31 #include "remoting/host/chromoting_host.h" |
34 #include "remoting/host/chromoting_host_context.h" | 32 #include "remoting/host/chromoting_host_context.h" |
33 #include "remoting/host/composite_host_config.h" | |
34 #include "remoting/host/constants.h" | |
35 #include "remoting/host/desktop_environment.h" | 35 #include "remoting/host/desktop_environment.h" |
36 #include "remoting/host/event_executor.h" | 36 #include "remoting/host/event_executor.h" |
37 #include "remoting/host/heartbeat_sender.h" | 37 #include "remoting/host/heartbeat_sender.h" |
38 #include "remoting/host/host_config.h" | 38 #include "remoting/host/host_config.h" |
39 #include "remoting/host/host_event_logger.h" | 39 #include "remoting/host/host_event_logger.h" |
40 #include "remoting/host/host_user_interface.h" | 40 #include "remoting/host/host_user_interface.h" |
41 #include "remoting/host/json_host_config.h" | |
42 #include "remoting/host/log_to_server.h" | 41 #include "remoting/host/log_to_server.h" |
43 #include "remoting/host/network_settings.h" | 42 #include "remoting/host/network_settings.h" |
44 #include "remoting/host/policy_hack/policy_watcher.h" | 43 #include "remoting/host/policy_hack/policy_watcher.h" |
45 #include "remoting/host/session_manager_factory.h" | 44 #include "remoting/host/session_manager_factory.h" |
46 #include "remoting/host/signaling_connector.h" | 45 #include "remoting/host/signaling_connector.h" |
47 #include "remoting/host/usage_stats_consent.h" | 46 #include "remoting/host/usage_stats_consent.h" |
47 #include "remoting/host/video_frame_capturer.h" | |
48 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 48 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
49 #include "remoting/protocol/me2me_host_authenticator_factory.h" | 49 #include "remoting/protocol/me2me_host_authenticator_factory.h" |
50 | 50 |
51 #if defined(OS_MACOSX) | 51 #if defined(OS_MACOSX) |
52 #include "base/mac/scoped_nsautorelease_pool.h" | 52 #include "base/mac/scoped_nsautorelease_pool.h" |
53 #include "remoting/host/sighup_listener_mac.h" | 53 #include "remoting/host/sighup_listener_mac.h" |
54 #endif | 54 #endif |
55 // N.B. OS_WIN is defined by including src/base headers. | 55 // N.B. OS_WIN is defined by including src/base headers. |
56 #if defined(OS_WIN) | 56 #if defined(OS_WIN) |
57 #include <commctrl.h> | 57 #include <commctrl.h> |
58 #endif | 58 #endif |
59 #if defined(TOOLKIT_GTK) | 59 #if defined(TOOLKIT_GTK) |
60 #include "ui/gfx/gtk_util.h" | 60 #include "ui/gfx/gtk_util.h" |
61 #endif | 61 #endif |
62 | 62 |
63 namespace { | 63 namespace { |
64 | 64 |
65 // This is used for tagging system event logs. | 65 // This is used for tagging system event logs. |
66 const char kApplicationName[] = "chromoting"; | 66 const char kApplicationName[] = "chromoting"; |
67 | 67 |
68 // These are used for parsing the config-file locations from the command line, | 68 // These are used for parsing the config-file locations from the command line, |
69 // and for defining the default locations if the switches are not present. | 69 // and for defining the default locations if the switches are not present. |
70 const char kAuthConfigSwitchName[] = "auth-config"; | 70 const char kAuthConfigSwitchName[] = "auth-config"; |
71 const char kHostConfigSwitchName[] = "host-config"; | 71 const char kHostConfigSwitchName[] = "host-config"; |
72 | 72 |
73 const FilePath::CharType kDefaultAuthConfigFile[] = | |
74 FILE_PATH_LITERAL("auth.json"); | |
75 const FilePath::CharType kDefaultHostConfigFile[] = | 73 const FilePath::CharType kDefaultHostConfigFile[] = |
76 FILE_PATH_LITERAL("host.json"); | 74 FILE_PATH_LITERAL("host.json"); |
77 | 75 |
78 const int kMinPortNumber = 12400; | 76 const int kMinPortNumber = 12400; |
79 const int kMaxPortNumber = 12409; | 77 const int kMaxPortNumber = 12409; |
80 | 78 |
81 const char kUnofficialOAuth2ClientId[] = | 79 const char kUnofficialOAuth2ClientId[] = |
82 "440925447803-2pi3v45bff6tp1rde2f7q6lgbor3o5uj.apps.googleusercontent.com"; | 80 "440925447803-2pi3v45bff6tp1rde2f7q6lgbor3o5uj.apps.googleusercontent.com"; |
83 const char kUnofficialOAuth2ClientSecret[] = "W2ieEsG-R1gIA4MMurGrgMc_"; | 81 const char kUnofficialOAuth2ClientSecret[] = "W2ieEsG-R1gIA4MMurGrgMc_"; |
84 | 82 |
(...skipping 21 matching lines...) Expand all Loading... | |
106 exit_code_(kSuccessExitCode) { | 104 exit_code_(kSuccessExitCode) { |
107 context_.reset( | 105 context_.reset( |
108 new ChromotingHostContext(message_loop_.message_loop_proxy())); | 106 new ChromotingHostContext(message_loop_.message_loop_proxy())); |
109 context_->Start(); | 107 context_->Start(); |
110 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 108 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
111 config_updated_timer_.reset(new base::DelayTimer<HostProcess>( | 109 config_updated_timer_.reset(new base::DelayTimer<HostProcess>( |
112 FROM_HERE, base::TimeDelta::FromSeconds(2), this, | 110 FROM_HERE, base::TimeDelta::FromSeconds(2), this, |
113 &HostProcess::ConfigUpdatedDelayed)); | 111 &HostProcess::ConfigUpdatedDelayed)); |
114 } | 112 } |
115 | 113 |
116 void InitWithCommandLine(const CommandLine* cmd_line) { | 114 bool InitWithCommandLine(const CommandLine* cmd_line) { |
117 FilePath default_config_dir = remoting::GetConfigDir(); | 115 FilePath default_config_dir = remoting::GetConfigDir(); |
118 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) { | 116 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) { |
119 auth_config_path_ = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName); | 117 FilePath path = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName); |
120 } else { | 118 if (!config_.AddConfigPath(path)) { |
121 auth_config_path_ = default_config_dir.Append(kDefaultAuthConfigFile); | 119 return false; |
120 } | |
122 } | 121 } |
123 | 122 |
123 FilePath config_path = default_config_dir.Append(kDefaultHostConfigFile); | |
124 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { | 124 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { |
125 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); | 125 config_path = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); |
126 } else { | 126 } |
127 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); | 127 if (!config_.AddConfigPath(config_path)) { |
128 return false; | |
128 } | 129 } |
129 | 130 |
130 #if defined(OS_LINUX) | 131 return true; |
131 VideoFrameCapturer::EnableXDamage(true); | |
132 #endif | |
133 } | 132 } |
134 | 133 |
135 void ConfigUpdated() { | 134 void ConfigUpdated() { |
136 // The timer should be set and cleaned up on the same thread. | 135 // The timer should be set and cleaned up on the same thread. |
137 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); | 136 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); |
138 | 137 |
139 // Call ConfigUpdatedDelayed after a short delay, so that this object won't | 138 // Call ConfigUpdatedDelayed after a short delay, so that this object won't |
140 // try to read the updated configuration file before it has been | 139 // try to read the updated configuration file before it has been |
141 // completely written. | 140 // completely written. |
142 // If the writer moves the new configuration file into place atomically, | 141 // If the writer moves the new configuration file into place atomically, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 } | 241 } |
243 | 242 |
244 private: | 243 private: |
245 void StartWatchingPolicy() { | 244 void StartWatchingPolicy() { |
246 policy_watcher_.reset( | 245 policy_watcher_.reset( |
247 policy_hack::PolicyWatcher::Create(context_->file_task_runner())); | 246 policy_hack::PolicyWatcher::Create(context_->file_task_runner())); |
248 policy_watcher_->StartWatching( | 247 policy_watcher_->StartWatching( |
249 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this))); | 248 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this))); |
250 } | 249 } |
251 | 250 |
252 // Read Host config from disk, returning true if successful. | 251 // Read Host config from disk, returning true if successful. |
Lambros
2012/08/01 01:12:48
Remove "from disk" from this comment? Looks like t
Sergey Ulanov
2012/08/01 01:19:11
Done.
| |
253 bool LoadConfig() { | 252 bool LoadConfig() { |
254 JsonHostConfig host_config(host_config_path_); | 253 if (!config_.GetString(kHostIdConfigPath, &host_id_)) { |
255 JsonHostConfig auth_config(auth_config_path_); | |
256 | |
257 FilePath failed_path; | |
258 if (!host_config.Read()) { | |
259 failed_path = host_config_path_; | |
260 } else if (!auth_config.Read()) { | |
261 failed_path = auth_config_path_; | |
262 } | |
263 if (!failed_path.empty()) { | |
264 LOG(ERROR) << "Failed to read configuration file " << failed_path.value(); | |
265 return false; | |
266 } | |
267 | |
268 if (!host_config.GetString(kHostIdConfigPath, &host_id_)) { | |
269 LOG(ERROR) << "host_id is not defined in the config."; | 254 LOG(ERROR) << "host_id is not defined in the config."; |
270 return false; | 255 return false; |
271 } | 256 } |
272 | 257 |
273 if (!key_pair_.Load(host_config)) { | 258 if (!key_pair_.Load(config_)) { |
274 return false; | 259 return false; |
275 } | 260 } |
276 | 261 |
277 std::string host_secret_hash_string; | 262 std::string host_secret_hash_string; |
278 if (!host_config.GetString(kHostSecretHashConfigPath, | 263 if (!config_.GetString(kHostSecretHashConfigPath, |
279 &host_secret_hash_string)) { | 264 &host_secret_hash_string)) { |
280 host_secret_hash_string = "plain:"; | 265 host_secret_hash_string = "plain:"; |
281 } | 266 } |
282 | 267 |
283 if (!host_secret_hash_.Parse(host_secret_hash_string)) { | 268 if (!host_secret_hash_.Parse(host_secret_hash_string)) { |
284 LOG(ERROR) << "Invalid host_secret_hash."; | 269 LOG(ERROR) << "Invalid host_secret_hash."; |
285 return false; | 270 return false; |
286 } | 271 } |
287 | 272 |
288 // Use an XMPP connection to the Talk network for session signalling. | 273 // Use an XMPP connection to the Talk network for session signalling. |
289 if (!auth_config.GetString(kXmppLoginConfigPath, &xmpp_login_) || | 274 if (!config_.GetString(kXmppLoginConfigPath, &xmpp_login_) || |
290 !(auth_config.GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token_) || | 275 !(config_.GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token_) || |
291 auth_config.GetString(kOAuthRefreshTokenConfigPath, | 276 config_.GetString(kOAuthRefreshTokenConfigPath, |
292 &oauth_refresh_token_))) { | 277 &oauth_refresh_token_))) { |
293 LOG(ERROR) << "XMPP credentials are not defined in the config."; | 278 LOG(ERROR) << "XMPP credentials are not defined in the config."; |
294 return false; | 279 return false; |
295 } | 280 } |
296 | 281 |
297 // It is okay to not have this value and we will use the default value | 282 // It is okay to not have this value and we will use the default value |
298 // depending on whether this is an official build or not. | 283 // depending on whether this is an official build or not. |
299 // If the client-Id type to use is not specified we default based on | 284 // If the client-Id type to use is not specified we default based on |
300 // the build type. | 285 // the build type. |
301 auth_config.GetBoolean(kOAuthUseOfficialClientIdConfigPath, | 286 config_.GetBoolean(kOAuthUseOfficialClientIdConfigPath, |
302 &oauth_use_official_client_id_); | 287 &oauth_use_official_client_id_); |
303 | 288 |
304 if (!oauth_refresh_token_.empty()) { | 289 if (!oauth_refresh_token_.empty()) { |
305 xmpp_auth_token_ = ""; // This will be set to the access token later. | 290 xmpp_auth_token_ = ""; // This will be set to the access token later. |
306 xmpp_auth_service_ = "oauth2"; | 291 xmpp_auth_service_ = "oauth2"; |
307 } else if (!auth_config.GetString(kXmppAuthServiceConfigPath, | 292 } else if (!config_.GetString(kXmppAuthServiceConfigPath, |
308 &xmpp_auth_service_)) { | 293 &xmpp_auth_service_)) { |
309 // For the me2me host, we default to ClientLogin token for chromiumsync | 294 // For the me2me host, we default to ClientLogin token for chromiumsync |
310 // because earlier versions of the host had no HTTP stack with which to | 295 // because earlier versions of the host had no HTTP stack with which to |
311 // request an OAuth2 access token. | 296 // request an OAuth2 access token. |
312 xmpp_auth_service_ = kChromotingTokenDefaultServiceName; | 297 xmpp_auth_service_ = kChromotingTokenDefaultServiceName; |
313 } | 298 } |
314 return true; | 299 return true; |
315 } | 300 } |
316 | 301 |
317 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) { | 302 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) { |
318 if (!context_->network_task_runner()->BelongsToCurrentThread()) { | 303 if (!context_->network_task_runner()->BelongsToCurrentThread()) { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 signaling_connector_.reset(); | 479 signaling_connector_.reset(); |
495 signal_strategy_.reset(); | 480 signal_strategy_.reset(); |
496 | 481 |
497 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 482 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
498 } | 483 } |
499 | 484 |
500 MessageLoop message_loop_; | 485 MessageLoop message_loop_; |
501 scoped_ptr<ChromotingHostContext> context_; | 486 scoped_ptr<ChromotingHostContext> context_; |
502 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 487 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
503 | 488 |
504 FilePath auth_config_path_; | 489 CompositeHostConfig config_; |
505 FilePath host_config_path_; | |
506 | 490 |
507 std::string host_id_; | 491 std::string host_id_; |
508 HostKeyPair key_pair_; | 492 HostKeyPair key_pair_; |
509 protocol::SharedSecretHash host_secret_hash_; | 493 protocol::SharedSecretHash host_secret_hash_; |
510 std::string xmpp_login_; | 494 std::string xmpp_login_; |
511 std::string xmpp_auth_token_; | 495 std::string xmpp_auth_token_; |
512 std::string xmpp_auth_service_; | 496 std::string xmpp_auth_service_; |
513 | 497 |
514 std::string oauth_refresh_token_; | 498 std::string oauth_refresh_token_; |
515 bool oauth_use_official_client_id_; | 499 bool oauth_use_official_client_id_; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 // Required for any calls into GTK functions, such as the Disconnect and | 556 // Required for any calls into GTK functions, such as the Disconnect and |
573 // Continue windows, though these should not be used for the Me2Me case | 557 // Continue windows, though these should not be used for the Me2Me case |
574 // (crbug.com/104377). | 558 // (crbug.com/104377). |
575 gfx::GtkInitFromCommandLine(*cmd_line); | 559 gfx::GtkInitFromCommandLine(*cmd_line); |
576 #endif // TOOLKIT_GTK | 560 #endif // TOOLKIT_GTK |
577 | 561 |
578 // Enable support for SSL server sockets, which must be done while still | 562 // Enable support for SSL server sockets, which must be done while still |
579 // single-threaded. | 563 // single-threaded. |
580 net::EnableSSLServerSockets(); | 564 net::EnableSSLServerSockets(); |
581 | 565 |
566 #if defined(OS_LINUX) | |
567 remoting::VideoFrameCapturer::EnableXDamage(true); | |
568 #endif | |
569 | |
582 remoting::HostProcess me2me_host; | 570 remoting::HostProcess me2me_host; |
583 me2me_host.InitWithCommandLine(cmd_line); | 571 if (!me2me_host.InitWithCommandLine(cmd_line)) { |
572 return remoting::kInvalidHostConfigurationExitCode; | |
573 } | |
584 | 574 |
585 return me2me_host.Run(); | 575 return me2me_host.Run(); |
586 } | 576 } |
587 | 577 |
588 #if defined(OS_WIN) | 578 #if defined(OS_WIN) |
589 HMODULE g_hModule = NULL; | 579 HMODULE g_hModule = NULL; |
590 | 580 |
591 int CALLBACK WinMain(HINSTANCE instance, | 581 int CALLBACK WinMain(HINSTANCE instance, |
592 HINSTANCE previous_instance, | 582 HINSTANCE previous_instance, |
593 LPSTR command_line, | 583 LPSTR command_line, |
(...skipping 25 matching lines...) Expand all Loading... | |
619 user32.GetFunctionPointer("SetProcessDPIAware")); | 609 user32.GetFunctionPointer("SetProcessDPIAware")); |
620 set_process_dpi_aware(); | 610 set_process_dpi_aware(); |
621 } | 611 } |
622 | 612 |
623 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 613 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
624 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 614 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
625 return main(0, NULL); | 615 return main(0, NULL); |
626 } | 616 } |
627 | 617 |
628 #endif // defined(OS_WIN) | 618 #endif // defined(OS_WIN) |
OLD | NEW |