Apply _RELATIVE relocations ahead of others.
[chromium-blink-merge.git] / content / common / child_process_host_impl.h
blobfa2b30bf97a43b421b61c50555c42b5d868071ca
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_COMMON_CHILD_PROCESS_HOST_IMPL_H_
6 #define CONTENT_COMMON_CHILD_PROCESS_HOST_IMPL_H_
8 #include <string>
9 #include <vector>
11 #include "build/build_config.h"
13 #include "base/basictypes.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/shared_memory.h"
16 #include "base/memory/singleton.h"
17 #include "base/strings/string16.h"
18 #include "content/public/common/child_process_host.h"
19 #include "ipc/ipc_listener.h"
20 #include "ui/gfx/gpu_memory_buffer.h"
22 namespace base {
23 class FilePath;
26 namespace IPC {
27 class MessageFilter;
30 namespace content {
31 class ChildProcessHostDelegate;
33 // Provides common functionality for hosting a child process and processing IPC
34 // messages between the host and the child process. Users are responsible
35 // for the actual launching and terminating of the child processes.
36 class CONTENT_EXPORT ChildProcessHostImpl : public ChildProcessHost,
37 public IPC::Listener {
38 public:
39 ~ChildProcessHostImpl() override;
41 // Public and static for reuse by RenderMessageFilter.
42 static void AllocateSharedMemory(
43 size_t buffer_size, base::ProcessHandle child_process,
44 base::SharedMemoryHandle* handle);
46 // Returns a unique ID to identify a child process. On construction, this
47 // function will be used to generate the id_, but it is also used to generate
48 // IDs for the RenderProcessHost, which doesn't inherit from us, and whose IDs
49 // must be unique for all child processes.
51 // This function is threadsafe since RenderProcessHost is on the UI thread,
52 // but normally this will be used on the IO thread.
54 // This will never return ChildProcessHost::kInvalidUniqueID.
55 static int GenerateChildProcessUniqueId();
57 // ChildProcessHost implementation
58 bool Send(IPC::Message* message) override;
59 void ForceShutdown() override;
60 std::string CreateChannel() override;
61 bool IsChannelOpening() override;
62 void AddFilter(IPC::MessageFilter* filter) override;
63 #if defined(OS_POSIX)
64 base::ScopedFD TakeClientFileDescriptor() override;
65 #endif
67 private:
68 friend class ChildProcessHost;
70 explicit ChildProcessHostImpl(ChildProcessHostDelegate* delegate);
72 // IPC::Listener methods:
73 bool OnMessageReceived(const IPC::Message& msg) override;
74 void OnChannelConnected(int32 peer_pid) override;
75 void OnChannelError() override;
76 void OnBadMessageReceived(const IPC::Message& message) override;
78 // Message handlers:
79 void OnShutdownRequest();
80 void OnAllocateSharedMemory(uint32 buffer_size,
81 base::SharedMemoryHandle* handle);
82 void OnAllocateGpuMemoryBuffer(uint32 width,
83 uint32 height,
84 gfx::GpuMemoryBuffer::Format format,
85 gfx::GpuMemoryBuffer::Usage usage,
86 IPC::Message* reply);
87 void OnDeletedGpuMemoryBuffer(gfx::GpuMemoryBufferType type,
88 gfx::GpuMemoryBufferId id,
89 uint32 sync_point);
91 void GpuMemoryBufferAllocated(IPC::Message* reply,
92 const gfx::GpuMemoryBufferHandle& handle);
94 ChildProcessHostDelegate* delegate_;
95 base::ProcessHandle peer_handle_;
96 bool opening_channel_; // True while we're waiting the channel to be opened.
97 scoped_ptr<IPC::Channel> channel_;
98 std::string channel_id_;
100 // Holds all the IPC message filters. Since this object lives on the IO
101 // thread, we don't have a IPC::ChannelProxy and so we manage filters
102 // manually.
103 std::vector<scoped_refptr<IPC::MessageFilter> > filters_;
105 DISALLOW_COPY_AND_ASSIGN(ChildProcessHostImpl);
108 } // namespace content
110 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_IMPL_H_