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

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

Issue 11118005: Pass the client end handle of the network-to-daemon IPC channel via handle inheritance. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/message_loop.h" 17 #include "base/message_loop.h"
18 #include "base/scoped_native_library.h" 18 #include "base/scoped_native_library.h"
19 #include "base/string_number_conversions.h"
19 #include "base/string_util.h" 20 #include "base/string_util.h"
20 #include "base/stringize_macros.h" 21 #include "base/stringize_macros.h"
21 #include "base/synchronization/waitable_event.h" 22 #include "base/synchronization/waitable_event.h"
22 #include "base/threading/thread.h" 23 #include "base/threading/thread.h"
23 #include "base/utf_string_conversions.h" 24 #include "base/utf_string_conversions.h"
24 #include "base/win/windows_version.h" 25 #include "base/win/windows_version.h"
25 #include "build/build_config.h" 26 #include "build/build_config.h"
26 #include "crypto/nss_util.h" 27 #include "crypto/nss_util.h"
27 #include "google_apis/google_api_keys.h" 28 #include "google_apis/google_api_keys.h"
28 #include "ipc/ipc_channel.h" 29 #include "ipc/ipc_channel.h"
(...skipping 26 matching lines...) Expand all
55 #include "remoting/host/resizing_host_observer.h" 56 #include "remoting/host/resizing_host_observer.h"
56 #include "remoting/host/session_manager_factory.h" 57 #include "remoting/host/session_manager_factory.h"
57 #include "remoting/host/signaling_connector.h" 58 #include "remoting/host/signaling_connector.h"
58 #include "remoting/host/usage_stats_consent.h" 59 #include "remoting/host/usage_stats_consent.h"
59 #include "remoting/host/video_frame_capturer.h" 60 #include "remoting/host/video_frame_capturer.h"
60 #include "remoting/jingle_glue/xmpp_signal_strategy.h" 61 #include "remoting/jingle_glue/xmpp_signal_strategy.h"
61 #include "remoting/protocol/me2me_host_authenticator_factory.h" 62 #include "remoting/protocol/me2me_host_authenticator_factory.h"
62 63
63 #if defined(OS_POSIX) 64 #if defined(OS_POSIX)
64 #include <signal.h> 65 #include <signal.h>
66 #include "base/file_descriptor_posix.h"
65 #include "remoting/host/posix/signal_handler.h" 67 #include "remoting/host/posix/signal_handler.h"
66 #endif // defined(OS_POSIX) 68 #endif // defined(OS_POSIX)
67 69
68 #if defined(OS_MACOSX) 70 #if defined(OS_MACOSX)
69 #include "base/mac/scoped_cftyperef.h" 71 #include "base/mac/scoped_cftyperef.h"
70 #include "base/mac/scoped_nsautorelease_pool.h" 72 #include "base/mac/scoped_nsautorelease_pool.h"
71 #endif // defined(OS_MACOSX) 73 #endif // defined(OS_MACOSX)
72 74
73 #if defined(OS_LINUX) 75 #if defined(OS_LINUX)
74 #include "remoting/host/audio_capturer_linux.h" 76 #include "remoting/host/audio_capturer_linux.h"
75 #endif // defined(OS_LINUX) 77 #endif // defined(OS_LINUX)
76 78
77 // N.B. OS_WIN is defined by including src/base headers. 79 // N.B. OS_WIN is defined by including src/base headers.
78 #if defined(OS_WIN) 80 #if defined(OS_WIN)
79 #include <commctrl.h> 81 #include <commctrl.h>
82 #include "base/win/scoped_handle.h"
80 #include "remoting/host/win/session_desktop_environment_factory.h" 83 #include "remoting/host/win/session_desktop_environment_factory.h"
81 #endif // defined(OS_WIN) 84 #endif // defined(OS_WIN)
82 85
83 #if defined(TOOLKIT_GTK) 86 #if defined(TOOLKIT_GTK)
84 #include "ui/gfx/gtk_util.h" 87 #include "ui/gfx/gtk_util.h"
85 #endif // defined(TOOLKIT_GTK) 88 #endif // defined(TOOLKIT_GTK)
86 89
87 namespace { 90 namespace {
88 91
89 // This is used for tagging system event logs. 92 // This is used for tagging system event logs.
90 const char kApplicationName[] = "chromoting"; 93 const char kApplicationName[] = "chromoting";
91 94
92 // The command line switch specifying the name of the daemon IPC endpoint. 95 // The command line switches specifying the daemon IPC endpoint.
simonmorris 2012/10/12 16:31:13 switches -> switch?
alexeypa (please no reviews) 2012/10/12 18:44:39 Done.
93 const char kDaemonIpcSwitchName[] = "daemon-pipe"; 96 const char kDaemonPipeSwitchName[] = "daemon-pipe";
94 97
95 // The command line switch used to get version of the daemon. 98 // The command line switch used to get version of the daemon.
96 const char kVersionSwitchName[] = "version"; 99 const char kVersionSwitchName[] = "version";
97 100
98 // The command line switch used to pass name of the pipe to capture audio on 101 // The command line switch used to pass name of the pipe to capture audio on
99 // linux. 102 // linux.
100 const char kAudioPipeSwitchName[] = "audio-pipe-name"; 103 const char kAudioPipeSwitchName[] = "audio-pipe-name";
101 104
102 const char kUnofficialOAuth2ClientId[] = 105 const char kUnofficialOAuth2ClientId[] =
103 "440925447803-2pi3v45bff6tp1rde2f7q6lgbor3o5uj.apps.googleusercontent.com"; 106 "440925447803-2pi3v45bff6tp1rde2f7q6lgbor3o5uj.apps.googleusercontent.com";
(...skipping 28 matching lines...) Expand all
132 desktop_resizer_(DesktopResizer::Create()), 135 desktop_resizer_(DesktopResizer::Create()),
133 exit_code_(kSuccessExitCode) { 136 exit_code_(kSuccessExitCode) {
134 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); 137 network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
135 curtain_ = CurtainMode::Create( 138 curtain_ = CurtainMode::Create(
136 base::Bind(&HostProcess::OnDisconnectRequested, 139 base::Bind(&HostProcess::OnDisconnectRequested,
137 base::Unretained(this)), 140 base::Unretained(this)),
138 base::Bind(&HostProcess::OnDisconnectRequested, 141 base::Bind(&HostProcess::OnDisconnectRequested,
139 base::Unretained(this))); 142 base::Unretained(this)));
140 } 143 }
141 144
145 #if defined(REMOTING_MULTI_PROCESS)
146
147 bool InitWithCommandLine(const CommandLine* cmd_line) {
148 // Parse the handle value and convert it to a handle/file descriptor.
149 std::string channel_name =
150 cmd_line->GetSwitchValueASCII(kDaemonPipeSwitchName);
151
152 int pipe_handle = 0;
153 if (channel_name.empty() ||
154 !base::StringToInt(channel_name, &pipe_handle)) {
155 LOG(ERROR) << "Invalid '" << kDaemonPipeSwitchName
156 << "' value: " << channel_name;
157 return false;
158 }
159
160 #if defined(OS_WIN)
161 base::win::ScopedHandle pipe(reinterpret_cast<HANDLE>(pipe_handle));
162 IPC::ChannelHandle channel_handle(pipe);
163 #elif defined(OS_POSIX)
164 base::FileDescriptor pipe(pipe_handle, true);
165 IPC::ChannelHandle channel_handle(channel_name, pipe);
166 #endif // defined(OS_POSIX)
167
168 // Connect to the daemon process.
169 daemon_channel_.reset(new IPC::ChannelProxy(
170 channel_handle,
171 IPC::Channel::MODE_CLIENT,
172 this,
173 context_->network_task_runner()));
174
175 return true;
176 }
177
178 #else // !defined(REMOTING_MULTI_PROCESS)
179
142 bool InitWithCommandLine(const CommandLine* cmd_line) { 180 bool InitWithCommandLine(const CommandLine* cmd_line) {
143 // Connect to the daemon process. 181 // Connect to the daemon process.
144 std::string channel_name = 182 std::string channel_name =
145 cmd_line->GetSwitchValueASCII(kDaemonIpcSwitchName); 183 cmd_line->GetSwitchValueASCII(kDaemonPipeSwitchName);
146
147 #if defined(REMOTING_MULTI_PROCESS)
148 if (channel_name.empty())
149 return false;
150 #endif // defined(REMOTING_MULTI_PROCESS)
151
152 if (!channel_name.empty()) { 184 if (!channel_name.empty()) {
153 daemon_channel_.reset(new IPC::ChannelProxy( 185 daemon_channel_.reset(new IPC::ChannelProxy(
154 channel_name, IPC::Channel::MODE_CLIENT, this, 186 channel_name, IPC::Channel::MODE_CLIENT, this,
155 context_->network_task_runner())); 187 context_->network_task_runner()));
156 } 188 }
157 189
158 #if !defined(REMOTING_MULTI_PROCESS)
159 FilePath default_config_dir = remoting::GetConfigDir(); 190 FilePath default_config_dir = remoting::GetConfigDir();
160 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); 191 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile);
161 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { 192 if (cmd_line->HasSwitch(kHostConfigSwitchName)) {
162 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); 193 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName);
163 } 194 }
164 #endif // !defined(REMOTING_MULTI_PROCESS)
165 195
166 return true; 196 return true;
167 } 197 }
168 198
199 #endif // !defined(REMOTING_MULTI_PROCESS)
200
169 #if defined(OS_POSIX) 201 #if defined(OS_POSIX)
170 void SigTermHandler(int signal_number) { 202 void SigTermHandler(int signal_number) {
171 DCHECK(signal_number == SIGTERM); 203 DCHECK(signal_number == SIGTERM);
172 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); 204 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
173 LOG(INFO) << "Caught SIGTERM: Shutting down..."; 205 LOG(INFO) << "Caught SIGTERM: Shutting down...";
174 Shutdown(kSuccessExitCode); 206 Shutdown(kSuccessExitCode);
175 } 207 }
176 #endif 208 #endif
177 209
178 virtual void OnConfigUpdated(const std::string& serialized_config) OVERRIDE { 210 virtual void OnConfigUpdated(const std::string& serialized_config) OVERRIDE {
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 user32.GetFunctionPointer("SetProcessDPIAware")); 831 user32.GetFunctionPointer("SetProcessDPIAware"));
800 set_process_dpi_aware(); 832 set_process_dpi_aware();
801 } 833 }
802 834
803 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting 835 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting
804 // the command line from GetCommandLineW(), so we can safely pass NULL here. 836 // the command line from GetCommandLineW(), so we can safely pass NULL here.
805 return main(0, NULL); 837 return main(0, NULL);
806 } 838 }
807 839
808 #endif // defined(OS_WIN) 840 #endif // defined(OS_WIN)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698