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

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

Issue 780223002: ChannelProxy: Send() from UI thread when ChannelMojo is used. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 "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 20 matching lines...) Expand all
31 StopWaiting(); 31 StopWaiting();
32 pipe_.reset(); 32 pipe_.reset();
33 OnPipeClosed(); 33 OnPipeClosed();
34 } 34 }
35 35
36 void MessagePipeReader::CloseWithError(MojoResult error) { 36 void MessagePipeReader::CloseWithError(MojoResult error) {
37 OnPipeError(error); 37 OnPipeError(error);
38 Close(); 38 Close();
39 } 39 }
40 40
41 bool MessagePipeReader::Send(scoped_ptr<Message> message) { 41 MojoResult MessagePipeReader::Send(scoped_ptr<Message> message) {
42 DCHECK(IsValid()); 42 DCHECK(IsValid());
43 43
44 message->TraceMessageBegin(); 44 message->TraceMessageBegin();
45 std::vector<MojoHandle> handles; 45 std::vector<MojoHandle> handles;
46 MojoResult result = MOJO_RESULT_OK; 46 MojoResult result = MOJO_RESULT_OK;
47 #if defined(OS_POSIX) && !defined(OS_NACL) 47 #if defined(OS_POSIX) && !defined(OS_NACL)
48 result = ChannelMojo::ReadFromFileDescriptorSet(message.get(), &handles); 48 result = ChannelMojo::ReadFromFileDescriptorSet(message.get(), &handles);
49 #endif 49 #endif
50 if (result == MOJO_RESULT_OK) { 50 if (result == MOJO_RESULT_OK) {
51 result = MojoWriteMessage(handle(), 51 result = MojoWriteMessage(handle(),
52 message->data(), 52 message->data(),
53 static_cast<uint32>(message->size()), 53 static_cast<uint32>(message->size()),
54 handles.empty() ? nullptr : &handles[0], 54 handles.empty() ? nullptr : &handles[0],
55 static_cast<uint32>(handles.size()), 55 static_cast<uint32>(handles.size()),
56 MOJO_WRITE_MESSAGE_FLAG_NONE); 56 MOJO_WRITE_MESSAGE_FLAG_NONE);
57 } 57 }
58 58
59 if (result != MOJO_RESULT_OK) { 59 if (result != MOJO_RESULT_OK)
60 std::for_each(handles.begin(), handles.end(), &MojoClose); 60 std::for_each(handles.begin(), handles.end(), &MojoClose);
61 CloseWithError(result); 61 return result;
62 return false;
63 }
64
65 return true;
66 } 62 }
67 63
68 // static 64 // static
69 void MessagePipeReader::InvokePipeIsReady(void* closure, MojoResult result) { 65 void MessagePipeReader::InvokePipeIsReady(void* closure, MojoResult result) {
70 reinterpret_cast<MessagePipeReader*>(closure)->PipeIsReady(result); 66 reinterpret_cast<MessagePipeReader*>(closure)->PipeIsReady(result);
71 } 67 }
72 68
73 void MessagePipeReader::OnMessageReceived() { 69 void MessagePipeReader::OnMessageReceived() {
74 Message message(data_buffer().empty() ? "" : &data_buffer()[0], 70 Message message(data_buffer().empty() ? "" : &data_buffer()[0],
75 static_cast<uint32>(data_buffer().size())); 71 static_cast<uint32>(data_buffer().size()));
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 195
200 void MessagePipeReader::DelayedDeleter::operator()( 196 void MessagePipeReader::DelayedDeleter::operator()(
201 MessagePipeReader* ptr) const { 197 MessagePipeReader* ptr) const {
202 ptr->Close(); 198 ptr->Close();
203 base::MessageLoopProxy::current()->PostTask( 199 base::MessageLoopProxy::current()->PostTask(
204 FROM_HERE, base::Bind(&DeleteNow, ptr)); 200 FROM_HERE, base::Bind(&DeleteNow, ptr));
205 } 201 }
206 202
207 } // namespace internal 203 } // namespace internal
208 } // namespace IPC 204 } // namespace IPC
OLDNEW
« ipc/mojo/ipc_channel_mojo.cc ('K') | « ipc/mojo/ipc_message_pipe_reader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698