Chromium Code Reviews| 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" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/files/file_path_watcher.h" | |
| 16 #include "base/logging.h" | 15 #include "base/logging.h" |
| 17 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/memory/weak_ptr.h" | |
| 18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 19 #include "base/scoped_native_library.h" | 19 #include "base/scoped_native_library.h" |
| 20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 21 #include "base/synchronization/waitable_event.h" | 21 #include "base/synchronization/waitable_event.h" |
| 22 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
| 23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| 24 #include "base/win/windows_version.h" | 24 #include "base/win/windows_version.h" |
| 25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 26 #include "crypto/nss_util.h" | 26 #include "crypto/nss_util.h" |
| 27 #include "ipc/ipc_channel.h" | 27 #include "ipc/ipc_channel.h" |
| 28 #include "ipc/ipc_channel_proxy.h" | 28 #include "ipc/ipc_channel_proxy.h" |
| 29 #include "net/base/network_change_notifier.h" | 29 #include "net/base/network_change_notifier.h" |
| 30 #include "net/socket/ssl_server_socket.h" | 30 #include "net/socket/ssl_server_socket.h" |
| 31 #include "remoting/base/auto_message_loop.h" | 31 #include "remoting/base/auto_message_loop.h" |
| 32 #include "remoting/base/breakpad.h" | 32 #include "remoting/base/breakpad.h" |
| 33 #include "remoting/base/constants.h" | 33 #include "remoting/base/constants.h" |
| 34 #include "remoting/host/branding.h" | 34 #include "remoting/host/branding.h" |
| 35 #include "remoting/host/chromoting_host.h" | 35 #include "remoting/host/chromoting_host.h" |
| 36 #include "remoting/host/chromoting_host_context.h" | 36 #include "remoting/host/chromoting_host_context.h" |
| 37 #include "remoting/host/composite_host_config.h" | 37 #include "remoting/host/chromoting_messages.h" |
| 38 #include "remoting/host/constants.h" | 38 #include "remoting/host/constants.h" |
| 39 #include "remoting/host/config_file_watcher.h" | |
| 39 #include "remoting/host/desktop_environment.h" | 40 #include "remoting/host/desktop_environment.h" |
| 40 #include "remoting/host/event_executor.h" | 41 #include "remoting/host/event_executor.h" |
| 41 #include "remoting/host/heartbeat_sender.h" | 42 #include "remoting/host/heartbeat_sender.h" |
| 42 #include "remoting/host/host_config.h" | 43 #include "remoting/host/host_config.h" |
| 43 #include "remoting/host/host_event_logger.h" | 44 #include "remoting/host/host_event_logger.h" |
| 44 #include "remoting/host/host_user_interface.h" | 45 #include "remoting/host/host_user_interface.h" |
| 46 #include "remoting/host/json_host_config.h" | |
| 45 #include "remoting/host/log_to_server.h" | 47 #include "remoting/host/log_to_server.h" |
| 46 #include "remoting/host/network_settings.h" | 48 #include "remoting/host/network_settings.h" |
| 47 #include "remoting/host/policy_hack/policy_watcher.h" | 49 #include "remoting/host/policy_hack/policy_watcher.h" |
| 48 #include "remoting/host/session_manager_factory.h" | 50 #include "remoting/host/session_manager_factory.h" |
| 49 #include "remoting/host/signaling_connector.h" | 51 #include "remoting/host/signaling_connector.h" |
| 50 #include "remoting/host/usage_stats_consent.h" | 52 #include "remoting/host/usage_stats_consent.h" |
| 51 #include "remoting/host/video_frame_capturer.h" | 53 #include "remoting/host/video_frame_capturer.h" |
| 52 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 54 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
| 53 #include "remoting/protocol/me2me_host_authenticator_factory.h" | 55 #include "remoting/protocol/me2me_host_authenticator_factory.h" |
| 54 | 56 |
| 55 #if defined(OS_POSIX) | |
| 56 #include "remoting/host/posix/sighup_listener.h" | |
| 57 #endif // defined(OS_POSIX) | |
| 58 | |
| 59 #if defined(OS_MACOSX) | 57 #if defined(OS_MACOSX) |
| 60 #include "base/mac/scoped_cftyperef.h" | 58 #include "base/mac/scoped_cftyperef.h" |
| 61 #include "base/mac/scoped_nsautorelease_pool.h" | 59 #include "base/mac/scoped_nsautorelease_pool.h" |
| 62 #include "remoting/host/curtain_mode_mac.h" | 60 #include "remoting/host/curtain_mode_mac.h" |
| 63 #endif // defined(OS_MACOSX) | 61 #endif // defined(OS_MACOSX) |
| 64 | 62 |
| 65 // N.B. OS_WIN is defined by including src/base headers. | 63 // N.B. OS_WIN is defined by including src/base headers. |
| 66 #if defined(OS_WIN) | 64 #if defined(OS_WIN) |
| 67 #include <commctrl.h> | 65 #include <commctrl.h> |
| 68 #endif // defined(OS_WIN) | 66 #endif // defined(OS_WIN) |
| 69 | 67 |
| 70 #if defined(TOOLKIT_GTK) | 68 #if defined(TOOLKIT_GTK) |
| 71 #include "ui/gfx/gtk_util.h" | 69 #include "ui/gfx/gtk_util.h" |
| 72 #endif // defined(TOOLKIT_GTK) | 70 #endif // defined(TOOLKIT_GTK) |
| 73 | 71 |
| 74 namespace { | 72 namespace { |
| 75 | 73 |
| 76 // This is used for tagging system event logs. | 74 // This is used for tagging system event logs. |
| 77 const char kApplicationName[] = "chromoting"; | 75 const char kApplicationName[] = "chromoting"; |
| 78 | 76 |
| 79 // The command line switch specifying the name of the Chromoting IPC channel. | 77 // The command line switch specifying the name of the daemon IPC endpoint. |
| 80 const char kDaemonIpcSwitchName[] = "chromoting-ipc"; | 78 const char kDaemonIpcSwitchName[] = "daemon-pipe"; |
| 81 | |
| 82 // These are used for parsing the config-file locations from the command line, | |
| 83 // and for defining the default locations if the switches are not present. | |
| 84 const char kAuthConfigSwitchName[] = "auth-config"; | |
| 85 const char kHostConfigSwitchName[] = "host-config"; | |
| 86 | |
| 87 const FilePath::CharType kDefaultHostConfigFile[] = | |
| 88 FILE_PATH_LITERAL("host.json"); | |
| 89 | 79 |
| 90 const int kMinPortNumber = 12400; | 80 const int kMinPortNumber = 12400; |
| 91 const int kMaxPortNumber = 12409; | 81 const int kMaxPortNumber = 12409; |
| 92 | 82 |
| 93 const char kUnofficialOAuth2ClientId[] = | 83 const char kUnofficialOAuth2ClientId[] = |
| 94 "440925447803-2pi3v45bff6tp1rde2f7q6lgbor3o5uj.apps.googleusercontent.com"; | 84 "440925447803-2pi3v45bff6tp1rde2f7q6lgbor3o5uj.apps.googleusercontent.com"; |
| 95 const char kUnofficialOAuth2ClientSecret[] = "W2ieEsG-R1gIA4MMurGrgMc_"; | 85 const char kUnofficialOAuth2ClientSecret[] = "W2ieEsG-R1gIA4MMurGrgMc_"; |
| 96 | 86 |
| 97 const char kOfficialOAuth2ClientId[] = | 87 const char kOfficialOAuth2ClientId[] = |
| 98 "440925447803-avn2sj1kc099s0r7v62je5s339mu0am1.apps.googleusercontent.com"; | 88 "440925447803-avn2sj1kc099s0r7v62je5s339mu0am1.apps.googleusercontent.com"; |
| 99 const char kOfficialOAuth2ClientSecret[] = "Bgur6DFiOMM1h8x-AQpuTQlK"; | 89 const char kOfficialOAuth2ClientSecret[] = "Bgur6DFiOMM1h8x-AQpuTQlK"; |
| 100 | 90 |
| 101 void QuitMessageLoop(MessageLoop* message_loop) { | 91 void QuitMessageLoop(MessageLoop* message_loop) { |
| 102 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 92 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 103 } | 93 } |
| 104 | 94 |
| 105 } // namespace | 95 } // namespace |
| 106 | 96 |
| 107 namespace remoting { | 97 namespace remoting { |
| 108 | 98 |
| 109 class HostProcess | 99 class HostProcess |
| 110 : public HeartbeatSender::Listener, | 100 : public HeartbeatSender::Listener, |
| 111 public IPC::Listener { | 101 public IPC::Listener, |
| 102 public ConfigFileWatcher::Delegate { | |
| 112 public: | 103 public: |
| 113 HostProcess(scoped_ptr<ChromotingHostContext> context) | 104 HostProcess(scoped_ptr<ChromotingHostContext> context) |
| 114 : context_(context.Pass()), | 105 : context_(context.Pass()), |
| 106 config_(FilePath()), | |
| 115 #ifdef OFFICIAL_BUILD | 107 #ifdef OFFICIAL_BUILD |
| 116 oauth_use_official_client_id_(true), | 108 oauth_use_official_client_id_(true), |
| 117 #else | 109 #else |
| 118 oauth_use_official_client_id_(false), | 110 oauth_use_official_client_id_(false), |
| 119 #endif | 111 #endif |
| 120 allow_nat_traversal_(true), | 112 allow_nat_traversal_(true), |
| 121 restarting_(false), | 113 restarting_(false), |
| 122 shutting_down_(false), | 114 shutting_down_(false), |
| 123 exit_code_(kSuccessExitCode) | 115 exit_code_(kSuccessExitCode), |
| 124 #if defined(OS_MACOSX) | 116 #if defined(OS_MACOSX) |
| 125 , curtain_(base::Bind(&HostProcess::OnDisconnectRequested, | 117 curtain_(base::Bind(&HostProcess::OnDisconnectRequested, |
| 126 base::Unretained(this)), | 118 base::Unretained(this)), |
| 127 base::Bind(&HostProcess::OnDisconnectRequested, | 119 base::Bind(&HostProcess::OnDisconnectRequested, |
| 128 base::Unretained(this))) | 120 base::Unretained(this))) |
|
Wez
2012/08/30 20:36:04
nit: Missing a comma here?
alexeypa (please no reviews)
2012/08/30 23:15:13
Yes, but not anymore.
| |
| 129 #endif | 121 #endif |
| 122 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) | |
| 130 { | 123 { |
| 131 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 124 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
| 132 config_updated_timer_.reset(new base::DelayTimer<HostProcess>( | |
| 133 FROM_HERE, base::TimeDelta::FromSeconds(2), this, | |
| 134 &HostProcess::ConfigUpdatedDelayed)); | |
| 135 } | 125 } |
| 136 | 126 |
| 137 bool InitWithCommandLine(const CommandLine* cmd_line) { | 127 bool InitWithCommandLine(const CommandLine* cmd_line) { |
| 138 // Connect to the daemon process. | 128 // Connect to the daemon process. |
| 139 std::string channel_name = | 129 std::string channel_name = |
| 140 cmd_line->GetSwitchValueASCII(kDaemonIpcSwitchName); | 130 cmd_line->GetSwitchValueASCII(kDaemonIpcSwitchName); |
| 141 | 131 |
| 142 #if defined(REMOTING_MULTI_PROCESS) | 132 #if defined(REMOTING_MULTI_PROCESS) |
| 143 if (channel_name.empty()) | 133 if (channel_name.empty()) |
| 144 return false; | 134 return false; |
| 145 #endif // defined(REMOTING_MULTI_PROCESS) | 135 #endif // defined(REMOTING_MULTI_PROCESS) |
| 146 | 136 |
| 147 if (!channel_name.empty()) { | 137 if (!channel_name.empty()) { |
| 148 daemon_channel_.reset(new IPC::ChannelProxy( | 138 daemon_channel_.reset(new IPC::ChannelProxy( |
| 149 channel_name, IPC::Channel::MODE_CLIENT, this, | 139 channel_name, IPC::Channel::MODE_CLIENT, this, |
| 150 context_->network_task_runner())); | 140 context_->network_task_runner())); |
| 151 } | 141 } |
| 152 | 142 |
| 143 #if !defined(REMOTING_MULTI_PROCESS) | |
| 153 FilePath default_config_dir = remoting::GetConfigDir(); | 144 FilePath default_config_dir = remoting::GetConfigDir(); |
| 154 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) { | |
| 155 FilePath path = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName); | |
| 156 config_.AddConfigPath(path); | |
| 157 } | |
| 158 | |
| 159 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); | 145 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); |
| 160 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { | 146 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { |
| 161 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); | 147 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); |
| 162 } | 148 } |
| 163 config_.AddConfigPath(host_config_path_); | 149 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 164 | 150 |
| 165 return true; | 151 return true; |
| 166 } | 152 } |
| 167 | 153 |
| 168 void ConfigUpdated() { | 154 virtual void OnConfigUpdated(const std::string& config) OVERRIDE { |
|
Wez
2012/08/30 20:36:04
nit: config -> config_str
alexeypa (please no reviews)
2012/08/30 23:15:13
The style guide does not allow Hungarian notation
Wez
2012/08/31 00:23:04
:P
I actually mean "str" as a well-known abbrevia
alexeypa (please no reviews)
2012/08/31 21:26:55
I understood. It is still a sort of Hungarian nota
Wez
2012/09/04 20:18:26
The difference here is that the types differ betwe
alexeypa (please no reviews)
2012/09/05 16:08:34
Done.
| |
| 169 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 155 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 170 | 156 |
| 171 // Call ConfigUpdatedDelayed after a short delay, so that this object won't | 157 LOG(INFO) << "Processing new host configuration."; |
| 172 // try to read the updated configuration file before it has been | |
| 173 // completely written. | |
| 174 // If the writer moves the new configuration file into place atomically, | |
| 175 // this delay may not be necessary. | |
| 176 config_updated_timer_->Reset(); | |
| 177 } | |
| 178 | 158 |
| 179 void ConfigUpdatedDelayed() { | 159 if (!config_.SetSerializedData(config)) { |
| 180 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 160 LOG(ERROR) << "Invalid configuration."; |
| 161 OnConfigWatcherError(); | |
| 162 return; | |
| 163 } | |
| 181 | 164 |
| 182 if (LoadConfig()) { | 165 if (!ApplyConfig()) { |
| 166 LOG(ERROR) << "Failed to apply the configuration."; | |
| 167 OnConfigWatcherError(); | |
| 168 return; | |
| 169 } | |
| 170 | |
| 171 // Start watching the policy (and eventually start the host) if this is | |
| 172 // the first configuration update. Otherwise, post a task to create new | |
| 173 // authenticator factory in case PIN has changed. | |
| 174 if (policy_watcher_.get() == NULL) { | |
| 175 #if defined(OS_MACOSX) || defined(OS_WIN) | |
| 176 host_user_interface_.reset(new HostUserInterface(context_.get())); | |
| 177 #endif | |
| 178 | |
| 179 StartWatchingPolicy(); | |
| 180 } else { | |
| 183 // PostTask to create new authenticator factory in case PIN has changed. | 181 // PostTask to create new authenticator factory in case PIN has changed. |
| 184 context_->network_task_runner()->PostTask( | 182 context_->network_task_runner()->PostTask( |
| 185 FROM_HERE, | 183 FROM_HERE, |
| 186 base::Bind(&HostProcess::CreateAuthenticatorFactory, | 184 base::Bind(&HostProcess::CreateAuthenticatorFactory, |
| 187 base::Unretained(this))); | 185 base::Unretained(this))); |
| 188 } else { | |
| 189 LOG(ERROR) << "Invalid configuration."; | |
| 190 } | 186 } |
| 191 } | 187 } |
| 192 | 188 |
| 193 #if defined(OS_WIN) | 189 virtual void OnConfigWatcherError() OVERRIDE { |
| 194 class ConfigChangedDelegate : public base::files::FilePathWatcher::Delegate { | 190 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 195 public: | |
| 196 ConfigChangedDelegate( | |
| 197 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 198 const base::Closure& callback) | |
| 199 : task_runner_(task_runner), | |
| 200 callback_(callback) { | |
| 201 } | |
| 202 | 191 |
| 203 void OnFilePathChanged(const FilePath& path) OVERRIDE { | 192 context_->network_task_runner()->PostTask( |
| 204 task_runner_->PostTask(FROM_HERE, callback_); | 193 FROM_HERE, |
| 205 } | 194 base::Bind(&HostProcess::Shutdown, base::Unretained(this), |
| 195 kInvalidHostConfigurationExitCode)); | |
| 196 } | |
| 206 | 197 |
| 207 void OnFilePathError(const FilePath& path) OVERRIDE { | 198 void StartWatchingConfigChanges() { |
| 208 } | 199 #if !defined(REMOTING_MULTI_PROCESS) |
| 209 | 200 // Start watching the host configuration file. |
| 210 private: | 201 config_watcher_.reset(new ConfigFileWatcher(context_->ui_task_runner(), |
| 211 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 202 context_->file_task_runner(), |
|
Wez
2012/08/30 20:36:04
nit: Indentation.
alexeypa (please no reviews)
2012/08/30 23:15:13
Done.
| |
| 212 base::Closure callback_; | 203 weak_factory_.GetWeakPtr())); |
| 213 | 204 config_watcher_->Watch(host_config_path_); |
| 214 DISALLOW_COPY_AND_ASSIGN(ConfigChangedDelegate); | 205 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 215 }; | |
| 216 #endif // defined(OS_WIN) | |
| 217 | |
| 218 void ListenForConfigChanges() { | |
| 219 #if defined(OS_POSIX) | |
| 220 remoting::RegisterHupSignalHandler( | |
| 221 base::Bind(&HostProcess::ConfigUpdatedDelayed, base::Unretained(this))); | |
| 222 #elif defined(OS_WIN) | |
| 223 scoped_refptr<base::files::FilePathWatcher::Delegate> delegate( | |
| 224 new ConfigChangedDelegate( | |
| 225 context_->ui_task_runner(), | |
| 226 base::Bind(&HostProcess::ConfigUpdated, base::Unretained(this)))); | |
| 227 config_watcher_.reset(new base::files::FilePathWatcher()); | |
| 228 if (!config_watcher_->Watch(host_config_path_, delegate)) { | |
| 229 LOG(ERROR) << "Couldn't watch file " << host_config_path_.value(); | |
| 230 } | |
| 231 #endif // defined (OS_WIN) | |
| 232 } | 206 } |
| 233 | 207 |
| 234 void CreateAuthenticatorFactory() { | 208 void CreateAuthenticatorFactory() { |
| 235 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 209 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 236 scoped_ptr<protocol::AuthenticatorFactory> factory( | 210 scoped_ptr<protocol::AuthenticatorFactory> factory( |
| 237 new protocol::Me2MeHostAuthenticatorFactory( | 211 new protocol::Me2MeHostAuthenticatorFactory( |
| 238 key_pair_.GenerateCertificate(), | 212 key_pair_.GenerateCertificate(), |
| 239 *key_pair_.private_key(), host_secret_hash_)); | 213 *key_pair_.private_key(), host_secret_hash_)); |
| 240 host_->SetAuthenticatorFactory(factory.Pass()); | 214 host_->SetAuthenticatorFactory(factory.Pass()); |
| 241 } | 215 } |
| 242 | 216 |
| 243 // IPC::Listener implementation. | 217 // IPC::Listener implementation. |
| 244 virtual bool OnMessageReceived(const IPC::Message& message) { | 218 virtual bool OnMessageReceived(const IPC::Message& message) { |
| 219 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | |
| 220 | |
| 221 #if defined(REMOTING_MULTI_PROCESS) | |
| 222 bool handled = true; | |
| 223 IPC_BEGIN_MESSAGE_MAP(HostProcess, message) | |
| 224 IPC_MESSAGE_HANDLER(ChromotingDaemonNetworkMsg_Configuration, | |
| 225 OnConfigUpdated) | |
| 226 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 227 IPC_END_MESSAGE_MAP() | |
| 228 return handled; | |
| 229 #else // !defined(REMOTING_MULTI_PROCESS) | |
| 245 return false; | 230 return false; |
| 231 #endif // !defined(REMOTING_MULTI_PROCESS) | |
| 246 } | 232 } |
| 247 | 233 |
| 248 void StartHostProcess() { | 234 void StartHostProcess() { |
| 249 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 235 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 250 | 236 |
| 251 if (!InitWithCommandLine(CommandLine::ForCurrentProcess()) || | 237 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) { |
| 252 !LoadConfig()) { | 238 OnConfigWatcherError(); |
| 253 context_->network_task_runner()->PostTask( | |
| 254 FROM_HERE, | |
| 255 base::Bind(&HostProcess::Shutdown, base::Unretained(this), | |
| 256 kInvalidHostConfigurationExitCode)); | |
| 257 return; | 239 return; |
| 258 } | 240 } |
| 259 | 241 |
| 260 #if defined(OS_MACOSX) || defined(OS_WIN) | 242 StartWatchingConfigChanges(); |
| 261 host_user_interface_.reset(new HostUserInterface(context_.get())); | |
| 262 #endif | |
| 263 | |
| 264 StartWatchingPolicy(); | |
| 265 | |
| 266 #if defined(OS_MACOSX) || defined(OS_WIN) | |
| 267 context_->file_task_runner()->PostTask( | |
| 268 FROM_HERE, | |
| 269 base::Bind(&HostProcess::ListenForConfigChanges, | |
| 270 base::Unretained(this))); | |
| 271 #endif | |
| 272 } | 243 } |
| 273 | 244 |
| 274 void ShutdownHostProcess() { | 245 void ShutdownHostProcess() { |
| 275 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 246 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 276 | 247 |
| 248 weak_factory_.InvalidateWeakPtrs(); | |
|
Wez
2012/08/30 20:36:04
nit: Add a short comment to explain why we're doin
alexeypa (please no reviews)
2012/08/30 23:15:13
Not needed anymore.
| |
| 249 | |
| 250 #if !defined(REMOTING_MULTI_PROCESS) | |
| 251 if (config_watcher_.get()) { | |
| 252 config_watcher_.release()->StopAndDelete(); | |
| 253 } | |
| 254 #endif // !defined(REMOTING_MULTI_PROCESS) | |
| 255 | |
| 277 daemon_channel_.reset(); | 256 daemon_channel_.reset(); |
| 278 | 257 |
| 279 #if defined(OS_MACOSX) || defined(OS_WIN) | 258 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 280 host_user_interface_.reset(); | 259 host_user_interface_.reset(); |
| 281 #endif | 260 #endif |
| 282 | 261 |
| 283 if (policy_watcher_.get()) { | 262 if (policy_watcher_.get()) { |
| 284 base::WaitableEvent done_event(true, false); | 263 base::WaitableEvent done_event(true, false); |
| 285 policy_watcher_->StopWatching(&done_event); | 264 policy_watcher_->StopWatching(&done_event); |
| 286 done_event.Wait(); | 265 done_event.Wait(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 302 } | 281 } |
| 303 | 282 |
| 304 private: | 283 private: |
| 305 void StartWatchingPolicy() { | 284 void StartWatchingPolicy() { |
| 306 policy_watcher_.reset( | 285 policy_watcher_.reset( |
| 307 policy_hack::PolicyWatcher::Create(context_->file_task_runner())); | 286 policy_hack::PolicyWatcher::Create(context_->file_task_runner())); |
| 308 policy_watcher_->StartWatching( | 287 policy_watcher_->StartWatching( |
| 309 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this))); | 288 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this))); |
| 310 } | 289 } |
| 311 | 290 |
| 312 // Read host config, returning true if successful. | 291 // Applies the host config, returning true if successful. |
| 313 bool LoadConfig() { | 292 bool ApplyConfig() { |
| 314 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 293 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 315 | 294 |
| 316 // TODO(sergeyu): There is a potential race condition: this function is | |
| 317 // called on the main thread while the class members it mutates are used on | |
| 318 // the network thread. Fix it. http://crbug.com/140986 . | |
| 319 | |
| 320 if (!config_.Read()) { | |
| 321 LOG(ERROR) << "Failed to read config file."; | |
| 322 return false; | |
| 323 } | |
| 324 | |
| 325 if (!config_.GetString(kHostIdConfigPath, &host_id_)) { | 295 if (!config_.GetString(kHostIdConfigPath, &host_id_)) { |
| 326 LOG(ERROR) << "host_id is not defined in the config."; | 296 LOG(ERROR) << "host_id is not defined in the config."; |
| 327 return false; | 297 return false; |
| 328 } | 298 } |
| 329 | 299 |
| 330 if (!key_pair_.Load(config_)) { | 300 if (!key_pair_.Load(config_)) { |
| 331 return false; | 301 return false; |
| 332 } | 302 } |
| 333 | 303 |
| 334 std::string host_secret_hash_string; | 304 std::string host_secret_hash_string; |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 context_->ui_task_runner()->PostTask( | 590 context_->ui_task_runner()->PostTask( |
| 621 FROM_HERE, | 591 FROM_HERE, |
| 622 base::Bind(&HostProcess::ShutdownHostProcess, | 592 base::Bind(&HostProcess::ShutdownHostProcess, |
| 623 base::Unretained(this))); | 593 base::Unretained(this))); |
| 624 } | 594 } |
| 625 | 595 |
| 626 scoped_ptr<ChromotingHostContext> context_; | 596 scoped_ptr<ChromotingHostContext> context_; |
| 627 scoped_ptr<IPC::ChannelProxy> daemon_channel_; | 597 scoped_ptr<IPC::ChannelProxy> daemon_channel_; |
| 628 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 598 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 629 | 599 |
| 600 JsonHostConfig config_; | |
| 601 #if !defined(REMOTING_MULTI_PROCESS) | |
| 630 FilePath host_config_path_; | 602 FilePath host_config_path_; |
| 631 CompositeHostConfig config_; | 603 scoped_ptr<ConfigFileWatcher> config_watcher_; |
| 604 #endif // !defined(REMOTING_MULTI_PROCESS) | |
| 632 | 605 |
| 633 std::string host_id_; | 606 std::string host_id_; |
| 634 HostKeyPair key_pair_; | 607 HostKeyPair key_pair_; |
| 635 protocol::SharedSecretHash host_secret_hash_; | 608 protocol::SharedSecretHash host_secret_hash_; |
| 636 std::string xmpp_login_; | 609 std::string xmpp_login_; |
| 637 std::string xmpp_auth_token_; | 610 std::string xmpp_auth_token_; |
| 638 std::string xmpp_auth_service_; | 611 std::string xmpp_auth_service_; |
| 639 | 612 |
| 640 std::string oauth_refresh_token_; | 613 std::string oauth_refresh_token_; |
| 641 bool oauth_use_official_client_id_; | 614 bool oauth_use_official_client_id_; |
| 642 | 615 |
| 643 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; | 616 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; |
| 644 bool allow_nat_traversal_; | 617 bool allow_nat_traversal_; |
| 645 scoped_ptr<base::files::FilePathWatcher> config_watcher_; | |
| 646 scoped_ptr<base::DelayTimer<HostProcess> > config_updated_timer_; | |
| 647 | 618 |
| 648 bool restarting_; | 619 bool restarting_; |
| 649 bool shutting_down_; | 620 bool shutting_down_; |
| 650 | 621 |
| 651 scoped_ptr<XmppSignalStrategy> signal_strategy_; | 622 scoped_ptr<XmppSignalStrategy> signal_strategy_; |
| 652 scoped_ptr<SignalingConnector> signaling_connector_; | 623 scoped_ptr<SignalingConnector> signaling_connector_; |
| 653 scoped_ptr<DesktopEnvironment> desktop_environment_; | 624 scoped_ptr<DesktopEnvironment> desktop_environment_; |
| 654 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 625 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
| 655 scoped_ptr<LogToServer> log_to_server_; | 626 scoped_ptr<LogToServer> log_to_server_; |
| 656 scoped_ptr<HostEventLogger> host_event_logger_; | 627 scoped_ptr<HostEventLogger> host_event_logger_; |
| 657 | 628 |
| 658 #if defined(OS_MACOSX) || defined(OS_WIN) | 629 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 659 scoped_ptr<HostUserInterface> host_user_interface_; | 630 scoped_ptr<HostUserInterface> host_user_interface_; |
| 660 #endif | 631 #endif |
| 661 | 632 |
| 662 scoped_refptr<ChromotingHost> host_; | 633 scoped_refptr<ChromotingHost> host_; |
| 663 | 634 |
| 664 int exit_code_; | 635 int exit_code_; |
| 665 | 636 |
| 666 #if defined(OS_MACOSX) | 637 #if defined(OS_MACOSX) |
| 667 remoting::CurtainMode curtain_; | 638 remoting::CurtainMode curtain_; |
| 668 #endif | 639 #endif |
| 640 | |
| 641 // WeakPtr used to avoid tasks accessing |this| after it is deleted. | |
| 642 base::WeakPtrFactory<HostProcess> weak_factory_; | |
| 669 }; | 643 }; |
| 670 | 644 |
| 671 } // namespace remoting | 645 } // namespace remoting |
| 672 | 646 |
| 673 int main(int argc, char** argv) { | 647 int main(int argc, char** argv) { |
| 674 #if defined(OS_MACOSX) | 648 #if defined(OS_MACOSX) |
| 675 // Needed so we don't leak objects when threads are created. | 649 // Needed so we don't leak objects when threads are created. |
| 676 base::mac::ScopedNSAutoreleasePool pool; | 650 base::mac::ScopedNSAutoreleasePool pool; |
| 677 #endif | 651 #endif |
| 678 | 652 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 716 MessageLoop message_loop(MessageLoop::TYPE_UI); | 690 MessageLoop message_loop(MessageLoop::TYPE_UI); |
| 717 base::Closure quit_message_loop = base::Bind(&QuitMessageLoop, | 691 base::Closure quit_message_loop = base::Bind(&QuitMessageLoop, |
| 718 base::Unretained(&message_loop)); | 692 base::Unretained(&message_loop)); |
| 719 scoped_ptr<remoting::ChromotingHostContext> context( | 693 scoped_ptr<remoting::ChromotingHostContext> context( |
| 720 new remoting::ChromotingHostContext( | 694 new remoting::ChromotingHostContext( |
| 721 new remoting::AutoMessageLoop(NULL, message_loop.message_loop_proxy(), | 695 new remoting::AutoMessageLoop(NULL, message_loop.message_loop_proxy(), |
| 722 quit_message_loop))); | 696 quit_message_loop))); |
| 723 if (!context->Start()) | 697 if (!context->Start()) |
| 724 return remoting::kHostInitializationFailed; | 698 return remoting::kHostInitializationFailed; |
| 725 | 699 |
| 726 // Create the host process instance and run the rest of the initialization on | 700 // Create the host process instance and enter the main message loop. |
| 727 // the main message loop. | |
| 728 remoting::HostProcess me2me_host(context.Pass()); | 701 remoting::HostProcess me2me_host(context.Pass()); |
|
Wez
2012/08/30 20:36:04
The HostProcess is created after |context|, so the
alexeypa (please no reviews)
2012/08/30 23:15:13
The ownership is transferred to HostProcess.
Wez
2012/08/31 00:23:04
Good point!
| |
| 729 message_loop.PostTask( | 702 me2me_host.StartHostProcess(); |
| 730 FROM_HERE, | |
| 731 base::Bind(&remoting::HostProcess::StartHostProcess, | |
| 732 base::Unretained(&me2me_host))); | |
| 733 return me2me_host.Run(&message_loop); | 703 return me2me_host.Run(&message_loop); |
| 734 } | 704 } |
| 735 | 705 |
| 736 #if defined(OS_WIN) | 706 #if defined(OS_WIN) |
| 737 HMODULE g_hModule = NULL; | 707 HMODULE g_hModule = NULL; |
| 738 | 708 |
| 739 int CALLBACK WinMain(HINSTANCE instance, | 709 int CALLBACK WinMain(HINSTANCE instance, |
| 740 HINSTANCE previous_instance, | 710 HINSTANCE previous_instance, |
| 741 LPSTR command_line, | 711 LPSTR command_line, |
| 742 int show_command) { | 712 int show_command) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 767 user32.GetFunctionPointer("SetProcessDPIAware")); | 737 user32.GetFunctionPointer("SetProcessDPIAware")); |
| 768 set_process_dpi_aware(); | 738 set_process_dpi_aware(); |
| 769 } | 739 } |
| 770 | 740 |
| 771 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 741 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
| 772 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 742 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
| 773 return main(0, NULL); | 743 return main(0, NULL); |
| 774 } | 744 } |
| 775 | 745 |
| 776 #endif // defined(OS_WIN) | 746 #endif // defined(OS_WIN) |
| OLD | NEW |