| Index: base/mp/mp_child_thread.h
|
| ===================================================================
|
| --- base/mp/mp_child_thread.h (revision 0)
|
| +++ base/mp/mp_child_thread.h (revision 0)
|
| @@ -0,0 +1,102 @@
|
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef BASE_MP_CHILD_THREAD_H_
|
| +#define BASE_MP_CHILD_THREAD_H_
|
| +
|
| +#include "base/basictypes.h"
|
| +#include "base/scoped_ptr.h"
|
| +#include "base/mp/message_router.h"
|
| +#include "ipc/ipc_sync_channel.h"
|
| +#include "ipc/ipc_message.h"
|
| +
|
| +namespace IPC {
|
| +class SyncMessageFilter;
|
| +}
|
| +
|
| +namespace base {
|
| +
|
| +// The main thread of a child process derives from this class.
|
| +class MpChildThread : public IPC::Channel::Listener,
|
| + public IPC::Message::Sender {
|
| + public:
|
| + // Creates the thread.
|
| + MpChildThread();
|
| + // Used for single-process mode.
|
| + explicit MpChildThread(const std::string& channel_name);
|
| + virtual ~MpChildThread();
|
| +
|
| + // IPC::Message::Sender implementation:
|
| + virtual bool Send(IPC::Message* msg);
|
| +
|
| + // IPC::Channel::Listener implementation:
|
| + virtual void OnMessageReceived(const IPC::Message& msg);
|
| +
|
| + // See documentation on MessageRouter for AddRoute and RemoveRoute
|
| + void AddRoute(int32 routing_id, IPC::Channel::Listener* listener);
|
| + void RemoveRoute(int32 routing_id);
|
| +
|
| + IPC::Channel::Listener* ResolveRoute(int32 routing_id);
|
| +
|
| + // Safe to call on any thread, as long as it's guaranteed that the thread's
|
| + // lifetime is less than the main thread.
|
| + IPC::SyncMessageFilter* sync_message_filter() { return sync_message_filter_; }
|
| +
|
| + MessageLoop* message_loop() { return message_loop_; }
|
| +
|
| + // Returns the one child thread.
|
| + static MpChildThread* current();
|
| +
|
| + protected:
|
| + friend class MpChildProcess;
|
| +
|
| + // Called when the process refcount is 0.
|
| + void OnProcessFinalRelease();
|
| +
|
| + virtual void OnControlMessageReceived(const IPC::Message& msg) { }
|
| + virtual void OnAskBeforeShutdown();
|
| + virtual void OnShutdown();
|
| +
|
| +#ifdef IPC_MESSAGE_LOG_ENABLED
|
| + virtual void OnSetIPCLoggingEnabled(bool enable);
|
| +#endif
|
| +
|
| + IPC::SyncChannel* channel() { return channel_.get(); }
|
| +
|
| + void set_on_channel_error_called(bool on_channel_error_called) {
|
| + on_channel_error_called_ = on_channel_error_called;
|
| + }
|
| +
|
| + private:
|
| + void Init();
|
| +
|
| + // IPC::Channel::Listener implementation:
|
| + virtual void OnChannelError();
|
| +
|
| + std::string channel_name_;
|
| + scoped_ptr<IPC::SyncChannel> channel_;
|
| +
|
| + // Allows threads other than the main thread to send sync messages.
|
| + scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_;
|
| +
|
| + // Implements message routing functionality to the consumers of MpChildThread.
|
| + MessageRouter router_;
|
| +
|
| + // If true, checks with the parent process before shutdown. This avoids race
|
| + // conditions if the process refcount is 0 but there's an IPC message inflight
|
| + // that would addref it.
|
| + bool check_with_parent_before_shutdown_;
|
| +
|
| + // The OnChannelError() callback was invoked - the channel is dead, don't
|
| + // attempt to communicate.
|
| + bool on_channel_error_called_;
|
| +
|
| + MessageLoop* message_loop_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(MpChildThread);
|
| +};
|
| +
|
| +} // namespace base
|
| +
|
| +#endif // BASE_MP_CHILD_THREAD_H_
|
|
|