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" | 15 #include "base/files/file_path_watcher.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_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 "net/base/network_change_notifier.h" | 28 #include "net/base/network_change_notifier.h" |
28 #include "net/socket/ssl_server_socket.h" | 29 #include "net/socket/ssl_server_socket.h" |
29 #include "remoting/base/breakpad.h" | 30 #include "remoting/base/breakpad.h" |
30 #include "remoting/base/constants.h" | 31 #include "remoting/base/constants.h" |
31 #include "remoting/host/branding.h" | 32 #include "remoting/host/branding.h" |
32 #include "remoting/host/chromoting_host.h" | 33 #include "remoting/host/chromoting_host.h" |
33 #include "remoting/host/chromoting_host_context.h" | 34 #include "remoting/host/chromoting_host_context.h" |
34 #include "remoting/host/composite_host_config.h" | 35 #include "remoting/host/composite_host_config.h" |
35 #include "remoting/host/constants.h" | 36 #include "remoting/host/constants.h" |
36 #include "remoting/host/desktop_environment.h" | 37 #include "remoting/host/desktop_environment.h" |
(...skipping 24 matching lines...) Expand all Loading... |
61 #endif | 62 #endif |
62 #if defined(TOOLKIT_GTK) | 63 #if defined(TOOLKIT_GTK) |
63 #include "ui/gfx/gtk_util.h" | 64 #include "ui/gfx/gtk_util.h" |
64 #endif | 65 #endif |
65 | 66 |
66 namespace { | 67 namespace { |
67 | 68 |
68 // This is used for tagging system event logs. | 69 // This is used for tagging system event logs. |
69 const char kApplicationName[] = "chromoting"; | 70 const char kApplicationName[] = "chromoting"; |
70 | 71 |
| 72 // The command line switch specifying the name of the Chromoting IPC channel. |
| 73 const char kDaemonIpcSwitchName[] = "chromoting-ipc"; |
| 74 |
71 // These are used for parsing the config-file locations from the command line, | 75 // These are used for parsing the config-file locations from the command line, |
72 // and for defining the default locations if the switches are not present. | 76 // and for defining the default locations if the switches are not present. |
73 const char kAuthConfigSwitchName[] = "auth-config"; | 77 const char kAuthConfigSwitchName[] = "auth-config"; |
74 const char kHostConfigSwitchName[] = "host-config"; | 78 const char kHostConfigSwitchName[] = "host-config"; |
75 | 79 |
76 const FilePath::CharType kDefaultHostConfigFile[] = | 80 const FilePath::CharType kDefaultHostConfigFile[] = |
77 FILE_PATH_LITERAL("host.json"); | 81 FILE_PATH_LITERAL("host.json"); |
78 | 82 |
79 const int kMinPortNumber = 12400; | 83 const int kMinPortNumber = 12400; |
80 const int kMaxPortNumber = 12409; | 84 const int kMaxPortNumber = 12409; |
81 | 85 |
82 const char kUnofficialOAuth2ClientId[] = | 86 const char kUnofficialOAuth2ClientId[] = |
83 "440925447803-2pi3v45bff6tp1rde2f7q6lgbor3o5uj.apps.googleusercontent.com"; | 87 "440925447803-2pi3v45bff6tp1rde2f7q6lgbor3o5uj.apps.googleusercontent.com"; |
84 const char kUnofficialOAuth2ClientSecret[] = "W2ieEsG-R1gIA4MMurGrgMc_"; | 88 const char kUnofficialOAuth2ClientSecret[] = "W2ieEsG-R1gIA4MMurGrgMc_"; |
85 | 89 |
86 const char kOfficialOAuth2ClientId[] = | 90 const char kOfficialOAuth2ClientId[] = |
87 "440925447803-avn2sj1kc099s0r7v62je5s339mu0am1.apps.googleusercontent.com"; | 91 "440925447803-avn2sj1kc099s0r7v62je5s339mu0am1.apps.googleusercontent.com"; |
88 const char kOfficialOAuth2ClientSecret[] = "Bgur6DFiOMM1h8x-AQpuTQlK"; | 92 const char kOfficialOAuth2ClientSecret[] = "Bgur6DFiOMM1h8x-AQpuTQlK"; |
89 | 93 |
90 } // namespace | 94 } // namespace |
91 | 95 |
92 namespace remoting { | 96 namespace remoting { |
93 | 97 |
94 class HostProcess | 98 class HostProcess |
95 : public HeartbeatSender::Listener { | 99 : public HeartbeatSender::Listener, |
| 100 public IPC::Listener { |
96 public: | 101 public: |
97 HostProcess() | 102 HostProcess() |
98 : message_loop_(MessageLoop::TYPE_UI), | 103 : message_loop_(MessageLoop::TYPE_UI), |
99 #ifdef OFFICIAL_BUILD | 104 #ifdef OFFICIAL_BUILD |
100 oauth_use_official_client_id_(true), | 105 oauth_use_official_client_id_(true), |
101 #else | 106 #else |
102 oauth_use_official_client_id_(false), | 107 oauth_use_official_client_id_(false), |
103 #endif | 108 #endif |
104 allow_nat_traversal_(true), | 109 allow_nat_traversal_(true), |
105 restarting_(false), | 110 restarting_(false), |
106 shutting_down_(false), | 111 shutting_down_(false), |
107 exit_code_(kSuccessExitCode) | 112 exit_code_(kSuccessExitCode) |
108 #if defined(OS_MACOSX) | 113 #if defined(OS_MACOSX) |
109 , curtain_(base::Bind(&HostProcess::OnDisconnectRequested, | 114 , curtain_(base::Bind(&HostProcess::OnDisconnectRequested, |
110 base::Unretained(this)), | 115 base::Unretained(this)), |
111 base::Bind(&HostProcess::OnDisconnectRequested, | 116 base::Bind(&HostProcess::OnDisconnectRequested, |
112 base::Unretained(this))) | 117 base::Unretained(this))) |
113 #endif | 118 #endif |
114 { | 119 { |
115 context_.reset( | 120 context_.reset( |
116 new ChromotingHostContext(message_loop_.message_loop_proxy())); | 121 new ChromotingHostContext(message_loop_.message_loop_proxy())); |
117 context_->Start(); | 122 context_->Start(); |
118 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 123 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
119 config_updated_timer_.reset(new base::DelayTimer<HostProcess>( | 124 config_updated_timer_.reset(new base::DelayTimer<HostProcess>( |
120 FROM_HERE, base::TimeDelta::FromSeconds(2), this, | 125 FROM_HERE, base::TimeDelta::FromSeconds(2), this, |
121 &HostProcess::ConfigUpdatedDelayed)); | 126 &HostProcess::ConfigUpdatedDelayed)); |
122 } | 127 } |
123 | 128 |
124 bool InitWithCommandLine(const CommandLine* cmd_line) { | 129 bool InitWithCommandLine(const CommandLine* cmd_line) { |
| 130 // Connect to the daemon process. |
| 131 std::string channel_name = |
| 132 cmd_line->GetSwitchValueASCII(kDaemonIpcSwitchName); |
| 133 |
| 134 #if defined(REMOTING_MULTI_PROCESS) |
| 135 if (channel_name.empty()) |
| 136 return false; |
| 137 #endif // defined(REMOTING_MULTI_PROCESS) |
| 138 |
| 139 if (!channel_name.empty()) |
| 140 context_->ConnectToDaemon(channel_name, this); |
| 141 |
125 FilePath default_config_dir = remoting::GetConfigDir(); | 142 FilePath default_config_dir = remoting::GetConfigDir(); |
126 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) { | 143 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) { |
127 FilePath path = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName); | 144 FilePath path = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName); |
128 config_.AddConfigPath(path); | 145 config_.AddConfigPath(path); |
129 } | 146 } |
130 | 147 |
131 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); | 148 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); |
132 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { | 149 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { |
133 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); | 150 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); |
134 } | 151 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 222 |
206 void CreateAuthenticatorFactory() { | 223 void CreateAuthenticatorFactory() { |
207 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 224 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
208 scoped_ptr<protocol::AuthenticatorFactory> factory( | 225 scoped_ptr<protocol::AuthenticatorFactory> factory( |
209 new protocol::Me2MeHostAuthenticatorFactory( | 226 new protocol::Me2MeHostAuthenticatorFactory( |
210 key_pair_.GenerateCertificate(), | 227 key_pair_.GenerateCertificate(), |
211 *key_pair_.private_key(), host_secret_hash_)); | 228 *key_pair_.private_key(), host_secret_hash_)); |
212 host_->SetAuthenticatorFactory(factory.Pass()); | 229 host_->SetAuthenticatorFactory(factory.Pass()); |
213 } | 230 } |
214 | 231 |
| 232 // IPC::Listener implementation. |
| 233 virtual bool OnMessageReceived(const IPC::Message& message) { |
| 234 return false; |
| 235 } |
| 236 |
215 int Run() { | 237 int Run() { |
216 if (!LoadConfig()) { | 238 if (!LoadConfig()) { |
217 return kInvalidHostConfigurationExitCode; | 239 return kInvalidHostConfigurationExitCode; |
218 } | 240 } |
219 | 241 |
220 #if defined(OS_MACOSX) || defined(OS_WIN) | 242 #if defined(OS_MACOSX) || defined(OS_WIN) |
221 host_user_interface_.reset(new HostUserInterface(context_.get())); | 243 host_user_interface_.reset(new HostUserInterface(context_.get())); |
222 #endif | 244 #endif |
223 | 245 |
224 StartWatchingPolicy(); | 246 StartWatchingPolicy(); |
225 | 247 |
226 #if defined(OS_MACOSX) || defined(OS_WIN) | 248 #if defined(OS_MACOSX) || defined(OS_WIN) |
227 context_->file_task_runner()->PostTask( | 249 context_->file_task_runner()->PostTask( |
228 FROM_HERE, | 250 FROM_HERE, |
229 base::Bind(&HostProcess::ListenForConfigChanges, | 251 base::Bind(&HostProcess::ListenForConfigChanges, |
230 base::Unretained(this))); | 252 base::Unretained(this))); |
231 #endif | 253 #endif |
232 message_loop_.Run(); | 254 message_loop_.Run(); |
233 | 255 |
234 #if defined(OS_MACOSX) || defined(OS_WIN) | 256 #if defined(OS_MACOSX) || defined(OS_WIN) |
235 host_user_interface_.reset(); | 257 host_user_interface_.reset(); |
236 #endif | 258 #endif |
237 | 259 |
| 260 context_->DisconnectFromDaemon(); |
238 base::WaitableEvent done_event(true, false); | 261 base::WaitableEvent done_event(true, false); |
239 policy_watcher_->StopWatching(&done_event); | 262 policy_watcher_->StopWatching(&done_event); |
240 done_event.Wait(); | 263 done_event.Wait(); |
241 policy_watcher_.reset(); | 264 policy_watcher_.reset(); |
242 | 265 |
243 return exit_code_; | 266 return exit_code_; |
244 } | 267 } |
245 | 268 |
246 // Overridden from HeartbeatSender::Listener | 269 // Overridden from HeartbeatSender::Listener |
247 virtual void OnUnknownHostIdError() OVERRIDE { | 270 virtual void OnUnknownHostIdError() OVERRIDE { |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 user32.GetFunctionPointer("SetProcessDPIAware")); | 721 user32.GetFunctionPointer("SetProcessDPIAware")); |
699 set_process_dpi_aware(); | 722 set_process_dpi_aware(); |
700 } | 723 } |
701 | 724 |
702 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 725 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
703 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 726 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
704 return main(0, NULL); | 727 return main(0, NULL); |
705 } | 728 } |
706 | 729 |
707 #endif // defined(OS_WIN) | 730 #endif // defined(OS_WIN) |
OLD | NEW |