Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(734)

Side by Side Diff: remoting/host/remoting_me2me_host.cc

Issue 10905081: Pass Me2Me config via stdin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Improved variable names. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "remoting/host/log_to_server.h" 47 #include "remoting/host/log_to_server.h"
48 #include "remoting/host/network_settings.h" 48 #include "remoting/host/network_settings.h"
49 #include "remoting/host/policy_hack/policy_watcher.h" 49 #include "remoting/host/policy_hack/policy_watcher.h"
50 #include "remoting/host/session_manager_factory.h" 50 #include "remoting/host/session_manager_factory.h"
51 #include "remoting/host/signaling_connector.h" 51 #include "remoting/host/signaling_connector.h"
52 #include "remoting/host/usage_stats_consent.h" 52 #include "remoting/host/usage_stats_consent.h"
53 #include "remoting/host/video_frame_capturer.h" 53 #include "remoting/host/video_frame_capturer.h"
54 #include "remoting/jingle_glue/xmpp_signal_strategy.h" 54 #include "remoting/jingle_glue/xmpp_signal_strategy.h"
55 #include "remoting/protocol/me2me_host_authenticator_factory.h" 55 #include "remoting/protocol/me2me_host_authenticator_factory.h"
56 56
57 #if defined(OS_POSIX)
58 #include <signal.h>
59 #include "remoting/host/posix/signal_handler.h"
60 #endif // defined(OS_POSIX)
61
57 #if defined(OS_MACOSX) 62 #if defined(OS_MACOSX)
58 #include "base/mac/scoped_cftyperef.h" 63 #include "base/mac/scoped_cftyperef.h"
59 #include "base/mac/scoped_nsautorelease_pool.h" 64 #include "base/mac/scoped_nsautorelease_pool.h"
60 #include "remoting/host/curtain_mode_mac.h" 65 #include "remoting/host/curtain_mode_mac.h"
61 #endif // defined(OS_MACOSX) 66 #endif // defined(OS_MACOSX)
62 67
63 #if defined(OS_POSIX) 68 #if defined(OS_POSIX)
64 #include <signal.h> 69 #include <signal.h>
65 #endif // defined(OS_POSIX) 70 #endif // defined(OS_POSIX)
66 71
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 FilePath default_config_dir = remoting::GetConfigDir(); 149 FilePath default_config_dir = remoting::GetConfigDir();
145 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); 150 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile);
146 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { 151 if (cmd_line->HasSwitch(kHostConfigSwitchName)) {
147 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); 152 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName);
148 } 153 }
149 #endif // !defined(REMOTING_MULTI_PROCESS) 154 #endif // !defined(REMOTING_MULTI_PROCESS)
150 155
151 return true; 156 return true;
152 } 157 }
153 158
159 #if defined(OS_POSIX)
160 void SigTermHandler(int signal_number) {
161 DCHECK(signal_number == SIGTERM);
162 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
163 LOG(INFO) << "Caught SIGTERM: Shutting down...";
164 Shutdown(kSuccessExitCode);
165 }
166 #endif
167
154 virtual void OnConfigUpdated(const std::string& serialized_config) OVERRIDE { 168 virtual void OnConfigUpdated(const std::string& serialized_config) OVERRIDE {
155 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); 169 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
156 170
157 LOG(INFO) << "Processing new host configuration."; 171 LOG(INFO) << "Processing new host configuration.";
158 172
159 if (!config_.SetSerializedData(serialized_config)) { 173 if (!config_.SetSerializedData(serialized_config)) {
160 LOG(ERROR) << "Invalid configuration."; 174 LOG(ERROR) << "Invalid configuration.";
161 OnConfigWatcherError(); 175 OnConfigWatcherError();
162 return; 176 return;
163 } 177 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 FROM_HERE, 224 FROM_HERE,
211 base::Bind(&HostProcess::Shutdown, base::Unretained(this), 225 base::Bind(&HostProcess::Shutdown, base::Unretained(this),
212 kInvalidHostConfigurationExitCode)); 226 kInvalidHostConfigurationExitCode));
213 } 227 }
214 228
215 void StartWatchingConfigChanges() { 229 void StartWatchingConfigChanges() {
216 #if !defined(REMOTING_MULTI_PROCESS) 230 #if !defined(REMOTING_MULTI_PROCESS)
217 231
218 #if defined(OS_POSIX) 232 #if defined(OS_POSIX)
219 // Ignore SIGHUP sent by the daemon controller since we use 233 // Ignore SIGHUP sent by the daemon controller since we use
220 // |ConfigFileWatcher| instead. 234 // |ConfigFileWatcher| on Mac and Windows and read the config
235 // from stdin on UNIX.
221 signal(SIGHUP, SIG_IGN); 236 signal(SIGHUP, SIG_IGN);
222 #endif // defined(OS_POSIX) 237 #endif // defined(OS_POSIX)
223 238
224 // Start watching the host configuration file. 239 // Start watching the host configuration file.
225 config_watcher_.reset(new ConfigFileWatcher(context_->ui_task_runner(), 240 config_watcher_.reset(new ConfigFileWatcher(context_->ui_task_runner(),
226 context_->file_task_runner(), 241 context_->file_task_runner(),
227 this)); 242 this));
228 config_watcher_->Watch(host_config_path_); 243 config_watcher_->Watch(host_config_path_);
229 #endif // !defined(REMOTING_MULTI_PROCESS) 244 #endif // !defined(REMOTING_MULTI_PROCESS)
230 } 245 }
231 246
247 #if defined(OS_POSIX)
248 void ListenForShutdownSignal() {
249 remoting::RegisterSignalHandler(
250 SIGTERM,
251 base::Bind(&HostProcess::SigTermHandler, base::Unretained(this)));
252 }
253 #endif // OS_POSIX
254
232 void CreateAuthenticatorFactory() { 255 void CreateAuthenticatorFactory() {
233 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); 256 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
234 scoped_ptr<protocol::AuthenticatorFactory> factory( 257 scoped_ptr<protocol::AuthenticatorFactory> factory(
235 new protocol::Me2MeHostAuthenticatorFactory( 258 new protocol::Me2MeHostAuthenticatorFactory(
236 key_pair_.GenerateCertificate(), 259 key_pair_.GenerateCertificate(),
237 *key_pair_.private_key(), host_secret_hash_)); 260 *key_pair_.private_key(), host_secret_hash_));
238 host_->SetAuthenticatorFactory(factory.Pass()); 261 host_->SetAuthenticatorFactory(factory.Pass());
239 } 262 }
240 263
241 // IPC::Listener implementation. 264 // IPC::Listener implementation.
(...skipping 14 matching lines...) Expand all
256 } 279 }
257 280
258 void StartHostProcess() { 281 void StartHostProcess() {
259 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); 282 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
260 283
261 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) { 284 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) {
262 OnConfigWatcherError(); 285 OnConfigWatcherError();
263 return; 286 return;
264 } 287 }
265 288
289 #if defined(OS_POSIX)
290 context_->network_task_runner()->PostTask(
291 FROM_HERE,
292 base::Bind(&HostProcess::ListenForShutdownSignal,
alexeypa (please no reviews) 2012/09/06 18:21:10 nit: You can bind to remoting::RegisterSignalHandl
293 base::Unretained(this)));
294 #endif // OS_POSIX
295
266 StartWatchingConfigChanges(); 296 StartWatchingConfigChanges();
267 } 297 }
268 298
269 int get_exit_code() const { return exit_code_; } 299 int get_exit_code() const { return exit_code_; }
270 300
271 private: 301 private:
272 void ShutdownHostProcess() { 302 void ShutdownHostProcess() {
273 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); 303 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
274 304
275 #if !defined(REMOTING_MULTI_PROCESS) 305 #if !defined(REMOTING_MULTI_PROCESS)
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 user32.GetFunctionPointer("SetProcessDPIAware")); 809 user32.GetFunctionPointer("SetProcessDPIAware"));
780 set_process_dpi_aware(); 810 set_process_dpi_aware();
781 } 811 }
782 812
783 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting 813 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting
784 // the command line from GetCommandLineW(), so we can safely pass NULL here. 814 // the command line from GetCommandLineW(), so we can safely pass NULL here.
785 return main(0, NULL); 815 return main(0, NULL);
786 } 816 }
787 817
788 #endif // defined(OS_WIN) 818 #endif // defined(OS_WIN)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698