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

Side by Side Diff: mojo/edk/embedder/platform_channel_pair_win.cc

Issue 728553002: Update mojo sdk to rev afb4440fd5a10cba980878c326180b7ad7960480 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 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/edk/embedder/platform_channel_pair.h" 5 #include "mojo/edk/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
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/rand_util.h" 13 #include "base/rand_util.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/win/windows_version.h" 16 #include "base/win/windows_version.h"
17 #include "mojo/edk/embedder/platform_handle.h" 17 #include "mojo/edk/embedder/platform_handle.h"
18 18
19 namespace mojo { 19 namespace mojo {
20 namespace embedder { 20 namespace embedder {
21 21
22 namespace { 22 namespace {
23 23
24 std::wstring GeneratePipeName() { 24 std::wstring GeneratePipeName() {
25 return base::StringPrintf(L"\\\\.\\pipe\\mojo.%u.%u.%I64u", 25 return base::StringPrintf(L"\\\\.\\pipe\\mojo.%u.%u.%I64u",
26 GetCurrentProcessId(), 26 GetCurrentProcessId(), GetCurrentThreadId(),
27 GetCurrentThreadId(),
28 base::RandUint64()); 27 base::RandUint64());
29 } 28 }
30 29
31 } // namespace 30 } // namespace
32 31
33 PlatformChannelPair::PlatformChannelPair() { 32 PlatformChannelPair::PlatformChannelPair() {
34 std::wstring pipe_name = GeneratePipeName(); 33 std::wstring pipe_name = GeneratePipeName();
35 34
36 const DWORD kOpenMode = 35 const DWORD kOpenMode =
37 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE; 36 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE;
38 const DWORD kPipeMode = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE; 37 const DWORD kPipeMode = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE;
39 server_handle_.reset(PlatformHandle( 38 server_handle_.reset(PlatformHandle(
40 CreateNamedPipeW(pipe_name.c_str(), 39 CreateNamedPipeW(pipe_name.c_str(), kOpenMode, kPipeMode,
41 kOpenMode,
42 kPipeMode,
43 1, // Max instances. 40 1, // Max instances.
44 4096, // Out buffer size. 41 4096, // Out buffer size.
45 4096, // In buffer size. 42 4096, // In buffer size.
46 5000, // Timeout in milliseconds. 43 5000, // Timeout in milliseconds.
47 nullptr))); // Default security descriptor. 44 nullptr))); // Default security descriptor.
48 PCHECK(server_handle_.is_valid()); 45 PCHECK(server_handle_.is_valid());
49 46
50 const DWORD kDesiredAccess = GENERIC_READ | GENERIC_WRITE; 47 const DWORD kDesiredAccess = GENERIC_READ | GENERIC_WRITE;
51 // The SECURITY_ANONYMOUS flag means that the server side cannot impersonate 48 // The SECURITY_ANONYMOUS flag means that the server side cannot impersonate
52 // the client. 49 // the client.
53 const DWORD kFlags = 50 const DWORD kFlags =
54 SECURITY_SQOS_PRESENT | SECURITY_ANONYMOUS | FILE_FLAG_OVERLAPPED; 51 SECURITY_SQOS_PRESENT | SECURITY_ANONYMOUS | FILE_FLAG_OVERLAPPED;
55 // Allow the handle to be inherited by child processes. 52 // Allow the handle to be inherited by child processes.
56 SECURITY_ATTRIBUTES security_attributes = { 53 SECURITY_ATTRIBUTES security_attributes = {
57 sizeof(SECURITY_ATTRIBUTES), nullptr, TRUE}; 54 sizeof(SECURITY_ATTRIBUTES), nullptr, TRUE};
58 client_handle_.reset( 55 client_handle_.reset(
59 PlatformHandle(CreateFileW(pipe_name.c_str(), 56 PlatformHandle(CreateFileW(pipe_name.c_str(), kDesiredAccess,
60 kDesiredAccess,
61 0, // No sharing. 57 0, // No sharing.
62 &security_attributes, 58 &security_attributes, OPEN_EXISTING, kFlags,
63 OPEN_EXISTING,
64 kFlags,
65 nullptr))); // No template file. 59 nullptr))); // No template file.
66 PCHECK(client_handle_.is_valid()); 60 PCHECK(client_handle_.is_valid());
67 61
68 // Since a client has connected, ConnectNamedPipe() should return zero and 62 // Since a client has connected, ConnectNamedPipe() should return zero and
69 // GetLastError() should return ERROR_PIPE_CONNECTED. 63 // GetLastError() should return ERROR_PIPE_CONNECTED.
70 CHECK(!ConnectNamedPipe(server_handle_.get().handle, nullptr)); 64 CHECK(!ConnectNamedPipe(server_handle_.get().handle, nullptr));
71 PCHECK(GetLastError() == ERROR_PIPE_CONNECTED); 65 PCHECK(GetLastError() == ERROR_PIPE_CONNECTED);
72 } 66 }
73 67
74 // static 68 // static
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 << command_line->GetSwitchValueASCII(kMojoPlatformChannelHandleSwitch); 102 << command_line->GetSwitchValueASCII(kMojoPlatformChannelHandleSwitch);
109 // (Any existing switch won't actually be removed from the command line, but 103 // (Any existing switch won't actually be removed from the command line, but
110 // the last one appended takes precedence.) 104 // the last one appended takes precedence.)
111 command_line->AppendSwitchASCII( 105 command_line->AppendSwitchASCII(
112 kMojoPlatformChannelHandleSwitch, 106 kMojoPlatformChannelHandleSwitch,
113 base::IntToString(HandleToLong(client_handle_.get().handle))); 107 base::IntToString(HandleToLong(client_handle_.get().handle)));
114 } 108 }
115 109
116 } // namespace embedder 110 } // namespace embedder
117 } // namespace mojo 111 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/embedder/platform_channel_pair_posix_unittest.cc ('k') | mojo/edk/embedder/platform_channel_utils_posix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698