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 <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 } | 29 } |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 PlatformChannelPair::PlatformChannelPair() { | 33 PlatformChannelPair::PlatformChannelPair() { |
34 std::wstring pipe_name = GeneratePipeName(); | 34 std::wstring pipe_name = GeneratePipeName(); |
35 | 35 |
36 const DWORD kOpenMode = | 36 const DWORD kOpenMode = |
37 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE; | 37 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE; |
38 const DWORD kPipeMode = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE; | 38 const DWORD kPipeMode = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE; |
39 server_handle_.reset( | 39 server_handle_.reset(PlatformHandle( |
40 PlatformHandle(CreateNamedPipeW(pipe_name.c_str(), | 40 CreateNamedPipeW(pipe_name.c_str(), |
41 kOpenMode, | 41 kOpenMode, |
42 kPipeMode, | 42 kPipeMode, |
43 1, // Max instances. | 43 1, // Max instances. |
44 4096, // Out buffer size. | 44 4096, // Out buffer size. |
45 4096, // In buffer size. | 45 4096, // In buffer size. |
46 5000, // Timeout in milliseconds. | 46 5000, // Timeout in milliseconds. |
47 NULL))); // Default security descriptor. | 47 nullptr))); // Default security descriptor. |
48 PCHECK(server_handle_.is_valid()); | 48 PCHECK(server_handle_.is_valid()); |
49 | 49 |
50 const DWORD kDesiredAccess = GENERIC_READ | GENERIC_WRITE; | 50 const DWORD kDesiredAccess = GENERIC_READ | GENERIC_WRITE; |
51 // The SECURITY_ANONYMOUS flag means that the server side cannot impersonate | 51 // The SECURITY_ANONYMOUS flag means that the server side cannot impersonate |
52 // the client. | 52 // the client. |
53 const DWORD kFlags = | 53 const DWORD kFlags = |
54 SECURITY_SQOS_PRESENT | SECURITY_ANONYMOUS | FILE_FLAG_OVERLAPPED; | 54 SECURITY_SQOS_PRESENT | SECURITY_ANONYMOUS | FILE_FLAG_OVERLAPPED; |
55 // Allow the handle to be inherited by child processes. | 55 // Allow the handle to be inherited by child processes. |
56 SECURITY_ATTRIBUTES security_attributes = {sizeof(SECURITY_ATTRIBUTES), NULL, | 56 SECURITY_ATTRIBUTES security_attributes = {sizeof(SECURITY_ATTRIBUTES), |
57 TRUE}; | 57 nullptr, TRUE}; |
58 client_handle_.reset(PlatformHandle(CreateFileW(pipe_name.c_str(), | 58 client_handle_.reset( |
59 kDesiredAccess, | 59 PlatformHandle(CreateFileW(pipe_name.c_str(), |
60 0, // No sharing. | 60 kDesiredAccess, |
61 &security_attributes, | 61 0, // No sharing. |
62 OPEN_EXISTING, | 62 &security_attributes, |
63 kFlags, | 63 OPEN_EXISTING, |
64 NULL))); // No template file. | 64 kFlags, |
| 65 nullptr))); // No template file. |
65 PCHECK(client_handle_.is_valid()); | 66 PCHECK(client_handle_.is_valid()); |
66 | 67 |
67 // Since a client has connected, ConnectNamedPipe() should return zero and | 68 // Since a client has connected, ConnectNamedPipe() should return zero and |
68 // GetLastError() should return ERROR_PIPE_CONNECTED. | 69 // GetLastError() should return ERROR_PIPE_CONNECTED. |
69 CHECK(!ConnectNamedPipe(server_handle_.get().handle, NULL)); | 70 CHECK(!ConnectNamedPipe(server_handle_.get().handle, nullptr)); |
70 PCHECK(GetLastError() == ERROR_PIPE_CONNECTED); | 71 PCHECK(GetLastError() == ERROR_PIPE_CONNECTED); |
71 } | 72 } |
72 | 73 |
73 // static | 74 // static |
74 ScopedPlatformHandle PlatformChannelPair::PassClientHandleFromParentProcess( | 75 ScopedPlatformHandle PlatformChannelPair::PassClientHandleFromParentProcess( |
75 const base::CommandLine& command_line) { | 76 const base::CommandLine& command_line) { |
76 std::string client_handle_string = | 77 std::string client_handle_string = |
77 command_line.GetSwitchValueASCII(kMojoPlatformChannelHandleSwitch); | 78 command_line.GetSwitchValueASCII(kMojoPlatformChannelHandleSwitch); |
78 | 79 |
79 int client_handle_value = 0; | 80 int client_handle_value = 0; |
(...skipping 27 matching lines...) Expand all Loading... |
107 << command_line->GetSwitchValueASCII(kMojoPlatformChannelHandleSwitch); | 108 << command_line->GetSwitchValueASCII(kMojoPlatformChannelHandleSwitch); |
108 // (Any existing switch won't actually be removed from the command line, but | 109 // (Any existing switch won't actually be removed from the command line, but |
109 // the last one appended takes precedence.) | 110 // the last one appended takes precedence.) |
110 command_line->AppendSwitchASCII( | 111 command_line->AppendSwitchASCII( |
111 kMojoPlatformChannelHandleSwitch, | 112 kMojoPlatformChannelHandleSwitch, |
112 base::IntToString(HandleToLong(client_handle_.get().handle))); | 113 base::IntToString(HandleToLong(client_handle_.get().handle))); |
113 } | 114 } |
114 | 115 |
115 } // namespace embedder | 116 } // namespace embedder |
116 } // namespace mojo | 117 } // namespace mojo |
OLD | NEW |