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

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: CR feedback and rebased on top of https://chromiumcodereview.appspot.com/10829467/ 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"
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/daemon_config_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 } // namespace 91 } // namespace
102 92
103 namespace remoting { 93 namespace remoting {
104 94
105 class HostProcess 95 class HostProcess
106 : public HeartbeatSender::Listener, 96 : public HeartbeatSender::Listener,
107 public IPC::Listener { 97 public IPC::Listener,
98 public DaemonConfigWatcher::Delegate {
108 public: 99 public:
109 HostProcess(scoped_ptr<ChromotingHostContext> context) 100 HostProcess(scoped_ptr<ChromotingHostContext> context)
110 : context_(context.Pass()), 101 : context_(context.Pass()),
102 config_(FilePath()),
111 #ifdef OFFICIAL_BUILD 103 #ifdef OFFICIAL_BUILD
112 oauth_use_official_client_id_(true), 104 oauth_use_official_client_id_(true),
113 #else 105 #else
114 oauth_use_official_client_id_(false), 106 oauth_use_official_client_id_(false),
115 #endif 107 #endif
116 allow_nat_traversal_(true), 108 allow_nat_traversal_(true),
117 restarting_(false), 109 restarting_(false),
118 shutting_down_(false), 110 shutting_down_(false),
119 exit_code_(kSuccessExitCode) 111 exit_code_(kSuccessExitCode),
120 #if defined(OS_MACOSX) 112 #if defined(OS_MACOSX)
121 , curtain_(base::Bind(&HostProcess::OnDisconnectRequested, 113 curtain_(base::Bind(&HostProcess::OnDisconnectRequested,
122 base::Unretained(this)), 114 base::Unretained(this)),
123 base::Bind(&HostProcess::OnDisconnectRequested, 115 base::Bind(&HostProcess::OnDisconnectRequested,
124 base::Unretained(this))) 116 base::Unretained(this)))
125 #endif 117 #endif
118 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this))
126 { 119 {
127 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); 120 network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
128 config_updated_timer_.reset(new base::DelayTimer<HostProcess>(
129 FROM_HERE, base::TimeDelta::FromSeconds(2), this,
130 &HostProcess::ConfigUpdatedDelayed));
131 } 121 }
132 122
133 bool InitWithCommandLine(const CommandLine* cmd_line) { 123 bool InitWithCommandLine(const CommandLine* cmd_line) {
134 // Connect to the daemon process. 124 // Connect to the daemon process.
135 std::string channel_name = 125 std::string channel_name =
136 cmd_line->GetSwitchValueASCII(kDaemonIpcSwitchName); 126 cmd_line->GetSwitchValueASCII(kDaemonIpcSwitchName);
137 127
138 #if defined(REMOTING_MULTI_PROCESS) 128 #if defined(REMOTING_MULTI_PROCESS)
139 if (channel_name.empty()) 129 if (channel_name.empty())
140 return false; 130 return false;
141 #endif // defined(REMOTING_MULTI_PROCESS) 131 #endif // defined(REMOTING_MULTI_PROCESS)
142 132
143 if (!channel_name.empty()) { 133 if (!channel_name.empty()) {
144 daemon_channel_.reset(new IPC::ChannelProxy( 134 daemon_channel_.reset(new IPC::ChannelProxy(
145 channel_name, IPC::Channel::MODE_CLIENT, this, 135 channel_name, IPC::Channel::MODE_CLIENT, this,
146 context_->network_task_runner())); 136 context_->network_task_runner()));
147 } 137 }
148 138
139 #if !defined(REMOTING_MULTI_PROCESS)
149 FilePath default_config_dir = remoting::GetConfigDir(); 140 FilePath default_config_dir = remoting::GetConfigDir();
150 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) {
151 FilePath path = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName);
152 config_.AddConfigPath(path);
153 }
154
155 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); 141 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile);
156 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { 142 if (cmd_line->HasSwitch(kHostConfigSwitchName)) {
157 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); 143 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName);
158 } 144 }
159 config_.AddConfigPath(host_config_path_); 145 #endif // !defined(REMOTING_MULTI_PROCESS)
160 146
161 return true; 147 return true;
162 } 148 }
163 149
164 void ConfigUpdated() { 150 virtual void OnConfigUpdated(const std::string& config) OVERRIDE {
165 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); 151 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
166 152
167 // Call ConfigUpdatedDelayed after a short delay, so that this object won't 153 LOG(INFO) << "Processing new host configuration.";
168 // try to read the updated configuration file before it has been
169 // completely written.
170 // If the writer moves the new configuration file into place atomically,
171 // this delay may not be necessary.
172 config_updated_timer_->Reset();
173 }
174 154
175 void ConfigUpdatedDelayed() { 155 if (!config_.SetSerializedData(config)) {
176 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); 156 LOG(ERROR) << "Invalid configuration.";
157 context_->network_task_runner()->PostTask(
158 FROM_HERE,
159 base::Bind(&HostProcess::Shutdown, base::Unretained(this),
160 kInvalidHostConfigurationExitCode));
Wez 2012/08/24 22:20:38 nit: Just call OnConfigWatcherError()?
alexeypa (please no reviews) 2012/08/27 23:16:41 Done.
161 return;
162 }
177 163
178 if (LoadConfig()) { 164 if (!ApplyConfig()) {
165 LOG(ERROR) << "Failed to apply the configuration.";
166 context_->network_task_runner()->PostTask(
167 FROM_HERE,
168 base::Bind(&HostProcess::Shutdown, base::Unretained(this),
169 kInvalidHostConfigurationExitCode));
Wez 2012/08/24 22:20:38 nit: Just invoke OnConfigWatcherError()?
alexeypa (please no reviews) 2012/08/27 23:16:41 Done.
170 return;
171 }
172
173 // Start watching the policy (and eventually start the host) if this is
174 // the first configuration update. Otherwise, post a task to create new
175 // authenticator factory in case PIN has changed.
176 if (policy_watcher_.get() == NULL) {
177 #if defined(OS_MACOSX) || defined(OS_WIN)
178 host_user_interface_.reset(new HostUserInterface(context_.get()));
179 #endif
180
181 StartWatchingPolicy();
182 } else {
179 // PostTask to create new authenticator factory in case PIN has changed. 183 // PostTask to create new authenticator factory in case PIN has changed.
180 context_->network_task_runner()->PostTask( 184 context_->network_task_runner()->PostTask(
181 FROM_HERE, 185 FROM_HERE,
182 base::Bind(&HostProcess::CreateAuthenticatorFactory, 186 base::Bind(&HostProcess::CreateAuthenticatorFactory,
183 base::Unretained(this))); 187 base::Unretained(this)));
184 } else {
185 LOG(ERROR) << "Invalid configuration.";
186 } 188 }
187 } 189 }
188 190
189 #if defined(OS_WIN) 191 virtual void OnConfigWatcherError() OVERRIDE {
190 class ConfigChangedDelegate : public base::files::FilePathWatcher::Delegate { 192 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
191 public:
192 ConfigChangedDelegate(
193 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
194 const base::Closure& callback)
195 : task_runner_(task_runner),
196 callback_(callback) {
197 }
198 193
199 void OnFilePathChanged(const FilePath& path) OVERRIDE { 194 context_->network_task_runner()->PostTask(
200 task_runner_->PostTask(FROM_HERE, callback_); 195 FROM_HERE,
201 } 196 base::Bind(&HostProcess::Shutdown, base::Unretained(this),
197 kInvalidHostConfigurationExitCode));
198 }
202 199
203 void OnFilePathError(const FilePath& path) OVERRIDE { 200 void StartWatchingConfigChanges() {
204 } 201 #if !defined(REMOTING_MULTI_PROCESS)
205 202 // Start watching the host configuration file.
206 private: 203 config_watcher_.reset(new DaemonConfigWatcher(context_->ui_task_runner(),
207 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 204 context_->file_task_runner(),
208 base::Closure callback_; 205 weak_factory_.GetWeakPtr()));
209 206 config_watcher_->Watch(host_config_path_);
210 DISALLOW_COPY_AND_ASSIGN(ConfigChangedDelegate); 207 #endif // !defined(REMOTING_MULTI_PROCESS)
211 };
212 #endif // defined(OS_WIN)
213
214 void ListenForConfigChanges() {
215 #if defined(OS_POSIX)
216 remoting::RegisterHupSignalHandler(
217 base::Bind(&HostProcess::ConfigUpdatedDelayed, base::Unretained(this)));
218 #elif defined(OS_WIN)
219 scoped_refptr<base::files::FilePathWatcher::Delegate> delegate(
220 new ConfigChangedDelegate(
221 context_->ui_task_runner(),
222 base::Bind(&HostProcess::ConfigUpdated, base::Unretained(this))));
223 config_watcher_.reset(new base::files::FilePathWatcher());
224 if (!config_watcher_->Watch(host_config_path_, delegate)) {
225 LOG(ERROR) << "Couldn't watch file " << host_config_path_.value();
226 }
227 #endif // defined (OS_WIN)
228 } 208 }
229 209
230 void CreateAuthenticatorFactory() { 210 void CreateAuthenticatorFactory() {
231 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); 211 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
232 scoped_ptr<protocol::AuthenticatorFactory> factory( 212 scoped_ptr<protocol::AuthenticatorFactory> factory(
233 new protocol::Me2MeHostAuthenticatorFactory( 213 new protocol::Me2MeHostAuthenticatorFactory(
234 key_pair_.GenerateCertificate(), 214 key_pair_.GenerateCertificate(),
235 *key_pair_.private_key(), host_secret_hash_)); 215 *key_pair_.private_key(), host_secret_hash_));
236 host_->SetAuthenticatorFactory(factory.Pass()); 216 host_->SetAuthenticatorFactory(factory.Pass());
237 } 217 }
238 218
239 // IPC::Listener implementation. 219 // IPC::Listener implementation.
240 virtual bool OnMessageReceived(const IPC::Message& message) { 220 virtual bool OnMessageReceived(const IPC::Message& message) {
221 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
222
223 #if defined(REMOTING_MULTI_PROCESS)
224 bool handled = true;
225 IPC_BEGIN_MESSAGE_MAP(HostProcess, message)
226 IPC_MESSAGE_HANDLER(ChromotingDaemonNetworkMsg_Configuration,
227 OnConfigUpdated)
228 IPC_MESSAGE_UNHANDLED(handled = false)
229 IPC_END_MESSAGE_MAP()
230 return handled;
231 #else // !defined(REMOTING_MULTI_PROCESS)
241 return false; 232 return false;
233 #endif // !defined(REMOTING_MULTI_PROCESS)
242 } 234 }
243 235
244 void StartHostProcess() { 236 void StartHostProcess() {
245 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); 237 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
246 238
247 if (!InitWithCommandLine(CommandLine::ForCurrentProcess()) || 239 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) {
248 !LoadConfig()) {
249 context_->network_task_runner()->PostTask( 240 context_->network_task_runner()->PostTask(
250 FROM_HERE, 241 FROM_HERE,
251 base::Bind(&HostProcess::Shutdown, base::Unretained(this), 242 base::Bind(&HostProcess::Shutdown, base::Unretained(this),
252 kInvalidHostConfigurationExitCode)); 243 kInvalidHostConfigurationExitCode));
Wez 2012/08/24 22:20:38 Feels like this thread-jump should be coded into S
alexeypa (please no reviews) 2012/08/27 23:16:41 Maybe, but there is a whole bunch of other assumpt
253 return; 244 return;
254 } 245 }
255 246
256 #if defined(OS_MACOSX) || defined(OS_WIN) 247 StartWatchingConfigChanges();
257 host_user_interface_.reset(new HostUserInterface(context_.get()));
258 #endif
259
260 StartWatchingPolicy();
261
262 #if defined(OS_MACOSX) || defined(OS_WIN)
263 context_->file_task_runner()->PostTask(
264 FROM_HERE,
265 base::Bind(&HostProcess::ListenForConfigChanges,
266 base::Unretained(this)));
267 #endif
268 } 248 }
269 249
270 void ShutdownHostProcess() { 250 void ShutdownHostProcess() {
271 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); 251 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
272 252
253 weak_factory_.InvalidateWeakPtrs();
254
255 #if !defined(REMOTING_MULTI_PROCESS)
256 if (config_watcher_.get()) {
257 DaemonConfigWatcher* config_watcher = config_watcher_.get();
258 config_watcher->Stop(config_watcher_.Pass());
259 }
260 #endif // !defined(REMOTING_MULTI_PROCESS)
261
273 daemon_channel_.reset(); 262 daemon_channel_.reset();
274 263
275 #if defined(OS_MACOSX) || defined(OS_WIN) 264 #if defined(OS_MACOSX) || defined(OS_WIN)
276 host_user_interface_.reset(); 265 host_user_interface_.reset();
277 #endif 266 #endif
278 267
279 if (policy_watcher_.get()) { 268 if (policy_watcher_.get()) {
280 base::WaitableEvent done_event(true, false); 269 base::WaitableEvent done_event(true, false);
281 policy_watcher_->StopWatching(&done_event); 270 policy_watcher_->StopWatching(&done_event);
282 done_event.Wait(); 271 done_event.Wait();
(...skipping 15 matching lines...) Expand all
298 } 287 }
299 288
300 private: 289 private:
301 void StartWatchingPolicy() { 290 void StartWatchingPolicy() {
302 policy_watcher_.reset( 291 policy_watcher_.reset(
303 policy_hack::PolicyWatcher::Create(context_->file_task_runner())); 292 policy_hack::PolicyWatcher::Create(context_->file_task_runner()));
304 policy_watcher_->StartWatching( 293 policy_watcher_->StartWatching(
305 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this))); 294 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this)));
306 } 295 }
307 296
308 // Read host config, returning true if successful. 297 // Applies the host config, returning true if successful.
309 bool LoadConfig() { 298 bool ApplyConfig() {
310 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); 299 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
311 300
312 // TODO(sergeyu): There is a potential race condition: this function is
313 // called on the main thread while the class members it mutates are used on
314 // the network thread. Fix it. http://crbug.com/140986 .
315
316 if (!config_.Read()) {
317 LOG(ERROR) << "Failed to read config file.";
318 return false;
319 }
320
321 if (!config_.GetString(kHostIdConfigPath, &host_id_)) { 301 if (!config_.GetString(kHostIdConfigPath, &host_id_)) {
322 LOG(ERROR) << "host_id is not defined in the config."; 302 LOG(ERROR) << "host_id is not defined in the config.";
323 return false; 303 return false;
324 } 304 }
325 305
326 if (!key_pair_.Load(config_)) { 306 if (!key_pair_.Load(config_)) {
327 return false; 307 return false;
328 } 308 }
329 309
330 std::string host_secret_hash_string; 310 std::string host_secret_hash_string;
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 context_->ui_task_runner()->PostTask( 595 context_->ui_task_runner()->PostTask(
616 FROM_HERE, 596 FROM_HERE,
617 base::Bind(&HostProcess::ShutdownHostProcess, 597 base::Bind(&HostProcess::ShutdownHostProcess,
618 base::Unretained(this))); 598 base::Unretained(this)));
619 } 599 }
620 600
621 scoped_ptr<ChromotingHostContext> context_; 601 scoped_ptr<ChromotingHostContext> context_;
622 scoped_ptr<IPC::ChannelProxy> daemon_channel_; 602 scoped_ptr<IPC::ChannelProxy> daemon_channel_;
623 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; 603 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
624 604
605 JsonHostConfig config_;
606 #if !defined(REMOTING_MULTI_PROCESS)
625 FilePath host_config_path_; 607 FilePath host_config_path_;
626 CompositeHostConfig config_; 608 scoped_ptr<DaemonConfigWatcher> config_watcher_;
609 #endif // !defined(REMOTING_MULTI_PROCESS)
627 610
628 std::string host_id_; 611 std::string host_id_;
629 HostKeyPair key_pair_; 612 HostKeyPair key_pair_;
630 protocol::SharedSecretHash host_secret_hash_; 613 protocol::SharedSecretHash host_secret_hash_;
631 std::string xmpp_login_; 614 std::string xmpp_login_;
632 std::string xmpp_auth_token_; 615 std::string xmpp_auth_token_;
633 std::string xmpp_auth_service_; 616 std::string xmpp_auth_service_;
634 617
635 std::string oauth_refresh_token_; 618 std::string oauth_refresh_token_;
636 bool oauth_use_official_client_id_; 619 bool oauth_use_official_client_id_;
637 620
638 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; 621 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_;
639 bool allow_nat_traversal_; 622 bool allow_nat_traversal_;
640 scoped_ptr<base::files::FilePathWatcher> config_watcher_;
641 scoped_ptr<base::DelayTimer<HostProcess> > config_updated_timer_;
642 623
643 bool restarting_; 624 bool restarting_;
644 bool shutting_down_; 625 bool shutting_down_;
645 626
646 scoped_ptr<XmppSignalStrategy> signal_strategy_; 627 scoped_ptr<XmppSignalStrategy> signal_strategy_;
647 scoped_ptr<SignalingConnector> signaling_connector_; 628 scoped_ptr<SignalingConnector> signaling_connector_;
648 scoped_ptr<DesktopEnvironment> desktop_environment_; 629 scoped_ptr<DesktopEnvironment> desktop_environment_;
649 scoped_ptr<HeartbeatSender> heartbeat_sender_; 630 scoped_ptr<HeartbeatSender> heartbeat_sender_;
650 scoped_ptr<LogToServer> log_to_server_; 631 scoped_ptr<LogToServer> log_to_server_;
651 scoped_ptr<HostEventLogger> host_event_logger_; 632 scoped_ptr<HostEventLogger> host_event_logger_;
652 633
653 #if defined(OS_MACOSX) || defined(OS_WIN) 634 #if defined(OS_MACOSX) || defined(OS_WIN)
654 scoped_ptr<HostUserInterface> host_user_interface_; 635 scoped_ptr<HostUserInterface> host_user_interface_;
655 #endif 636 #endif
656 637
657 scoped_refptr<ChromotingHost> host_; 638 scoped_refptr<ChromotingHost> host_;
658 639
659 int exit_code_; 640 int exit_code_;
660 641
661 #if defined(OS_MACOSX) 642 #if defined(OS_MACOSX)
662 remoting::CurtainMode curtain_; 643 remoting::CurtainMode curtain_;
663 #endif 644 #endif
645
646 // WeakPtr used to avoid tasks accessing |this| after it is deleted.
647 base::WeakPtrFactory<HostProcess> weak_factory_;
664 }; 648 };
665 649
666 } // namespace remoting 650 } // namespace remoting
667 651
668 int main(int argc, char** argv) { 652 int main(int argc, char** argv) {
669 #if defined(OS_MACOSX) 653 #if defined(OS_MACOSX)
670 // Needed so we don't leak objects when threads are created. 654 // Needed so we don't leak objects when threads are created.
671 base::mac::ScopedNSAutoreleasePool pool; 655 base::mac::ScopedNSAutoreleasePool pool;
672 #endif 656 #endif
673 657
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 new remoting::AutoMessageLoop(&message_loop))); 698 new remoting::AutoMessageLoop(&message_loop)));
715 if (!context->Start()) 699 if (!context->Start())
716 return remoting::kHostInitializationFailed; 700 return remoting::kHostInitializationFailed;
717 701
718 // Create the host process instance and run the rest of the initialization on 702 // Create the host process instance and run the rest of the initialization on
719 // the main message loop. 703 // the main message loop.
720 remoting::HostProcess me2me_host(context.Pass()); 704 remoting::HostProcess me2me_host(context.Pass());
721 message_loop.PostTask( 705 message_loop.PostTask(
722 FROM_HERE, 706 FROM_HERE,
723 base::Bind(&remoting::HostProcess::StartHostProcess, 707 base::Bind(&remoting::HostProcess::StartHostProcess,
724 base::Unretained(&me2me_host))); 708 base::Unretained(&me2me_host)));
Wez 2012/08/24 22:20:38 Why do you need to post a task for this, rather th
alexeypa (please no reviews) 2012/08/27 23:16:41 Done.
725 return me2me_host.Run(&message_loop); 709 return me2me_host.Run(&message_loop);
726 } 710 }
727 711
728 #if defined(OS_WIN) 712 #if defined(OS_WIN)
729 HMODULE g_hModule = NULL; 713 HMODULE g_hModule = NULL;
730 714
731 int CALLBACK WinMain(HINSTANCE instance, 715 int CALLBACK WinMain(HINSTANCE instance,
732 HINSTANCE previous_instance, 716 HINSTANCE previous_instance,
733 LPSTR command_line, 717 LPSTR command_line,
734 int show_command) { 718 int show_command) {
(...skipping 24 matching lines...) Expand all
759 user32.GetFunctionPointer("SetProcessDPIAware")); 743 user32.GetFunctionPointer("SetProcessDPIAware"));
760 set_process_dpi_aware(); 744 set_process_dpi_aware();
761 } 745 }
762 746
763 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting 747 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting
764 // the command line from GetCommandLineW(), so we can safely pass NULL here. 748 // the command line from GetCommandLineW(), so we can safely pass NULL here.
765 return main(0, NULL); 749 return main(0, NULL);
766 } 750 }
767 751
768 #endif // defined(OS_WIN) 752 #endif // defined(OS_WIN)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698