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

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

Issue 10837291: [Chromoting] Moving the daemon IPC channel to ChromotingHostContext. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years, 4 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/desktop_environment.cc ('k') | remoting/host/session_event_executor_win.h » ('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" 15 #include "base/files/file_path_watcher.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/message_loop.h" 18 #include "base/message_loop.h"
19 #include "base/scoped_native_library.h" 19 #include "base/scoped_native_library.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "base/synchronization/waitable_event.h" 21 #include "base/synchronization/waitable_event.h"
22 #include "base/threading/thread.h" 22 #include "base/threading/thread.h"
23 #include "base/utf_string_conversions.h" 23 #include "base/utf_string_conversions.h"
24 #include "base/win/windows_version.h" 24 #include "base/win/windows_version.h"
25 #include "build/build_config.h" 25 #include "build/build_config.h"
26 #include "crypto/nss_util.h" 26 #include "crypto/nss_util.h"
27 #include "ipc/ipc_channel.h"
28 #include "ipc/ipc_channel_proxy.h"
27 #include "net/base/network_change_notifier.h" 29 #include "net/base/network_change_notifier.h"
28 #include "net/socket/ssl_server_socket.h" 30 #include "net/socket/ssl_server_socket.h"
29 #include "remoting/base/breakpad.h" 31 #include "remoting/base/breakpad.h"
30 #include "remoting/base/constants.h" 32 #include "remoting/base/constants.h"
31 #include "remoting/host/branding.h" 33 #include "remoting/host/branding.h"
32 #include "remoting/host/chromoting_host.h" 34 #include "remoting/host/chromoting_host.h"
33 #include "remoting/host/chromoting_host_context.h" 35 #include "remoting/host/chromoting_host_context.h"
34 #include "remoting/host/composite_host_config.h" 36 #include "remoting/host/composite_host_config.h"
35 #include "remoting/host/constants.h" 37 #include "remoting/host/constants.h"
36 #include "remoting/host/desktop_environment.h" 38 #include "remoting/host/desktop_environment.h"
(...skipping 29 matching lines...) Expand all
66 68
67 #if defined(TOOLKIT_GTK) 69 #if defined(TOOLKIT_GTK)
68 #include "ui/gfx/gtk_util.h" 70 #include "ui/gfx/gtk_util.h"
69 #endif // defined(TOOLKIT_GTK) 71 #endif // defined(TOOLKIT_GTK)
70 72
71 namespace { 73 namespace {
72 74
73 // This is used for tagging system event logs. 75 // This is used for tagging system event logs.
74 const char kApplicationName[] = "chromoting"; 76 const char kApplicationName[] = "chromoting";
75 77
78 // The command line switch specifying the name of the Chromoting IPC channel.
79 const char kDaemonIpcSwitchName[] = "chromoting-ipc";
80
76 // These are used for parsing the config-file locations from the command line, 81 // These are used for parsing the config-file locations from the command line,
77 // and for defining the default locations if the switches are not present. 82 // and for defining the default locations if the switches are not present.
78 const char kAuthConfigSwitchName[] = "auth-config"; 83 const char kAuthConfigSwitchName[] = "auth-config";
79 const char kHostConfigSwitchName[] = "host-config"; 84 const char kHostConfigSwitchName[] = "host-config";
80 85
81 const FilePath::CharType kDefaultHostConfigFile[] = 86 const FilePath::CharType kDefaultHostConfigFile[] =
82 FILE_PATH_LITERAL("host.json"); 87 FILE_PATH_LITERAL("host.json");
83 88
84 const int kMinPortNumber = 12400; 89 const int kMinPortNumber = 12400;
85 const int kMaxPortNumber = 12409; 90 const int kMaxPortNumber = 12409;
86 91
87 const char kUnofficialOAuth2ClientId[] = 92 const char kUnofficialOAuth2ClientId[] =
88 "440925447803-2pi3v45bff6tp1rde2f7q6lgbor3o5uj.apps.googleusercontent.com"; 93 "440925447803-2pi3v45bff6tp1rde2f7q6lgbor3o5uj.apps.googleusercontent.com";
89 const char kUnofficialOAuth2ClientSecret[] = "W2ieEsG-R1gIA4MMurGrgMc_"; 94 const char kUnofficialOAuth2ClientSecret[] = "W2ieEsG-R1gIA4MMurGrgMc_";
90 95
91 const char kOfficialOAuth2ClientId[] = 96 const char kOfficialOAuth2ClientId[] =
92 "440925447803-avn2sj1kc099s0r7v62je5s339mu0am1.apps.googleusercontent.com"; 97 "440925447803-avn2sj1kc099s0r7v62je5s339mu0am1.apps.googleusercontent.com";
93 const char kOfficialOAuth2ClientSecret[] = "Bgur6DFiOMM1h8x-AQpuTQlK"; 98 const char kOfficialOAuth2ClientSecret[] = "Bgur6DFiOMM1h8x-AQpuTQlK";
94 99
95 } // namespace 100 } // namespace
96 101
97 namespace remoting { 102 namespace remoting {
98 103
99 class HostProcess 104 class HostProcess
100 : public HeartbeatSender::Listener { 105 : public HeartbeatSender::Listener,
106 public IPC::Listener {
101 public: 107 public:
102 HostProcess() 108 HostProcess()
103 : message_loop_(MessageLoop::TYPE_UI), 109 : message_loop_(MessageLoop::TYPE_UI),
104 #ifdef OFFICIAL_BUILD 110 #ifdef OFFICIAL_BUILD
105 oauth_use_official_client_id_(true), 111 oauth_use_official_client_id_(true),
106 #else 112 #else
107 oauth_use_official_client_id_(false), 113 oauth_use_official_client_id_(false),
108 #endif 114 #endif
109 allow_nat_traversal_(true), 115 allow_nat_traversal_(true),
110 restarting_(false), 116 restarting_(false),
111 shutting_down_(false), 117 shutting_down_(false),
112 exit_code_(kSuccessExitCode) 118 exit_code_(kSuccessExitCode)
113 #if defined(OS_MACOSX) 119 #if defined(OS_MACOSX)
114 , curtain_(base::Bind(&HostProcess::OnDisconnectRequested, 120 , curtain_(base::Bind(&HostProcess::OnDisconnectRequested,
115 base::Unretained(this)), 121 base::Unretained(this)),
116 base::Bind(&HostProcess::OnDisconnectRequested, 122 base::Bind(&HostProcess::OnDisconnectRequested,
117 base::Unretained(this))) 123 base::Unretained(this)))
118 #endif 124 #endif
119 { 125 {
120 context_.reset( 126 context_.reset(
121 new ChromotingHostContext(message_loop_.message_loop_proxy())); 127 new ChromotingHostContext(message_loop_.message_loop_proxy()));
122 context_->Start(); 128 context_->Start();
123 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); 129 network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
124 config_updated_timer_.reset(new base::DelayTimer<HostProcess>( 130 config_updated_timer_.reset(new base::DelayTimer<HostProcess>(
125 FROM_HERE, base::TimeDelta::FromSeconds(2), this, 131 FROM_HERE, base::TimeDelta::FromSeconds(2), this,
126 &HostProcess::ConfigUpdatedDelayed)); 132 &HostProcess::ConfigUpdatedDelayed));
127 } 133 }
128 134
129 bool InitWithCommandLine(const CommandLine* cmd_line) { 135 bool InitWithCommandLine(const CommandLine* cmd_line) {
136 // Connect to the daemon process.
137 std::string channel_name =
138 cmd_line->GetSwitchValueASCII(kDaemonIpcSwitchName);
139
140 #if defined(REMOTING_MULTI_PROCESS)
141 if (channel_name.empty())
142 return false;
143 #endif // defined(REMOTING_MULTI_PROCESS)
144
145 if (!channel_name.empty()) {
146 daemon_channel_.reset(new IPC::ChannelProxy(
147 channel_name, IPC::Channel::MODE_CLIENT, this,
148 context_->network_task_runner()));
149 }
150
130 FilePath default_config_dir = remoting::GetConfigDir(); 151 FilePath default_config_dir = remoting::GetConfigDir();
131 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) { 152 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) {
132 FilePath path = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName); 153 FilePath path = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName);
133 config_.AddConfigPath(path); 154 config_.AddConfigPath(path);
134 } 155 }
135 156
136 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); 157 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile);
137 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { 158 if (cmd_line->HasSwitch(kHostConfigSwitchName)) {
138 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); 159 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName);
139 } 160 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 231
211 void CreateAuthenticatorFactory() { 232 void CreateAuthenticatorFactory() {
212 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); 233 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
213 scoped_ptr<protocol::AuthenticatorFactory> factory( 234 scoped_ptr<protocol::AuthenticatorFactory> factory(
214 new protocol::Me2MeHostAuthenticatorFactory( 235 new protocol::Me2MeHostAuthenticatorFactory(
215 key_pair_.GenerateCertificate(), 236 key_pair_.GenerateCertificate(),
216 *key_pair_.private_key(), host_secret_hash_)); 237 *key_pair_.private_key(), host_secret_hash_));
217 host_->SetAuthenticatorFactory(factory.Pass()); 238 host_->SetAuthenticatorFactory(factory.Pass());
218 } 239 }
219 240
241 // IPC::Listener implementation.
242 virtual bool OnMessageReceived(const IPC::Message& message) {
243 return false;
244 }
245
220 int Run() { 246 int Run() {
221 if (!LoadConfig()) { 247 if (!LoadConfig()) {
222 return kInvalidHostConfigurationExitCode; 248 return kInvalidHostConfigurationExitCode;
223 } 249 }
224 250
225 #if defined(OS_MACOSX) || defined(OS_WIN) 251 #if defined(OS_MACOSX) || defined(OS_WIN)
226 host_user_interface_.reset(new HostUserInterface(context_.get())); 252 host_user_interface_.reset(new HostUserInterface(context_.get()));
227 #endif 253 #endif
228 254
229 StartWatchingPolicy(); 255 StartWatchingPolicy();
230 256
231 #if defined(OS_MACOSX) || defined(OS_WIN) 257 #if defined(OS_MACOSX) || defined(OS_WIN)
232 context_->file_task_runner()->PostTask( 258 context_->file_task_runner()->PostTask(
233 FROM_HERE, 259 FROM_HERE,
234 base::Bind(&HostProcess::ListenForConfigChanges, 260 base::Bind(&HostProcess::ListenForConfigChanges,
235 base::Unretained(this))); 261 base::Unretained(this)));
236 #endif 262 #endif
237 message_loop_.Run(); 263 message_loop_.Run();
238 264
239 #if defined(OS_MACOSX) || defined(OS_WIN) 265 #if defined(OS_MACOSX) || defined(OS_WIN)
240 host_user_interface_.reset(); 266 host_user_interface_.reset();
241 #endif 267 #endif
242 268
269 daemon_channel_.reset();
243 base::WaitableEvent done_event(true, false); 270 base::WaitableEvent done_event(true, false);
244 policy_watcher_->StopWatching(&done_event); 271 policy_watcher_->StopWatching(&done_event);
245 done_event.Wait(); 272 done_event.Wait();
246 policy_watcher_.reset(); 273 policy_watcher_.reset();
247 274
248 return exit_code_; 275 return exit_code_;
249 } 276 }
250 277
251 // Overridden from HeartbeatSender::Listener 278 // Overridden from HeartbeatSender::Listener
252 virtual void OnUnknownHostIdError() OVERRIDE { 279 virtual void OnUnknownHostIdError() OVERRIDE {
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 log_to_server_.reset(); 593 log_to_server_.reset();
567 heartbeat_sender_.reset(); 594 heartbeat_sender_.reset();
568 signaling_connector_.reset(); 595 signaling_connector_.reset();
569 signal_strategy_.reset(); 596 signal_strategy_.reset();
570 597
571 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); 598 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure());
572 } 599 }
573 600
574 MessageLoop message_loop_; 601 MessageLoop message_loop_;
575 scoped_ptr<ChromotingHostContext> context_; 602 scoped_ptr<ChromotingHostContext> context_;
603 scoped_ptr<IPC::ChannelProxy> daemon_channel_;
576 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; 604 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
577 605
578 FilePath host_config_path_; 606 FilePath host_config_path_;
579 CompositeHostConfig config_; 607 CompositeHostConfig config_;
580 608
581 std::string host_id_; 609 std::string host_id_;
582 HostKeyPair key_pair_; 610 HostKeyPair key_pair_;
583 protocol::SharedSecretHash host_secret_hash_; 611 protocol::SharedSecretHash host_secret_hash_;
584 std::string xmpp_login_; 612 std::string xmpp_login_;
585 std::string xmpp_auth_token_; 613 std::string xmpp_auth_token_;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 user32.GetFunctionPointer("SetProcessDPIAware")); 731 user32.GetFunctionPointer("SetProcessDPIAware"));
704 set_process_dpi_aware(); 732 set_process_dpi_aware();
705 } 733 }
706 734
707 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting 735 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting
708 // the command line from GetCommandLineW(), so we can safely pass NULL here. 736 // the command line from GetCommandLineW(), so we can safely pass NULL here.
709 return main(0, NULL); 737 return main(0, NULL);
710 } 738 }
711 739
712 #endif // defined(OS_WIN) 740 #endif // defined(OS_WIN)
OLDNEW
« no previous file with comments | « remoting/host/desktop_environment.cc ('k') | remoting/host/session_event_executor_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698