OLD | NEW |
---|---|
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 #include "components/nacl/browser/nacl_process_host.h" | 5 #include "components/nacl/browser/nacl_process_host.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 } // namespace | 209 } // namespace |
210 | 210 |
211 unsigned NaClProcessHost::keepalive_throttle_interval_milliseconds_ = | 211 unsigned NaClProcessHost::keepalive_throttle_interval_milliseconds_ = |
212 ppapi::kKeepaliveThrottleIntervalDefaultMilliseconds; | 212 ppapi::kKeepaliveThrottleIntervalDefaultMilliseconds; |
213 | 213 |
214 // Unfortunately, we cannot use ScopedGeneric directly for IPC::ChannelHandle, | 214 // Unfortunately, we cannot use ScopedGeneric directly for IPC::ChannelHandle, |
215 // because there is neither operator== nor operator != definition for it. | 215 // because there is neither operator== nor operator != definition for it. |
216 // Instead, define a simple wrapper for IPC::ChannelHandle with an assumption | 216 // Instead, define a simple wrapper for IPC::ChannelHandle with an assumption |
217 // that this only takes a transferred IPC::ChannelHandle or one to be | 217 // that this only takes a transferred IPC::ChannelHandle or one to be |
218 // transferred via IPC. | 218 // transferred via IPC. |
219 class NaClProcessHost::ScopedChannelHandle { | 219 class NaClProcessHost::ScopedChannelHandle { |
Mark Seaborn
2016/10/13 21:27:51
Presumably at some point this could be removed and
Sam McNally
2016/10/14 02:35:02
How about now? :)
| |
220 public: | 220 public: |
221 ScopedChannelHandle() { | 221 ScopedChannelHandle() { |
222 } | 222 } |
223 explicit ScopedChannelHandle(const IPC::ChannelHandle& handle) | 223 explicit ScopedChannelHandle(const IPC::ChannelHandle& handle) |
224 : handle_(handle) { | 224 : handle_(handle) { |
225 DCHECK(IsSupportedHandle(handle_)); | 225 DCHECK(IsSupportedHandle(handle_)); |
226 } | 226 } |
227 ScopedChannelHandle(ScopedChannelHandle&& other) : handle_(other.handle_) { | 227 ScopedChannelHandle(ScopedChannelHandle&& other) : handle_(other.handle_) { |
228 other.handle_ = IPC::ChannelHandle(); | 228 other.handle_ = IPC::ChannelHandle(); |
229 DCHECK(IsSupportedHandle(handle_)); | 229 DCHECK(IsSupportedHandle(handle_)); |
230 } | 230 } |
231 ~ScopedChannelHandle() { | 231 ~ScopedChannelHandle() { |
232 CloseIfNecessary(); | 232 CloseIfNecessary(); |
233 } | 233 } |
234 | 234 |
235 const IPC::ChannelHandle& get() const { return handle_; } | 235 const IPC::ChannelHandle& get() const { return handle_; } |
236 IPC::ChannelHandle release() WARN_UNUSED_RESULT { | 236 IPC::ChannelHandle release() WARN_UNUSED_RESULT { |
237 IPC::ChannelHandle result = handle_; | 237 IPC::ChannelHandle result = handle_; |
238 handle_ = IPC::ChannelHandle(); | 238 handle_ = IPC::ChannelHandle(); |
239 return result; | 239 return result; |
240 } | 240 } |
241 | 241 |
242 void reset(const IPC::ChannelHandle& handle = IPC::ChannelHandle()) { | 242 void reset() { |
243 CloseIfNecessary(); | |
244 handle_ = IPC::ChannelHandle(); | |
245 } | |
246 | |
247 void reset(const IPC::ChannelHandle& handle) { | |
243 DCHECK(IsSupportedHandle(handle)); | 248 DCHECK(IsSupportedHandle(handle)); |
244 #if defined(OS_POSIX) | |
245 // Following the manner of base::ScopedGeneric, we do not support | 249 // Following the manner of base::ScopedGeneric, we do not support |
246 // reset() with same handle for simplicity of the implementation. | 250 // reset() with same handle for simplicity of the implementation. |
247 CHECK(handle.socket.fd == -1 || handle.socket.fd != handle_.socket.fd); | 251 CHECK(handle.mojo_handle.value() != handle_.mojo_handle.value()); |
248 #endif | |
249 CloseIfNecessary(); | 252 CloseIfNecessary(); |
250 handle_ = handle; | 253 handle_ = handle; |
251 } | 254 } |
252 | 255 |
253 private: | 256 private: |
254 // Returns true if the given handle is closable automatically by this | 257 // Returns true if the given handle is closable automatically by this |
255 // class. This function is just a helper for validation. | 258 // class. This function is just a helper for validation. |
256 static bool IsSupportedHandle(const IPC::ChannelHandle& handle) { | 259 static bool IsSupportedHandle(const IPC::ChannelHandle& handle) { |
257 #if defined(OS_WIN) | 260 // Only ChannelMojo is supported. |
258 // On Windows, it is not supported to marshal the |pipe.handle|. | 261 return handle.mojo_handle.is_valid(); |
259 // In our case, we wrap a transferred ChannelHandle (or one to be | |
260 // transferred) via IPC, so we can assume |handle.pipe.handle| is NULL. | |
261 return handle.pipe.handle == NULL; | |
262 #else | |
263 return true; | |
264 #endif | |
265 } | 262 } |
266 | 263 |
267 void CloseIfNecessary() { | 264 void CloseIfNecessary() { |
268 #if defined(OS_POSIX) | 265 if (handle_.mojo_handle.is_valid()) |
269 if (handle_.socket.auto_close) { | 266 handle_.mojo_handle.Close(); |
270 // Defer closing task to the ScopedFD. | |
271 base::ScopedFD(handle_.socket.fd); | |
272 } | |
273 #endif | |
274 } | 267 } |
275 | 268 |
276 IPC::ChannelHandle handle_; | 269 IPC::ChannelHandle handle_; |
277 | 270 |
278 DISALLOW_COPY_AND_ASSIGN(ScopedChannelHandle); | 271 DISALLOW_COPY_AND_ASSIGN(ScopedChannelHandle); |
279 }; | 272 }; |
280 | 273 |
281 NaClProcessHost::NaClProcessHost( | 274 NaClProcessHost::NaClProcessHost( |
282 const GURL& manifest_url, | 275 const GURL& manifest_url, |
283 base::File nexe_file, | 276 base::File nexe_file, |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1026 } | 1019 } |
1027 | 1020 |
1028 #if defined(OS_LINUX) | 1021 #if defined(OS_LINUX) |
1029 // static | 1022 // static |
1030 bool NaClProcessHost::CreateChannelHandlePair( | 1023 bool NaClProcessHost::CreateChannelHandlePair( |
1031 ScopedChannelHandle* channel_handle1, | 1024 ScopedChannelHandle* channel_handle1, |
1032 ScopedChannelHandle* channel_handle2) { | 1025 ScopedChannelHandle* channel_handle2) { |
1033 DCHECK(channel_handle1); | 1026 DCHECK(channel_handle1); |
1034 DCHECK(channel_handle2); | 1027 DCHECK(channel_handle2); |
1035 | 1028 |
1036 int fd1 = -1; | 1029 IPC::ChannelHandle handle1; |
1037 int fd2 = -1; | 1030 IPC::ChannelHandle handle2; |
1038 if (!IPC::SocketPair(&fd1, &fd2)) { | 1031 IPC::Channel::GenerateMojoChannelHandlePair("NaCl", &handle1, &handle2); |
1039 return false; | 1032 channel_handle1->reset(handle1); |
1040 } | 1033 channel_handle2->reset(handle2); |
1041 | 1034 |
1042 IPC::ChannelHandle handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); | |
1043 handle.socket = base::FileDescriptor(fd1, true); | |
1044 channel_handle1->reset(handle); | |
1045 handle.socket = base::FileDescriptor(fd2, true); | |
1046 channel_handle2->reset(handle); | |
1047 return true; | 1035 return true; |
1048 } | 1036 } |
1049 #endif | 1037 #endif |
1050 | 1038 |
1051 bool NaClProcessHost::StartPPAPIProxy(ScopedChannelHandle channel_handle) { | 1039 bool NaClProcessHost::StartPPAPIProxy(ScopedChannelHandle channel_handle) { |
1052 if (ipc_proxy_channel_.get()) { | 1040 if (ipc_proxy_channel_.get()) { |
1053 // Attempt to open more than 1 browser channel is not supported. | 1041 // Attempt to open more than 1 browser channel is not supported. |
1054 // Shut down the NaCl process. | 1042 // Shut down the NaCl process. |
1055 process_->GetHost()->ForceShutdown(); | 1043 process_->GetHost()->ForceShutdown(); |
1056 return false; | 1044 return false; |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1298 NaClStartDebugExceptionHandlerThread( | 1286 NaClStartDebugExceptionHandlerThread( |
1299 std::move(process), info, base::ThreadTaskRunnerHandle::Get(), | 1287 std::move(process), info, base::ThreadTaskRunnerHandle::Get(), |
1300 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 1288 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
1301 weak_factory_.GetWeakPtr())); | 1289 weak_factory_.GetWeakPtr())); |
1302 return true; | 1290 return true; |
1303 } | 1291 } |
1304 } | 1292 } |
1305 #endif | 1293 #endif |
1306 | 1294 |
1307 } // namespace nacl | 1295 } // namespace nacl |
OLD | NEW |