Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : // Copyright (c) 2009 The Chromium Authors. All rights reserved.
4 : // Use of this source code is governed by a BSD-style license that can be
5 : // found in the LICENSE file.
6 :
7 : #ifndef CHROME_COMMON_CHILD_THREAD_H_
8 : #define CHROME_COMMON_CHILD_THREAD_H_
9 :
10 : #include "base/thread.h"
11 : #include "chrome/common/ipc_channel.h"
12 : #include "mozilla/UniquePtr.h"
13 :
14 : class ResourceDispatcher;
15 :
16 : // Child processes's background thread should derive from this class.
17 : class ChildThread : public IPC::Channel::Listener,
18 : public base::Thread {
19 : public:
20 : // Creates the thread.
21 : explicit ChildThread(Thread::Options options);
22 : virtual ~ChildThread();
23 :
24 : protected:
25 : friend class ChildProcess;
26 :
27 : // Starts the thread.
28 : bool Run();
29 :
30 : protected:
31 : // Returns the one child thread.
32 : static ChildThread* current();
33 :
34 2 : IPC::Channel* channel() { return channel_.get(); }
35 :
36 : // Thread implementation.
37 : virtual void Init();
38 : virtual void CleanUp();
39 :
40 : private:
41 : // IPC::Channel::Listener implementation:
42 : virtual void OnMessageReceived(IPC::Message&& msg);
43 : virtual void OnChannelError();
44 :
45 : // The message loop used to run tasks on the thread that started this thread.
46 : MessageLoop* owner_loop_;
47 :
48 : std::wstring channel_name_;
49 : mozilla::UniquePtr<IPC::Channel> channel_;
50 :
51 : Thread::Options options_;
52 :
53 : DISALLOW_EVIL_CONSTRUCTORS(ChildThread);
54 : };
55 :
56 : #endif // CHROME_COMMON_CHILD_THREAD_H_
|