summaryrefslogtreecommitdiffstats
path: root/chrome/common/child_thread.h
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-21 08:05:28 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-21 08:05:28 +0000
commit8930d471c128ed74b11beaa78ea1b171c1ac7157 (patch)
tree5a20cb03c8e5019385709bc069e67f03488c41a1 /chrome/common/child_thread.h
parenta41fae8db8109bfeed047015b77b0d9227118540 (diff)
downloadchromium_src-8930d471c128ed74b11beaa78ea1b171c1ac7157.zip
chromium_src-8930d471c128ed74b11beaa78ea1b171c1ac7157.tar.gz
chromium_src-8930d471c128ed74b11beaa78ea1b171c1ac7157.tar.bz2
Refactor code from RenderThread and PluginThread and move it to ChildThread. ChildProcess now owns the ChildThread, which removes duplicate code and simplifies things.
Clean up ChildProcess, there really was no need for all the templates and statics in it and its subclasses. Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=10080 Review URL: http://codereview.chromium.org/21502 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10144 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/child_thread.h')
-rw-r--r--chrome/common/child_thread.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/chrome/common/child_thread.h b/chrome/common/child_thread.h
new file mode 100644
index 0000000..ac835cc
--- /dev/null
+++ b/chrome/common/child_thread.h
@@ -0,0 +1,76 @@
+// Copyright (c) 2009 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 CHROME_COMMON_CHILD_THREAD_H_
+#define CHROME_COMMON_CHILD_THREAD_H_
+
+#include "base/thread.h"
+#include "chrome/common/ipc_sync_channel.h"
+#include "chrome/common/message_router.h"
+
+// Child processes's background thread should derive from this class.
+class ChildThread : public IPC::Channel::Listener,
+ public IPC::Message::Sender,
+ public base::Thread {
+ public:
+ // Creates the thread.
+ ChildThread(Thread::Options options);
+ virtual ~ChildThread();
+
+ // IPC::Message::Sender implementation:
+ virtual bool Send(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);
+
+ MessageLoop* owner_loop() { return owner_loop_; }
+
+ protected:
+ friend class ChildProcess;
+
+ // Starts the thread.
+ bool Run();
+
+ // Overrides the channel name. Used for --single-process mode.
+ void SetChannelName(const std::wstring& name) { channel_name_ = name; }
+
+ protected:
+ virtual void OnControlMessageReceived(const IPC::Message& msg) { }
+
+ // Returns the one child thread.
+ static ChildThread* current();
+
+ IPC::SyncChannel* channel() { return channel_.get(); }
+
+ // Indicates if ChildThread::Send() is on the call stack.
+ virtual bool InSend() const { return in_send_ != 0; }
+
+ // Thread implementation.
+ virtual void Init();
+ virtual void CleanUp();
+
+ private:
+ // IPC::Channel::Listener implementation:
+ virtual void OnMessageReceived(const IPC::Message& msg);
+ virtual void OnChannelError();
+
+ // The message loop used to run tasks on the thread that started this thread.
+ MessageLoop* owner_loop_;
+
+ std::wstring channel_name_;
+ scoped_ptr<IPC::SyncChannel> channel_;
+
+ // Used only on the background render thread to implement message routing
+ // functionality to the consumers of the ChildThread.
+ MessageRouter router_;
+
+ int in_send_;
+
+ Thread::Options options_;
+
+ DISALLOW_EVIL_CONSTRUCTORS(ChildThread);
+};
+
+#endif // CHROME_COMMON_CHILD_THREAD_H_