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