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

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

Issue 728043002: Revert of 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(), GetCurrentThreadId(), 26 GetCurrentProcessId(),
27 GetCurrentThreadId(),
27 base::RandUint64()); 28 base::RandUint64());
28 } 29 }
29 30
30 } // namespace 31 } // namespace
31 32
32 PlatformChannelPair::PlatformChannelPair() { 33 PlatformChannelPair::PlatformChannelPair() {
33 std::wstring pipe_name = GeneratePipeName(); 34 std::wstring pipe_name = GeneratePipeName();
34 35
35 const DWORD kOpenMode = 36 const DWORD kOpenMode =
36 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE; 37 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE;
37 const DWORD kPipeMode = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE; 38 const DWORD kPipeMode = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE;
38 server_handle_.reset(PlatformHandle( 39 server_handle_.reset(PlatformHandle(
39 CreateNamedPipeW(pipe_name.c_str(), kOpenMode, kPipeMode, 40 CreateNamedPipeW(pipe_name.c_str(),
41 kOpenMode,
42 kPipeMode,
40 1, // Max instances. 43 1, // Max instances.
41 4096, // Out buffer size. 44 4096, // Out buffer size.
42 4096, // In buffer size. 45 4096, // In buffer size.
43 5000, // Timeout in milliseconds. 46 5000, // Timeout in milliseconds.
44 nullptr))); // Default security descriptor. 47 nullptr))); // Default security descriptor.
45 PCHECK(server_handle_.is_valid()); 48 PCHECK(server_handle_.is_valid());
46 49
47 const DWORD kDesiredAccess = GENERIC_READ | GENERIC_WRITE; 50 const DWORD kDesiredAccess = GENERIC_READ | GENERIC_WRITE;
48 // The SECURITY_ANONYMOUS flag means that the server side cannot impersonate 51 // The SECURITY_ANONYMOUS flag means that the server side cannot impersonate
49 // the client. 52 // the client.
50 const DWORD kFlags = 53 const DWORD kFlags =
51 SECURITY_SQOS_PRESENT | SECURITY_ANONYMOUS | FILE_FLAG_OVERLAPPED; 54 SECURITY_SQOS_PRESENT | SECURITY_ANONYMOUS | FILE_FLAG_OVERLAPPED;
52 // Allow the handle to be inherited by child processes. 55 // Allow the handle to be inherited by child processes.
53 SECURITY_ATTRIBUTES security_attributes = { 56 SECURITY_ATTRIBUTES security_attributes = {
54 sizeof(SECURITY_ATTRIBUTES), nullptr, TRUE}; 57 sizeof(SECURITY_ATTRIBUTES), nullptr, TRUE};
55 client_handle_.reset( 58 client_handle_.reset(
56 PlatformHandle(CreateFileW(pipe_name.c_str(), kDesiredAccess, 59 PlatformHandle(CreateFileW(pipe_name.c_str(),
60 kDesiredAccess,
57 0, // No sharing. 61 0, // No sharing.
58 &security_attributes, OPEN_EXISTING, kFlags, 62 &security_attributes,
63 OPEN_EXISTING,
64 kFlags,
59 nullptr))); // No template file. 65 nullptr))); // No template file.
60 PCHECK(client_handle_.is_valid()); 66 PCHECK(client_handle_.is_valid());
61 67
62 // Since a client has connected, ConnectNamedPipe() should return zero and 68 // Since a client has connected, ConnectNamedPipe() should return zero and
63 // GetLastError() should return ERROR_PIPE_CONNECTED. 69 // GetLastError() should return ERROR_PIPE_CONNECTED.
64 CHECK(!ConnectNamedPipe(server_handle_.get().handle, nullptr)); 70 CHECK(!ConnectNamedPipe(server_handle_.get().handle, nullptr));
65 PCHECK(GetLastError() == ERROR_PIPE_CONNECTED); 71 PCHECK(GetLastError() == ERROR_PIPE_CONNECTED);
66 } 72 }
67 73
68 // static 74 // static
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 << command_line->GetSwitchValueASCII(kMojoPlatformChannelHandleSwitch); 108 << command_line->GetSwitchValueASCII(kMojoPlatformChannelHandleSwitch);
103 // (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
104 // the last one appended takes precedence.) 110 // the last one appended takes precedence.)
105 command_line->AppendSwitchASCII( 111 command_line->AppendSwitchASCII(
106 kMojoPlatformChannelHandleSwitch, 112 kMojoPlatformChannelHandleSwitch,
107 base::IntToString(HandleToLong(client_handle_.get().handle))); 113 base::IntToString(HandleToLong(client_handle_.get().handle)));
108 } 114 }
109 115
110 } // namespace embedder 116 } // namespace embedder
111 } // namespace mojo 117 } // 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