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/atomic_sequence_num.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/hash.h" | 12 #include "base/hash.h" |
13 #include "base/lazy_instance.h" | |
14 #include "base/logging.h" | 13 #include "base/logging.h" |
15 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
16 #include "base/numerics/safe_math.h" | 15 #include "base/numerics/safe_math.h" |
17 #include "base/path_service.h" | 16 #include "base/path_service.h" |
18 #include "base/process/process_metrics.h" | 17 #include "base/process/process_metrics.h" |
19 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
20 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
21 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
22 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 21 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
23 #include "content/common/child_process_messages.h" | 22 #include "content/common/child_process_messages.h" |
24 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" | 23 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" |
25 #include "content/public/common/child_process_host_delegate.h" | 24 #include "content/public/common/child_process_host_delegate.h" |
26 #include "content/public/common/content_paths.h" | 25 #include "content/public/common/content_paths.h" |
27 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
28 #include "ipc/attachment_broker.h" | 27 #include "ipc/attachment_broker.h" |
| 28 #include "ipc/attachment_broker_privileged.h" |
29 #include "ipc/ipc_channel.h" | 29 #include "ipc/ipc_channel.h" |
30 #include "ipc/ipc_logging.h" | 30 #include "ipc/ipc_logging.h" |
31 #include "ipc/message_filter.h" | 31 #include "ipc/message_filter.h" |
32 | 32 |
33 #if defined(OS_LINUX) | 33 #if defined(OS_LINUX) |
34 #include "base/linux_util.h" | 34 #include "base/linux_util.h" |
35 #elif defined(OS_WIN) | 35 #elif defined(OS_WIN) |
36 #include "content/common/font_cache_dispatcher_win.h" | 36 #include "content/common/font_cache_dispatcher_win.h" |
37 #endif // OS_LINUX | 37 #endif // OS_LINUX |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 #if USE_ATTACHMENT_BROKER | |
42 // This class is wrapped in a singleton to ensure that its constructor is only | |
43 // called once. The constructor creates an attachment broker and | |
44 // sets it as the global broker. | |
45 class AttachmentBrokerWrapper { | |
46 public: | |
47 AttachmentBrokerWrapper() { | |
48 attachment_broker_.reset( | |
49 IPC::AttachmentBrokerPrivileged::CreateBroker().release()); | |
50 } | |
51 | |
52 IPC::AttachmentBrokerPrivileged* GetAttachmentBroker() { | |
53 return attachment_broker_.get(); | |
54 } | |
55 | |
56 private: | |
57 scoped_ptr<IPC::AttachmentBrokerPrivileged> attachment_broker_; | |
58 }; | |
59 | |
60 base::LazyInstance<AttachmentBrokerWrapper>::Leaky | |
61 g_attachment_broker_wrapper = LAZY_INSTANCE_INITIALIZER; | |
62 | |
63 IPC::AttachmentBrokerPrivileged* GetAttachmentBroker() { | |
64 return g_attachment_broker_wrapper.Get().GetAttachmentBroker(); | |
65 } | |
66 #endif // USE_ATTACHMENT_BROKER | |
67 | |
68 // Global atomic to generate child process unique IDs. | 41 // Global atomic to generate child process unique IDs. |
69 base::StaticAtomicSequenceNumber g_unique_id; | 42 base::StaticAtomicSequenceNumber g_unique_id; |
70 | 43 |
71 } // namespace | 44 } // namespace |
72 | 45 |
73 namespace content { | 46 namespace content { |
74 | 47 |
75 int ChildProcessHost::kInvalidUniqueID = -1; | 48 int ChildProcessHost::kInvalidUniqueID = -1; |
76 | 49 |
77 uint64 ChildProcessHost::kBrowserTracingProcessId = | 50 uint64 ChildProcessHost::kBrowserTracingProcessId = |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 : delegate_(delegate), | 83 : delegate_(delegate), |
111 opening_channel_(false) { | 84 opening_channel_(false) { |
112 #if defined(OS_WIN) | 85 #if defined(OS_WIN) |
113 AddFilter(new FontCacheDispatcher()); | 86 AddFilter(new FontCacheDispatcher()); |
114 #endif | 87 #endif |
115 #if USE_ATTACHMENT_BROKER | 88 #if USE_ATTACHMENT_BROKER |
116 // Construct the privileged attachment broker early in the life cycle of a | 89 // Construct the privileged attachment broker early in the life cycle of a |
117 // child process. This ensures that when a test is being run in one of the | 90 // child process. This ensures that when a test is being run in one of the |
118 // single process modes, the global attachment broker is the privileged | 91 // single process modes, the global attachment broker is the privileged |
119 // attachment broker, rather than an unprivileged attachment broker. | 92 // attachment broker, rather than an unprivileged attachment broker. |
120 GetAttachmentBroker(); | 93 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(); |
121 #endif | 94 #endif |
122 } | 95 } |
123 | 96 |
124 ChildProcessHostImpl::~ChildProcessHostImpl() { | 97 ChildProcessHostImpl::~ChildProcessHostImpl() { |
125 #if USE_ATTACHMENT_BROKER | 98 #if USE_ATTACHMENT_BROKER |
126 GetAttachmentBroker()->DeregisterCommunicationChannel(channel_.get()); | 99 GetAttachmentBroker()->DeregisterCommunicationChannel(channel_.get()); |
127 #endif | 100 #endif |
128 for (size_t i = 0; i < filters_.size(); ++i) { | 101 for (size_t i = 0; i < filters_.size(); ++i) { |
129 filters_[i]->OnChannelClosing(); | 102 filters_[i]->OnChannelClosing(); |
130 filters_[i]->OnFilterRemoved(); | 103 filters_[i]->OnFilterRemoved(); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 } | 309 } |
337 | 310 |
338 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( | 311 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( |
339 gfx::GpuMemoryBufferId id, | 312 gfx::GpuMemoryBufferId id, |
340 uint32 sync_point) { | 313 uint32 sync_point) { |
341 // Note: Nothing to do here as ownership of shared memory backed | 314 // Note: Nothing to do here as ownership of shared memory backed |
342 // GpuMemoryBuffers is passed with IPC. | 315 // GpuMemoryBuffers is passed with IPC. |
343 } | 316 } |
344 | 317 |
345 } // namespace content | 318 } // namespace content |
OLD | NEW |