OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "content/common/child_process.h" | 10 #include "content/common/child_process.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 DCHECK(MessageLoop::current() == message_loop()); | 118 DCHECK(MessageLoop::current() == message_loop()); |
119 | 119 |
120 return router_.ResolveRoute(routing_id); | 120 return router_.ResolveRoute(routing_id); |
121 } | 121 } |
122 | 122 |
123 webkit_glue::ResourceLoaderBridge* ChildThread::CreateBridge( | 123 webkit_glue::ResourceLoaderBridge* ChildThread::CreateBridge( |
124 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { | 124 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { |
125 return resource_dispatcher()->CreateBridge(request_info); | 125 return resource_dispatcher()->CreateBridge(request_info); |
126 } | 126 } |
127 | 127 |
| 128 base::SharedMemory* ChildThread::AllocateSharedMemory( |
| 129 size_t buf_size) { |
| 130 scoped_ptr<base::SharedMemory> shared_buf; |
| 131 #if defined(OS_WIN) |
| 132 shared_buf.reset(new base::SharedMemory); |
| 133 if (!shared_buf->CreateAndMapAnonymous(buf_size)) { |
| 134 NOTREACHED(); |
| 135 return NULL; |
| 136 } |
| 137 #else |
| 138 // On POSIX, we need to ask the browser to create the shared memory for us, |
| 139 // since this is blocked by the sandbox. |
| 140 base::SharedMemoryHandle shared_mem_handle; |
| 141 if (Send(new ChildProcessHostMsg_SyncAllocateSharedMemory( |
| 142 buf_size, &shared_mem_handle))) { |
| 143 if (base::SharedMemory::IsHandleValid(shared_mem_handle)) { |
| 144 shared_buf.reset(new base::SharedMemory(shared_mem_handle, false)); |
| 145 if (!shared_buf->Map(buf_size)) { |
| 146 NOTREACHED() << "Map failed"; |
| 147 return NULL; |
| 148 } |
| 149 } else { |
| 150 NOTREACHED() << "Browser failed to allocate shared memory"; |
| 151 return NULL; |
| 152 } |
| 153 } else { |
| 154 NOTREACHED() << "Browser allocation request message failed"; |
| 155 return NULL; |
| 156 } |
| 157 #endif |
| 158 return shared_buf.release(); |
| 159 } |
| 160 |
128 ResourceDispatcher* ChildThread::resource_dispatcher() { | 161 ResourceDispatcher* ChildThread::resource_dispatcher() { |
129 return resource_dispatcher_.get(); | 162 return resource_dispatcher_.get(); |
130 } | 163 } |
131 | 164 |
132 IPC::SyncMessageFilter* ChildThread::sync_message_filter() { | 165 IPC::SyncMessageFilter* ChildThread::sync_message_filter() { |
133 return sync_message_filter_; | 166 return sync_message_filter_; |
134 } | 167 } |
135 | 168 |
136 MessageLoop* ChildThread::message_loop() { | 169 MessageLoop* ChildThread::message_loop() { |
137 return message_loop_; | 170 return message_loop_; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 MessageLoop::current()->Quit(); | 246 MessageLoop::current()->Quit(); |
214 return; | 247 return; |
215 } | 248 } |
216 | 249 |
217 // The child process shutdown sequence is a request response based mechanism, | 250 // The child process shutdown sequence is a request response based mechanism, |
218 // where we send out an initial feeler request to the child process host | 251 // where we send out an initial feeler request to the child process host |
219 // instance in the browser to verify if it's ok to shutdown the child process. | 252 // instance in the browser to verify if it's ok to shutdown the child process. |
220 // The browser then sends back a response if it's ok to shutdown. | 253 // The browser then sends back a response if it's ok to shutdown. |
221 Send(new ChildProcessHostMsg_ShutdownRequest); | 254 Send(new ChildProcessHostMsg_ShutdownRequest); |
222 } | 255 } |
OLD | NEW |