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

Side by Side Diff: ipc/mojo/ipc_message_pipe_reader.cc

Issue 1051443003: Implement IPC::ParamTraits<mojo::MessagePipeHandle> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Made tests work, actually, on Windows. Created 5 years, 8 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 | « ipc/mojo/ipc_channel_mojo_unittest.cc ('k') | ipc/mojo/ipc_mojo.gyp » ('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 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 "ipc/mojo/ipc_message_pipe_reader.h" 5 #include "ipc/mojo/ipc_message_pipe_reader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 27 matching lines...) Expand all
38 OnPipeError(error); 38 OnPipeError(error);
39 Close(); 39 Close();
40 } 40 }
41 41
42 bool MessagePipeReader::Send(scoped_ptr<Message> message) { 42 bool MessagePipeReader::Send(scoped_ptr<Message> message) {
43 DCHECK(IsValid()); 43 DCHECK(IsValid());
44 44
45 message->TraceMessageBegin(); 45 message->TraceMessageBegin();
46 std::vector<MojoHandle> handles; 46 std::vector<MojoHandle> handles;
47 MojoResult result = MOJO_RESULT_OK; 47 MojoResult result = MOJO_RESULT_OK;
48 #if defined(OS_POSIX) && !defined(OS_NACL)
49 result = ChannelMojo::ReadFromMessageAttachmentSet(message.get(), &handles); 48 result = ChannelMojo::ReadFromMessageAttachmentSet(message.get(), &handles);
50 #endif
51 if (result == MOJO_RESULT_OK) { 49 if (result == MOJO_RESULT_OK) {
52 result = MojoWriteMessage(handle(), 50 result = MojoWriteMessage(handle(),
53 message->data(), 51 message->data(),
54 static_cast<uint32>(message->size()), 52 static_cast<uint32>(message->size()),
55 handles.empty() ? nullptr : &handles[0], 53 handles.empty() ? nullptr : &handles[0],
56 static_cast<uint32>(handles.size()), 54 static_cast<uint32>(handles.size()),
57 MOJO_WRITE_MESSAGE_FLAG_NONE); 55 MOJO_WRITE_MESSAGE_FLAG_NONE);
58 } 56 }
59 57
60 if (result != MOJO_RESULT_OK) { 58 if (result != MOJO_RESULT_OK) {
61 std::for_each(handles.begin(), handles.end(), &MojoClose); 59 std::for_each(handles.begin(), handles.end(), &MojoClose);
62 CloseWithError(result); 60 CloseWithError(result);
63 return false; 61 return false;
64 } 62 }
65 63
66 return true; 64 return true;
67 } 65 }
68 66
69 void MessagePipeReader::OnMessageReceived() { 67 void MessagePipeReader::OnMessageReceived() {
70 Message message(data_buffer().empty() ? "" : &data_buffer()[0], 68 Message message(data_buffer().empty() ? "" : &data_buffer()[0],
71 static_cast<uint32>(data_buffer().size())); 69 static_cast<uint32>(data_buffer().size()));
72 70
73 std::vector<MojoHandle> handle_buffer; 71 std::vector<MojoHandle> handle_buffer;
74 TakeHandleBuffer(&handle_buffer); 72 TakeHandleBuffer(&handle_buffer);
75 #if defined(OS_POSIX) && !defined(OS_NACL)
76 MojoResult write_result = 73 MojoResult write_result =
77 ChannelMojo::WriteToMessageAttachmentSet(handle_buffer, &message); 74 ChannelMojo::WriteToMessageAttachmentSet(handle_buffer, &message);
78 if (write_result != MOJO_RESULT_OK) { 75 if (write_result != MOJO_RESULT_OK) {
79 CloseWithError(write_result); 76 CloseWithError(write_result);
80 return; 77 return;
81 } 78 }
82 #else
83 DCHECK(handle_buffer.empty());
84 #endif
85 79
86 message.TraceMessageEnd(); 80 message.TraceMessageEnd();
87 delegate_->OnMessageReceived(message); 81 delegate_->OnMessageReceived(message);
88 } 82 }
89 83
90 void MessagePipeReader::OnPipeClosed() { 84 void MessagePipeReader::OnPipeClosed() {
91 if (!delegate_) 85 if (!delegate_)
92 return; 86 return;
93 delegate_->OnPipeClosed(this); 87 delegate_->OnPipeClosed(this);
94 delegate_ = nullptr; 88 delegate_ = nullptr;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 191
198 void MessagePipeReader::DelayedDeleter::operator()( 192 void MessagePipeReader::DelayedDeleter::operator()(
199 MessagePipeReader* ptr) const { 193 MessagePipeReader* ptr) const {
200 ptr->Close(); 194 ptr->Close();
201 base::MessageLoopProxy::current()->PostTask( 195 base::MessageLoopProxy::current()->PostTask(
202 FROM_HERE, base::Bind(&DeleteNow, ptr)); 196 FROM_HERE, base::Bind(&DeleteNow, ptr));
203 } 197 }
204 198
205 } // namespace internal 199 } // namespace internal
206 } // namespace IPC 200 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/mojo/ipc_channel_mojo_unittest.cc ('k') | ipc/mojo/ipc_mojo.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698