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

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

Issue 10855249: [Chromoting] The daemon process now starts the networking process and passes the host configuration… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added missing signal.h 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
« no previous file with comments | « remoting/host/me2me_preference_pane.mm ('k') | remoting/host/win/host_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
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"
18 #include "base/message_loop.h" 17 #include "base/message_loop.h"
19 #include "base/scoped_native_library.h" 18 #include "base/scoped_native_library.h"
20 #include "base/string_util.h" 19 #include "base/string_util.h"
21 #include "base/synchronization/waitable_event.h" 20 #include "base/synchronization/waitable_event.h"
22 #include "base/threading/thread.h" 21 #include "base/threading/thread.h"
23 #include "base/utf_string_conversions.h" 22 #include "base/utf_string_conversions.h"
24 #include "base/win/windows_version.h" 23 #include "base/win/windows_version.h"
25 #include "build/build_config.h" 24 #include "build/build_config.h"
26 #include "crypto/nss_util.h" 25 #include "crypto/nss_util.h"
27 #include "ipc/ipc_channel.h" 26 #include "ipc/ipc_channel.h"
28 #include "ipc/ipc_channel_proxy.h" 27 #include "ipc/ipc_channel_proxy.h"
29 #include "net/base/network_change_notifier.h" 28 #include "net/base/network_change_notifier.h"
30 #include "net/socket/ssl_server_socket.h" 29 #include "net/socket/ssl_server_socket.h"
31 #include "remoting/base/auto_thread_task_runner.h" 30 #include "remoting/base/auto_thread_task_runner.h"
32 #include "remoting/base/breakpad.h" 31 #include "remoting/base/breakpad.h"
33 #include "remoting/base/constants.h" 32 #include "remoting/base/constants.h"
34 #include "remoting/host/branding.h" 33 #include "remoting/host/branding.h"
35 #include "remoting/host/chromoting_host.h" 34 #include "remoting/host/chromoting_host.h"
36 #include "remoting/host/chromoting_host_context.h" 35 #include "remoting/host/chromoting_host_context.h"
37 #include "remoting/host/composite_host_config.h" 36 #include "remoting/host/chromoting_messages.h"
38 #include "remoting/host/constants.h" 37 #include "remoting/host/constants.h"
38 #include "remoting/host/config_file_watcher.h"
39 #include "remoting/host/desktop_environment.h" 39 #include "remoting/host/desktop_environment.h"
40 #include "remoting/host/dns_blackhole_checker.h" 40 #include "remoting/host/dns_blackhole_checker.h"
41 #include "remoting/host/event_executor.h" 41 #include "remoting/host/event_executor.h"
42 #include "remoting/host/heartbeat_sender.h" 42 #include "remoting/host/heartbeat_sender.h"
43 #include "remoting/host/host_config.h" 43 #include "remoting/host/host_config.h"
44 #include "remoting/host/host_event_logger.h" 44 #include "remoting/host/host_event_logger.h"
45 #include "remoting/host/host_user_interface.h" 45 #include "remoting/host/host_user_interface.h"
46 #include "remoting/host/json_host_config.h"
46 #include "remoting/host/log_to_server.h" 47 #include "remoting/host/log_to_server.h"
47 #include "remoting/host/network_settings.h" 48 #include "remoting/host/network_settings.h"
48 #include "remoting/host/policy_hack/policy_watcher.h" 49 #include "remoting/host/policy_hack/policy_watcher.h"
49 #include "remoting/host/session_manager_factory.h" 50 #include "remoting/host/session_manager_factory.h"
50 #include "remoting/host/signaling_connector.h" 51 #include "remoting/host/signaling_connector.h"
51 #include "remoting/host/usage_stats_consent.h" 52 #include "remoting/host/usage_stats_consent.h"
52 #include "remoting/host/video_frame_capturer.h" 53 #include "remoting/host/video_frame_capturer.h"
53 #include "remoting/jingle_glue/xmpp_signal_strategy.h" 54 #include "remoting/jingle_glue/xmpp_signal_strategy.h"
54 #include "remoting/protocol/me2me_host_authenticator_factory.h" 55 #include "remoting/protocol/me2me_host_authenticator_factory.h"
55 56
56 #if defined(OS_POSIX)
57 #include "remoting/host/posix/sighup_listener.h"
58 #endif // defined(OS_POSIX)
59
60 #if defined(OS_MACOSX) 57 #if defined(OS_MACOSX)
61 #include "base/mac/scoped_cftyperef.h" 58 #include "base/mac/scoped_cftyperef.h"
62 #include "base/mac/scoped_nsautorelease_pool.h" 59 #include "base/mac/scoped_nsautorelease_pool.h"
63 #include "remoting/host/curtain_mode_mac.h" 60 #include "remoting/host/curtain_mode_mac.h"
64 #endif // defined(OS_MACOSX) 61 #endif // defined(OS_MACOSX)
65 62
63 #if defined(OS_POSIX)
64 #include <signal.h>
65 #endif // defined(OS_POSIX)
66
66 // N.B. OS_WIN is defined by including src/base headers. 67 // N.B. OS_WIN is defined by including src/base headers.
67 #if defined(OS_WIN) 68 #if defined(OS_WIN)
68 #include <commctrl.h> 69 #include <commctrl.h>
69 #endif // defined(OS_WIN) 70 #endif // defined(OS_WIN)
70 71
71 #if defined(TOOLKIT_GTK) 72 #if defined(TOOLKIT_GTK)
72 #include "ui/gfx/gtk_util.h" 73 #include "ui/gfx/gtk_util.h"
73 #endif // defined(TOOLKIT_GTK) 74 #endif // defined(TOOLKIT_GTK)
74 75
75 namespace { 76 namespace {
76 77
77 // This is used for tagging system event logs. 78 // This is used for tagging system event logs.
78 const char kApplicationName[] = "chromoting"; 79 const char kApplicationName[] = "chromoting";
79 80
80 // The command line switch specifying the name of the Chromoting IPC channel. 81 // The command line switch specifying the name of the daemon IPC endpoint.
81 const char kDaemonIpcSwitchName[] = "chromoting-ipc"; 82 const char kDaemonIpcSwitchName[] = "daemon-pipe";
82
83 // These are used for parsing the config-file locations from the command line,
84 // and for defining the default locations if the switches are not present.
85 const char kAuthConfigSwitchName[] = "auth-config";
86 const char kHostConfigSwitchName[] = "host-config";
87
88 const FilePath::CharType kDefaultHostConfigFile[] =
89 FILE_PATH_LITERAL("host.json");
90 83
91 const char kUnofficialOAuth2ClientId[] = 84 const char kUnofficialOAuth2ClientId[] =
92 "440925447803-2pi3v45bff6tp1rde2f7q6lgbor3o5uj.apps.googleusercontent.com"; 85 "440925447803-2pi3v45bff6tp1rde2f7q6lgbor3o5uj.apps.googleusercontent.com";
93 const char kUnofficialOAuth2ClientSecret[] = "W2ieEsG-R1gIA4MMurGrgMc_"; 86 const char kUnofficialOAuth2ClientSecret[] = "W2ieEsG-R1gIA4MMurGrgMc_";
94 87
95 const char kOfficialOAuth2ClientId[] = 88 const char kOfficialOAuth2ClientId[] =
96 "440925447803-avn2sj1kc099s0r7v62je5s339mu0am1.apps.googleusercontent.com"; 89 "440925447803-avn2sj1kc099s0r7v62je5s339mu0am1.apps.googleusercontent.com";
97 const char kOfficialOAuth2ClientSecret[] = "Bgur6DFiOMM1h8x-AQpuTQlK"; 90 const char kOfficialOAuth2ClientSecret[] = "Bgur6DFiOMM1h8x-AQpuTQlK";
98 91
99 void QuitMessageLoop(MessageLoop* message_loop) { 92 void QuitMessageLoop(MessageLoop* message_loop) {
100 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 93 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure());
101 } 94 }
102 95
103 } // namespace 96 } // namespace
104 97
105 namespace remoting { 98 namespace remoting {
106 99
107 class HostProcess 100 class HostProcess
108 : public HeartbeatSender::Listener, 101 : public HeartbeatSender::Listener,
109 public IPC::Listener { 102 public IPC::Listener,
103 public ConfigFileWatcher::Delegate {
110 public: 104 public:
111 HostProcess(scoped_ptr<ChromotingHostContext> context) 105 HostProcess(scoped_ptr<ChromotingHostContext> context)
112 : context_(context.Pass()), 106 : context_(context.Pass()),
107 config_(FilePath()),
113 #ifdef OFFICIAL_BUILD 108 #ifdef OFFICIAL_BUILD
114 oauth_use_official_client_id_(true), 109 oauth_use_official_client_id_(true),
115 #else 110 #else
116 oauth_use_official_client_id_(false), 111 oauth_use_official_client_id_(false),
117 #endif 112 #endif
118 allow_nat_traversal_(true), 113 allow_nat_traversal_(true),
119 restarting_(false), 114 restarting_(false),
120 shutting_down_(false), 115 shutting_down_(false),
121 exit_code_(kSuccessExitCode) 116 exit_code_(kSuccessExitCode)
122 #if defined(OS_MACOSX) 117 #if defined(OS_MACOSX)
123 , curtain_(base::Bind(&HostProcess::OnDisconnectRequested, 118 , curtain_(base::Bind(&HostProcess::OnDisconnectRequested,
124 base::Unretained(this)), 119 base::Unretained(this)),
125 base::Bind(&HostProcess::OnDisconnectRequested, 120 base::Bind(&HostProcess::OnDisconnectRequested,
126 base::Unretained(this))) 121 base::Unretained(this)))
127 #endif 122 #endif
128 { 123 {
129 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); 124 network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
130 config_updated_timer_.reset(new base::DelayTimer<HostProcess>(
131 FROM_HERE, base::TimeDelta::FromSeconds(2), this,
132 &HostProcess::ConfigUpdatedDelayed));
133 } 125 }
134 126
135 bool InitWithCommandLine(const CommandLine* cmd_line) { 127 bool InitWithCommandLine(const CommandLine* cmd_line) {
136 // Connect to the daemon process. 128 // Connect to the daemon process.
137 std::string channel_name = 129 std::string channel_name =
138 cmd_line->GetSwitchValueASCII(kDaemonIpcSwitchName); 130 cmd_line->GetSwitchValueASCII(kDaemonIpcSwitchName);
139 131
140 #if defined(REMOTING_MULTI_PROCESS) 132 #if defined(REMOTING_MULTI_PROCESS)
141 if (channel_name.empty()) 133 if (channel_name.empty())
142 return false; 134 return false;
143 #endif // defined(REMOTING_MULTI_PROCESS) 135 #endif // defined(REMOTING_MULTI_PROCESS)
144 136
145 if (!channel_name.empty()) { 137 if (!channel_name.empty()) {
146 daemon_channel_.reset(new IPC::ChannelProxy( 138 daemon_channel_.reset(new IPC::ChannelProxy(
147 channel_name, IPC::Channel::MODE_CLIENT, this, 139 channel_name, IPC::Channel::MODE_CLIENT, this,
148 context_->network_task_runner())); 140 context_->network_task_runner()));
149 } 141 }
150 142
143 #if !defined(REMOTING_MULTI_PROCESS)
151 FilePath default_config_dir = remoting::GetConfigDir(); 144 FilePath default_config_dir = remoting::GetConfigDir();
152 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) {
153 FilePath path = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName);
154 config_.AddConfigPath(path);
155 }
156
157 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); 145 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile);
158 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { 146 if (cmd_line->HasSwitch(kHostConfigSwitchName)) {
159 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); 147 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName);
160 } 148 }
161 config_.AddConfigPath(host_config_path_); 149 #endif // !defined(REMOTING_MULTI_PROCESS)
162 150
163 return true; 151 return true;
164 } 152 }
165 153
166 void ConfigUpdated() { 154 virtual void OnConfigUpdated(const std::string& serialized_config) OVERRIDE {
167 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); 155 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
168 156
169 // Call ConfigUpdatedDelayed after a short delay, so that this object won't 157 LOG(INFO) << "Processing new host configuration.";
170 // try to read the updated configuration file before it has been
171 // completely written.
172 // If the writer moves the new configuration file into place atomically,
173 // this delay may not be necessary.
174 config_updated_timer_->Reset();
175 }
176 158
177 void ConfigUpdatedDelayed() { 159 if (!config_.SetSerializedData(serialized_config)) {
178 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); 160 LOG(ERROR) << "Invalid configuration.";
161 OnConfigWatcherError();
162 return;
163 }
179 164
180 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 bool want_user_interface = true;
177
178 #if defined(OS_MACOSX)
179 // Don't try to display any UI on top of the system's login screen as this
180 // is rejected by the Window Server on OS X 10.7.4, and prevents the
181 // capturer from working (http://crbug.com/140984).
182 base::mac::ScopedCFTypeRef<CFDictionaryRef> session(
183 CGSessionCopyCurrentDictionary());
184 const void* logged_in = CFDictionaryGetValue(session,
185 kCGSessionLoginDoneKey);
186 if (logged_in != kCFBooleanTrue) {
187 want_user_interface = false;
188 }
189 #endif // OS_MACOSX
190
191 if (want_user_interface) {
192 host_user_interface_.reset(new HostUserInterface(context_.get()));
193 }
194 #endif // OS_MACOSX || OS_WIN
195
196 StartWatchingPolicy();
197 } else {
181 // PostTask to create new authenticator factory in case PIN has changed. 198 // PostTask to create new authenticator factory in case PIN has changed.
182 context_->network_task_runner()->PostTask( 199 context_->network_task_runner()->PostTask(
183 FROM_HERE, 200 FROM_HERE,
184 base::Bind(&HostProcess::CreateAuthenticatorFactory, 201 base::Bind(&HostProcess::CreateAuthenticatorFactory,
185 base::Unretained(this))); 202 base::Unretained(this)));
186 } else {
187 LOG(ERROR) << "Invalid configuration.";
188 } 203 }
189 } 204 }
190 205
191 #if defined(OS_WIN) 206 virtual void OnConfigWatcherError() OVERRIDE {
192 class ConfigChangedDelegate : public base::files::FilePathWatcher::Delegate { 207 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
193 public:
194 ConfigChangedDelegate(
195 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
196 const base::Closure& callback)
197 : task_runner_(task_runner),
198 callback_(callback) {
199 }
200 208
201 void OnFilePathChanged(const FilePath& path) OVERRIDE { 209 context_->network_task_runner()->PostTask(
202 task_runner_->PostTask(FROM_HERE, callback_); 210 FROM_HERE,
203 } 211 base::Bind(&HostProcess::Shutdown, base::Unretained(this),
212 kInvalidHostConfigurationExitCode));
213 }
204 214
205 void OnFilePathError(const FilePath& path) OVERRIDE { 215 void StartWatchingConfigChanges() {
206 } 216 #if !defined(REMOTING_MULTI_PROCESS)
207 217
208 private: 218 #if defined(OS_POSIX)
209 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 219 // Ignore SIGHUP sent by the daemon controller since we use
210 base::Closure callback_; 220 // |ConfigFileWatcher| instead.
221 signal(SIGHUP, SIG_IGN);
222 #endif // defined(OS_POSIX)
211 223
212 DISALLOW_COPY_AND_ASSIGN(ConfigChangedDelegate); 224 // Start watching the host configuration file.
213 }; 225 config_watcher_.reset(new ConfigFileWatcher(context_->ui_task_runner(),
214 #endif // defined(OS_WIN) 226 context_->file_task_runner(),
215 227 this));
216 void ListenForConfigChanges() { 228 config_watcher_->Watch(host_config_path_);
217 #if defined(OS_POSIX) 229 #endif // !defined(REMOTING_MULTI_PROCESS)
218 remoting::RegisterHupSignalHandler(
219 base::Bind(&HostProcess::ConfigUpdatedDelayed, base::Unretained(this)));
220 #elif defined(OS_WIN)
221 scoped_refptr<base::files::FilePathWatcher::Delegate> delegate(
222 new ConfigChangedDelegate(
223 context_->ui_task_runner(),
224 base::Bind(&HostProcess::ConfigUpdated, base::Unretained(this))));
225 config_watcher_.reset(new base::files::FilePathWatcher());
226 if (!config_watcher_->Watch(host_config_path_, delegate)) {
227 LOG(ERROR) << "Couldn't watch file " << host_config_path_.value();
228 }
229 #endif // defined (OS_WIN)
230 } 230 }
231 231
232 void CreateAuthenticatorFactory() { 232 void CreateAuthenticatorFactory() {
233 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); 233 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
234 scoped_ptr<protocol::AuthenticatorFactory> factory( 234 scoped_ptr<protocol::AuthenticatorFactory> factory(
235 new protocol::Me2MeHostAuthenticatorFactory( 235 new protocol::Me2MeHostAuthenticatorFactory(
236 key_pair_.GenerateCertificate(), 236 key_pair_.GenerateCertificate(),
237 *key_pair_.private_key(), host_secret_hash_)); 237 *key_pair_.private_key(), host_secret_hash_));
238 host_->SetAuthenticatorFactory(factory.Pass()); 238 host_->SetAuthenticatorFactory(factory.Pass());
239 } 239 }
240 240
241 // IPC::Listener implementation. 241 // IPC::Listener implementation.
242 virtual bool OnMessageReceived(const IPC::Message& message) { 242 virtual bool OnMessageReceived(const IPC::Message& message) {
243 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
244
245 #if defined(REMOTING_MULTI_PROCESS)
246 bool handled = true;
247 IPC_BEGIN_MESSAGE_MAP(HostProcess, message)
248 IPC_MESSAGE_HANDLER(ChromotingDaemonNetworkMsg_Configuration,
249 OnConfigUpdated)
250 IPC_MESSAGE_UNHANDLED(handled = false)
251 IPC_END_MESSAGE_MAP()
252 return handled;
253 #else // !defined(REMOTING_MULTI_PROCESS)
243 return false; 254 return false;
255 #endif // !defined(REMOTING_MULTI_PROCESS)
244 } 256 }
245 257
246 void StartHostProcess() { 258 void StartHostProcess() {
247 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); 259 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
248 260
249 if (!InitWithCommandLine(CommandLine::ForCurrentProcess()) || 261 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) {
250 !LoadConfig()) { 262 OnConfigWatcherError();
251 context_->network_task_runner()->PostTask(
252 FROM_HERE,
253 base::Bind(&HostProcess::Shutdown, base::Unretained(this),
254 kInvalidHostConfigurationExitCode));
255 return; 263 return;
256 } 264 }
257 265
258 #if defined(OS_MACOSX) || defined(OS_WIN) 266 StartWatchingConfigChanges();
259 bool want_user_interface = true;
260
261 #if defined(OS_MACOSX)
262 // Don't try to display any UI on top of the system's login screen as this
263 // is rejected by the Window Server on OS X 10.7.4, and prevents the
264 // capturer from working (http://crbug.com/140984).
265 base::mac::ScopedCFTypeRef<CFDictionaryRef> session(
266 CGSessionCopyCurrentDictionary());
267 const void* logged_in = CFDictionaryGetValue(session,
268 kCGSessionLoginDoneKey);
269 if (logged_in != kCFBooleanTrue) {
270 want_user_interface = false;
271 }
272 #endif // OS_MACOSX
273
274 if (want_user_interface) {
275 host_user_interface_.reset(new HostUserInterface(context_.get()));
276 }
277 #endif // OS_MACOSX || OS_WIN
278
279 StartWatchingPolicy();
280
281 #if defined(OS_MACOSX) || defined(OS_WIN)
282 context_->file_task_runner()->PostTask(
283 FROM_HERE,
284 base::Bind(&HostProcess::ListenForConfigChanges,
285 base::Unretained(this)));
286 #endif
287 } 267 }
288 268
289 int get_exit_code() const { return exit_code_; } 269 int get_exit_code() const { return exit_code_; }
290 270
291 private: 271 private:
292 void ShutdownHostProcess() { 272 void ShutdownHostProcess() {
293 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); 273 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
294 274
275 #if !defined(REMOTING_MULTI_PROCESS)
276 config_watcher_.reset();
277 #endif // !defined(REMOTING_MULTI_PROCESS)
278
295 daemon_channel_.reset(); 279 daemon_channel_.reset();
296 280
297 #if defined(OS_MACOSX) || defined(OS_WIN) 281 #if defined(OS_MACOSX) || defined(OS_WIN)
298 host_user_interface_.reset(); 282 host_user_interface_.reset();
299 #endif 283 #endif
300 284
301 if (policy_watcher_.get()) { 285 if (policy_watcher_.get()) {
302 base::WaitableEvent done_event(true, false); 286 base::WaitableEvent done_event(true, false);
303 policy_watcher_->StopWatching(&done_event); 287 policy_watcher_->StopWatching(&done_event);
304 done_event.Wait(); 288 done_event.Wait();
305 policy_watcher_.reset(); 289 policy_watcher_.reset();
306 } 290 }
307 291
308 context_.reset(); 292 context_.reset();
309 } 293 }
310 294
311 // Overridden from HeartbeatSender::Listener 295 // Overridden from HeartbeatSender::Listener
312 virtual void OnUnknownHostIdError() OVERRIDE { 296 virtual void OnUnknownHostIdError() OVERRIDE {
313 LOG(ERROR) << "Host ID not found."; 297 LOG(ERROR) << "Host ID not found.";
314 Shutdown(kInvalidHostIdExitCode); 298 Shutdown(kInvalidHostIdExitCode);
315 } 299 }
316 300
317 void StartWatchingPolicy() { 301 void StartWatchingPolicy() {
318 policy_watcher_.reset( 302 policy_watcher_.reset(
319 policy_hack::PolicyWatcher::Create(context_->file_task_runner())); 303 policy_hack::PolicyWatcher::Create(context_->file_task_runner()));
320 policy_watcher_->StartWatching( 304 policy_watcher_->StartWatching(
321 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this))); 305 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this)));
322 } 306 }
323 307
324 // Read host config, returning true if successful. 308 // Applies the host config, returning true if successful.
325 bool LoadConfig() { 309 bool ApplyConfig() {
326 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); 310 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
327 311
328 // TODO(sergeyu): There is a potential race condition: this function is
329 // called on the main thread while the class members it mutates are used on
330 // the network thread. Fix it. http://crbug.com/140986 .
331
332 if (!config_.Read()) {
333 LOG(ERROR) << "Failed to read config file.";
334 return false;
335 }
336
337 if (!config_.GetString(kHostIdConfigPath, &host_id_)) { 312 if (!config_.GetString(kHostIdConfigPath, &host_id_)) {
338 LOG(ERROR) << "host_id is not defined in the config."; 313 LOG(ERROR) << "host_id is not defined in the config.";
339 return false; 314 return false;
340 } 315 }
341 316
342 if (!key_pair_.Load(config_)) { 317 if (!key_pair_.Load(config_)) {
343 return false; 318 return false;
344 } 319 }
345 320
346 std::string host_secret_hash_string; 321 std::string host_secret_hash_string;
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 log_to_server_.reset(); 634 log_to_server_.reset();
660 heartbeat_sender_.reset(); 635 heartbeat_sender_.reset();
661 signaling_connector_.reset(); 636 signaling_connector_.reset();
662 signal_strategy_.reset(); 637 signal_strategy_.reset();
663 } 638 }
664 639
665 scoped_ptr<ChromotingHostContext> context_; 640 scoped_ptr<ChromotingHostContext> context_;
666 scoped_ptr<IPC::ChannelProxy> daemon_channel_; 641 scoped_ptr<IPC::ChannelProxy> daemon_channel_;
667 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; 642 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
668 643
644 JsonHostConfig config_;
645 #if !defined(REMOTING_MULTI_PROCESS)
669 FilePath host_config_path_; 646 FilePath host_config_path_;
670 CompositeHostConfig config_; 647 scoped_ptr<ConfigFileWatcher> config_watcher_;
648 #endif // !defined(REMOTING_MULTI_PROCESS)
671 649
672 std::string host_id_; 650 std::string host_id_;
673 HostKeyPair key_pair_; 651 HostKeyPair key_pair_;
674 protocol::SharedSecretHash host_secret_hash_; 652 protocol::SharedSecretHash host_secret_hash_;
675 std::string xmpp_login_; 653 std::string xmpp_login_;
676 std::string xmpp_auth_token_; 654 std::string xmpp_auth_token_;
677 std::string xmpp_auth_service_; 655 std::string xmpp_auth_service_;
678 656
679 std::string oauth_refresh_token_; 657 std::string oauth_refresh_token_;
680 bool oauth_use_official_client_id_; 658 bool oauth_use_official_client_id_;
681 659
682 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; 660 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_;
683 bool allow_nat_traversal_; 661 bool allow_nat_traversal_;
684 std::string talkgadget_prefix_; 662 std::string talkgadget_prefix_;
685 663
686 scoped_ptr<base::files::FilePathWatcher> config_watcher_;
687 scoped_ptr<base::DelayTimer<HostProcess> > config_updated_timer_;
688
689 bool restarting_; 664 bool restarting_;
690 bool shutting_down_; 665 bool shutting_down_;
691 666
692 scoped_ptr<XmppSignalStrategy> signal_strategy_; 667 scoped_ptr<XmppSignalStrategy> signal_strategy_;
693 scoped_ptr<SignalingConnector> signaling_connector_; 668 scoped_ptr<SignalingConnector> signaling_connector_;
694 scoped_ptr<DesktopEnvironment> desktop_environment_; 669 scoped_ptr<DesktopEnvironment> desktop_environment_;
695 scoped_ptr<HeartbeatSender> heartbeat_sender_; 670 scoped_ptr<HeartbeatSender> heartbeat_sender_;
696 scoped_ptr<LogToServer> log_to_server_; 671 scoped_ptr<LogToServer> log_to_server_;
697 scoped_ptr<HostEventLogger> host_event_logger_; 672 scoped_ptr<HostEventLogger> host_event_logger_;
698 673
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 // Create the main message loop and start helper threads. 731 // Create the main message loop and start helper threads.
757 MessageLoop message_loop(MessageLoop::TYPE_UI); 732 MessageLoop message_loop(MessageLoop::TYPE_UI);
758 base::Closure quit_message_loop = base::Bind(&QuitMessageLoop, &message_loop); 733 base::Closure quit_message_loop = base::Bind(&QuitMessageLoop, &message_loop);
759 scoped_ptr<remoting::ChromotingHostContext> context( 734 scoped_ptr<remoting::ChromotingHostContext> context(
760 new remoting::ChromotingHostContext( 735 new remoting::ChromotingHostContext(
761 new remoting::AutoThreadTaskRunner(message_loop.message_loop_proxy(), 736 new remoting::AutoThreadTaskRunner(message_loop.message_loop_proxy(),
762 quit_message_loop))); 737 quit_message_loop)));
763 if (!context->Start()) 738 if (!context->Start())
764 return remoting::kHostInitializationFailed; 739 return remoting::kHostInitializationFailed;
765 740
766 // Create the host process instance and run the rest of the initialization on 741 // Create the host process instance and enter the main message loop.
767 // the main message loop.
768 remoting::HostProcess me2me_host(context.Pass()); 742 remoting::HostProcess me2me_host(context.Pass());
769 message_loop.PostTask( 743 me2me_host.StartHostProcess();
770 FROM_HERE,
771 base::Bind(&remoting::HostProcess::StartHostProcess,
772 base::Unretained(&me2me_host)));
773 message_loop.Run(); 744 message_loop.Run();
774 return me2me_host.get_exit_code(); 745 return me2me_host.get_exit_code();
775 } 746 }
776 747
777 #if defined(OS_WIN) 748 #if defined(OS_WIN)
778 HMODULE g_hModule = NULL; 749 HMODULE g_hModule = NULL;
779 750
780 int CALLBACK WinMain(HINSTANCE instance, 751 int CALLBACK WinMain(HINSTANCE instance,
781 HINSTANCE previous_instance, 752 HINSTANCE previous_instance,
782 LPSTR command_line, 753 LPSTR command_line,
(...skipping 25 matching lines...) Expand all
808 user32.GetFunctionPointer("SetProcessDPIAware")); 779 user32.GetFunctionPointer("SetProcessDPIAware"));
809 set_process_dpi_aware(); 780 set_process_dpi_aware();
810 } 781 }
811 782
812 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting 783 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting
813 // the command line from GetCommandLineW(), so we can safely pass NULL here. 784 // the command line from GetCommandLineW(), so we can safely pass NULL here.
814 return main(0, NULL); 785 return main(0, NULL);
815 } 786 }
816 787
817 #endif // defined(OS_WIN) 788 #endif // defined(OS_WIN)
OLDNEW
« no previous file with comments | « remoting/host/me2me_preference_pane.mm ('k') | remoting/host/win/host_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698