summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsheu@chromium.org <sheu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-13 10:15:37 +0000
committersheu@chromium.org <sheu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-13 10:15:37 +0000
commit4795329fcd7308914fcdbee6f824c250cfae2629 (patch)
tree905e1ab545c681bc6ab40043bd9370e7a7f8e89e
parentd732891b4ee22048d942a6d6523fbaa311c11cb4 (diff)
downloadchromium_src-4795329fcd7308914fcdbee6f824c250cfae2629.zip
chromium_src-4795329fcd7308914fcdbee6f824c250cfae2629.tar.gz
chromium_src-4795329fcd7308914fcdbee6f824c250cfae2629.tar.bz2
Remove some content_child dependency from content_common
content_common does not have an explicit dependency on content_child in the GYP files, yet depends on symbols from content_child. This causes order-dependent linker errors on some builds (e.g. win8_aura). Fix this by refactoring content::ChildThread to remove the need for that dependency, namely: * Refactor content::ChildThread to allow users to access (and pass around) its content::MessageRouter member for use in IPC messaging, instead of passing around the ChildThread itself. * Remove explicit check for ChildThread in content::VaapiVideoDecodeAccelerator. * Update DEPS files accordingly. BUG=351948 TEST=local build on desktop Linux Review URL: https://codereview.chromium.org/198073003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256787 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/child/child_thread.cc23
-rw-r--r--content/child/child_thread.h18
-rw-r--r--content/child/webmessageportchannel_impl.cc6
-rw-r--r--content/common/gpu/DEPS3
-rw-r--r--content/common/gpu/gpu_channel_manager.cc16
-rw-r--r--content/common/gpu/gpu_channel_manager.h13
-rw-r--r--content/common/gpu/media/vaapi_video_decode_accelerator.cc19
-rw-r--r--content/gpu/gpu_child_thread.cc2
-rw-r--r--content/renderer/pepper/ppb_broker_impl.cc4
-rw-r--r--content/renderer/render_thread_impl.cc4
-rw-r--r--content/renderer/shared_worker_repository.cc2
-rw-r--r--content/renderer/websharedworker_proxy.cc12
-rw-r--r--content/renderer/websharedworker_proxy.h6
-rw-r--r--content/worker/websharedworker_stub.cc4
14 files changed, 61 insertions, 71 deletions
diff --git a/content/child/child_thread.cc b/content/child/child_thread.cc
index 8c160ad..57919e5 100644
--- a/content/child/child_thread.cc
+++ b/content/child/child_thread.cc
@@ -192,8 +192,17 @@ void QuitMainThreadMessageLoop() {
} // namespace
+ChildThread::ChildThreadMessageRouter::ChildThreadMessageRouter(
+ IPC::Sender* sender)
+ : sender_(sender) {}
+
+bool ChildThread::ChildThreadMessageRouter::Send(IPC::Message* msg) {
+ return sender_->Send(msg);
+}
+
ChildThread::ChildThread()
- : channel_connected_factory_(this),
+ : router_(this),
+ channel_connected_factory_(this),
in_browser_process_(false) {
channel_name_ = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessChannelID);
@@ -202,6 +211,7 @@ ChildThread::ChildThread()
ChildThread::ChildThread(const std::string& channel_name)
: channel_name_(channel_name),
+ router_(this),
channel_connected_factory_(this),
in_browser_process_(true) {
Init();
@@ -349,16 +359,9 @@ bool ChildThread::Send(IPC::Message* msg) {
return channel_->Send(msg);
}
-void ChildThread::AddRoute(int32 routing_id, IPC::Listener* listener) {
+MessageRouter* ChildThread::GetRouter() {
DCHECK(base::MessageLoop::current() == message_loop());
-
- router_.AddRoute(routing_id, listener);
-}
-
-void ChildThread::RemoveRoute(int32 routing_id) {
- DCHECK(base::MessageLoop::current() == message_loop());
-
- router_.RemoveRoute(routing_id);
+ return &router_;
}
webkit_glue::ResourceLoaderBridge* ChildThread::CreateBridge(
diff --git a/content/child/child_thread.h b/content/child/child_thread.h
index 89156ba..33083bf 100644
--- a/content/child/child_thread.h
+++ b/content/child/child_thread.h
@@ -66,12 +66,10 @@ class CONTENT_EXPORT ChildThread : public IPC::Listener, public IPC::Sender {
// IPC::Sender implementation:
virtual bool Send(IPC::Message* msg) OVERRIDE;
- // See documentation on MessageRouter for AddRoute and RemoveRoute
- void AddRoute(int32 routing_id, IPC::Listener* listener);
- void RemoveRoute(int32 routing_id);
-
IPC::SyncChannel* channel() { return channel_.get(); }
+ MessageRouter* GetRouter();
+
// Creates a ResourceLoaderBridge.
// Tests can override this method if they want a custom loading behavior.
virtual webkit_glue::ResourceLoaderBridge* CreateBridge(
@@ -164,6 +162,16 @@ class CONTENT_EXPORT ChildThread : public IPC::Listener, public IPC::Sender {
virtual void OnChannelError() OVERRIDE;
private:
+ class ChildThreadMessageRouter : public MessageRouter {
+ public:
+ // |sender| must outlive this object.
+ explicit ChildThreadMessageRouter(IPC::Sender* sender);
+ virtual bool Send(IPC::Message* msg) OVERRIDE;
+
+ private:
+ IPC::Sender* const sender_;
+ };
+
void Init();
// IPC message handlers.
@@ -189,7 +197,7 @@ class CONTENT_EXPORT ChildThread : public IPC::Listener, public IPC::Sender {
scoped_refptr<ThreadSafeSender> thread_safe_sender_;
// Implements message routing functionality to the consumers of ChildThread.
- MessageRouter router_;
+ ChildThreadMessageRouter router_;
// Handles resource loads for this process.
scoped_ptr<ResourceDispatcher> resource_dispatcher_;
diff --git a/content/child/webmessageportchannel_impl.cc b/content/child/webmessageportchannel_impl.cc
index 86e80fb..cf439cc 100644
--- a/content/child/webmessageportchannel_impl.cc
+++ b/content/child/webmessageportchannel_impl.cc
@@ -56,7 +56,7 @@ WebMessagePortChannelImpl::~WebMessagePortChannelImpl() {
Send(new MessagePortHostMsg_DestroyMessagePort(message_port_id_));
if (route_id_ != MSG_ROUTING_NONE)
- ChildThread::current()->RemoveRoute(route_id_);
+ ChildThread::current()->GetRouter()->RemoveRoute(route_id_);
}
void WebMessagePortChannelImpl::setClient(WebMessagePortChannelClient* client) {
@@ -149,7 +149,7 @@ void WebMessagePortChannelImpl::Init() {
&route_id_, &message_port_id_));
}
- ChildThread::current()->AddRoute(route_id_, this);
+ ChildThread::current()->GetRouter()->AddRoute(route_id_, this);
}
void WebMessagePortChannelImpl::Entangle(
@@ -193,7 +193,7 @@ void WebMessagePortChannelImpl::Send(IPC::Message* message) {
return;
}
- ChildThread::current()->Send(message);
+ ChildThread::current()->GetRouter()->Send(message);
}
bool WebMessagePortChannelImpl::OnMessageReceived(const IPC::Message& message) {
diff --git a/content/common/gpu/DEPS b/content/common/gpu/DEPS
index 7d19c09..f58a808 100644
--- a/content/common/gpu/DEPS
+++ b/content/common/gpu/DEPS
@@ -6,7 +6,4 @@ include_rules = [
"+media/video/video_encode_accelerator.h",
"+skia",
"+third_party/mesa",
-
- # For single process mode
- "+content/child/child_thread.h",
]
diff --git a/content/common/gpu/gpu_channel_manager.cc b/content/common/gpu/gpu_channel_manager.cc
index 016e357..86ea2bf 100644
--- a/content/common/gpu/gpu_channel_manager.cc
+++ b/content/common/gpu/gpu_channel_manager.cc
@@ -6,11 +6,11 @@
#include "base/bind.h"
#include "base/command_line.h"
-#include "content/child/child_thread.h"
#include "content/common/gpu/gpu_channel.h"
#include "content/common/gpu/gpu_memory_manager.h"
#include "content/common/gpu/gpu_messages.h"
#include "content/common/gpu/sync_point_manager.h"
+#include "content/common/message_router.h"
#include "gpu/command_buffer/service/feature_info.h"
#include "gpu/command_buffer/service/gpu_switches.h"
#include "gpu/command_buffer/service/mailbox_manager.h"
@@ -29,20 +29,20 @@ GpuChannelManager::ImageOperation::ImageOperation(
GpuChannelManager::ImageOperation::~ImageOperation() {
}
-GpuChannelManager::GpuChannelManager(ChildThread* gpu_child_thread,
+GpuChannelManager::GpuChannelManager(MessageRouter* router,
GpuWatchdog* watchdog,
base::MessageLoopProxy* io_message_loop,
base::WaitableEvent* shutdown_event)
: weak_factory_(this),
io_message_loop_(io_message_loop),
shutdown_event_(shutdown_event),
- gpu_child_thread_(gpu_child_thread),
+ router_(router),
gpu_memory_manager_(
this,
GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit),
watchdog_(watchdog),
sync_point_manager_(new SyncPointManager) {
- DCHECK(gpu_child_thread);
+ DCHECK(router_);
DCHECK(io_message_loop);
DCHECK(shutdown_event);
}
@@ -78,11 +78,11 @@ int GpuChannelManager::GenerateRouteID() {
}
void GpuChannelManager::AddRoute(int32 routing_id, IPC::Listener* listener) {
- gpu_child_thread_->AddRoute(routing_id, listener);
+ router_->AddRoute(routing_id, listener);
}
void GpuChannelManager::RemoveRoute(int32 routing_id) {
- gpu_child_thread_->RemoveRoute(routing_id);
+ router_->RemoveRoute(routing_id);
}
GpuChannel* GpuChannelManager::LookupChannel(int32 client_id) {
@@ -109,9 +109,7 @@ bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) {
return handled;
}
-bool GpuChannelManager::Send(IPC::Message* msg) {
- return gpu_child_thread_->Send(msg);
-}
+bool GpuChannelManager::Send(IPC::Message* msg) { return router_->Send(msg); }
void GpuChannelManager::OnEstablishChannel(int client_id, bool share_context) {
IPC::ChannelHandle channel_handle;
diff --git a/content/common/gpu/gpu_channel_manager.h b/content/common/gpu/gpu_channel_manager.h
index eb4d224..638028e 100644
--- a/content/common/gpu/gpu_channel_manager.h
+++ b/content/common/gpu/gpu_channel_manager.h
@@ -44,25 +44,18 @@ struct ChannelHandle;
struct GPUCreateCommandBufferConfig;
namespace content {
-class ChildThread;
class GpuChannel;
class GpuWatchdog;
+class MessageRouter;
class SyncPointManager;
// A GpuChannelManager is a thread responsible for issuing rendering commands
// managing the lifetimes of GPU channels and forwarding IPC requests from the
// browser process to them based on the corresponding renderer ID.
-//
-// A GpuChannelManager can also be hosted in the browser process in single
-// process or in-process GPU modes. In this case there is no corresponding
-// GpuChildThread and this is the reason the GpuChildThread is referenced via
-// a pointer to IPC::Sender, which can be implemented by other hosts to send
-// IPC messages to the browser process IO thread on the GpuChannelManager's
-// behalf.
class GpuChannelManager : public IPC::Listener,
public IPC::Sender {
public:
- GpuChannelManager(ChildThread* gpu_child_thread,
+ GpuChannelManager(MessageRouter* router,
GpuWatchdog* watchdog,
base::MessageLoopProxy* io_message_loop,
base::WaitableEvent* shutdown_event);
@@ -138,7 +131,7 @@ class GpuChannelManager : public IPC::Listener,
base::WaitableEvent* shutdown_event_;
// Used to send and receive IPC messages from the browser process.
- ChildThread* gpu_child_thread_;
+ MessageRouter* const router_;
// These objects manage channels to individual renderer processes there is
// one channel for each renderer process that has connected to this GPU
diff --git a/content/common/gpu/media/vaapi_video_decode_accelerator.cc b/content/common/gpu/media/vaapi_video_decode_accelerator.cc
index 79860d5b..30a974b 100644
--- a/content/common/gpu/media/vaapi_video_decode_accelerator.cc
+++ b/content/common/gpu/media/vaapi_video_decode_accelerator.cc
@@ -9,7 +9,7 @@
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/synchronization/waitable_event.h"
-#include "content/child/child_thread.h"
+#include "base/threading/non_thread_safe.h"
#include "content/common/gpu/gpu_channel.h"
#include "content/common/gpu/media/vaapi_video_decode_accelerator.h"
#include "media/base/bind_to_current_loop.h"
@@ -68,7 +68,7 @@ void VaapiVideoDecodeAccelerator::NotifyError(Error error) {
//
// TFPPictures are used for output, contents of VASurfaces passed from decoder
// are put into the associated pixmap memory and sent to client.
-class VaapiVideoDecodeAccelerator::TFPPicture {
+class VaapiVideoDecodeAccelerator::TFPPicture : public base::NonThreadSafe {
public:
~TFPPicture();
@@ -158,10 +158,7 @@ VaapiVideoDecodeAccelerator::TFPPicture::Create(
bool VaapiVideoDecodeAccelerator::TFPPicture::Initialize(
const GLXFBConfig& fb_config) {
- // Check for NULL prevents unittests from crashing on nonexistent ChildThread.
- DCHECK(ChildThread::current() == NULL ||
- ChildThread::current()->message_loop() == base::MessageLoop::current());
-
+ DCHECK(CalledOnValidThread());
if (!make_context_current_.Run())
return false;
@@ -193,10 +190,7 @@ bool VaapiVideoDecodeAccelerator::TFPPicture::Initialize(
}
VaapiVideoDecodeAccelerator::TFPPicture::~TFPPicture() {
- // Check for NULL prevents unittests from crashing on nonexistent ChildThread.
- DCHECK(ChildThread::current() == NULL ||
- ChildThread::current()->message_loop() == base::MessageLoop::current());
-
+ DCHECK(CalledOnValidThread());
// Unbind surface from texture and deallocate resources.
if (glx_pixmap_ && make_context_current_.Run()) {
glXReleaseTexImageEXT(x_display_, glx_pixmap_, GLX_FRONT_LEFT_EXT);
@@ -209,12 +203,9 @@ VaapiVideoDecodeAccelerator::TFPPicture::~TFPPicture() {
}
bool VaapiVideoDecodeAccelerator::TFPPicture::Bind() {
+ DCHECK(CalledOnValidThread());
DCHECK(x_pixmap_);
DCHECK(glx_pixmap_);
- // Check for NULL prevents unittests from crashing on nonexistent ChildThread.
- DCHECK(ChildThread::current() == NULL ||
- ChildThread::current()->message_loop() == base::MessageLoop::current());
-
if (!make_context_current_.Run())
return false;
diff --git a/content/gpu/gpu_child_thread.cc b/content/gpu/gpu_child_thread.cc
index 56614c3..8f67d68 100644
--- a/content/gpu/gpu_child_thread.cc
+++ b/content/gpu/gpu_child_thread.cc
@@ -150,7 +150,7 @@ void GpuChildThread::OnInitialize() {
// IPC messages before the sandbox has been enabled and all other necessary
// initialization has succeeded.
gpu_channel_manager_.reset(
- new GpuChannelManager(this,
+ new GpuChannelManager(GetRouter(),
watchdog_thread_.get(),
ChildProcess::current()->io_message_loop_proxy(),
ChildProcess::current()->GetShutDownEvent()));
diff --git a/content/renderer/pepper/ppb_broker_impl.cc b/content/renderer/pepper/ppb_broker_impl.cc
index 882c5db..bec93e0 100644
--- a/content/renderer/pepper/ppb_broker_impl.cc
+++ b/content/renderer/pepper/ppb_broker_impl.cc
@@ -33,7 +33,7 @@ PPB_Broker_Impl::PPB_Broker_Impl(PP_Instance instance)
connect_callback_(),
pipe_handle_(PlatformFileToInt(base::kInvalidPlatformFileValue)),
routing_id_(RenderThreadImpl::current()->GenerateRoutingID()) {
- ChildThread::current()->AddRoute(routing_id_, this);
+ ChildThread::current()->GetRouter()->AddRoute(routing_id_, this);
}
PPB_Broker_Impl::~PPB_Broker_Impl() {
@@ -44,7 +44,7 @@ PPB_Broker_Impl::~PPB_Broker_Impl() {
// The plugin owns the handle.
pipe_handle_ = PlatformFileToInt(base::kInvalidPlatformFileValue);
- ChildThread::current()->RemoveRoute(routing_id_);
+ ChildThread::current()->GetRouter()->RemoveRoute(routing_id_);
}
PPB_Broker_API* PPB_Broker_Impl::AsPPB_Broker_API() {
diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc
index 95b76d2..689fd8d 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -654,11 +654,11 @@ scoped_refptr<base::MessageLoopProxy>
}
void RenderThreadImpl::AddRoute(int32 routing_id, IPC::Listener* listener) {
- ChildThread::AddRoute(routing_id, listener);
+ ChildThread::GetRouter()->AddRoute(routing_id, listener);
}
void RenderThreadImpl::RemoveRoute(int32 routing_id) {
- ChildThread::RemoveRoute(routing_id);
+ ChildThread::GetRouter()->RemoveRoute(routing_id);
}
int RenderThreadImpl::GenerateRoutingID() {
diff --git a/content/renderer/shared_worker_repository.cc b/content/renderer/shared_worker_repository.cc
index 29dacfd..a34a331 100644
--- a/content/renderer/shared_worker_repository.cc
+++ b/content/renderer/shared_worker_repository.cc
@@ -39,7 +39,7 @@ SharedWorkerRepository::createSharedWorkerConnector(
if (route_id == MSG_ROUTING_NONE)
return NULL;
documents_with_workers_.insert(document_id);
- return new WebSharedWorkerProxy(ChildThread::current(),
+ return new WebSharedWorkerProxy(ChildThread::current()->GetRouter(),
document_id,
route_id,
params.render_frame_route_id);
diff --git a/content/renderer/websharedworker_proxy.cc b/content/renderer/websharedworker_proxy.cc
index 840224a..272b4e2 100644
--- a/content/renderer/websharedworker_proxy.cc
+++ b/content/renderer/websharedworker_proxy.cc
@@ -4,8 +4,8 @@
#include "content/renderer/websharedworker_proxy.h"
-#include "content/child/child_thread.h"
#include "content/child/webmessageportchannel_impl.h"
+#include "content/common/message_router.h"
#include "content/common/view_messages.h"
#include "content/common/worker_messages.h"
#include "third_party/WebKit/public/platform/WebURL.h"
@@ -13,18 +13,18 @@
namespace content {
-WebSharedWorkerProxy::WebSharedWorkerProxy(ChildThread* child_thread,
+WebSharedWorkerProxy::WebSharedWorkerProxy(MessageRouter* router,
unsigned long long document_id,
int route_id,
int render_frame_route_id)
: route_id_(route_id),
render_frame_route_id_(render_frame_route_id),
- child_thread_(child_thread),
+ router_(router),
document_id_(document_id),
pending_route_id_(route_id),
connect_listener_(NULL),
created_(false) {
- child_thread_->AddRoute(route_id_, this);
+ router_->AddRoute(route_id_, this);
}
WebSharedWorkerProxy::~WebSharedWorkerProxy() {
@@ -42,7 +42,7 @@ void WebSharedWorkerProxy::Disconnect() {
// So the messages from WorkerContext (like WorkerContextDestroyed) do not
// come after nobody is listening. Since Worker and WorkerContext can
// terminate independently, already sent messages may still be in the pipe.
- child_thread_->RemoveRoute(route_id_);
+ router_->RemoveRoute(route_id_);
route_id_ = MSG_ROUTING_NONE;
}
@@ -62,7 +62,7 @@ bool WebSharedWorkerProxy::Send(IPC::Message* message) {
// TODO(jabdelmalek): handle sync messages if we need them.
IPC::Message* wrapped_msg = new ViewHostMsg_ForwardToWorker(*message);
delete message;
- return child_thread_->Send(wrapped_msg);
+ return router_->Send(wrapped_msg);
}
void WebSharedWorkerProxy::SendQueuedMessages() {
diff --git a/content/renderer/websharedworker_proxy.h b/content/renderer/websharedworker_proxy.h
index b11138b..0a07489 100644
--- a/content/renderer/websharedworker_proxy.h
+++ b/content/renderer/websharedworker_proxy.h
@@ -16,7 +16,7 @@
namespace content {
-class ChildThread;
+class MessageRouter;
// Implementation of the WebSharedWorker APIs. This object is intended to only
// live long enough to allow the caller to send a "connect" event to the worker
@@ -27,7 +27,7 @@ class WebSharedWorkerProxy : public blink::WebSharedWorkerConnector,
private IPC::Listener {
public:
// If the worker not loaded yet, route_id == MSG_ROUTING_NONE
- WebSharedWorkerProxy(ChildThread* child_thread,
+ WebSharedWorkerProxy(MessageRouter* router,
unsigned long long document_id,
int route_id,
int render_frame_route_id);
@@ -67,7 +67,7 @@ class WebSharedWorkerProxy : public blink::WebSharedWorkerConnector,
// The routing id for the RenderFrame that created this worker.
int render_frame_route_id_;
- ChildThread* child_thread_;
+ MessageRouter* const router_;
// ID of our parent document (used to shutdown workers when the parent
// document is detached).
diff --git a/content/worker/websharedworker_stub.cc b/content/worker/websharedworker_stub.cc
index 2737f6c..fd33a61 100644
--- a/content/worker/websharedworker_stub.cc
+++ b/content/worker/websharedworker_stub.cc
@@ -33,7 +33,7 @@ WebSharedWorkerStub::WebSharedWorkerStub(
DCHECK(worker_thread);
worker_thread->AddWorkerStub(this);
// Start processing incoming IPCs for this worker.
- worker_thread->AddRoute(route_id_, this);
+ worker_thread->GetRouter()->AddRoute(route_id_, this);
// TODO(atwilson): Add support for NaCl when they support MessagePorts.
impl_ = blink::WebSharedWorker::create(client());
@@ -48,7 +48,7 @@ WebSharedWorkerStub::~WebSharedWorkerStub() {
WorkerThread* worker_thread = WorkerThread::current();
DCHECK(worker_thread);
worker_thread->RemoveWorkerStub(this);
- worker_thread->RemoveRoute(route_id_);
+ worker_thread->GetRouter()->RemoveRoute(route_id_);
}
void WebSharedWorkerStub::Shutdown() {