Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: content/common/child_process_host_impl.cc

Issue 126033004: Clean up ChildProcessHost unique id generation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: mac Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/common/child_process_host_impl.h ('k') | content/public/browser/render_process_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/atomic_sequence_num.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/process/process_metrics.h" 15 #include "base/process/process_metrics.h"
16 #include "base/rand_util.h" 16 #include "base/rand_util.h"
17 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
18 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 18 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
19 #include "content/common/child_process_messages.h" 19 #include "content/common/child_process_messages.h"
20 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" 20 #include "content/common/gpu/client/gpu_memory_buffer_impl.h"
21 #include "content/public/common/child_process_host_delegate.h" 21 #include "content/public/common/child_process_host_delegate.h"
22 #include "content/public/common/content_paths.h" 22 #include "content/public/common/content_paths.h"
23 #include "content/public/common/content_switches.h" 23 #include "content/public/common/content_switches.h"
24 #include "ipc/ipc_channel.h" 24 #include "ipc/ipc_channel.h"
25 #include "ipc/ipc_logging.h" 25 #include "ipc/ipc_logging.h"
26 26
27 #if defined(OS_LINUX) 27 #if defined(OS_LINUX)
28 #include "base/linux_util.h" 28 #include "base/linux_util.h"
29 #elif defined(OS_WIN) 29 #elif defined(OS_WIN)
30 #include "content/common/font_cache_dispatcher_win.h" 30 #include "content/common/font_cache_dispatcher_win.h"
31 #endif // OS_LINUX 31 #endif // OS_LINUX
32 32
33 #if defined(OS_MACOSX)
34 namespace { 33 namespace {
35 34
35 #if defined(OS_MACOSX)
36 // Given |path| identifying a Mac-style child process executable path, adjusts 36 // Given |path| identifying a Mac-style child process executable path, adjusts
37 // it to correspond to |feature|. For a child process path such as 37 // it to correspond to |feature|. For a child process path such as
38 // ".../Chromium Helper.app/Contents/MacOS/Chromium Helper", the transformed 38 // ".../Chromium Helper.app/Contents/MacOS/Chromium Helper", the transformed
39 // path for feature "NP" would be 39 // path for feature "NP" would be
40 // ".../Chromium Helper NP.app/Contents/MacOS/Chromium Helper NP". The new 40 // ".../Chromium Helper NP.app/Contents/MacOS/Chromium Helper NP". The new
41 // path is returned. 41 // path is returned.
42 base::FilePath TransformPathForFeature(const base::FilePath& path, 42 base::FilePath TransformPathForFeature(const base::FilePath& path,
43 const std::string& feature) { 43 const std::string& feature) {
44 std::string basename = path.BaseName().value(); 44 std::string basename = path.BaseName().value();
45 45
(...skipping 13 matching lines...) Expand all
59 59
60 base::FilePath root_path = helper_app_path.DirName(); 60 base::FilePath root_path = helper_app_path.DirName();
61 61
62 std::string new_basename = basename; 62 std::string new_basename = basename;
63 new_basename.append(1, ' '); 63 new_basename.append(1, ' ');
64 new_basename.append(feature); 64 new_basename.append(feature);
65 std::string new_basename_app = new_basename; 65 std::string new_basename_app = new_basename;
66 new_basename_app.append(kAppExtension); 66 new_basename_app.append(kAppExtension);
67 67
68 base::FilePath new_path = root_path.Append(new_basename_app) 68 base::FilePath new_path = root_path.Append(new_basename_app)
69 .Append(kContentsName) 69 .Append(kContentsName)
70 .Append(kMacOSName) 70 .Append(kMacOSName)
71 .Append(new_basename); 71 .Append(new_basename);
72 72
73 return new_path; 73 return new_path;
74 } 74 }
75 #endif // OS_MACOSX
76
77 // Global atomic to generate child process unique IDs.
78 base::StaticAtomicSequenceNumber g_unique_id;
75 79
76 } // namespace 80 } // namespace
77 #endif // OS_MACOSX
78 81
79 namespace content { 82 namespace content {
80 83
81 int ChildProcessHostImpl::kInvalidChildProcessId = -1; 84 int ChildProcessHost::kInvalidUniqueID = -1;
82 85
83 // static 86 // static
84 ChildProcessHost* ChildProcessHost::Create(ChildProcessHostDelegate* delegate) { 87 ChildProcessHost* ChildProcessHost::Create(ChildProcessHostDelegate* delegate) {
85 return new ChildProcessHostImpl(delegate); 88 return new ChildProcessHostImpl(delegate);
86 } 89 }
87 90
88 // static 91 // static
89 base::FilePath ChildProcessHost::GetChildPath(int flags) { 92 base::FilePath ChildProcessHost::GetChildPath(int flags) {
90 base::FilePath child_path; 93 base::FilePath child_path;
91 94
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 *shared_memory_handle = base::SharedMemory::NULLHandle(); 208 *shared_memory_handle = base::SharedMemory::NULLHandle();
206 NOTREACHED() << "Cannot create shared memory buffer"; 209 NOTREACHED() << "Cannot create shared memory buffer";
207 return; 210 return;
208 } 211 }
209 shared_buf.GiveToProcess(child_process_handle, shared_memory_handle); 212 shared_buf.GiveToProcess(child_process_handle, shared_memory_handle);
210 } 213 }
211 214
212 int ChildProcessHostImpl::GenerateChildProcessUniqueId() { 215 int ChildProcessHostImpl::GenerateChildProcessUniqueId() {
213 // This function must be threadsafe. 216 // This function must be threadsafe.
214 // 217 //
215 // TODO(ajwong): Why not StaticAtomicSequenceNumber? 218 // Historically, this function returned ids started with 1, so in several
216 static base::subtle::Atomic32 last_unique_child_id = 0; 219 // places in the code a value of 0 (rather than kInvalidUniqueID) was used as
217 int id = base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1); 220 // an invalid value. So we retain those semantics.
221 int id = g_unique_id.GetNext() + 1;
218 222
219 CHECK_NE(kInvalidChildProcessId, id); 223 CHECK_NE(0, id);
224 CHECK_NE(kInvalidUniqueID, id);
220 225
221 return id; 226 return id;
222 } 227 }
223 228
224 bool ChildProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { 229 bool ChildProcessHostImpl::OnMessageReceived(const IPC::Message& msg) {
225 #ifdef IPC_MESSAGE_LOG_ENABLED 230 #ifdef IPC_MESSAGE_LOG_ENABLED
226 IPC::Logging* logger = IPC::Logging::GetInstance(); 231 IPC::Logging* logger = IPC::Logging::GetInstance();
227 if (msg.type() == IPC_LOGGING_ID) { 232 if (msg.type() == IPC_LOGGING_ID) {
228 logger->OnReceivedLoggingMessage(msg); 233 logger->OnReceivedLoggingMessage(msg);
229 return true; 234 return true;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 uint32 internalformat, 307 uint32 internalformat,
303 gfx::GpuMemoryBufferHandle* handle) { 308 gfx::GpuMemoryBufferHandle* handle) {
304 handle->type = gfx::SHARED_MEMORY_BUFFER; 309 handle->type = gfx::SHARED_MEMORY_BUFFER;
305 AllocateSharedMemory( 310 AllocateSharedMemory(
306 width * height * GpuMemoryBufferImpl::BytesPerPixel(internalformat), 311 width * height * GpuMemoryBufferImpl::BytesPerPixel(internalformat),
307 peer_handle_, 312 peer_handle_,
308 &handle->handle); 313 &handle->handle);
309 } 314 }
310 315
311 } // namespace content 316 } // namespace content
OLDNEW
« no previous file with comments | « content/common/child_process_host_impl.h ('k') | content/public/browser/render_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698