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

Side by Side Diff: mojo/edk/system/channel_win.cc

Issue 2008953003: [mojo-edk] Explicitly serialise HANDLEs into messages instead of PlatformHandles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cast2 Created 4 years, 6 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
« no previous file with comments | « mojo/edk/system/channel.cc ('k') | mojo/edk/system/message_pipe_dispatcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/system/channel.h" 5 #include "mojo/edk/system/channel.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <windows.h> 8 #include <windows.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 114 }
115 } 115 }
116 116
117 bool GetReadPlatformHandles( 117 bool GetReadPlatformHandles(
118 size_t num_handles, 118 size_t num_handles,
119 const void* extra_header, 119 const void* extra_header,
120 size_t extra_header_size, 120 size_t extra_header_size,
121 ScopedPlatformHandleVectorPtr* handles) override { 121 ScopedPlatformHandleVectorPtr* handles) override {
122 if (num_handles > std::numeric_limits<uint16_t>::max()) 122 if (num_handles > std::numeric_limits<uint16_t>::max())
123 return false; 123 return false;
124 size_t handles_size = sizeof(PlatformHandle) * num_handles; 124 using HandleEntry = Channel::Message::HandleEntry;
125 size_t handles_size = sizeof(HandleEntry) * num_handles;
125 if (handles_size > extra_header_size) 126 if (handles_size > extra_header_size)
126 return false; 127 return false;
127 DCHECK(extra_header); 128 DCHECK(extra_header);
128 handles->reset(new PlatformHandleVector(num_handles)); 129 handles->reset(new PlatformHandleVector(num_handles));
129 memcpy((*handles)->data(), extra_header, handles_size); 130 const HandleEntry* extra_header_handles =
131 reinterpret_cast<const HandleEntry*>(extra_header);
132 for (size_t i = 0; i < num_handles; i++) {
133 (*handles)->at(i).handle = reinterpret_cast<HANDLE>(
134 static_cast<uintptr_t>(extra_header_handles[i].handle));
135 }
130 return true; 136 return true;
131 } 137 }
132 138
133 private: 139 private:
134 // May run on any thread. 140 // May run on any thread.
135 ~ChannelWin() override {} 141 ~ChannelWin() override {}
136 142
137 void StartOnIOThread() { 143 void StartOnIOThread() {
138 base::MessageLoop::current()->AddDestructionObserver(this); 144 base::MessageLoop::current()->AddDestructionObserver(this);
139 base::MessageLoopForIO::current()->RegisterIOHandler( 145 base::MessageLoopForIO::current()->RegisterIOHandler(
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 // static 302 // static
297 scoped_refptr<Channel> Channel::Create( 303 scoped_refptr<Channel> Channel::Create(
298 Delegate* delegate, 304 Delegate* delegate,
299 ScopedPlatformHandle platform_handle, 305 ScopedPlatformHandle platform_handle,
300 scoped_refptr<base::TaskRunner> io_task_runner) { 306 scoped_refptr<base::TaskRunner> io_task_runner) {
301 return new ChannelWin(delegate, std::move(platform_handle), io_task_runner); 307 return new ChannelWin(delegate, std::move(platform_handle), io_task_runner);
302 } 308 }
303 309
304 } // namespace edk 310 } // namespace edk
305 } // namespace mojo 311 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/channel.cc ('k') | mojo/edk/system/message_pipe_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698