#ifndef CONTENT_COMMON_CHILD_THREAD_H_
#define CONTENT_COMMON_CHILD_THREAD_H_
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/shared_memory.h"
#include "base/tracked_objects.h"
#include "content/common/content_export.h"
#include "content/common/message_router.h"
#include "ipc/ipc_message.h"
#include "webkit/glue/resource_loader_bridge.h"
class FileSystemDispatcher;
class MessageLoop;
class QuotaDispatcher;
class SocketStreamDispatcher;
namespace content {
class ChildHistogramMessageFilter;
class ResourceDispatcher;
}
namespace IPC {
class SyncChannel;
class SyncMessageFilter;
}
namespace WebKit {
class WebFrame;
}
class CONTENT_EXPORT ChildThread : public IPC::Listener, public IPC::Sender {
public:
ChildThread();
explicit ChildThread(const std::string& channel_name);
virtual ~ChildThread();
virtual bool Send(IPC::Message* msg) OVERRIDE;
void AddRoute(int32 routing_id, IPC::Listener* listener);
void RemoveRoute(int32 routing_id);
IPC::Listener* ResolveRoute(int32 routing_id);
IPC::SyncChannel* channel() { return channel_.get(); }
virtual webkit_glue::ResourceLoaderBridge* CreateBridge(
const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info);
base::SharedMemory* AllocateSharedMemory(size_t buf_size);
content::ResourceDispatcher* resource_dispatcher();
SocketStreamDispatcher* socket_stream_dispatcher() {
return socket_stream_dispatcher_.get();
}
FileSystemDispatcher* file_system_dispatcher() const {
return file_system_dispatcher_.get();
}
QuotaDispatcher* quota_dispatcher() const {
return quota_dispatcher_.get();
}
IPC::SyncMessageFilter* sync_message_filter();
content::ChildHistogramMessageFilter* child_histogram_message_filter() const {
return histogram_message_filter_.get();
}
MessageLoop* message_loop();
static ChildThread* current();
virtual bool IsWebFrameValid(WebKit::WebFrame* frame);
protected:
friend class ChildProcess;
void OnProcessFinalRelease();
virtual bool OnControlMessageReceived(const IPC::Message& msg);
void set_on_channel_error_called(bool on_channel_error_called) {
on_channel_error_called_ = on_channel_error_called;
}
virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
virtual void OnChannelError() OVERRIDE;
private:
void Init();
void OnShutdown();
void OnSetProfilerStatus(tracked_objects::ThreadData::Status status);
void OnGetChildProfilerData(int sequence_number);
void OnDumpHandles();
#ifdef IPC_MESSAGE_LOG_ENABLED
void OnSetIPCLoggingEnabled(bool enable);
#endif
#if defined(USE_TCMALLOC)
void OnGetTcmallocStats();
#endif
void EnsureConnected();
std::string channel_name_;
scoped_ptr<IPC::SyncChannel> channel_;
scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_;
MessageRouter router_;
scoped_ptr<content::ResourceDispatcher> resource_dispatcher_;
scoped_ptr<SocketStreamDispatcher> socket_stream_dispatcher_;
bool on_channel_error_called_;
MessageLoop* message_loop_;
scoped_ptr<FileSystemDispatcher> file_system_dispatcher_;
scoped_ptr<QuotaDispatcher> quota_dispatcher_;
scoped_refptr<content::ChildHistogramMessageFilter> histogram_message_filter_;
base::WeakPtrFactory<ChildThread> channel_connected_factory_;
DISALLOW_COPY_AND_ASSIGN(ChildThread);
};
#endif