OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_COMMON_CHILD_PROCESS_HOST_IMPL_H_ | 5 #ifndef CONTENT_COMMON_CHILD_PROCESS_HOST_IMPL_H_ |
6 #define CONTENT_COMMON_CHILD_PROCESS_HOST_IMPL_H_ | 6 #define CONTENT_COMMON_CHILD_PROCESS_HOST_IMPL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
17 #include "base/shared_memory.h" | 17 #include "base/shared_memory.h" |
18 #include "base/string16.h" | 18 #include "base/string16.h" |
| 19 #include "ipc/ipc_listener.h" |
19 #include "content/public/common/child_process_host.h" | 20 #include "content/public/common/child_process_host.h" |
20 | 21 |
21 class FilePath; | 22 class FilePath; |
22 | 23 |
23 namespace content { | 24 namespace content { |
24 class ChildProcessHostDelegate; | 25 class ChildProcessHostDelegate; |
25 | 26 |
26 // Provides common functionality for hosting a child process and processing IPC | 27 // Provides common functionality for hosting a child process and processing IPC |
27 // messages between the host and the child process. Users are responsible | 28 // messages between the host and the child process. Users are responsible |
28 // for the actual launching and terminating of the child processes. | 29 // for the actual launching and terminating of the child processes. |
29 class CONTENT_EXPORT ChildProcessHostImpl : public ChildProcessHost, | 30 class CONTENT_EXPORT ChildProcessHostImpl : public ChildProcessHost, |
30 public IPC::Channel::Listener { | 31 public IPC::Listener { |
31 public: | 32 public: |
32 virtual ~ChildProcessHostImpl(); | 33 virtual ~ChildProcessHostImpl(); |
33 | 34 |
34 // Public and static for reuse by RenderMessageFilter. | 35 // Public and static for reuse by RenderMessageFilter. |
35 static void AllocateSharedMemory( | 36 static void AllocateSharedMemory( |
36 uint32 buffer_size, base::ProcessHandle child_process, | 37 uint32 buffer_size, base::ProcessHandle child_process, |
37 base::SharedMemoryHandle* handle); | 38 base::SharedMemoryHandle* handle); |
38 | 39 |
39 // Returns a unique ID to identify a child process. On construction, this | 40 // Returns a unique ID to identify a child process. On construction, this |
40 // function will be used to generate the id_, but it is also used to generate | 41 // function will be used to generate the id_, but it is also used to generate |
(...skipping 12 matching lines...) Expand all Loading... |
53 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE; | 54 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE; |
54 #if defined(OS_POSIX) | 55 #if defined(OS_POSIX) |
55 virtual int TakeClientFileDescriptor() OVERRIDE; | 56 virtual int TakeClientFileDescriptor() OVERRIDE; |
56 #endif | 57 #endif |
57 | 58 |
58 private: | 59 private: |
59 friend class ChildProcessHost; | 60 friend class ChildProcessHost; |
60 | 61 |
61 explicit ChildProcessHostImpl(ChildProcessHostDelegate* delegate); | 62 explicit ChildProcessHostImpl(ChildProcessHostDelegate* delegate); |
62 | 63 |
63 // IPC::Channel::Listener methods: | 64 // IPC::Listener methods: |
64 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 65 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
65 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 66 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
66 virtual void OnChannelError() OVERRIDE; | 67 virtual void OnChannelError() OVERRIDE; |
67 | 68 |
68 // Message handlers: | 69 // Message handlers: |
69 void OnShutdownRequest(); | 70 void OnShutdownRequest(); |
70 void OnAllocateSharedMemory(uint32 buffer_size, | 71 void OnAllocateSharedMemory(uint32 buffer_size, |
71 base::SharedMemoryHandle* handle); | 72 base::SharedMemoryHandle* handle); |
72 | 73 |
73 ChildProcessHostDelegate* delegate_; | 74 ChildProcessHostDelegate* delegate_; |
74 base::ProcessHandle peer_handle_; | 75 base::ProcessHandle peer_handle_; |
75 bool opening_channel_; // True while we're waiting the channel to be opened. | 76 bool opening_channel_; // True while we're waiting the channel to be opened. |
76 scoped_ptr<IPC::Channel> channel_; | 77 scoped_ptr<IPC::Channel> channel_; |
77 std::string channel_id_; | 78 std::string channel_id_; |
78 | 79 |
79 // Holds all the IPC message filters. Since this object lives on the IO | 80 // Holds all the IPC message filters. Since this object lives on the IO |
80 // thread, we don't have a IPC::ChannelProxy and so we manage filters | 81 // thread, we don't have a IPC::ChannelProxy and so we manage filters |
81 // manually. | 82 // manually. |
82 std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_; | 83 std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_; |
83 | 84 |
84 DISALLOW_COPY_AND_ASSIGN(ChildProcessHostImpl); | 85 DISALLOW_COPY_AND_ASSIGN(ChildProcessHostImpl); |
85 }; | 86 }; |
86 | 87 |
87 } // namespace content | 88 } // namespace content |
88 | 89 |
89 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_IMPL_H_ | 90 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_IMPL_H_ |
OLD | NEW |