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 #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/logging.h" | 20 #include "base/logging.h" |
20 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
21 #include "base/message_loop.h" | 22 #include "base/message_loop.h" |
22 #include "base/threading/thread.h" | 23 #include "base/threading/thread.h" |
23 #include "build/build_config.h" | 24 #include "build/build_config.h" |
24 #include "crypto/nss_util.h" | 25 #include "crypto/nss_util.h" |
25 #include "net/base/network_change_notifier.h" | 26 #include "net/base/network_change_notifier.h" |
26 #include "remoting/base/constants.h" | 27 #include "remoting/base/constants.h" |
27 #include "remoting/host/branding.h" | 28 #include "remoting/host/branding.h" |
28 #include "remoting/host/capturer.h" | 29 #include "remoting/host/capturer.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 allow_nat_traversal_(true), | 82 allow_nat_traversal_(true), |
82 restarting_(false) { | 83 restarting_(false) { |
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()); |
92 config_updated_timer_.reset(new base::DelayTimer<HostProcess>( | |
Sergey Ulanov
2012/04/17 05:42:18
Add a comment here or in OnFilePathChanged() to ex
simonmorris
2012/04/17 15:55:47
Done.
| |
93 FROM_HERE, base::TimeDelta::FromSeconds(2), this, | |
94 &HostProcess::ConfigUpdated)); | |
91 } | 95 } |
92 | 96 |
93 void InitWithCommandLine(const CommandLine* cmd_line) { | 97 void InitWithCommandLine(const CommandLine* cmd_line) { |
94 FilePath default_config_dir = remoting::GetConfigDir(); | 98 FilePath default_config_dir = remoting::GetConfigDir(); |
95 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) { | 99 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) { |
96 auth_config_path_ = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName); | 100 auth_config_path_ = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName); |
97 } else { | 101 } else { |
98 auth_config_path_ = default_config_dir.Append(kDefaultAuthConfigFile); | 102 auth_config_path_ = default_config_dir.Append(kDefaultAuthConfigFile); |
99 } | 103 } |
100 | 104 |
(...skipping 15 matching lines...) Expand all Loading... | |
116 if (LoadConfig(file_io_thread_.message_loop_proxy(), &tokens_pending)) { | 120 if (LoadConfig(file_io_thread_.message_loop_proxy(), &tokens_pending)) { |
117 context_->network_message_loop()->PostTask( | 121 context_->network_message_loop()->PostTask( |
118 FROM_HERE, | 122 FROM_HERE, |
119 base::Bind(&HostProcess::CreateAuthenticatorFactory, | 123 base::Bind(&HostProcess::CreateAuthenticatorFactory, |
120 base::Unretained(this))); | 124 base::Unretained(this))); |
121 } else { | 125 } else { |
122 LOG(ERROR) << "Invalid configuration."; | 126 LOG(ERROR) << "Invalid configuration."; |
123 } | 127 } |
124 } | 128 } |
125 | 129 |
130 #if defined(OS_WIN) | |
131 class ConfigChangedDelegate : public base::files::FilePathWatcher::Delegate { | |
132 public: | |
133 ConfigChangedDelegate(HostProcess* host_process) : | |
134 host_process_(host_process) { | |
135 } | |
136 void OnFilePathChanged(const FilePath& path) OVERRIDE { | |
137 host_process_->config_updated_timer_->Reset(); | |
138 } | |
139 void OnFilePathError(const FilePath& path) OVERRIDE { | |
140 } | |
141 private: | |
142 HostProcess* host_process_; | |
143 | |
144 DISALLOW_COPY_AND_ASSIGN(ConfigChangedDelegate); | |
145 }; | |
146 #endif // defined(OS_WIN) | |
147 | |
148 void ListenForConfigChanges() { | |
126 #if defined(OS_MACOSX) | 149 #if defined(OS_MACOSX) |
127 void ListenForConfigChanges() { | |
128 remoting::RegisterHupSignalHandler( | 150 remoting::RegisterHupSignalHandler( |
129 base::Bind(&HostProcess::ConfigUpdated, base::Unretained(this))); | 151 base::Bind(&HostProcess::ConfigUpdated, base::Unretained(this))); |
152 #elif defined(OS_WIN) | |
153 scoped_refptr<base::files::FilePathWatcher::Delegate> delegate( | |
154 new ConfigChangedDelegate(this)); | |
155 config_watcher_.reset(new base::files::FilePathWatcher()); | |
156 if (!config_watcher_->Watch(host_config_path_, delegate)) { | |
157 LOG(ERROR) << "Couldn't watch file " << host_config_path_.value(); | |
158 } | |
159 #endif | |
130 } | 160 } |
131 #endif | |
132 | 161 |
133 void CreateAuthenticatorFactory() { | 162 void CreateAuthenticatorFactory() { |
134 scoped_ptr<protocol::AuthenticatorFactory> factory( | 163 scoped_ptr<protocol::AuthenticatorFactory> factory( |
135 new protocol::Me2MeHostAuthenticatorFactory( | 164 new protocol::Me2MeHostAuthenticatorFactory( |
136 xmpp_login_, key_pair_.GenerateCertificate(), | 165 xmpp_login_, key_pair_.GenerateCertificate(), |
137 *key_pair_.private_key(), host_secret_hash_)); | 166 *key_pair_.private_key(), host_secret_hash_)); |
138 host_->SetAuthenticatorFactory(factory.Pass()); | 167 host_->SetAuthenticatorFactory(factory.Pass()); |
139 } | 168 } |
140 | 169 |
141 int Run() { | 170 int Run() { |
142 bool tokens_pending = false; | 171 bool tokens_pending = false; |
143 if (!LoadConfig(file_io_thread_.message_loop_proxy(), &tokens_pending)) { | 172 if (!LoadConfig(file_io_thread_.message_loop_proxy(), &tokens_pending)) { |
144 return kInvalidHostConfigurationExitCode; | 173 return kInvalidHostConfigurationExitCode; |
145 } | 174 } |
146 if (tokens_pending) { | 175 if (tokens_pending) { |
147 // If we have an OAuth refresh token, then XmppSignalStrategy can't | 176 // If we have an OAuth refresh token, then XmppSignalStrategy can't |
148 // handle it directly, so refresh it asynchronously. A task will be | 177 // handle it directly, so refresh it asynchronously. A task will be |
149 // posted on the message loop to start watching the NAT policy when | 178 // posted on the message loop to start watching the NAT policy when |
150 // the access token is available. | 179 // the access token is available. |
151 // | 180 // |
152 // TODO(sergeyu): Move this code to SignalingConnector. | 181 // TODO(sergeyu): Move this code to SignalingConnector. |
153 oauth_client_.Start(oauth_refresh_token_, this, | 182 oauth_client_.Start(oauth_refresh_token_, this, |
154 message_loop_.message_loop_proxy()); | 183 message_loop_.message_loop_proxy()); |
155 } else { | 184 } else { |
156 StartWatchingNatPolicy(); | 185 StartWatchingNatPolicy(); |
157 } | 186 } |
158 | 187 |
159 #if defined(OS_MACOSX) | 188 #if defined(OS_MACOSX) || defined(OS_WIN) |
160 file_io_thread_.message_loop_proxy()->PostTask( | 189 file_io_thread_.message_loop_proxy()->PostTask( |
161 FROM_HERE, | 190 FROM_HERE, |
162 base::Bind(&HostProcess::ListenForConfigChanges, | 191 base::Bind(&HostProcess::ListenForConfigChanges, |
163 base::Unretained(this))); | 192 base::Unretained(this))); |
164 #endif | 193 #endif |
165 message_loop_.Run(); | 194 message_loop_.Run(); |
166 | 195 |
167 return kSuccessExitCode; | 196 return kSuccessExitCode; |
168 } | 197 } |
169 | 198 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
355 protocol::SharedSecretHash host_secret_hash_; | 384 protocol::SharedSecretHash host_secret_hash_; |
356 std::string xmpp_login_; | 385 std::string xmpp_login_; |
357 std::string xmpp_auth_token_; | 386 std::string xmpp_auth_token_; |
358 std::string xmpp_auth_service_; | 387 std::string xmpp_auth_service_; |
359 | 388 |
360 std::string oauth_refresh_token_; | 389 std::string oauth_refresh_token_; |
361 OAuthClient oauth_client_; | 390 OAuthClient oauth_client_; |
362 | 391 |
363 scoped_ptr<policy_hack::NatPolicy> nat_policy_; | 392 scoped_ptr<policy_hack::NatPolicy> nat_policy_; |
364 bool allow_nat_traversal_; | 393 bool allow_nat_traversal_; |
394 scoped_ptr<base::files::FilePathWatcher> config_watcher_; | |
395 scoped_ptr<base::DelayTimer<HostProcess> > config_updated_timer_; | |
365 | 396 |
366 bool restarting_; | 397 bool restarting_; |
367 | 398 |
368 scoped_ptr<XmppSignalStrategy> signal_strategy_; | 399 scoped_ptr<XmppSignalStrategy> signal_strategy_; |
369 scoped_ptr<SignalingConnector> signaling_connector_; | 400 scoped_ptr<SignalingConnector> signaling_connector_; |
370 scoped_ptr<DesktopEnvironment> desktop_environment_; | 401 scoped_ptr<DesktopEnvironment> desktop_environment_; |
371 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 402 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
372 scoped_ptr<LogToServer> log_to_server_; | 403 scoped_ptr<LogToServer> log_to_server_; |
373 scoped_ptr<HostEventLogger> host_event_logger_; | 404 scoped_ptr<HostEventLogger> host_event_logger_; |
374 scoped_refptr<ChromotingHost> host_; | 405 scoped_refptr<ChromotingHost> host_; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 int CALLBACK WinMain(HINSTANCE instance, | 445 int CALLBACK WinMain(HINSTANCE instance, |
415 HINSTANCE previous_instance, | 446 HINSTANCE previous_instance, |
416 LPSTR command_line, | 447 LPSTR command_line, |
417 int show_command) { | 448 int show_command) { |
418 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 449 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
419 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 450 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
420 return main(0, NULL); | 451 return main(0, NULL); |
421 } | 452 } |
422 | 453 |
423 #endif | 454 #endif |
OLD | NEW |