| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/embedder/platform_channel_pair.h" | 5 #include "mojo/embedder/platform_channel_pair.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 #endif // defined(OS_MACOSX) | 53 #endif // defined(OS_MACOSX) |
| 54 | 54 |
| 55 server_handle_.reset(PlatformHandle(fds[0])); | 55 server_handle_.reset(PlatformHandle(fds[0])); |
| 56 DCHECK(server_handle_.is_valid()); | 56 DCHECK(server_handle_.is_valid()); |
| 57 client_handle_.reset(PlatformHandle(fds[1])); | 57 client_handle_.reset(PlatformHandle(fds[1])); |
| 58 DCHECK(client_handle_.is_valid()); | 58 DCHECK(client_handle_.is_valid()); |
| 59 } | 59 } |
| 60 | 60 |
| 61 // static | 61 // static |
| 62 ScopedPlatformHandle PlatformChannelPair::PassClientHandleFromParentProcess( | 62 ScopedPlatformHandle PlatformChannelPair::PassClientHandleFromParentProcess( |
| 63 const CommandLine& command_line) { | 63 const base::CommandLine& command_line) { |
| 64 std::string client_fd_string = | 64 std::string client_fd_string = |
| 65 command_line.GetSwitchValueASCII(kMojoPlatformChannelHandleSwitch); | 65 command_line.GetSwitchValueASCII(kMojoPlatformChannelHandleSwitch); |
| 66 int client_fd = -1; | 66 int client_fd = -1; |
| 67 if (client_fd_string.empty() || | 67 if (client_fd_string.empty() || |
| 68 !base::StringToInt(client_fd_string, &client_fd) || | 68 !base::StringToInt(client_fd_string, &client_fd) || |
| 69 client_fd < base::GlobalDescriptors::kBaseDescriptor) { | 69 client_fd < base::GlobalDescriptors::kBaseDescriptor) { |
| 70 LOG(ERROR) << "Missing or invalid --" << kMojoPlatformChannelHandleSwitch; | 70 LOG(ERROR) << "Missing or invalid --" << kMojoPlatformChannelHandleSwitch; |
| 71 return ScopedPlatformHandle(); | 71 return ScopedPlatformHandle(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 return ScopedPlatformHandle(PlatformHandle(client_fd)); | 74 return ScopedPlatformHandle(PlatformHandle(client_fd)); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void PlatformChannelPair::PrepareToPassClientHandleToChildProcess( | 77 void PlatformChannelPair::PrepareToPassClientHandleToChildProcess( |
| 78 CommandLine* command_line, | 78 base::CommandLine* command_line, |
| 79 base::FileHandleMappingVector* handle_passing_info) const { | 79 base::FileHandleMappingVector* handle_passing_info) const { |
| 80 DCHECK(command_line); | 80 DCHECK(command_line); |
| 81 DCHECK(handle_passing_info); | 81 DCHECK(handle_passing_info); |
| 82 // This is an arbitrary sanity check. (Note that this guarantees that the loop | 82 // This is an arbitrary sanity check. (Note that this guarantees that the loop |
| 83 // below will terminate sanely.) | 83 // below will terminate sanely.) |
| 84 CHECK_LT(handle_passing_info->size(), 1000u); | 84 CHECK_LT(handle_passing_info->size(), 1000u); |
| 85 | 85 |
| 86 DCHECK(client_handle_.is_valid()); | 86 DCHECK(client_handle_.is_valid()); |
| 87 | 87 |
| 88 // Find a suitable FD to map our client handle to in the child process. | 88 // Find a suitable FD to map our client handle to in the child process. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 102 << kMojoPlatformChannelHandleSwitch << "=" | 102 << kMojoPlatformChannelHandleSwitch << "=" |
| 103 << command_line->GetSwitchValueASCII(kMojoPlatformChannelHandleSwitch); | 103 << command_line->GetSwitchValueASCII(kMojoPlatformChannelHandleSwitch); |
| 104 // (Any existing switch won't actually be removed from the command line, but | 104 // (Any existing switch won't actually be removed from the command line, but |
| 105 // the last one appended takes precedence.) | 105 // the last one appended takes precedence.) |
| 106 command_line->AppendSwitchASCII(kMojoPlatformChannelHandleSwitch, | 106 command_line->AppendSwitchASCII(kMojoPlatformChannelHandleSwitch, |
| 107 base::IntToString(target_fd)); | 107 base::IntToString(target_fd)); |
| 108 } | 108 } |
| 109 | 109 |
| 110 } // namespace embedder | 110 } // namespace embedder |
| 111 } // namespace mojo | 111 } // namespace mojo |
| OLD | NEW |