summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrockot <rockot@chromium.org>2015-08-06 23:23:59 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-07 06:24:36 +0000
commit29ade1b15c854942b553c446df18ad3f3f46a931 (patch)
tree91ac428dc18c19f51a121b628af812557a0e3878
parent37ca25b5d3030b6d2f929c597f533478679a9fe1 (diff)
downloadchromium_src-29ade1b15c854942b553c446df18ad3f3f46a931.zip
chromium_src-29ade1b15c854942b553c446df18ad3f3f46a931.tar.gz
chromium_src-29ade1b15c854942b553c446df18ad3f3f46a931.tar.bz2
Complete SyncMessageFilter initialization after SyncChannel initialization
This changes SyncChannel to keep track of any SyncMessageFilters it creates prior to ChannelProxy::Init being called. Once Init completes, initialization of all tracked SyncMessageFilters is completed by updating their is_channel_send_thread_safe flag. BUG=516464 R=jam@chromium.org Review URL: https://codereview.chromium.org/1279863004 Cr-Commit-Position: refs/heads/master@{#342308}
-rw-r--r--ipc/ipc_channel_proxy.cc4
-rw-r--r--ipc/ipc_channel_proxy.h6
-rw-r--r--ipc/ipc_sync_channel.cc10
-rw-r--r--ipc/ipc_sync_channel.h9
-rw-r--r--ipc/ipc_sync_message_filter.h4
5 files changed, 32 insertions, 1 deletions
diff --git a/ipc/ipc_channel_proxy.cc b/ipc/ipc_channel_proxy.cc
index adb3d67..2398b51 100644
--- a/ipc/ipc_channel_proxy.cc
+++ b/ipc/ipc_channel_proxy.cc
@@ -430,6 +430,7 @@ void ChannelProxy::Init(scoped_ptr<ChannelFactory> factory,
FROM_HERE, base::Bind(&Context::OnChannelOpened, context_.get()));
did_init_ = true;
+ OnChannelInit();
}
void ChannelProxy::Close() {
@@ -514,6 +515,9 @@ void ChannelProxy::SetAttachmentBrokerEndpoint(bool is_endpoint) {
context()->set_attachment_broker_endpoint(is_endpoint);
}
+void ChannelProxy::OnChannelInit() {
+}
+
//-----------------------------------------------------------------------------
} // namespace IPC
diff --git a/ipc/ipc_channel_proxy.h b/ipc/ipc_channel_proxy.h
index f9f7d31..b01ccbc 100644
--- a/ipc/ipc_channel_proxy.h
+++ b/ipc/ipc_channel_proxy.h
@@ -289,9 +289,15 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe {
}
#endif
+ protected:
+ bool did_init() const { return did_init_; }
+
private:
friend class IpcSecurityTestUtil;
+ // Always called once immediately after Init.
+ virtual void OnChannelInit();
+
// By maintaining this indirection (ref-counted) to our internal state, we
// can safely be destroyed while the background thread continues to do stuff
// that involves this data.
diff --git a/ipc/ipc_sync_channel.cc b/ipc/ipc_sync_channel.cc
index 845eccd..04ebd41 100644
--- a/ipc/ipc_sync_channel.cc
+++ b/ipc/ipc_sync_channel.cc
@@ -465,6 +465,8 @@ scoped_refptr<SyncMessageFilter> SyncChannel::CreateSyncMessageFilter() {
sync_context()->shutdown_event(),
sync_context()->IsChannelSendThreadSafe());
AddFilter(filter.get());
+ if (!did_init())
+ pre_init_sync_message_filters_.push_back(filter);
return filter;
}
@@ -592,4 +594,12 @@ void SyncChannel::StartWatching() {
dispatch_watcher_callback_);
}
+void SyncChannel::OnChannelInit() {
+ for (const auto& filter : pre_init_sync_message_filters_) {
+ filter->set_is_channel_send_thread_safe(
+ context()->IsChannelSendThreadSafe());
+ }
+ pre_init_sync_message_filters_.clear();
+}
+
} // namespace IPC
diff --git a/ipc/ipc_sync_channel.h b/ipc/ipc_sync_channel.h
index 2fd1b11..243d6b0 100644
--- a/ipc/ipc_sync_channel.h
+++ b/ipc/ipc_sync_channel.h
@@ -5,8 +5,9 @@
#ifndef IPC_IPC_SYNC_CHANNEL_H_
#define IPC_IPC_SYNC_CHANNEL_H_
-#include <string>
#include <deque>
+#include <string>
+#include <vector>
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
@@ -233,10 +234,16 @@ class IPC_EXPORT SyncChannel : public ChannelProxy {
// Starts the dispatch watcher.
void StartWatching();
+ // ChannelProxy overrides:
+ void OnChannelInit() override;
+
// Used to signal events between the IPC and listener threads.
base::WaitableEventWatcher dispatch_watcher_;
base::WaitableEventWatcher::EventCallback dispatch_watcher_callback_;
+ // Tracks SyncMessageFilters created before complete channel initialization.
+ std::vector<scoped_refptr<SyncMessageFilter>> pre_init_sync_message_filters_;
+
DISALLOW_COPY_AND_ASSIGN(SyncChannel);
};
diff --git a/ipc/ipc_sync_message_filter.h b/ipc/ipc_sync_message_filter.h
index 2a3c4e8..6e4f991 100644
--- a/ipc/ipc_sync_message_filter.h
+++ b/ipc/ipc_sync_message_filter.h
@@ -48,6 +48,10 @@ class IPC_EXPORT SyncMessageFilter : public MessageFilter, public Sender {
private:
friend class SyncChannel;
+ void set_is_channel_send_thread_safe(bool is_channel_send_thread_safe) {
+ is_channel_send_thread_safe_ = is_channel_send_thread_safe;
+ }
+
void SendOnIOThread(Message* message);
// Signal all the pending sends as done, used in an error condition.
void SignalAllEvents();