1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// This file implements a standalone host process for Me2Me.
#include <string>
#include "base/at_exit.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/scoped_native_library.h"
#include "base/string_util.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/thread.h"
#include "base/utf_string_conversions.h"
#include "base/win/windows_version.h"
#include "build/build_config.h"
#include "chrome/common/net/google_apis/google_api_keys.h"
#include "crypto/nss_util.h"
#include "ipc/ipc_channel.h"
#include "ipc/ipc_channel_proxy.h"
#include "net/base/network_change_notifier.h"
#include "net/socket/ssl_server_socket.h"
#include "remoting/base/auto_thread_task_runner.h"
#include "remoting/base/breakpad.h"
#include "remoting/base/constants.h"
#include "remoting/host/branding.h"
#include "remoting/host/chromoting_host.h"
#include "remoting/host/chromoting_host_context.h"
#include "remoting/host/chromoting_messages.h"
#include "remoting/host/constants.h"
#include "remoting/host/config_file_watcher.h"
#include "remoting/host/desktop_environment.h"
#include "remoting/host/dns_blackhole_checker.h"
#include "remoting/host/event_executor.h"
#include "remoting/host/heartbeat_sender.h"
#include "remoting/host/host_config.h"
#include "remoting/host/host_event_logger.h"
#include "remoting/host/host_user_interface.h"
#include "remoting/host/json_host_config.h"
#include "remoting/host/log_to_server.h"
#include "remoting/host/network_settings.h"
#include "remoting/host/policy_hack/policy_watcher.h"
#include "remoting/host/session_manager_factory.h"
#include "remoting/host/signaling_connector.h"
#include "remoting/host/usage_stats_consent.h"
#include "remoting/host/video_frame_capturer.h"
#include "remoting/jingle_glue/xmpp_signal_strategy.h"
#include "remoting/protocol/me2me_host_authenticator_factory.h"
#if defined(OS_MACOSX)
#include "base/mac/scoped_cftyperef.h"
#include "base/mac/scoped_nsautorelease_pool.h"
#include "remoting/host/curtain_mode_mac.h"
#endif // defined(OS_MACOSX)
#if defined(OS_POSIX)
#include <signal.h>
#endif // defined(OS_POSIX)
// N.B. OS_WIN is defined by including src/base headers.
#if defined(OS_WIN)
#include <commctrl.h>
#endif // defined(OS_WIN)
#if defined(TOOLKIT_GTK)
#include "ui/gfx/gtk_util.h"
#endif // defined(TOOLKIT_GTK)
namespace {
// This is used for tagging system event logs.
const char kApplicationName[] = "chromoting";
// The command line switch specifying the name of the daemon IPC endpoint.
const char kDaemonIpcSwitchName[] = "daemon-pipe";
const char kUnofficialOAuth2ClientId[] =
"440925447803-2pi3v45bff6tp1rde2f7q6lgbor3o5uj.apps.googleusercontent.com";
const char kUnofficialOAuth2ClientSecret[] = "W2ieEsG-R1gIA4MMurGrgMc_";
void QuitMessageLoop(MessageLoop* message_loop) {
message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure());
}
} // namespace
namespace remoting {
class HostProcess
: public HeartbeatSender::Listener,
public IPC::Listener,
public ConfigFileWatcher::Delegate {
public:
HostProcess(scoped_ptr<ChromotingHostContext> context)
: context_(context.Pass()),
config_(FilePath()),
#ifdef OFFICIAL_BUILD
oauth_use_official_client_id_(true),
#else
oauth_use_official_client_id_(false),
#endif
allow_nat_traversal_(true),
restarting_(false),
shutting_down_(false),
exit_code_(kSuccessExitCode)
#if defined(OS_MACOSX)
, curtain_(base::Bind(&HostProcess::OnDisconnectRequested,
base::Unretained(this)),
base::Bind(&HostProcess::OnDisconnectRequested,
base::Unretained(this)))
#endif
{
network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
}
bool InitWithCommandLine(const CommandLine* cmd_line) {
// Connect to the daemon process.
std::string channel_name =
cmd_line->GetSwitchValueASCII(kDaemonIpcSwitchName);
#if defined(REMOTING_MULTI_PROCESS)
if (channel_name.empty())
return false;
#endif // defined(REMOTING_MULTI_PROCESS)
if (!channel_name.empty()) {
daemon_channel_.reset(new IPC::ChannelProxy(
channel_name, IPC::Channel::MODE_CLIENT, this,
context_->network_task_runner()));
}
#if !defined(REMOTING_MULTI_PROCESS)
FilePath default_config_dir = remoting::GetConfigDir();
host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile);
if (cmd_line->HasSwitch(kHostConfigSwitchName)) {
host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName);
}
#endif // !defined(REMOTING_MULTI_PROCESS)
return true;
}
virtual void OnConfigUpdated(const std::string& serialized_config) OVERRIDE {
DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
LOG(INFO) << "Processing new host configuration.";
if (!config_.SetSerializedData(serialized_config)) {
LOG(ERROR) << "Invalid configuration.";
OnConfigWatcherError();
return;
}
if (!ApplyConfig()) {
LOG(ERROR) << "Failed to apply the configuration.";
OnConfigWatcherError();
return;
}
// Start watching the policy (and eventually start the host) if this is
// the first configuration update. Otherwise, post a task to create new
// authenticator factory in case PIN has changed.
if (policy_watcher_.get() == NULL) {
#if defined(OS_MACOSX) || defined(OS_WIN)
bool want_user_interface = true;
#if defined(OS_MACOSX)
// Don't try to display any UI on top of the system's login screen as this
// is rejected by the Window Server on OS X 10.7.4, and prevents the
// capturer from working (http://crbug.com/140984).
base::mac::ScopedCFTypeRef<CFDictionaryRef> session(
CGSessionCopyCurrentDictionary());
const void* logged_in = CFDictionaryGetValue(session,
kCGSessionLoginDoneKey);
if (logged_in != kCFBooleanTrue) {
want_user_interface = false;
}
#endif // OS_MACOSX
if (want_user_interface) {
host_user_interface_.reset(new HostUserInterface(context_.get()));
}
#endif // OS_MACOSX || OS_WIN
StartWatchingPolicy();
} else {
// PostTask to create new authenticator factory in case PIN has changed.
context_->network_task_runner()->PostTask(
FROM_HERE,
base::Bind(&HostProcess::CreateAuthenticatorFactory,
base::Unretained(this)));
}
}
virtual void OnConfigWatcherError() OVERRIDE {
DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
context_->network_task_runner()->PostTask(
FROM_HERE,
base::Bind(&HostProcess::Shutdown, base::Unretained(this),
kInvalidHostConfigurationExitCode));
}
void StartWatchingConfigChanges() {
#if !defined(REMOTING_MULTI_PROCESS)
#if defined(OS_POSIX)
// Ignore SIGHUP sent by the daemon controller since we use
// |ConfigFileWatcher| instead.
signal(SIGHUP, SIG_IGN);
#endif // defined(OS_POSIX)
// Start watching the host configuration file.
config_watcher_.reset(new ConfigFileWatcher(context_->ui_task_runner(),
context_->file_task_runner(),
this));
config_watcher_->Watch(host_config_path_);
#endif // !defined(REMOTING_MULTI_PROCESS)
}
void CreateAuthenticatorFactory() {
DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
scoped_ptr<protocol::AuthenticatorFactory> factory(
new protocol::Me2MeHostAuthenticatorFactory(
key_pair_.GenerateCertificate(),
*key_pair_.private_key(), host_secret_hash_));
host_->SetAuthenticatorFactory(factory.Pass());
}
// IPC::Listener implementation.
virtual bool OnMessageReceived(const IPC::Message& message) {
DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
#if defined(REMOTING_MULTI_PROCESS)
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(HostProcess, message)
IPC_MESSAGE_HANDLER(ChromotingDaemonNetworkMsg_Configuration,
OnConfigUpdated)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
#else // !defined(REMOTING_MULTI_PROCESS)
return false;
#endif // !defined(REMOTING_MULTI_PROCESS)
}
void StartHostProcess() {
DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) {
OnConfigWatcherError();
return;
}
StartWatchingConfigChanges();
}
int get_exit_code() const { return exit_code_; }
private:
void ShutdownHostProcess() {
DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
#if !defined(REMOTING_MULTI_PROCESS)
config_watcher_.reset();
#endif // !defined(REMOTING_MULTI_PROCESS)
daemon_channel_.reset();
#if defined(OS_MACOSX) || defined(OS_WIN)
host_user_interface_.reset();
#endif
if (policy_watcher_.get()) {
base::WaitableEvent done_event(true, false);
policy_watcher_->StopWatching(&done_event);
done_event.Wait();
policy_watcher_.reset();
}
context_.reset();
}
// Overridden from HeartbeatSender::Listener
virtual void OnUnknownHostIdError() OVERRIDE {
LOG(ERROR) << "Host ID not found.";
Shutdown(kInvalidHostIdExitCode);
}
void StartWatchingPolicy() {
policy_watcher_.reset(
policy_hack::PolicyWatcher::Create(context_->file_task_runner()));
policy_watcher_->StartWatching(
base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this)));
}
// Applies the host config, returning true if successful.
bool ApplyConfig() {
DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
if (!config_.GetString(kHostIdConfigPath, &host_id_)) {
LOG(ERROR) << "host_id is not defined in the config.";
return false;
}
if (!key_pair_.Load(config_)) {
return false;
}
std::string host_secret_hash_string;
if (!config_.GetString(kHostSecretHashConfigPath,
&host_secret_hash_string)) {
host_secret_hash_string = "plain:";
}
if (!host_secret_hash_.Parse(host_secret_hash_string)) {
LOG(ERROR) << "Invalid host_secret_hash.";
return false;
}
// Use an XMPP connection to the Talk network for session signalling.
if (!config_.GetString(kXmppLoginConfigPath, &xmpp_login_) ||
!(config_.GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token_) ||
config_.GetString(kOAuthRefreshTokenConfigPath,
&oauth_refresh_token_))) {
LOG(ERROR) << "XMPP credentials are not defined in the config.";
return false;
}
// It is okay to not have this value and we will use the default value
// depending on whether this is an official build or not.
// If the client-Id type to use is not specified we default based on
// the build type.
config_.GetBoolean(kOAuthUseOfficialClientIdConfigPath,
&oauth_use_official_client_id_);
if (!oauth_refresh_token_.empty()) {
xmpp_auth_token_ = ""; // This will be set to the access token later.
xmpp_auth_service_ = "oauth2";
} else if (!config_.GetString(kXmppAuthServiceConfigPath,
&xmpp_auth_service_)) {
// For the me2me host, we default to ClientLogin token for chromiumsync
// because earlier versions of the host had no HTTP stack with which to
// request an OAuth2 access token.
xmpp_auth_service_ = kChromotingTokenDefaultServiceName;
}
return true;
}
void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) {
if (!context_->network_task_runner()->BelongsToCurrentThread()) {
context_->network_task_runner()->PostTask(FROM_HERE, base::Bind(
&HostProcess::OnPolicyUpdate, base::Unretained(this),
base::Passed(&policies)));
return;
}
if (!host_) {
StartHost();
}
bool bool_value;
std::string string_value;
if (policies->GetString(policy_hack::PolicyWatcher::kHostDomainPolicyName,
&string_value)) {
OnHostDomainPolicyUpdate(string_value);
}
if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName,
&bool_value)) {
OnNatPolicyUpdate(bool_value);
}
if (policies->GetBoolean(
policy_hack::PolicyWatcher::kHostRequireCurtainPolicyName,
&bool_value)) {
OnCurtainPolicyUpdate(bool_value);
}
if (policies->GetString(
policy_hack::PolicyWatcher::kHostTalkGadgetPrefixPolicyName,
&string_value)) {
OnHostTalkGadgetPrefixPolicyUpdate(string_value);
}
}
void OnHostDomainPolicyUpdate(const std::string& host_domain) {
if (!context_->network_task_runner()->BelongsToCurrentThread()) {
context_->network_task_runner()->PostTask(FROM_HERE, base::Bind(
&HostProcess::OnHostDomainPolicyUpdate, base::Unretained(this),
host_domain));
return;
}
if (!host_domain.empty() &&
!EndsWith(xmpp_login_, std::string("@") + host_domain, false)) {
Shutdown(kInvalidHostDomainExitCode);
}
}
void OnNatPolicyUpdate(bool nat_traversal_enabled) {
if (!context_->network_task_runner()->BelongsToCurrentThread()) {
context_->network_task_runner()->PostTask(FROM_HERE, base::Bind(
&HostProcess::OnNatPolicyUpdate, base::Unretained(this),
nat_traversal_enabled));
return;
}
bool policy_changed = allow_nat_traversal_ != nat_traversal_enabled;
allow_nat_traversal_ = nat_traversal_enabled;
if (policy_changed) {
RestartHost();
}
}
void OnCurtainPolicyUpdate(bool curtain_required) {
#if defined(OS_MACOSX)
if (!context_->network_task_runner()->BelongsToCurrentThread()) {
context_->network_task_runner()->PostTask(FROM_HERE, base::Bind(
&HostProcess::OnCurtainPolicyUpdate, base::Unretained(this),
curtain_required));
return;
}
if (curtain_required) {
// If curtain mode is required, then we can't currently support remoting
// the login screen. This is because we don't curtain the login screen
// and the current daemon architecture means that the connction is closed
// immediately after login, leaving the host system uncurtained.
//
// TODO(jamiewalch): Fix this once we have implemented the multi-process
// daemon architecture (crbug.com/134894)
base::mac::ScopedCFTypeRef<CFDictionaryRef> session(
CGSessionCopyCurrentDictionary());
const void* logged_in = CFDictionaryGetValue(session,
kCGSessionLoginDoneKey);
if (logged_in != kCFBooleanTrue) {
Shutdown(kLoginScreenNotSupportedExitCode);
return;
}
host_->AddStatusObserver(&curtain_);
curtain_.SetEnabled(true);
} else {
curtain_.SetEnabled(false);
host_->RemoveStatusObserver(&curtain_);
}
#endif
}
void OnHostTalkGadgetPrefixPolicyUpdate(
const std::string& talkgadget_prefix) {
if (!context_->network_task_runner()->BelongsToCurrentThread()) {
context_->network_task_runner()->PostTask(FROM_HERE, base::Bind(
&HostProcess::OnHostTalkGadgetPrefixPolicyUpdate,
base::Unretained(this), talkgadget_prefix));
return;
}
if (talkgadget_prefix != talkgadget_prefix_) {
LOG(INFO) << "Restarting host due to updated talkgadget policy:";
talkgadget_prefix_ = talkgadget_prefix;
RestartHost();
}
}
void StartHost() {
DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
DCHECK(!host_);
DCHECK(!signal_strategy_.get());
if (shutting_down_)
return;
signal_strategy_.reset(
new XmppSignalStrategy(context_->url_request_context_getter(),
xmpp_login_, xmpp_auth_token_,
xmpp_auth_service_));
scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker(
new DnsBlackholeChecker(context_.get(), talkgadget_prefix_));
signaling_connector_.reset(new SignalingConnector(
signal_strategy_.get(), context_.get(), dns_blackhole_checker.Pass(),
base::Bind(&HostProcess::OnAuthFailed, base::Unretained(this))));
if (!oauth_refresh_token_.empty()) {
OAuthClientInfo client_info = {
kUnofficialOAuth2ClientId,
kUnofficialOAuth2ClientSecret
};
#ifdef OFFICIAL_BUILD
if (oauth_use_official_client_id_) {
OAuthClientInfo official_client_info = {
google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING),
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING)
};
client_info = official_client_info;
}
#endif // OFFICIAL_BUILD
scoped_ptr<SignalingConnector::OAuthCredentials> oauth_credentials(
new SignalingConnector::OAuthCredentials(
xmpp_login_, oauth_refresh_token_, client_info));
signaling_connector_->EnableOAuth(oauth_credentials.Pass());
}
if (!desktop_environment_.get()) {
desktop_environment_ =
DesktopEnvironment::CreateForService(context_.get());
}
NetworkSettings network_settings(
allow_nat_traversal_ ?
NetworkSettings::NAT_TRAVERSAL_ENABLED :
NetworkSettings::NAT_TRAVERSAL_DISABLED);
if (!allow_nat_traversal_) {
network_settings.min_port = NetworkSettings::kDefaultMinPort;
network_settings.max_port = NetworkSettings::kDefaultMaxPort;
}
host_ = new ChromotingHost(
context_.get(), signal_strategy_.get(), desktop_environment_.get(),
CreateHostSessionManager(network_settings,
context_->url_request_context_getter()));
// TODO(simonmorris): Get the maximum session duration from a policy.
#if defined(OS_LINUX)
host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20));
#endif
heartbeat_sender_.reset(new HeartbeatSender(
this, host_id_, signal_strategy_.get(), &key_pair_));
log_to_server_.reset(
new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get()));
host_event_logger_ = HostEventLogger::Create(host_, kApplicationName);
#if defined(OS_MACOSX) || defined(OS_WIN)
if (host_user_interface_.get()) {
host_user_interface_->Start(
host_, base::Bind(&HostProcess::OnDisconnectRequested,
base::Unretained(this)));
}
#endif
host_->Start(xmpp_login_);
CreateAuthenticatorFactory();
}
void OnAuthFailed() {
Shutdown(kInvalidOauthCredentialsExitCode);
}
// Invoked when the user uses the Disconnect windows to terminate
// the sessions.
void OnDisconnectRequested() {
DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
host_->DisconnectAllClients();
}
void RestartHost() {
DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
if (restarting_ || shutting_down_)
return;
restarting_ = true;
host_->Shutdown(base::Bind(
&HostProcess::RestartOnHostShutdown, base::Unretained(this)));
}
void RestartOnHostShutdown() {
DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
if (shutting_down_)
return;
restarting_ = false;
host_ = NULL;
ResetHost();
StartHost();
}
void Shutdown(int exit_code) {
DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
if (shutting_down_)
return;
shutting_down_ = true;
exit_code_ = exit_code;
if (host_) {
host_->Shutdown(base::Bind(
&HostProcess::OnShutdownFinished, base::Unretained(this)));
} else {
OnShutdownFinished();
}
}
void OnShutdownFinished() {
DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
// Destroy networking objects while we are on the network thread.
host_ = NULL;
ResetHost();
// Complete the rest of shutdown on the main thread.
context_->ui_task_runner()->PostTask(
FROM_HERE,
base::Bind(&HostProcess::ShutdownHostProcess,
base::Unretained(this)));
}
void ResetHost() {
DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
desktop_environment_.reset();
host_event_logger_.reset();
log_to_server_.reset();
heartbeat_sender_.reset();
signaling_connector_.reset();
signal_strategy_.reset();
}
scoped_ptr<ChromotingHostContext> context_;
scoped_ptr<IPC::ChannelProxy> daemon_channel_;
scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
JsonHostConfig config_;
#if !defined(REMOTING_MULTI_PROCESS)
FilePath host_config_path_;
scoped_ptr<ConfigFileWatcher> config_watcher_;
#endif // !defined(REMOTING_MULTI_PROCESS)
std::string host_id_;
HostKeyPair key_pair_;
protocol::SharedSecretHash host_secret_hash_;
std::string xmpp_login_;
std::string xmpp_auth_token_;
std::string xmpp_auth_service_;
std::string oauth_refresh_token_;
bool oauth_use_official_client_id_;
scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_;
bool allow_nat_traversal_;
std::string talkgadget_prefix_;
bool restarting_;
bool shutting_down_;
scoped_ptr<XmppSignalStrategy> signal_strategy_;
scoped_ptr<SignalingConnector> signaling_connector_;
scoped_ptr<DesktopEnvironment> desktop_environment_;
scoped_ptr<HeartbeatSender> heartbeat_sender_;
scoped_ptr<LogToServer> log_to_server_;
scoped_ptr<HostEventLogger> host_event_logger_;
#if defined(OS_MACOSX) || defined(OS_WIN)
scoped_ptr<HostUserInterface> host_user_interface_;
#endif
scoped_refptr<ChromotingHost> host_;
int exit_code_;
#if defined(OS_MACOSX)
remoting::CurtainMode curtain_;
#endif
};
} // namespace remoting
int main(int argc, char** argv) {
#if defined(OS_MACOSX)
// Needed so we don't leak objects when threads are created.
base::mac::ScopedNSAutoreleasePool pool;
#endif
CommandLine::Init(argc, argv);
// This object instance is required by Chrome code (for example,
// LazyInstance, MessageLoop).
base::AtExitManager exit_manager;
// Initialize logging with an appropriate log-file location, and default to
// log to that on Windows, or to standard error output otherwise.
FilePath debug_log = remoting::GetConfigDir().
Append(FILE_PATH_LITERAL("debug.log"));
InitLogging(debug_log.value().c_str(),
#if defined(OS_WIN)
logging::LOG_ONLY_TO_FILE,
#else
logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
#endif
logging::DONT_LOCK_LOG_FILE,
logging::APPEND_TO_OLD_LOG_FILE,
logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS);
#if defined(OS_MACOSX)
// Exit permanently if there appears to be no window server running.
base::mac::ScopedCFTypeRef<CFDictionaryRef> session(
CGSessionCopyCurrentDictionary());
if (!session.get()) {
// TODO(lambroslambrou): Add a new exit-code to reflect this error.
LOG(ERROR) << "Failed to connect to Window Server";
return remoting::kInvalidHostConfigurationExitCode;
}
#endif // OS_MACOSX
#if defined(TOOLKIT_GTK)
// Required for any calls into GTK functions, such as the Disconnect and
// Continue windows, though these should not be used for the Me2Me case
// (crbug.com/104377).
const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
gfx::GtkInitFromCommandLine(*cmd_line);
#endif // TOOLKIT_GTK
// Enable support for SSL server sockets, which must be done while still
// single-threaded.
net::EnableSSLServerSockets();
#if defined(OS_LINUX)
remoting::VideoFrameCapturer::EnableXDamage(true);
#endif
// Create the main message loop and start helper threads.
MessageLoop message_loop(MessageLoop::TYPE_UI);
base::Closure quit_message_loop = base::Bind(&QuitMessageLoop, &message_loop);
scoped_ptr<remoting::ChromotingHostContext> context(
new remoting::ChromotingHostContext(
new remoting::AutoThreadTaskRunner(message_loop.message_loop_proxy(),
quit_message_loop)));
if (!context->Start())
return remoting::kHostInitializationFailed;
// Create the host process instance and enter the main message loop.
remoting::HostProcess me2me_host(context.Pass());
me2me_host.StartHostProcess();
message_loop.Run();
return me2me_host.get_exit_code();
}
#if defined(OS_WIN)
HMODULE g_hModule = NULL;
int CALLBACK WinMain(HINSTANCE instance,
HINSTANCE previous_instance,
LPSTR command_line,
int show_command) {
#ifdef OFFICIAL_BUILD
if (remoting::IsUsageStatsAllowed()) {
remoting::InitializeCrashReporting();
}
#endif // OFFICIAL_BUILD
g_hModule = instance;
// Register and initialize common controls.
INITCOMMONCONTROLSEX info;
info.dwSize = sizeof(info);
info.dwICC = ICC_STANDARD_CLASSES;
InitCommonControlsEx(&info);
// Mark the process as DPI-aware, so Windows won't scale coordinates in APIs.
// N.B. This API exists on Vista and above.
if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
FilePath path(base::GetNativeLibraryName(UTF8ToUTF16("user32")));
base::ScopedNativeLibrary user32(path);
CHECK(user32.is_valid());
typedef BOOL (WINAPI * SetProcessDPIAwareFn)();
SetProcessDPIAwareFn set_process_dpi_aware =
static_cast<SetProcessDPIAwareFn>(
user32.GetFunctionPointer("SetProcessDPIAware"));
set_process_dpi_aware();
}
// CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting
// the command line from GetCommandLineW(), so we can safely pass NULL here.
return main(0, NULL);
}
#endif // defined(OS_WIN)
|