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

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

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 #ifndef IPC_IPC_MESSAGE_PIPE_READER_H_ 5 #ifndef IPC_IPC_MESSAGE_PIPE_READER_H_
6 #define IPC_IPC_MESSAGE_PIPE_READER_H_ 6 #define IPC_IPC_MESSAGE_PIPE_READER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/task_runner.h"
12 #include "ipc/ipc_message.h" 13 #include "ipc/ipc_message.h"
13 #include "mojo/public/c/environment/async_waiter.h" 14 #include "mojo/public/c/environment/async_waiter.h"
14 #include "mojo/public/cpp/system/core.h" 15 #include "mojo/public/cpp/system/core.h"
15 16
16 namespace IPC { 17 namespace IPC {
17 namespace internal { 18 namespace internal {
18 19
19 // A helper class to handle bytestream directly over mojo::MessagePipe 20 // A helper class to handle bytestream directly over mojo::MessagePipe
20 // in template-method pattern. MessagePipeReader manages the lifetime 21 // in template-method pattern. MessagePipeReader manages the lifetime
21 // of given MessagePipe and participates the event loop, and 22 // of given MessagePipe and participates the event loop, and
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 handle_buffer_.swap(*handle_buffer); 74 handle_buffer_.swap(*handle_buffer);
74 } 75 }
75 76
76 // Close and destroy the MessagePipe. 77 // Close and destroy the MessagePipe.
77 void Close(); 78 void Close();
78 // Close the mesage pipe with notifying the client with the error. 79 // Close the mesage pipe with notifying the client with the error.
79 void CloseWithError(MojoResult error); 80 void CloseWithError(MojoResult error);
80 // Return true if the MessagePipe is alive. 81 // Return true if the MessagePipe is alive.
81 bool IsValid() { return pipe_.is_valid(); } 82 bool IsValid() { return pipe_.is_valid(); }
82 83
83 bool Send(scoped_ptr<Message> message); 84 // |Send()| doesn't notify error nor close the message pipe. The caller must
85 // handle the error if the return value isn't |MOJO_RESULT_OK|. This policy
86 // gives some flexibility when to do the error notification.
87 MojoResult Send(scoped_ptr<Message> message);
84 88
85 private: 89 private:
86 static void InvokePipeIsReady(void* closure, MojoResult result); 90 static void InvokePipeIsReady(void* closure, MojoResult result);
87 91
88 void OnMessageReceived(); 92 void OnMessageReceived();
89 void OnPipeClosed(); 93 void OnPipeClosed();
90 void OnPipeError(MojoResult error); 94 void OnPipeError(MojoResult error);
91 95
92 MojoResult ReadMessageBytes(); 96 MojoResult ReadMessageBytes();
93 void PipeIsReady(MojoResult wait_result); 97 void PipeIsReady(MojoResult wait_result);
94 void StartWaiting(); 98 void StartWaiting();
95 void StopWaiting(); 99 void StopWaiting();
96 100
97 std::vector<char> data_buffer_; 101 std::vector<char> data_buffer_;
98 std::vector<MojoHandle> handle_buffer_; 102 std::vector<MojoHandle> handle_buffer_;
99 MojoAsyncWaitID pipe_wait_id_; 103 MojoAsyncWaitID pipe_wait_id_;
100 mojo::ScopedMessagePipeHandle pipe_; 104 mojo::ScopedMessagePipeHandle pipe_;
101 // Is null once the message pipe is closed. 105 // Is null once the message pipe is closed.
102 Delegate* delegate_; 106 Delegate* delegate_;
103 107
104 DISALLOW_COPY_AND_ASSIGN(MessagePipeReader); 108 DISALLOW_COPY_AND_ASSIGN(MessagePipeReader);
105 }; 109 };
106 110
107 } // namespace internal 111 } // namespace internal
108 } // namespace IPC 112 } // namespace IPC
109 113
110 #endif // IPC_IPC_MESSAGE_PIPE_READER_H_ 114 #endif // IPC_IPC_MESSAGE_PIPE_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698