[email protected] | 5c41e6e1 | 2012-03-17 02:20:46 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 5 | #include "content/common/child_process_host_impl.h" |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 6 | |
[email protected] | 4306c379 | 2011-12-02 01:57:53 | [diff] [blame] | 7 | #include <limits> |
| 8 | |
[email protected] | 3cb7cc953 | 2014-01-08 22:55:51 | [diff] [blame] | 9 | #include "base/atomic_sequence_num.h" |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 10 | #include "base/command_line.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 11 | #include "base/files/file_path.h" |
ssid | 1050d80 | 2015-07-28 20:28:14 | [diff] [blame] | 12 | #include "base/hash.h" |
[email protected] | 8c40f32 | 2011-08-24 03:33:36 | [diff] [blame] | 13 | #include "base/logging.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 14 | #include "base/metrics/histogram.h" |
reveman | 22dd929 | 2014-10-13 20:52:05 | [diff] [blame] | 15 | #include "base/numerics/safe_math.h" |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 16 | #include "base/path_service.h" |
[email protected] | 71ed8e02 | 2013-07-25 14:39:57 | [diff] [blame] | 17 | #include "base/process/process_metrics.h" |
[email protected] | 4306c379 | 2011-12-02 01:57:53 | [diff] [blame] | 18 | #include "base/rand_util.h" |
[email protected] | 30fe1f9 | 2013-06-12 16:34:34 | [diff] [blame] | 19 | #include "base/strings/stringprintf.h" |
erikchen | 5708aae | 2015-09-14 17:45:12 | [diff] [blame] | 20 | #include "base/synchronization/lock.h" |
[email protected] | a5f28b4 | 2011-01-17 10:30:13 | [diff] [blame] | 21 | #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
[email protected] | ff47b296 | 2011-03-07 23:51:49 | [diff] [blame] | 22 | #include "content/common/child_process_messages.h" |
reveman | 22dd929 | 2014-10-13 20:52:05 | [diff] [blame] | 23 | #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" |
[email protected] | 4cb4310 | 2011-12-02 20:24:49 | [diff] [blame] | 24 | #include "content/public/common/child_process_host_delegate.h" |
[email protected] | 5d921d4c | 2011-10-21 22:26:14 | [diff] [blame] | 25 | #include "content/public/common/content_paths.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 26 | #include "content/public/common/content_switches.h" |
erikchen | 87397e0 | 2015-10-10 01:10:24 | [diff] [blame] | 27 | #include "ipc/attachment_broker.h" |
[email protected] | 5c41e6e1 | 2012-03-17 02:20:46 | [diff] [blame] | 28 | #include "ipc/ipc_channel.h" |
[email protected] | a83d4229 | 2010-08-17 22:51:10 | [diff] [blame] | 29 | #include "ipc/ipc_logging.h" |
[email protected] | 7412204 | 2014-04-25 00:07:30 | [diff] [blame] | 30 | #include "ipc/message_filter.h" |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 31 | |
| 32 | #if defined(OS_LINUX) |
| 33 | #include "base/linux_util.h" |
[email protected] | e35c9a8 | 2011-12-01 18:48:41 | [diff] [blame] | 34 | #elif defined(OS_WIN) |
| 35 | #include "content/common/font_cache_dispatcher_win.h" |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 36 | #endif // OS_LINUX |
| 37 | |
[email protected] | 8c40f32 | 2011-08-24 03:33:36 | [diff] [blame] | 38 | namespace { |
| 39 | |
[email protected] | 3cb7cc953 | 2014-01-08 22:55:51 | [diff] [blame] | 40 | // Global atomic to generate child process unique IDs. |
| 41 | base::StaticAtomicSequenceNumber g_unique_id; |
[email protected] | 8c40f32 | 2011-08-24 03:33:36 | [diff] [blame] | 42 | |
| 43 | } // namespace |
[email protected] | 8c40f32 | 2011-08-24 03:33:36 | [diff] [blame] | 44 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 45 | namespace content { |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 46 | |
[email protected] | 3cb7cc953 | 2014-01-08 22:55:51 | [diff] [blame] | 47 | int ChildProcessHost::kInvalidUniqueID = -1; |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 48 | |
ssid | 1050d80 | 2015-07-28 20:28:14 | [diff] [blame] | 49 | uint64 ChildProcessHost::kBrowserTracingProcessId = |
| 50 | std::numeric_limits<uint64>::max(); |
| 51 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 52 | // static |
| 53 | ChildProcessHost* ChildProcessHost::Create(ChildProcessHostDelegate* delegate) { |
| 54 | return new ChildProcessHostImpl(delegate); |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | // static |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 58 | base::FilePath ChildProcessHost::GetChildPath(int flags) { |
| 59 | base::FilePath child_path; |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 60 | |
[email protected] | 47927870 | 2014-08-11 20:32:09 | [diff] [blame] | 61 | child_path = base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 62 | switches::kBrowserSubprocessPath); |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 63 | |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 64 | #if defined(OS_LINUX) |
| 65 | // Use /proc/self/exe rather than our known binary path so updates |
| 66 | // can't swap out the binary from underneath us. |
[email protected] | a5f28b4 | 2011-01-17 10:30:13 | [diff] [blame] | 67 | // When running under Valgrind, forking /proc/self/exe ends up forking the |
| 68 | // Valgrind executable, which then crashes. However, it's almost safe to |
| 69 | // assume that the updates won't happen while testing with Valgrind tools. |
[email protected] | bfd4748 | 2011-08-24 13:57:26 | [diff] [blame] | 70 | if (child_path.empty() && flags & CHILD_ALLOW_SELF && !RunningOnValgrind()) |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 71 | child_path = base::FilePath(base::kProcSelfExe); |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 72 | #endif |
| 73 | |
| 74 | // On most platforms, the child executable is the same as the current |
| 75 | // executable. |
[email protected] | bfd4748 | 2011-08-24 13:57:26 | [diff] [blame] | 76 | if (child_path.empty()) |
[email protected] | dcc72db | 2013-01-02 00:44:18 | [diff] [blame] | 77 | PathService::Get(CHILD_PROCESS_EXE, &child_path); |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 78 | return child_path; |
| 79 | } |
| 80 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 81 | ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate) |
| 82 | : delegate_(delegate), |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 83 | opening_channel_(false) { |
| 84 | #if defined(OS_WIN) |
| 85 | AddFilter(new FontCacheDispatcher()); |
| 86 | #endif |
| 87 | } |
| 88 | |
| 89 | ChildProcessHostImpl::~ChildProcessHostImpl() { |
erikchen | 1bfccba | 2015-07-31 01:09:27 | [diff] [blame] | 90 | #if USE_ATTACHMENT_BROKER |
erikchen | d8a3d902 | 2015-10-22 20:02:02 | [diff] [blame] | 91 | IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( |
| 92 | channel_.get()); |
erikchen | 1bfccba | 2015-07-31 01:09:27 | [diff] [blame] | 93 | #endif |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 94 | for (size_t i = 0; i < filters_.size(); ++i) { |
| 95 | filters_[i]->OnChannelClosing(); |
| 96 | filters_[i]->OnFilterRemoved(); |
| 97 | } |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 98 | } |
| 99 | |
[email protected] | 7412204 | 2014-04-25 00:07:30 | [diff] [blame] | 100 | void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) { |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 101 | filters_.push_back(filter); |
| 102 | |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 103 | if (channel_) |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 104 | filter->OnFilterAdded(channel_.get()); |
| 105 | } |
| 106 | |
| 107 | void ChildProcessHostImpl::ForceShutdown() { |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 108 | Send(new ChildProcessMsg_Shutdown()); |
| 109 | } |
[email protected] | 91443fc | 2010-07-14 05:08:46 | [diff] [blame] | 110 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 111 | std::string ChildProcessHostImpl::CreateChannel() { |
[email protected] | 5c41e6e1 | 2012-03-17 02:20:46 | [diff] [blame] | 112 | channel_id_ = IPC::Channel::GenerateVerifiedChannelID(std::string()); |
erikchen | 5708aae | 2015-09-14 17:45:12 | [diff] [blame] | 113 | channel_ = IPC::Channel::CreateServer(channel_id_, this); |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 114 | if (!channel_->Connect()) |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 115 | return std::string(); |
erikchen | 1bfccba | 2015-07-31 01:09:27 | [diff] [blame] | 116 | #if USE_ATTACHMENT_BROKER |
erikchen | d8a3d902 | 2015-10-22 20:02:02 | [diff] [blame] | 117 | IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( |
| 118 | channel_.get()); |
erikchen | 1bfccba | 2015-07-31 01:09:27 | [diff] [blame] | 119 | #endif |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 120 | |
[email protected] | 8e2b647 | 2010-12-15 22:19:48 | [diff] [blame] | 121 | for (size_t i = 0; i < filters_.size(); ++i) |
| 122 | filters_[i]->OnFilterAdded(channel_.get()); |
| 123 | |
[email protected] | 91443fc | 2010-07-14 05:08:46 | [diff] [blame] | 124 | // Make sure these messages get sent first. |
| 125 | #if defined(IPC_MESSAGE_LOG_ENABLED) |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 126 | bool enabled = IPC::Logging::GetInstance()->Enabled(); |
[email protected] | ff47b296 | 2011-03-07 23:51:49 | [diff] [blame] | 127 | Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled)); |
[email protected] | 91443fc | 2010-07-14 05:08:46 | [diff] [blame] | 128 | #endif |
| 129 | |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 130 | opening_channel_ = true; |
| 131 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 132 | return channel_id_; |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 133 | } |
| 134 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 135 | bool ChildProcessHostImpl::IsChannelOpening() { |
| 136 | return opening_channel_; |
| 137 | } |
| 138 | |
| 139 | #if defined(OS_POSIX) |
morrita | a409ccc | 2014-10-20 23:53:25 | [diff] [blame] | 140 | base::ScopedFD ChildProcessHostImpl::TakeClientFileDescriptor() { |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 141 | return channel_->TakeClientFileDescriptor(); |
| 142 | } |
| 143 | #endif |
| 144 | |
| 145 | bool ChildProcessHostImpl::Send(IPC::Message* message) { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 146 | if (!channel_) { |
[email protected] | 8e2b647 | 2010-12-15 22:19:48 | [diff] [blame] | 147 | delete message; |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 148 | return false; |
| 149 | } |
[email protected] | 8e2b647 | 2010-12-15 22:19:48 | [diff] [blame] | 150 | return channel_->Send(message); |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 151 | } |
| 152 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 153 | void ChildProcessHostImpl::AllocateSharedMemory( |
[email protected] | 3f89283 | 2013-01-11 03:23:59 | [diff] [blame] | 154 | size_t buffer_size, base::ProcessHandle child_process_handle, |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 155 | base::SharedMemoryHandle* shared_memory_handle) { |
| 156 | base::SharedMemory shared_buf; |
[email protected] | e607e2c1 | 2013-09-13 09:46:58 | [diff] [blame] | 157 | if (!shared_buf.CreateAnonymous(buffer_size)) { |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 158 | *shared_memory_handle = base::SharedMemory::NULLHandle(); |
[email protected] | e607e2c1 | 2013-09-13 09:46:58 | [diff] [blame] | 159 | NOTREACHED() << "Cannot create shared memory buffer"; |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 160 | return; |
| 161 | } |
| 162 | shared_buf.GiveToProcess(child_process_handle, shared_memory_handle); |
| 163 | } |
| 164 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 165 | int ChildProcessHostImpl::GenerateChildProcessUniqueId() { |
[email protected] | 4306c379 | 2011-12-02 01:57:53 | [diff] [blame] | 166 | // This function must be threadsafe. |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 167 | // |
[email protected] | 3cb7cc953 | 2014-01-08 22:55:51 | [diff] [blame] | 168 | // Historically, this function returned ids started with 1, so in several |
| 169 | // places in the code a value of 0 (rather than kInvalidUniqueID) was used as |
| 170 | // an invalid value. So we retain those semantics. |
| 171 | int id = g_unique_id.GetNext() + 1; |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 172 | |
[email protected] | 3cb7cc953 | 2014-01-08 22:55:51 | [diff] [blame] | 173 | CHECK_NE(0, id); |
| 174 | CHECK_NE(kInvalidUniqueID, id); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 175 | |
| 176 | return id; |
[email protected] | 4306c379 | 2011-12-02 01:57:53 | [diff] [blame] | 177 | } |
| 178 | |
ssid | 1050d80 | 2015-07-28 20:28:14 | [diff] [blame] | 179 | uint64 ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId( |
| 180 | int child_process_id) { |
| 181 | // In single process mode, all the children are hosted in the same process, |
| 182 | // therefore the generated memory dump guids should not be conditioned by the |
| 183 | // child process id. The clients need not be aware of SPM and the conversion |
| 184 | // takes care of the SPM special case while translating child process ids to |
| 185 | // tracing process ids. |
| 186 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 187 | switches::kSingleProcess)) |
| 188 | return ChildProcessHost::kBrowserTracingProcessId; |
| 189 | |
| 190 | // The hash value is incremented so that the tracing id is never equal to |
| 191 | // MemoryDumpManager::kInvalidTracingProcessId. |
| 192 | return static_cast<uint64>( |
| 193 | base::Hash(reinterpret_cast<const char*>(&child_process_id), |
| 194 | sizeof(child_process_id))) + |
| 195 | 1; |
| 196 | } |
| 197 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 198 | bool ChildProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 199 | #ifdef IPC_MESSAGE_LOG_ENABLED |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 200 | IPC::Logging* logger = IPC::Logging::GetInstance(); |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 201 | if (msg.type() == IPC_LOGGING_ID) { |
| 202 | logger->OnReceivedLoggingMessage(msg); |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 203 | return true; |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | if (logger->Enabled()) |
| 207 | logger->OnPreDispatchMessage(msg); |
| 208 | #endif |
| 209 | |
[email protected] | 8e2b647 | 2010-12-15 22:19:48 | [diff] [blame] | 210 | bool handled = false; |
[email protected] | 4cb4310 | 2011-12-02 20:24:49 | [diff] [blame] | 211 | for (size_t i = 0; i < filters_.size(); ++i) { |
| 212 | if (filters_[i]->OnMessageReceived(msg)) { |
[email protected] | 8e2b647 | 2010-12-15 22:19:48 | [diff] [blame] | 213 | handled = true; |
| 214 | break; |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 218 | if (!handled) { |
[email protected] | e525743 | 2010-12-21 01:18:37 | [diff] [blame] | 219 | handled = true; |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 220 | IPC_BEGIN_MESSAGE_MAP(ChildProcessHostImpl, msg) |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 221 | IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ShutdownRequest, |
| 222 | OnShutdownRequest) |
avi | ef875b52 | 2015-09-11 20:58:51 | [diff] [blame] | 223 | // NB: The SyncAllocateSharedMemory, SyncAllocateGpuMemoryBuffer, and |
| 224 | // DeletedGpuMemoryBuffer IPCs are handled here for non-renderer child |
| 225 | // processes. For renderer processes, they are handled in |
| 226 | // RenderMessageFilter. |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 227 | IPC_MESSAGE_HANDLER(ChildProcessHostMsg_SyncAllocateSharedMemory, |
| 228 | OnAllocateSharedMemory) |
jam | 81366316 | 2015-03-26 16:46:29 | [diff] [blame] | 229 | IPC_MESSAGE_HANDLER(ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer, |
| 230 | OnAllocateGpuMemoryBuffer) |
reveman | 22dd929 | 2014-10-13 20:52:05 | [diff] [blame] | 231 | IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DeletedGpuMemoryBuffer, |
| 232 | OnDeletedGpuMemoryBuffer) |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 233 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | 4cb4310 | 2011-12-02 20:24:49 | [diff] [blame] | 234 | IPC_END_MESSAGE_MAP() |
[email protected] | e525743 | 2010-12-21 01:18:37 | [diff] [blame] | 235 | |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 236 | if (!handled) |
[email protected] | 4cb4310 | 2011-12-02 20:24:49 | [diff] [blame] | 237 | handled = delegate_->OnMessageReceived(msg); |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 238 | } |
[email protected] | 8e2b647 | 2010-12-15 22:19:48 | [diff] [blame] | 239 | |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 240 | #ifdef IPC_MESSAGE_LOG_ENABLED |
| 241 | if (logger->Enabled()) |
[email protected] | 4cb4310 | 2011-12-02 20:24:49 | [diff] [blame] | 242 | logger->OnPostDispatchMessage(msg, channel_id_); |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 243 | #endif |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 244 | return handled; |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 245 | } |
| 246 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 247 | void ChildProcessHostImpl::OnChannelConnected(int32 peer_pid) { |
rvargas | 5779b38 | 2014-11-18 20:44:11 | [diff] [blame] | 248 | if (!peer_process_.IsValid()) { |
rvargas | 1c376a8 | 2015-03-16 23:03:52 | [diff] [blame] | 249 | peer_process_ = base::Process::OpenWithExtraPrivileges(peer_pid); |
rvargas | 747ff24 | 2015-01-17 02:46:47 | [diff] [blame] | 250 | if (!peer_process_.IsValid()) |
| 251 | peer_process_ = delegate_->GetProcess().Duplicate(); |
rvargas | 5779b38 | 2014-11-18 20:44:11 | [diff] [blame] | 252 | DCHECK(peer_process_.IsValid()); |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 253 | } |
[email protected] | 4cb4310 | 2011-12-02 20:24:49 | [diff] [blame] | 254 | opening_channel_ = false; |
| 255 | delegate_->OnChannelConnected(peer_pid); |
| 256 | for (size_t i = 0; i < filters_.size(); ++i) |
| 257 | filters_[i]->OnChannelConnected(peer_pid); |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 258 | } |
| 259 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 260 | void ChildProcessHostImpl::OnChannelError() { |
[email protected] | 4cb4310 | 2011-12-02 20:24:49 | [diff] [blame] | 261 | opening_channel_ = false; |
| 262 | delegate_->OnChannelError(); |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 263 | |
[email protected] | 4cb4310 | 2011-12-02 20:24:49 | [diff] [blame] | 264 | for (size_t i = 0; i < filters_.size(); ++i) |
| 265 | filters_[i]->OnChannelError(); |
[email protected] | 8e2b647 | 2010-12-15 22:19:48 | [diff] [blame] | 266 | |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 267 | // This will delete host_, which will also destroy this! |
[email protected] | 4cb4310 | 2011-12-02 20:24:49 | [diff] [blame] | 268 | delegate_->OnChildDisconnected(); |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 269 | } |
| 270 | |
[email protected] | ef2f6ba | 2014-05-15 23:06:07 | [diff] [blame] | 271 | void ChildProcessHostImpl::OnBadMessageReceived(const IPC::Message& message) { |
| 272 | delegate_->OnBadMessageReceived(message); |
| 273 | } |
| 274 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 275 | void ChildProcessHostImpl::OnAllocateSharedMemory( |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 276 | uint32 buffer_size, |
| 277 | base::SharedMemoryHandle* handle) { |
rvargas | 5779b38 | 2014-11-18 20:44:11 | [diff] [blame] | 278 | AllocateSharedMemory(buffer_size, peer_process_.Handle(), handle); |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 279 | } |
| 280 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 281 | void ChildProcessHostImpl::OnShutdownRequest() { |
[email protected] | 4cb4310 | 2011-12-02 20:24:49 | [diff] [blame] | 282 | if (delegate_->CanShutdown()) |
| 283 | Send(new ChildProcessMsg_Shutdown()); |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 284 | } |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 285 | |
[email protected] | bc10f46 | 2013-10-22 23:13:09 | [diff] [blame] | 286 | void ChildProcessHostImpl::OnAllocateGpuMemoryBuffer( |
ericrk | c9984ebe | 2015-08-17 14:22:37 | [diff] [blame] | 287 | gfx::GpuMemoryBufferId id, |
[email protected] | 8810516 | 2013-12-05 01:02:12 | [diff] [blame] | 288 | uint32 width, |
| 289 | uint32 height, |
spang | fcf5fab4 | 2015-08-04 19:25:35 | [diff] [blame] | 290 | gfx::BufferFormat format, |
| 291 | gfx::BufferUsage usage, |
jam | 81366316 | 2015-03-26 16:46:29 | [diff] [blame] | 292 | gfx::GpuMemoryBufferHandle* handle) { |
reveman | 22dd929 | 2014-10-13 20:52:05 | [diff] [blame] | 293 | // TODO(reveman): Add support for other types of GpuMemoryBuffers. |
reveman | bc2de2b | 2014-11-17 03:21:32 | [diff] [blame] | 294 | |
| 295 | // AllocateForChildProcess() will check if |width| and |height| are valid |
| 296 | // and handle failure in a controlled way when not. We just need to make |
reveman | 485728ba | 2015-10-23 18:43:22 | [diff] [blame^] | 297 | // sure |usage| is supported here. |
| 298 | if (GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage)) { |
jam | 81366316 | 2015-03-26 16:46:29 | [diff] [blame] | 299 | *handle = GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( |
ericrk | c9984ebe | 2015-08-17 14:22:37 | [diff] [blame] | 300 | id, gfx::Size(width, height), format, peer_process_.Handle()); |
reveman | 22dd929 | 2014-10-13 20:52:05 | [diff] [blame] | 301 | } |
reveman | 22dd929 | 2014-10-13 20:52:05 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( |
reveman | 510a6e0 | 2014-11-05 00:59:18 | [diff] [blame] | 305 | gfx::GpuMemoryBufferId id, |
alexst | 2992e56 | 2014-11-04 03:01:03 | [diff] [blame] | 306 | uint32 sync_point) { |
reveman | 22dd929 | 2014-10-13 20:52:05 | [diff] [blame] | 307 | // Note: Nothing to do here as ownership of shared memory backed |
| 308 | // GpuMemoryBuffers is passed with IPC. |
| 309 | } |
| 310 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 311 | } // namespace content |