OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
| 9 #include <tuple> |
| 10 |
9 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
11 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
12 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/shared_memory.h" | 15 #include "base/memory/shared_memory.h" |
14 #include "base/memory/shared_memory_handle.h" | 16 #include "base/memory/shared_memory_handle.h" |
15 #include "base/win/scoped_handle.h" | 17 #include "base/win/scoped_handle.h" |
16 #include "ipc/attachment_broker_privileged_win.h" | 18 #include "ipc/attachment_broker_privileged_win.h" |
17 #include "ipc/attachment_broker_unprivileged_win.h" | 19 #include "ipc/attachment_broker_unprivileged_win.h" |
18 #include "ipc/handle_attachment_win.h" | 20 #include "ipc/handle_attachment_win.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 return ScopedHandle(nullptr); | 71 return ScopedHandle(nullptr); |
70 } | 72 } |
71 | 73 |
72 TestHandleWinMsg::Schema::Param p; | 74 TestHandleWinMsg::Schema::Param p; |
73 bool success = TestHandleWinMsg::Read(&message, &p); | 75 bool success = TestHandleWinMsg::Read(&message, &p); |
74 if (!success) { | 76 if (!success) { |
75 LOG(INFO) << "Failed to deserialize message."; | 77 LOG(INFO) << "Failed to deserialize message."; |
76 return ScopedHandle(nullptr); | 78 return ScopedHandle(nullptr); |
77 } | 79 } |
78 | 80 |
79 IPC::HandleWin handle_win = base::get<1>(p); | 81 IPC::HandleWin handle_win = std::get<1>(p); |
80 return ScopedHandle(handle_win.get_handle()); | 82 return ScopedHandle(handle_win.get_handle()); |
81 } | 83 } |
82 | 84 |
83 // Returns a mapped, shared memory region based on the handle in |message|. | 85 // Returns a mapped, shared memory region based on the handle in |message|. |
84 scoped_ptr<base::SharedMemory> GetSharedMemoryFromSharedMemoryHandleMsg1( | 86 scoped_ptr<base::SharedMemory> GetSharedMemoryFromSharedMemoryHandleMsg1( |
85 const IPC::Message& message, | 87 const IPC::Message& message, |
86 size_t size) { | 88 size_t size) { |
87 // Expect a message with a brokered attachment. | 89 // Expect a message with a brokered attachment. |
88 if (!message.HasBrokerableAttachments()) { | 90 if (!message.HasBrokerableAttachments()) { |
89 LOG(INFO) << "Message missing brokerable attachment."; | 91 LOG(INFO) << "Message missing brokerable attachment."; |
90 return nullptr; | 92 return nullptr; |
91 } | 93 } |
92 | 94 |
93 TestSharedMemoryHandleMsg1::Schema::Param p; | 95 TestSharedMemoryHandleMsg1::Schema::Param p; |
94 bool success = TestSharedMemoryHandleMsg1::Read(&message, &p); | 96 bool success = TestSharedMemoryHandleMsg1::Read(&message, &p); |
95 if (!success) { | 97 if (!success) { |
96 LOG(INFO) << "Failed to deserialize message."; | 98 LOG(INFO) << "Failed to deserialize message."; |
97 return nullptr; | 99 return nullptr; |
98 } | 100 } |
99 | 101 |
100 base::SharedMemoryHandle handle = base::get<0>(p); | 102 base::SharedMemoryHandle handle = std::get<0>(p); |
101 scoped_ptr<base::SharedMemory> shared_memory( | 103 scoped_ptr<base::SharedMemory> shared_memory( |
102 new base::SharedMemory(handle, false)); | 104 new base::SharedMemory(handle, false)); |
103 | 105 |
104 shared_memory->Map(size); | 106 shared_memory->Map(size); |
105 return shared_memory; | 107 return shared_memory; |
106 } | 108 } |
107 | 109 |
108 // |message| must be deserializable as a TestTwoHandleWinMsg. Returns the | 110 // |message| must be deserializable as a TestTwoHandleWinMsg. Returns the |
109 // HANDLE, or nullptr if deserialization failed. | 111 // HANDLE, or nullptr if deserialization failed. |
110 bool GetHandleFromTestTwoHandleWinMsg(const IPC::Message& message, | 112 bool GetHandleFromTestTwoHandleWinMsg(const IPC::Message& message, |
111 HANDLE* h1, | 113 HANDLE* h1, |
112 HANDLE* h2) { | 114 HANDLE* h2) { |
113 // Expect a message with a brokered attachment. | 115 // Expect a message with a brokered attachment. |
114 if (!message.HasBrokerableAttachments()) { | 116 if (!message.HasBrokerableAttachments()) { |
115 LOG(INFO) << "Message missing brokerable attachment."; | 117 LOG(INFO) << "Message missing brokerable attachment."; |
116 return false; | 118 return false; |
117 } | 119 } |
118 | 120 |
119 TestTwoHandleWinMsg::Schema::Param p; | 121 TestTwoHandleWinMsg::Schema::Param p; |
120 bool success = TestTwoHandleWinMsg::Read(&message, &p); | 122 bool success = TestTwoHandleWinMsg::Read(&message, &p); |
121 if (!success) { | 123 if (!success) { |
122 LOG(INFO) << "Failed to deserialize message."; | 124 LOG(INFO) << "Failed to deserialize message."; |
123 return false; | 125 return false; |
124 } | 126 } |
125 | 127 |
126 IPC::HandleWin handle_win = base::get<0>(p); | 128 IPC::HandleWin handle_win = std::get<0>(p); |
127 *h1 = handle_win.get_handle(); | 129 *h1 = handle_win.get_handle(); |
128 handle_win = base::get<1>(p); | 130 handle_win = std::get<1>(p); |
129 *h2 = handle_win.get_handle(); | 131 *h2 = handle_win.get_handle(); |
130 return true; | 132 return true; |
131 } | 133 } |
132 | 134 |
133 // |message| must be deserializable as a TestHandleWinMsg. Returns true if the | 135 // |message| must be deserializable as a TestHandleWinMsg. Returns true if the |
134 // attached file HANDLE has contents |kDataBuffer|. | 136 // attached file HANDLE has contents |kDataBuffer|. |
135 bool CheckContentsOfTestMessage(const IPC::Message& message) { | 137 bool CheckContentsOfTestMessage(const IPC::Message& message) { |
136 ScopedHandle h(GetHandleFromTestHandleWinMsg(message)); | 138 ScopedHandle h(GetHandleFromTestHandleWinMsg(message)); |
137 if (h.Get() == nullptr) { | 139 if (h.Get() == nullptr) { |
138 LOG(INFO) << "Failed to get handle from TestHandleWinMsg."; | 140 LOG(INFO) << "Failed to get handle from TestHandleWinMsg."; |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 memcmp(shared_memory->memory(), kDataBuffer, strlen(kDataBuffer)) == 0; | 645 memcmp(shared_memory->memory(), kDataBuffer, strlen(kDataBuffer)) == 0; |
644 SendControlMessage(sender, success); | 646 SendControlMessage(sender, success); |
645 } | 647 } |
646 | 648 |
647 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendSharedMemoryHandle) { | 649 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendSharedMemoryHandle) { |
648 return CommonPrivilegedProcessMain(&SendSharedMemoryHandleCallback, | 650 return CommonPrivilegedProcessMain(&SendSharedMemoryHandleCallback, |
649 "SendSharedMemoryHandle"); | 651 "SendSharedMemoryHandle"); |
650 } | 652 } |
651 | 653 |
652 } // namespace | 654 } // namespace |
OLD | NEW |