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_process_host_impl.h" | 5 #include "content/common/child_process_host_impl.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 .Append(new_basename); | 70 .Append(new_basename); |
71 | 71 |
72 return new_path; | 72 return new_path; |
73 } | 73 } |
74 | 74 |
75 } // namespace | 75 } // namespace |
76 #endif // OS_MACOSX | 76 #endif // OS_MACOSX |
77 | 77 |
78 namespace content { | 78 namespace content { |
79 | 79 |
| 80 int ChildProcessHostImpl::kInvalidChildProcessId = -1; |
| 81 |
80 // static | 82 // static |
81 ChildProcessHost* ChildProcessHost::Create(ChildProcessHostDelegate* delegate) { | 83 ChildProcessHost* ChildProcessHost::Create(ChildProcessHostDelegate* delegate) { |
82 return new ChildProcessHostImpl(delegate); | 84 return new ChildProcessHostImpl(delegate); |
83 } | 85 } |
84 | 86 |
85 // static | 87 // static |
86 FilePath ChildProcessHost::GetChildPath(int flags) { | 88 FilePath ChildProcessHost::GetChildPath(int flags) { |
87 FilePath child_path; | 89 FilePath child_path; |
88 | 90 |
89 child_path = CommandLine::ForCurrentProcess()->GetSwitchValuePath( | 91 child_path = CommandLine::ForCurrentProcess()->GetSwitchValuePath( |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 if (!shared_buf.CreateAndMapAnonymous(buffer_size)) { | 203 if (!shared_buf.CreateAndMapAnonymous(buffer_size)) { |
202 *shared_memory_handle = base::SharedMemory::NULLHandle(); | 204 *shared_memory_handle = base::SharedMemory::NULLHandle(); |
203 NOTREACHED() << "Cannot map shared memory buffer"; | 205 NOTREACHED() << "Cannot map shared memory buffer"; |
204 return; | 206 return; |
205 } | 207 } |
206 shared_buf.GiveToProcess(child_process_handle, shared_memory_handle); | 208 shared_buf.GiveToProcess(child_process_handle, shared_memory_handle); |
207 } | 209 } |
208 | 210 |
209 int ChildProcessHostImpl::GenerateChildProcessUniqueId() { | 211 int ChildProcessHostImpl::GenerateChildProcessUniqueId() { |
210 // This function must be threadsafe. | 212 // This function must be threadsafe. |
| 213 // |
| 214 // TODO(ajwong): Why not StaticAtomicSequenceNumber? |
211 static base::subtle::Atomic32 last_unique_child_id = 0; | 215 static base::subtle::Atomic32 last_unique_child_id = 0; |
212 return base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1); | 216 int id = base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1); |
| 217 |
| 218 CHECK_NE(kInvalidChildProcessId, id); |
| 219 |
| 220 return id; |
213 } | 221 } |
214 | 222 |
215 bool ChildProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { | 223 bool ChildProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { |
216 #ifdef IPC_MESSAGE_LOG_ENABLED | 224 #ifdef IPC_MESSAGE_LOG_ENABLED |
217 IPC::Logging* logger = IPC::Logging::GetInstance(); | 225 IPC::Logging* logger = IPC::Logging::GetInstance(); |
218 if (msg.type() == IPC_LOGGING_ID) { | 226 if (msg.type() == IPC_LOGGING_ID) { |
219 logger->OnReceivedLoggingMessage(msg); | 227 logger->OnReceivedLoggingMessage(msg); |
220 return true; | 228 return true; |
221 } | 229 } |
222 | 230 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 base::SharedMemoryHandle* handle) { | 287 base::SharedMemoryHandle* handle) { |
280 AllocateSharedMemory(buffer_size, peer_handle_, handle); | 288 AllocateSharedMemory(buffer_size, peer_handle_, handle); |
281 } | 289 } |
282 | 290 |
283 void ChildProcessHostImpl::OnShutdownRequest() { | 291 void ChildProcessHostImpl::OnShutdownRequest() { |
284 if (delegate_->CanShutdown()) | 292 if (delegate_->CanShutdown()) |
285 Send(new ChildProcessMsg_Shutdown()); | 293 Send(new ChildProcessMsg_Shutdown()); |
286 } | 294 } |
287 | 295 |
288 } // namespace content | 296 } // namespace content |
OLD | NEW |