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

Side by Side Diff: components/nacl/browser/nacl_process_host.cc

Issue 2301103003: Use ChannelMojo for NaCl PPAPI channels. (Closed)
Patch Set: Created 4 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
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 #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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 CHECK(handle.socket.fd == -1 || handle.socket.fd != handle_.socket.fd); 248 CHECK(handle.socket.fd == -1 || handle.socket.fd != handle_.socket.fd);
249 #endif 249 #endif
250 CloseIfNecessary(); 250 CloseIfNecessary();
251 handle_ = handle; 251 handle_ = handle;
252 } 252 }
253 253
254 private: 254 private:
255 // Returns true if the given handle is closable automatically by this 255 // Returns true if the given handle is closable automatically by this
256 // class. This function is just a helper for validation. 256 // class. This function is just a helper for validation.
257 static bool IsSupportedHandle(const IPC::ChannelHandle& handle) { 257 static bool IsSupportedHandle(const IPC::ChannelHandle& handle) {
258 #if defined(OS_WIN) 258 #if defined(OS_POSIX)
259 // Only ChannelMojo is supported.
Mark Seaborn 2016/10/12 00:57:24 It looks like this comment should apply to Windows
Sam McNally 2016/10/12 03:15:32 Done.
260 return handle.socket.fd == -1;
261 #elif defined(OS_WIN)
259 // On Windows, it is not supported to marshal the |pipe.handle|. 262 // On Windows, it is not supported to marshal the |pipe.handle|.
260 // In our case, we wrap a transferred ChannelHandle (or one to be 263 // In our case, we wrap a transferred ChannelHandle (or one to be
261 // transferred) via IPC, so we can assume |handle.pipe.handle| is NULL. 264 // transferred) via IPC, so we can assume |handle.pipe.handle| is NULL.
262 return handle.pipe.handle == NULL; 265 return handle.pipe.handle == NULL;
263 #else 266 #else
264 return true; 267 return true;
265 #endif 268 #endif // defined(OS_POSIX)
266 } 269 }
267 270
268 void CloseIfNecessary() { 271 void CloseIfNecessary() {
272 if (handle_.mojo_handle.is_valid())
273 handle_.mojo_handle.Close();
274
269 #if defined(OS_POSIX) 275 #if defined(OS_POSIX)
Mark Seaborn 2016/10/12 00:57:24 This block shouldn't be necessary if "Only Channel
Sam McNally 2016/10/12 03:15:32 Done.
270 if (handle_.socket.auto_close) { 276 if (handle_.socket.auto_close) {
271 // Defer closing task to the ScopedFD. 277 // Defer closing task to the ScopedFD.
272 base::ScopedFD(handle_.socket.fd); 278 base::ScopedFD(handle_.socket.fd);
273 } 279 }
274 #endif 280 #endif
275 } 281 }
276 282
277 IPC::ChannelHandle handle_; 283 IPC::ChannelHandle handle_;
278 284
279 DISALLOW_COPY_AND_ASSIGN(ScopedChannelHandle); 285 DISALLOW_COPY_AND_ASSIGN(ScopedChannelHandle);
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 } 1033 }
1028 1034
1029 #if defined(OS_LINUX) 1035 #if defined(OS_LINUX)
1030 // static 1036 // static
1031 bool NaClProcessHost::CreateChannelHandlePair( 1037 bool NaClProcessHost::CreateChannelHandlePair(
1032 ScopedChannelHandle* channel_handle1, 1038 ScopedChannelHandle* channel_handle1,
1033 ScopedChannelHandle* channel_handle2) { 1039 ScopedChannelHandle* channel_handle2) {
1034 DCHECK(channel_handle1); 1040 DCHECK(channel_handle1);
1035 DCHECK(channel_handle2); 1041 DCHECK(channel_handle2);
1036 1042
1037 int fd1 = -1; 1043 IPC::ChannelHandle handle1;
1038 int fd2 = -1; 1044 IPC::ChannelHandle handle2;
1039 if (!IPC::SocketPair(&fd1, &fd2)) { 1045 IPC::Channel::GenerateMojoChannelHandlePair("NaCl", &handle1, &handle2);
1040 return false; 1046 channel_handle1->reset(handle1);
1041 } 1047 channel_handle2->reset(handle2);
1042 1048
1043 IPC::ChannelHandle handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
1044 handle.socket = base::FileDescriptor(fd1, true);
1045 channel_handle1->reset(handle);
1046 handle.socket = base::FileDescriptor(fd2, true);
1047 channel_handle2->reset(handle);
1048 return true; 1049 return true;
1049 } 1050 }
1050 #endif 1051 #endif
1051 1052
1052 bool NaClProcessHost::StartPPAPIProxy(ScopedChannelHandle channel_handle) { 1053 bool NaClProcessHost::StartPPAPIProxy(ScopedChannelHandle channel_handle) {
1053 if (ipc_proxy_channel_.get()) { 1054 if (ipc_proxy_channel_.get()) {
1054 // Attempt to open more than 1 browser channel is not supported. 1055 // Attempt to open more than 1 browser channel is not supported.
1055 // Shut down the NaCl process. 1056 // Shut down the NaCl process.
1056 process_->GetHost()->ForceShutdown(); 1057 process_->GetHost()->ForceShutdown();
1057 return false; 1058 return false;
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 NaClStartDebugExceptionHandlerThread( 1300 NaClStartDebugExceptionHandlerThread(
1300 std::move(process), info, base::ThreadTaskRunnerHandle::Get(), 1301 std::move(process), info, base::ThreadTaskRunnerHandle::Get(),
1301 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, 1302 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker,
1302 weak_factory_.GetWeakPtr())); 1303 weak_factory_.GetWeakPtr()));
1303 return true; 1304 return true;
1304 } 1305 }
1305 } 1306 }
1306 #endif 1307 #endif
1307 1308
1308 } // namespace nacl 1309 } // namespace nacl
OLDNEW
« no previous file with comments | « no previous file | components/nacl/loader/nacl_ipc_adapter.h » ('j') | components/nacl/loader/nacl_ipc_adapter.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698