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

Unified Diff: ipc/ipc_channel_proxy.cc

Issue 1991323002: Send input event IPCs directly from the UI thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ipc/ipc_channel_proxy.h ('k') | ipc/ipc_sync_channel.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/ipc_channel_proxy.cc
diff --git a/ipc/ipc_channel_proxy.cc b/ipc/ipc_channel_proxy.cc
index b3424124158d5034c5cd142c8779a81c17c83923..4fd8a9aa02cb268217b948660cbdffd6f9f272e3 100644
--- a/ipc/ipc_channel_proxy.cc
+++ b/ipc/ipc_channel_proxy.cc
@@ -318,23 +318,20 @@ void ChannelProxy::Context::ClearChannel() {
channel_.reset();
}
-void ChannelProxy::Context::SendFromThisThread(Message* message) {
- base::AutoLock l(channel_lifetime_lock_);
- if (!channel_)
- return;
- DCHECK(channel_->IsSendThreadSafe());
- channel_->Send(message);
-}
-
-void ChannelProxy::Context::Send(Message* message) {
- if (channel_send_thread_safe_) {
- SendFromThisThread(message);
- return;
+bool ChannelProxy::Context::Send(std::unique_ptr<Message> message,
+ bool force_io_thread) {
+ if (channel_send_thread_safe_ && !force_io_thread) {
+ base::AutoLock l(channel_lifetime_lock_);
+ if (!channel_)
+ return false;
+ DCHECK(channel_->IsSendThreadSafe());
+ return channel_->Send(message.release());
}
ipc_task_runner()->PostTask(
FROM_HERE, base::Bind(&ChannelProxy::Context::OnSendMessage, this,
- base::Passed(base::WrapUnique(message))));
+ base::Passed(&message)));
+ return true;
}
bool ChannelProxy::Context::IsChannelSendThreadSafe() const {
@@ -377,11 +374,7 @@ ChannelProxy::ChannelProxy(Context* context)
ChannelProxy::ChannelProxy(
Listener* listener,
const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner)
- : context_(new Context(listener, ipc_task_runner)), did_init_(false) {
-#if defined(ENABLE_IPC_FUZZER)
- outgoing_message_filter_ = NULL;
-#endif
-}
+ : ChannelProxy(new Context(listener, ipc_task_runner)) {}
ChannelProxy::~ChannelProxy() {
DCHECK(CalledOnValidThread());
@@ -444,25 +437,15 @@ void ChannelProxy::Close() {
}
bool ChannelProxy::Send(Message* message) {
- DCHECK(did_init_);
-
- // TODO(alexeypa): add DCHECK(CalledOnValidThread()) here. Currently there are
- // tests that call Send() from a wrong thread. See http://crbug.com/163523.
-
-#ifdef ENABLE_IPC_FUZZER
- // In IPC fuzzing builds, it is possible to define a filter to apply to
- // outgoing messages. It will either rewrite the message and return a new
- // one, freeing the original, or return the message unchanged.
- if (outgoing_message_filter())
- message = outgoing_message_filter()->Rewrite(message);
-#endif
+ return SendImpl(base::WrapUnique(message), true /* force_io_thread */);
+}
-#ifdef IPC_MESSAGE_LOG_ENABLED
- Logging::GetInstance()->OnSendMessage(message, context_->channel_id());
-#endif
+bool ChannelProxy::SendNow(std::unique_ptr<Message> message) {
+ return SendImpl(std::move(message), false /* force_io_thread */);
+}
- context_->Send(message);
- return true;
+bool ChannelProxy::SendOnIPCThread(std::unique_ptr<Message> message) {
+ return SendImpl(std::move(message), true /* force_io_thread */);
}
void ChannelProxy::AddFilter(MessageFilter* filter) {
@@ -519,6 +502,28 @@ base::ScopedFD ChannelProxy::TakeClientFileDescriptor() {
void ChannelProxy::OnChannelInit() {
}
+bool ChannelProxy::SendImpl(std::unique_ptr<Message> message,
+ bool force_io_thread) {
+ DCHECK(did_init_);
+
+ // TODO(alexeypa): add DCHECK(CalledOnValidThread()) here. Currently there are
+ // tests that call Send() from a wrong thread. See http://crbug.com/163523.
+
+#ifdef ENABLE_IPC_FUZZER
+ // In IPC fuzzing builds, it is possible to define a filter to apply to
+ // outgoing messages. It will either rewrite the message and return a new
+ // one, freeing the original, or return the message unchanged.
+ if (outgoing_message_filter())
+ message.reset(outgoing_message_filter()->Rewrite(message.release()));
+#endif
+
+#ifdef IPC_MESSAGE_LOG_ENABLED
+ Logging::GetInstance()->OnSendMessage(message.get(), context_->channel_id());
+#endif
+
+ return context_->Send(std::move(message), force_io_thread);
+}
+
//-----------------------------------------------------------------------------
} // namespace IPC
« no previous file with comments | « ipc/ipc_channel_proxy.h ('k') | ipc/ipc_sync_channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698