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" |
29 #include "ipc/ipc_channel.h" | 28 #include "ipc/ipc_channel.h" |
30 #include "ipc/ipc_logging.h" | 29 #include "ipc/ipc_logging.h" |
31 #include "ipc/message_filter.h" | 30 #include "ipc/message_filter.h" |
32 | 31 |
33 #if defined(OS_LINUX) | 32 #if defined(OS_LINUX) |
34 #include "base/linux_util.h" | 33 #include "base/linux_util.h" |
35 #elif defined(OS_WIN) | 34 #elif defined(OS_WIN) |
36 #include "content/common/font_cache_dispatcher_win.h" | 35 #include "content/common/font_cache_dispatcher_win.h" |
37 #endif // OS_LINUX | 36 #endif // OS_LINUX |
38 | 37 |
39 namespace { | 38 namespace { |
40 | 39 |
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. | 40 // Global atomic to generate child process unique IDs. |
69 base::StaticAtomicSequenceNumber g_unique_id; | 41 base::StaticAtomicSequenceNumber g_unique_id; |
70 | 42 |
71 } // namespace | 43 } // namespace |
72 | 44 |
73 namespace content { | 45 namespace content { |
74 | 46 |
75 int ChildProcessHost::kInvalidUniqueID = -1; | 47 int ChildProcessHost::kInvalidUniqueID = -1; |
76 | 48 |
77 uint64 ChildProcessHost::kBrowserTracingProcessId = | 49 uint64 ChildProcessHost::kBrowserTracingProcessId = |
(...skipping 27 matching lines...) Expand all Loading... |
105 PathService::Get(CHILD_PROCESS_EXE, &child_path); | 77 PathService::Get(CHILD_PROCESS_EXE, &child_path); |
106 return child_path; | 78 return child_path; |
107 } | 79 } |
108 | 80 |
109 ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate) | 81 ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate) |
110 : delegate_(delegate), | 82 : delegate_(delegate), |
111 opening_channel_(false) { | 83 opening_channel_(false) { |
112 #if defined(OS_WIN) | 84 #if defined(OS_WIN) |
113 AddFilter(new FontCacheDispatcher()); | 85 AddFilter(new FontCacheDispatcher()); |
114 #endif | 86 #endif |
115 #if USE_ATTACHMENT_BROKER | |
116 // 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 | |
118 // single process modes, the global attachment broker is the privileged | |
119 // attachment broker, rather than an unprivileged attachment broker. | |
120 GetAttachmentBroker(); | |
121 #endif | |
122 } | 87 } |
123 | 88 |
124 ChildProcessHostImpl::~ChildProcessHostImpl() { | 89 ChildProcessHostImpl::~ChildProcessHostImpl() { |
125 #if USE_ATTACHMENT_BROKER | 90 #if USE_ATTACHMENT_BROKER |
126 GetAttachmentBroker()->DeregisterCommunicationChannel(channel_.get()); | 91 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( |
| 92 channel_.get()); |
127 #endif | 93 #endif |
128 for (size_t i = 0; i < filters_.size(); ++i) { | 94 for (size_t i = 0; i < filters_.size(); ++i) { |
129 filters_[i]->OnChannelClosing(); | 95 filters_[i]->OnChannelClosing(); |
130 filters_[i]->OnFilterRemoved(); | 96 filters_[i]->OnFilterRemoved(); |
131 } | 97 } |
132 } | 98 } |
133 | 99 |
134 void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) { | 100 void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) { |
135 filters_.push_back(filter); | 101 filters_.push_back(filter); |
136 | 102 |
137 if (channel_) | 103 if (channel_) |
138 filter->OnFilterAdded(channel_.get()); | 104 filter->OnFilterAdded(channel_.get()); |
139 } | 105 } |
140 | 106 |
141 void ChildProcessHostImpl::ForceShutdown() { | 107 void ChildProcessHostImpl::ForceShutdown() { |
142 Send(new ChildProcessMsg_Shutdown()); | 108 Send(new ChildProcessMsg_Shutdown()); |
143 } | 109 } |
144 | 110 |
145 std::string ChildProcessHostImpl::CreateChannel() { | 111 std::string ChildProcessHostImpl::CreateChannel() { |
146 channel_id_ = IPC::Channel::GenerateVerifiedChannelID(std::string()); | 112 channel_id_ = IPC::Channel::GenerateVerifiedChannelID(std::string()); |
147 channel_ = IPC::Channel::CreateServer(channel_id_, this); | 113 channel_ = IPC::Channel::CreateServer(channel_id_, this); |
148 if (!channel_->Connect()) | 114 if (!channel_->Connect()) |
149 return std::string(); | 115 return std::string(); |
150 #if USE_ATTACHMENT_BROKER | 116 #if USE_ATTACHMENT_BROKER |
151 GetAttachmentBroker()->RegisterCommunicationChannel(channel_.get()); | 117 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( |
| 118 channel_.get()); |
152 #endif | 119 #endif |
153 | 120 |
154 for (size_t i = 0; i < filters_.size(); ++i) | 121 for (size_t i = 0; i < filters_.size(); ++i) |
155 filters_[i]->OnFilterAdded(channel_.get()); | 122 filters_[i]->OnFilterAdded(channel_.get()); |
156 | 123 |
157 // Make sure these messages get sent first. | 124 // Make sure these messages get sent first. |
158 #if defined(IPC_MESSAGE_LOG_ENABLED) | 125 #if defined(IPC_MESSAGE_LOG_ENABLED) |
159 bool enabled = IPC::Logging::GetInstance()->Enabled(); | 126 bool enabled = IPC::Logging::GetInstance()->Enabled(); |
160 Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled)); | 127 Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled)); |
161 #endif | 128 #endif |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 } | 303 } |
337 | 304 |
338 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( | 305 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( |
339 gfx::GpuMemoryBufferId id, | 306 gfx::GpuMemoryBufferId id, |
340 uint32 sync_point) { | 307 uint32 sync_point) { |
341 // Note: Nothing to do here as ownership of shared memory backed | 308 // Note: Nothing to do here as ownership of shared memory backed |
342 // GpuMemoryBuffers is passed with IPC. | 309 // GpuMemoryBuffers is passed with IPC. |
343 } | 310 } |
344 | 311 |
345 } // namespace content | 312 } // namespace content |
OLD | NEW |