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" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 PathService::Get(CHILD_PROCESS_EXE, &child_path); | 79 PathService::Get(CHILD_PROCESS_EXE, &child_path); |
80 return child_path; | 80 return child_path; |
81 } | 81 } |
82 | 82 |
83 ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate) | 83 ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate) |
84 : delegate_(delegate), | 84 : delegate_(delegate), |
85 opening_channel_(false) { | 85 opening_channel_(false) { |
86 #if defined(OS_WIN) | 86 #if defined(OS_WIN) |
87 AddFilter(new FontCacheDispatcher()); | 87 AddFilter(new FontCacheDispatcher()); |
88 #endif | 88 #endif |
89 | |
90 #if USE_ATTACHMENT_BROKER | |
91 #if defined(OS_MACOSX) && !defined(OS_IOS) | |
92 // On Mac, the privileged AttachmentBroker needs a reference to the Mach port | |
93 // Provider, which is only available in the chrome/ module. The attachment | |
94 // broker must already be created. | |
95 DCHECK(IPC::AttachmentBroker::GetGlobal()); | |
96 #else | |
97 // Construct the privileged attachment broker early in the life cycle of a | |
98 // child process. | |
99 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(); | |
100 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | |
101 #endif // USE_ATTACHMENT_BROKER | |
102 } | 89 } |
103 | 90 |
104 ChildProcessHostImpl::~ChildProcessHostImpl() { | 91 ChildProcessHostImpl::~ChildProcessHostImpl() { |
105 // If a channel was never created than it wasn't registered and the filters | 92 // If a channel was never created than it wasn't registered and the filters |
106 // weren't notified. For the sake of symmetry don't call the matching teardown | 93 // weren't notified. For the sake of symmetry don't call the matching teardown |
107 // functions. This is analogous to how RenderProcessHostImpl handles things. | 94 // functions. This is analogous to how RenderProcessHostImpl handles things. |
108 if (!channel_) | 95 if (!channel_) |
109 return; | 96 return; |
110 | 97 |
111 #if USE_ATTACHMENT_BROKER | 98 #if USE_ATTACHMENT_BROKER |
112 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | 99 // In unit tests, the attachment broker may not have been initialized. |
113 channel_.get()); | 100 if (IPC::AttachmentBroker::GetGlobal()) { |
| 101 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( |
| 102 channel_.get()); |
| 103 } |
114 #endif | 104 #endif |
115 for (size_t i = 0; i < filters_.size(); ++i) { | 105 for (size_t i = 0; i < filters_.size(); ++i) { |
116 filters_[i]->OnChannelClosing(); | 106 filters_[i]->OnChannelClosing(); |
117 filters_[i]->OnFilterRemoved(); | 107 filters_[i]->OnFilterRemoved(); |
118 } | 108 } |
119 } | 109 } |
120 | 110 |
121 void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) { | 111 void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) { |
122 filters_.push_back(filter); | 112 filters_.push_back(filter); |
123 | 113 |
124 if (channel_) | 114 if (channel_) |
125 filter->OnFilterAdded(channel_.get()); | 115 filter->OnFilterAdded(channel_.get()); |
126 } | 116 } |
127 | 117 |
128 void ChildProcessHostImpl::ForceShutdown() { | 118 void ChildProcessHostImpl::ForceShutdown() { |
129 Send(new ChildProcessMsg_Shutdown()); | 119 Send(new ChildProcessMsg_Shutdown()); |
130 } | 120 } |
131 | 121 |
132 std::string ChildProcessHostImpl::CreateChannel() { | 122 std::string ChildProcessHostImpl::CreateChannel() { |
133 channel_id_ = IPC::Channel::GenerateVerifiedChannelID(std::string()); | 123 channel_id_ = IPC::Channel::GenerateVerifiedChannelID(std::string()); |
134 channel_ = IPC::Channel::CreateServer(channel_id_, this); | 124 channel_ = IPC::Channel::CreateServer(channel_id_, this); |
135 if (!channel_->Connect()) | 125 if (!channel_->Connect()) |
136 return std::string(); | 126 return std::string(); |
137 #if USE_ATTACHMENT_BROKER | 127 #if USE_ATTACHMENT_BROKER |
138 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( | 128 // In unit tests, the attachment broker may not have been initialized. |
139 channel_.get()); | 129 if (IPC::AttachmentBroker::GetGlobal()) { |
| 130 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( |
| 131 channel_.get()); |
| 132 } |
140 #endif | 133 #endif |
141 | 134 |
142 for (size_t i = 0; i < filters_.size(); ++i) | 135 for (size_t i = 0; i < filters_.size(); ++i) |
143 filters_[i]->OnFilterAdded(channel_.get()); | 136 filters_[i]->OnFilterAdded(channel_.get()); |
144 | 137 |
145 // Make sure these messages get sent first. | 138 // Make sure these messages get sent first. |
146 #if defined(IPC_MESSAGE_LOG_ENABLED) | 139 #if defined(IPC_MESSAGE_LOG_ENABLED) |
147 bool enabled = IPC::Logging::GetInstance()->Enabled(); | 140 bool enabled = IPC::Logging::GetInstance()->Enabled(); |
148 Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled)); | 141 Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled)); |
149 #endif | 142 #endif |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 } | 316 } |
324 | 317 |
325 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( | 318 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( |
326 gfx::GpuMemoryBufferId id, | 319 gfx::GpuMemoryBufferId id, |
327 const gpu::SyncToken& sync_token) { | 320 const gpu::SyncToken& sync_token) { |
328 // Note: Nothing to do here as ownership of shared memory backed | 321 // Note: Nothing to do here as ownership of shared memory backed |
329 // GpuMemoryBuffers is passed with IPC. | 322 // GpuMemoryBuffers is passed with IPC. |
330 } | 323 } |
331 | 324 |
332 } // namespace content | 325 } // namespace content |
OLD | NEW |