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, which is currently | 5 // This file implements a standalone host process for Me2Me, which is currently |
6 // used for the Linux-only Virtual Me2Me build. | 6 // used for the Linux-only Virtual Me2Me build. |
7 | 7 |
8 #if defined(OS_WIN) | |
9 #include <windows.h> | |
10 #endif | |
11 | |
8 #include <string> | 12 #include <string> |
9 | 13 |
10 #include "base/at_exit.h" | 14 #include "base/at_exit.h" |
11 #include "base/bind.h" | 15 #include "base/bind.h" |
12 #include "base/callback.h" | 16 #include "base/callback.h" |
13 #include "base/command_line.h" | 17 #include "base/command_line.h" |
14 #include "base/file_path.h" | 18 #include "base/file_path.h" |
15 #include "base/file_util.h" | 19 #include "base/file_util.h" |
16 #include "base/logging.h" | 20 #include "base/logging.h" |
17 #include "base/message_loop.h" | 21 #include "base/message_loop.h" |
22 #include "base/path_service.h" | |
Jamie
2012/03/01 18:22:32
If this is only needed on Windows, it should proba
alexeypa (please no reviews)
2012/03/01 20:33:58
base/path_service.h is a cross-platfporm header. #
Jamie
2012/03/01 20:59:09
I guess the question is why are we using it in a p
| |
18 #include "base/threading/thread.h" | 23 #include "base/threading/thread.h" |
19 #include "build/build_config.h" | 24 #include "build/build_config.h" |
20 #include "crypto/nss_util.h" | 25 #include "crypto/nss_util.h" |
21 #include "net/base/network_change_notifier.h" | 26 #include "net/base/network_change_notifier.h" |
22 #include "remoting/base/constants.h" | 27 #include "remoting/base/constants.h" |
23 #include "remoting/host/capturer.h" | 28 #include "remoting/host/capturer.h" |
24 #include "remoting/host/chromoting_host.h" | 29 #include "remoting/host/chromoting_host.h" |
25 #include "remoting/host/chromoting_host_context.h" | 30 #include "remoting/host/chromoting_host_context.h" |
26 #include "remoting/host/desktop_environment.h" | 31 #include "remoting/host/desktop_environment.h" |
27 #include "remoting/host/event_executor.h" | 32 #include "remoting/host/event_executor.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 context_(message_loop_.message_loop_proxy()), | 76 context_(message_loop_.message_loop_proxy()), |
72 allow_nat_traversal_(true), | 77 allow_nat_traversal_(true), |
73 restarting_(false) { | 78 restarting_(false) { |
74 context_.Start(); | 79 context_.Start(); |
75 file_io_thread_.StartWithOptions( | 80 file_io_thread_.StartWithOptions( |
76 base::Thread::Options(MessageLoop::TYPE_IO, 0)); | 81 base::Thread::Options(MessageLoop::TYPE_IO, 0)); |
77 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 82 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
78 } | 83 } |
79 | 84 |
80 void InitWithCommandLine(const CommandLine* cmd_line) { | 85 void InitWithCommandLine(const CommandLine* cmd_line) { |
81 FilePath default_config_dir = | 86 FilePath default_config_dir; |
82 file_util::GetHomeDir().Append(kDefaultConfigDir); | 87 |
88 #if defined(OS_WIN) | |
89 PathService::Get(base::DIR_PROFILE, &default_config_dir); | |
90 #else | |
91 default_config_dir = file_util::GetHomeDir(); | |
92 #endif | |
93 | |
94 default_config_dir = default_config_dir.Append(kDefaultConfigDir); | |
Wez
2012/03/01 18:03:06
nit: Fold the |default_config_dir| logic into a st
alexeypa (please no reviews)
2012/03/01 20:33:58
Done.
| |
83 | 95 |
84 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) { | 96 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) { |
85 auth_config_path_ = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName); | 97 auth_config_path_ = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName); |
86 } else { | 98 } else { |
87 auth_config_path_ = default_config_dir.Append(kDefaultAuthConfigFile); | 99 auth_config_path_ = default_config_dir.Append(kDefaultAuthConfigFile); |
88 } | 100 } |
89 | 101 |
90 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { | 102 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { |
91 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); | 103 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); |
92 } else { | 104 } else { |
(...skipping 21 matching lines...) Expand all Loading... | |
114 } | 126 } |
115 | 127 |
116 private: | 128 private: |
117 // Read Host config from disk, returning true if successful. | 129 // Read Host config from disk, returning true if successful. |
118 bool LoadConfig(base::MessageLoopProxy* io_message_loop) { | 130 bool LoadConfig(base::MessageLoopProxy* io_message_loop) { |
119 scoped_refptr<JsonHostConfig> host_config = | 131 scoped_refptr<JsonHostConfig> host_config = |
120 new JsonHostConfig(host_config_path_, io_message_loop); | 132 new JsonHostConfig(host_config_path_, io_message_loop); |
121 scoped_refptr<JsonHostConfig> auth_config = | 133 scoped_refptr<JsonHostConfig> auth_config = |
122 new JsonHostConfig(auth_config_path_, io_message_loop); | 134 new JsonHostConfig(auth_config_path_, io_message_loop); |
123 | 135 |
124 std::string failed_path; | 136 FilePath failed_path; |
125 if (!host_config->Read()) { | 137 if (!host_config->Read()) { |
126 failed_path = host_config_path_.value(); | 138 failed_path = host_config_path_; |
127 } else if (!auth_config->Read()) { | 139 } else if (!auth_config->Read()) { |
128 failed_path = auth_config_path_.value(); | 140 failed_path = auth_config_path_; |
129 } | 141 } |
130 if (!failed_path.empty()) { | 142 if (!failed_path.empty()) { |
131 LOG(ERROR) << "Failed to read configuration file " << failed_path; | 143 LOG(ERROR) << "Failed to read configuration file " << failed_path.value(); |
132 return false; | 144 return false; |
133 } | 145 } |
134 | 146 |
135 if (!host_config->GetString(kHostIdConfigPath, &host_id_)) { | 147 if (!host_config->GetString(kHostIdConfigPath, &host_id_)) { |
136 LOG(ERROR) << "host_id is not defined in the config."; | 148 LOG(ERROR) << "host_id is not defined in the config."; |
137 return false; | 149 return false; |
138 } | 150 } |
139 | 151 |
140 if (!key_pair_.Load(host_config)) { | 152 if (!key_pair_.Load(host_config)) { |
141 return false; | 153 return false; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 | 229 |
218 host_ = new ChromotingHost( | 230 host_ = new ChromotingHost( |
219 &context_, signal_strategy_.get(), desktop_environment_.get(), | 231 &context_, signal_strategy_.get(), desktop_environment_.get(), |
220 network_settings); | 232 network_settings); |
221 | 233 |
222 heartbeat_sender_.reset( | 234 heartbeat_sender_.reset( |
223 new HeartbeatSender(host_id_, signal_strategy_.get(), &key_pair_)); | 235 new HeartbeatSender(host_id_, signal_strategy_.get(), &key_pair_)); |
224 | 236 |
225 log_to_server_.reset( | 237 log_to_server_.reset( |
226 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); | 238 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); |
227 host_event_logger_.reset(new HostEventLogger(host_, kApplicationName)); | 239 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); |
228 | 240 |
229 host_->Start(); | 241 host_->Start(); |
230 | 242 |
231 // Create authenticator factory. | 243 // Create authenticator factory. |
232 scoped_ptr<protocol::AuthenticatorFactory> factory( | 244 scoped_ptr<protocol::AuthenticatorFactory> factory( |
233 new protocol::Me2MeHostAuthenticatorFactory( | 245 new protocol::Me2MeHostAuthenticatorFactory( |
234 xmpp_login_, key_pair_.GenerateCertificate(), | 246 xmpp_login_, key_pair_.GenerateCertificate(), |
235 *key_pair_.private_key(), host_secret_hash_)); | 247 *key_pair_.private_key(), host_secret_hash_)); |
236 host_->SetAuthenticatorFactory(factory.Pass()); | 248 host_->SetAuthenticatorFactory(factory.Pass()); |
237 } | 249 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 // Continue windows, though these should not be used for the Me2Me case | 317 // Continue windows, though these should not be used for the Me2Me case |
306 // (crbug.com/104377). | 318 // (crbug.com/104377). |
307 gfx::GtkInitFromCommandLine(*cmd_line); | 319 gfx::GtkInitFromCommandLine(*cmd_line); |
308 #endif // TOOLKIT_USES_GTK | 320 #endif // TOOLKIT_USES_GTK |
309 | 321 |
310 remoting::HostProcess me2me_host; | 322 remoting::HostProcess me2me_host; |
311 me2me_host.InitWithCommandLine(cmd_line); | 323 me2me_host.InitWithCommandLine(cmd_line); |
312 | 324 |
313 return me2me_host.Run(); | 325 return me2me_host.Run(); |
314 } | 326 } |
327 | |
328 #if defined(OS_WIN) | |
329 | |
330 int CALLBACK WinMain(HINSTANCE instance, | |
331 HINSTANCE previous_instance, | |
332 LPSTR command_line, | |
333 int show_command) { | |
334 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | |
335 // the command line from GetCommandLineW(). | |
Wez
2012/03/01 18:03:06
nit: At a first glance, it's not clear whether you
alexeypa (please no reviews)
2012/03/01 20:33:58
Done.
| |
336 return main(0, NULL); | |
337 } | |
338 | |
339 #endif | |
OLD | NEW |