aura: Remove more code related to layerless windows.
[chromium-blink-merge.git] / content / common / child_process_host_impl.h
blob93ff0ebe1d1b33802cd7b4ca2348c6e74a13a41f
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/process/process.h"
18 #include "base/strings/string16.h"
19 #include "content/public/common/child_process_host.h"
20 #include "ipc/ipc_listener.h"
21 #include "ui/gfx/gpu_memory_buffer.h"
23 namespace base {
24 class FilePath;
27 namespace IPC {
28 class MessageFilter;
31 namespace content {
32 class ChildProcessHostDelegate;
34 // Provides common functionality for hosting a child process and processing IPC
35 // messages between the host and the child process. Users are responsible
36 // for the actual launching and terminating of the child processes.
37 class CONTENT_EXPORT ChildProcessHostImpl : public ChildProcessHost,
38 public IPC::Listener {
39 public:
40 ~ChildProcessHostImpl() override;
42 // Public and static for reuse by RenderMessageFilter.
43 static void AllocateSharedMemory(
44 size_t buffer_size, base::ProcessHandle child_process,
45 base::SharedMemoryHandle* handle);
47 // Returns a unique ID to identify a child process. On construction, this
48 // function will be used to generate the id_, but it is also used to generate
49 // IDs for the RenderProcessHost, which doesn't inherit from us, and whose IDs
50 // must be unique for all child processes.
52 // This function is threadsafe since RenderProcessHost is on the UI thread,
53 // but normally this will be used on the IO thread.
55 // This will never return ChildProcessHost::kInvalidUniqueID.
56 static int GenerateChildProcessUniqueId();
58 // ChildProcessHost implementation
59 bool Send(IPC::Message* message) override;
60 void ForceShutdown() override;
61 std::string CreateChannel() override;
62 bool IsChannelOpening() override;
63 void AddFilter(IPC::MessageFilter* filter) override;
64 #if defined(OS_POSIX)
65 base::ScopedFD TakeClientFileDescriptor() override;
66 #endif
68 private:
69 friend class ChildProcessHost;
71 explicit ChildProcessHostImpl(ChildProcessHostDelegate* delegate);
73 // IPC::Listener methods:
74 bool OnMessageReceived(const IPC::Message& msg) override;
75 void OnChannelConnected(int32 peer_pid) override;
76 void OnChannelError() override;
77 void OnBadMessageReceived(const IPC::Message& message) override;
79 // Message handlers:
80 void OnShutdownRequest();
81 void OnAllocateSharedMemory(uint32 buffer_size,
82 base::SharedMemoryHandle* handle);
83 void OnAllocateGpuMemoryBuffer(uint32 width,
84 uint32 height,
85 gfx::GpuMemoryBuffer::Format format,
86 gfx::GpuMemoryBuffer::Usage usage,
87 gfx::GpuMemoryBufferHandle* handle);
88 void OnDeletedGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
89 uint32 sync_point);
91 ChildProcessHostDelegate* delegate_;
92 base::Process peer_process_;
93 bool opening_channel_; // True while we're waiting the channel to be opened.
94 scoped_ptr<IPC::Channel> channel_;
95 std::string channel_id_;
97 // Holds all the IPC message filters. Since this object lives on the IO
98 // thread, we don't have a IPC::ChannelProxy and so we manage filters
99 // manually.
100 std::vector<scoped_refptr<IPC::MessageFilter> > filters_;
102 DISALLOW_COPY_AND_ASSIGN(ChildProcessHostImpl);
105 } // namespace content
107 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_IMPL_H_