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 #include "content/common/child_thread.h" | 5 #include "content/common/child_thread.h" |
6 | 6 |
7 #include "base/allocator/allocator_extension.h" | 7 #include "base/allocator/allocator_extension.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/process.h" | 10 #include "base/process.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 DCHECK(MessageLoop::current() == message_loop()); | 185 DCHECK(MessageLoop::current() == message_loop()); |
186 | 186 |
187 return router_.ResolveRoute(routing_id); | 187 return router_.ResolveRoute(routing_id); |
188 } | 188 } |
189 | 189 |
190 webkit_glue::ResourceLoaderBridge* ChildThread::CreateBridge( | 190 webkit_glue::ResourceLoaderBridge* ChildThread::CreateBridge( |
191 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { | 191 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { |
192 return resource_dispatcher()->CreateBridge(request_info); | 192 return resource_dispatcher()->CreateBridge(request_info); |
193 } | 193 } |
194 | 194 |
195 static bool SendFromAnyThread(ChildThread* child_thread, IPC::Message* msg) { | |
196 if (child_thread->message_loop() == MessageLoop::current()) | |
197 child_thread->Send(msg); | |
198 else | |
199 child_thread->sync_message_filter()->Send(msg); | |
200 } | |
kinuko
2013/01/07 08:52:01
This change can probably be landed independently?
| |
201 | |
195 base::SharedMemory* ChildThread::AllocateSharedMemory( | 202 base::SharedMemory* ChildThread::AllocateSharedMemory( |
196 size_t buf_size) { | 203 size_t buf_size) { |
197 scoped_ptr<base::SharedMemory> shared_buf; | 204 scoped_ptr<base::SharedMemory> shared_buf; |
198 #if defined(OS_WIN) | 205 #if defined(OS_WIN) |
199 shared_buf.reset(new base::SharedMemory); | 206 shared_buf.reset(new base::SharedMemory); |
200 if (!shared_buf->CreateAndMapAnonymous(buf_size)) { | 207 if (!shared_buf->CreateAndMapAnonymous(buf_size)) { |
201 NOTREACHED(); | 208 NOTREACHED(); |
202 return NULL; | 209 return NULL; |
203 } | 210 } |
204 #else | 211 #else |
205 // On POSIX, we need to ask the browser to create the shared memory for us, | 212 // On POSIX, we need to ask the browser to create the shared memory for us, |
206 // since this is blocked by the sandbox. | 213 // since this is blocked by the sandbox. |
207 base::SharedMemoryHandle shared_mem_handle; | 214 base::SharedMemoryHandle shared_mem_handle; |
208 if (Send(new ChildProcessHostMsg_SyncAllocateSharedMemory( | 215 if (SendFromAnyThread(new ChildProcessHostMsg_SyncAllocateSharedMemory( |
209 buf_size, &shared_mem_handle))) { | 216 buf_size, &shared_mem_handle))) { |
210 if (base::SharedMemory::IsHandleValid(shared_mem_handle)) { | 217 if (base::SharedMemory::IsHandleValid(shared_mem_handle)) { |
211 shared_buf.reset(new base::SharedMemory(shared_mem_handle, false)); | 218 shared_buf.reset(new base::SharedMemory(shared_mem_handle, false)); |
212 if (!shared_buf->Map(buf_size)) { | 219 if (!shared_buf->Map(buf_size)) { |
213 NOTREACHED() << "Map failed"; | 220 NOTREACHED() << "Map failed"; |
214 return NULL; | 221 return NULL; |
215 } | 222 } |
216 } else { | 223 } else { |
217 NOTREACHED() << "Browser failed to allocate shared memory"; | 224 NOTREACHED() << "Browser failed to allocate shared memory"; |
218 return NULL; | 225 return NULL; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 // inflight that would addref it. | 358 // inflight that would addref it. |
352 Send(new ChildProcessHostMsg_ShutdownRequest); | 359 Send(new ChildProcessHostMsg_ShutdownRequest); |
353 } | 360 } |
354 | 361 |
355 void ChildThread::EnsureConnected() { | 362 void ChildThread::EnsureConnected() { |
356 LOG(INFO) << "ChildThread::EnsureConnected()"; | 363 LOG(INFO) << "ChildThread::EnsureConnected()"; |
357 base::KillProcess(base::GetCurrentProcessHandle(), 0, false); | 364 base::KillProcess(base::GetCurrentProcessHandle(), 0, false); |
358 } | 365 } |
359 | 366 |
360 } // namespace content | 367 } // namespace content |
OLD | NEW |