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

Side by Side Diff: ipc/attachment_broker_privileged_win_unittest.cc

Issue 1770013002: Replace base::Tuple in //ipc with std::tuple (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months 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 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 "base/files/file_path.h" 9 #include "base/files/file_path.h"
Tom Sepez 2016/03/07 19:05:01 ditto
tzik 2016/03/08 03:32:59 Done.
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/shared_memory.h" 13 #include "base/memory/shared_memory.h"
14 #include "base/memory/shared_memory_handle.h" 14 #include "base/memory/shared_memory_handle.h"
15 #include "base/win/scoped_handle.h" 15 #include "base/win/scoped_handle.h"
16 #include "ipc/attachment_broker_privileged_win.h" 16 #include "ipc/attachment_broker_privileged_win.h"
17 #include "ipc/attachment_broker_unprivileged_win.h" 17 #include "ipc/attachment_broker_unprivileged_win.h"
18 #include "ipc/handle_attachment_win.h" 18 #include "ipc/handle_attachment_win.h"
19 #include "ipc/handle_win.h" 19 #include "ipc/handle_win.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 return ScopedHandle(nullptr); 69 return ScopedHandle(nullptr);
70 } 70 }
71 71
72 TestHandleWinMsg::Schema::Param p; 72 TestHandleWinMsg::Schema::Param p;
73 bool success = TestHandleWinMsg::Read(&message, &p); 73 bool success = TestHandleWinMsg::Read(&message, &p);
74 if (!success) { 74 if (!success) {
75 LOG(INFO) << "Failed to deserialize message."; 75 LOG(INFO) << "Failed to deserialize message.";
76 return ScopedHandle(nullptr); 76 return ScopedHandle(nullptr);
77 } 77 }
78 78
79 IPC::HandleWin handle_win = base::get<1>(p); 79 IPC::HandleWin handle_win = std::get<1>(p);
80 return ScopedHandle(handle_win.get_handle()); 80 return ScopedHandle(handle_win.get_handle());
81 } 81 }
82 82
83 // Returns a mapped, shared memory region based on the handle in |message|. 83 // Returns a mapped, shared memory region based on the handle in |message|.
84 scoped_ptr<base::SharedMemory> GetSharedMemoryFromSharedMemoryHandleMsg1( 84 scoped_ptr<base::SharedMemory> GetSharedMemoryFromSharedMemoryHandleMsg1(
85 const IPC::Message& message, 85 const IPC::Message& message,
86 size_t size) { 86 size_t size) {
87 // Expect a message with a brokered attachment. 87 // Expect a message with a brokered attachment.
88 if (!message.HasBrokerableAttachments()) { 88 if (!message.HasBrokerableAttachments()) {
89 LOG(INFO) << "Message missing brokerable attachment."; 89 LOG(INFO) << "Message missing brokerable attachment.";
90 return nullptr; 90 return nullptr;
91 } 91 }
92 92
93 TestSharedMemoryHandleMsg1::Schema::Param p; 93 TestSharedMemoryHandleMsg1::Schema::Param p;
94 bool success = TestSharedMemoryHandleMsg1::Read(&message, &p); 94 bool success = TestSharedMemoryHandleMsg1::Read(&message, &p);
95 if (!success) { 95 if (!success) {
96 LOG(INFO) << "Failed to deserialize message."; 96 LOG(INFO) << "Failed to deserialize message.";
97 return nullptr; 97 return nullptr;
98 } 98 }
99 99
100 base::SharedMemoryHandle handle = base::get<0>(p); 100 base::SharedMemoryHandle handle = std::get<0>(p);
101 scoped_ptr<base::SharedMemory> shared_memory( 101 scoped_ptr<base::SharedMemory> shared_memory(
102 new base::SharedMemory(handle, false)); 102 new base::SharedMemory(handle, false));
103 103
104 shared_memory->Map(size); 104 shared_memory->Map(size);
105 return shared_memory; 105 return shared_memory;
106 } 106 }
107 107
108 // |message| must be deserializable as a TestTwoHandleWinMsg. Returns the 108 // |message| must be deserializable as a TestTwoHandleWinMsg. Returns the
109 // HANDLE, or nullptr if deserialization failed. 109 // HANDLE, or nullptr if deserialization failed.
110 bool GetHandleFromTestTwoHandleWinMsg(const IPC::Message& message, 110 bool GetHandleFromTestTwoHandleWinMsg(const IPC::Message& message,
111 HANDLE* h1, 111 HANDLE* h1,
112 HANDLE* h2) { 112 HANDLE* h2) {
113 // Expect a message with a brokered attachment. 113 // Expect a message with a brokered attachment.
114 if (!message.HasBrokerableAttachments()) { 114 if (!message.HasBrokerableAttachments()) {
115 LOG(INFO) << "Message missing brokerable attachment."; 115 LOG(INFO) << "Message missing brokerable attachment.";
116 return false; 116 return false;
117 } 117 }
118 118
119 TestTwoHandleWinMsg::Schema::Param p; 119 TestTwoHandleWinMsg::Schema::Param p;
120 bool success = TestTwoHandleWinMsg::Read(&message, &p); 120 bool success = TestTwoHandleWinMsg::Read(&message, &p);
121 if (!success) { 121 if (!success) {
122 LOG(INFO) << "Failed to deserialize message."; 122 LOG(INFO) << "Failed to deserialize message.";
123 return false; 123 return false;
124 } 124 }
125 125
126 IPC::HandleWin handle_win = base::get<0>(p); 126 IPC::HandleWin handle_win = std::get<0>(p);
127 *h1 = handle_win.get_handle(); 127 *h1 = handle_win.get_handle();
128 handle_win = base::get<1>(p); 128 handle_win = std::get<1>(p);
129 *h2 = handle_win.get_handle(); 129 *h2 = handle_win.get_handle();
130 return true; 130 return true;
131 } 131 }
132 132
133 // |message| must be deserializable as a TestHandleWinMsg. Returns true if the 133 // |message| must be deserializable as a TestHandleWinMsg. Returns true if the
134 // attached file HANDLE has contents |kDataBuffer|. 134 // attached file HANDLE has contents |kDataBuffer|.
135 bool CheckContentsOfTestMessage(const IPC::Message& message) { 135 bool CheckContentsOfTestMessage(const IPC::Message& message) {
136 ScopedHandle h(GetHandleFromTestHandleWinMsg(message)); 136 ScopedHandle h(GetHandleFromTestHandleWinMsg(message));
137 if (h.Get() == nullptr) { 137 if (h.Get() == nullptr) {
138 LOG(INFO) << "Failed to get handle from TestHandleWinMsg."; 138 LOG(INFO) << "Failed to get handle from TestHandleWinMsg.";
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 memcmp(shared_memory->memory(), kDataBuffer, strlen(kDataBuffer)) == 0; 643 memcmp(shared_memory->memory(), kDataBuffer, strlen(kDataBuffer)) == 0;
644 SendControlMessage(sender, success); 644 SendControlMessage(sender, success);
645 } 645 }
646 646
647 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendSharedMemoryHandle) { 647 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendSharedMemoryHandle) {
648 return CommonPrivilegedProcessMain(&SendSharedMemoryHandleCallback, 648 return CommonPrivilegedProcessMain(&SendSharedMemoryHandleCallback,
649 "SendSharedMemoryHandle"); 649 "SendSharedMemoryHandle");
650 } 650 }
651 651
652 } // namespace 652 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698