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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 if (LoadConfig(file_io_thread_.message_loop_proxy(), &tokens_pending)) { | 117 if (LoadConfig(file_io_thread_.message_loop_proxy(), &tokens_pending)) { |
117 context_->network_message_loop()->PostTask( | 118 context_->network_message_loop()->PostTask( |
118 FROM_HERE, | 119 FROM_HERE, |
119 base::Bind(&HostProcess::CreateAuthenticatorFactory, | 120 base::Bind(&HostProcess::CreateAuthenticatorFactory, |
120 base::Unretained(this))); | 121 base::Unretained(this))); |
121 } else { | 122 } else { |
122 LOG(ERROR) << "Invalid configuration."; | 123 LOG(ERROR) << "Invalid configuration."; |
123 } | 124 } |
124 } | 125 } |
125 | 126 |
127 #if defined(OS_WIN) | |
128 class ConfigChangedDelegate : public base::files::FilePathWatcher::Delegate { | |
129 public: | |
130 ConfigChangedDelegate(HostProcess* host_process) : | |
131 host_process_(host_process) { | |
132 } | |
133 void OnFilePathChanged(const FilePath& path) OVERRIDE { | |
134 host_process_->ConfigUpdated(); | |
Sergey Ulanov
2012/04/16 23:36:24
It might be better to wait for a couple of seconds
simonmorris
2012/04/17 00:04:55
Done, but please check the code.
| |
135 } | |
136 void OnFilePathError(const FilePath& path) OVERRIDE { | |
137 } | |
138 private: | |
139 HostProcess* host_process_; | |
140 | |
141 DISALLOW_COPY_AND_ASSIGN(ConfigChangedDelegate); | |
142 }; | |
143 #endif // defined(OS_WIN) | |
144 | |
145 void ListenForConfigChanges() { | |
126 #if defined(OS_MACOSX) | 146 #if defined(OS_MACOSX) |
127 void ListenForConfigChanges() { | |
128 remoting::RegisterHupSignalHandler( | 147 remoting::RegisterHupSignalHandler( |
129 base::Bind(&HostProcess::ConfigUpdated, base::Unretained(this))); | 148 base::Bind(&HostProcess::ConfigUpdated, base::Unretained(this))); |
149 #elif defined(OS_WIN) | |
150 scoped_refptr<base::files::FilePathWatcher::Delegate> delegate( | |
151 new ConfigChangedDelegate(this)); | |
152 config_watcher_.reset(new base::files::FilePathWatcher()); | |
153 if (!config_watcher_->Watch(host_config_path_, delegate)) { | |
154 LOG(ERROR) << "Couldn't watch file " << host_config_path_.value(); | |
155 } | |
156 #endif | |
130 } | 157 } |
131 #endif | |
132 | 158 |
133 void CreateAuthenticatorFactory() { | 159 void CreateAuthenticatorFactory() { |
134 scoped_ptr<protocol::AuthenticatorFactory> factory( | 160 scoped_ptr<protocol::AuthenticatorFactory> factory( |
135 new protocol::Me2MeHostAuthenticatorFactory( | 161 new protocol::Me2MeHostAuthenticatorFactory( |
136 xmpp_login_, key_pair_.GenerateCertificate(), | 162 xmpp_login_, key_pair_.GenerateCertificate(), |
137 *key_pair_.private_key(), host_secret_hash_)); | 163 *key_pair_.private_key(), host_secret_hash_)); |
138 host_->SetAuthenticatorFactory(factory.Pass()); | 164 host_->SetAuthenticatorFactory(factory.Pass()); |
139 } | 165 } |
140 | 166 |
141 int Run() { | 167 int Run() { |
142 bool tokens_pending = false; | 168 bool tokens_pending = false; |
143 if (!LoadConfig(file_io_thread_.message_loop_proxy(), &tokens_pending)) { | 169 if (!LoadConfig(file_io_thread_.message_loop_proxy(), &tokens_pending)) { |
144 return kInvalidHostConfigurationExitCode; | 170 return kInvalidHostConfigurationExitCode; |
145 } | 171 } |
146 if (tokens_pending) { | 172 if (tokens_pending) { |
147 // If we have an OAuth refresh token, then XmppSignalStrategy can't | 173 // If we have an OAuth refresh token, then XmppSignalStrategy can't |
148 // handle it directly, so refresh it asynchronously. A task will be | 174 // handle it directly, so refresh it asynchronously. A task will be |
149 // posted on the message loop to start watching the NAT policy when | 175 // posted on the message loop to start watching the NAT policy when |
150 // the access token is available. | 176 // the access token is available. |
151 // | 177 // |
152 // TODO(sergeyu): Move this code to SignalingConnector. | 178 // TODO(sergeyu): Move this code to SignalingConnector. |
153 oauth_client_.Start(oauth_refresh_token_, this, | 179 oauth_client_.Start(oauth_refresh_token_, this, |
154 message_loop_.message_loop_proxy()); | 180 message_loop_.message_loop_proxy()); |
155 } else { | 181 } else { |
156 StartWatchingNatPolicy(); | 182 StartWatchingNatPolicy(); |
157 } | 183 } |
158 | 184 |
159 #if defined(OS_MACOSX) | 185 #if defined(OS_MACOSX) || defined(OS_WIN) |
160 file_io_thread_.message_loop_proxy()->PostTask( | 186 file_io_thread_.message_loop_proxy()->PostTask( |
161 FROM_HERE, | 187 FROM_HERE, |
162 base::Bind(&HostProcess::ListenForConfigChanges, | 188 base::Bind(&HostProcess::ListenForConfigChanges, |
163 base::Unretained(this))); | 189 base::Unretained(this))); |
164 #endif | 190 #endif |
165 message_loop_.Run(); | 191 message_loop_.Run(); |
166 | 192 |
167 return kSuccessExitCode; | 193 return kSuccessExitCode; |
168 } | 194 } |
169 | 195 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
355 protocol::SharedSecretHash host_secret_hash_; | 381 protocol::SharedSecretHash host_secret_hash_; |
356 std::string xmpp_login_; | 382 std::string xmpp_login_; |
357 std::string xmpp_auth_token_; | 383 std::string xmpp_auth_token_; |
358 std::string xmpp_auth_service_; | 384 std::string xmpp_auth_service_; |
359 | 385 |
360 std::string oauth_refresh_token_; | 386 std::string oauth_refresh_token_; |
361 OAuthClient oauth_client_; | 387 OAuthClient oauth_client_; |
362 | 388 |
363 scoped_ptr<policy_hack::NatPolicy> nat_policy_; | 389 scoped_ptr<policy_hack::NatPolicy> nat_policy_; |
364 bool allow_nat_traversal_; | 390 bool allow_nat_traversal_; |
391 scoped_ptr<base::files::FilePathWatcher> config_watcher_; | |
365 | 392 |
366 bool restarting_; | 393 bool restarting_; |
367 | 394 |
368 scoped_ptr<XmppSignalStrategy> signal_strategy_; | 395 scoped_ptr<XmppSignalStrategy> signal_strategy_; |
369 scoped_ptr<SignalingConnector> signaling_connector_; | 396 scoped_ptr<SignalingConnector> signaling_connector_; |
370 scoped_ptr<DesktopEnvironment> desktop_environment_; | 397 scoped_ptr<DesktopEnvironment> desktop_environment_; |
371 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 398 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
372 scoped_ptr<LogToServer> log_to_server_; | 399 scoped_ptr<LogToServer> log_to_server_; |
373 scoped_ptr<HostEventLogger> host_event_logger_; | 400 scoped_ptr<HostEventLogger> host_event_logger_; |
374 scoped_refptr<ChromotingHost> host_; | 401 scoped_refptr<ChromotingHost> host_; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 int CALLBACK WinMain(HINSTANCE instance, | 441 int CALLBACK WinMain(HINSTANCE instance, |
415 HINSTANCE previous_instance, | 442 HINSTANCE previous_instance, |
416 LPSTR command_line, | 443 LPSTR command_line, |
417 int show_command) { | 444 int show_command) { |
418 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 445 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
419 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 446 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
420 return main(0, NULL); | 447 return main(0, NULL); |
421 } | 448 } |
422 | 449 |
423 #endif | 450 #endif |
OLD | NEW |