| 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/browser/browser_child_process_host_impl.h" | 5 #include "content/browser/browser_child_process_host_impl.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/dump_without_crashing.h" | 10 #include "base/debug/dump_without_crashing.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // TODO(phajdan.jr): Check thread after fixing http://crbug.com/167126. | 154 // TODO(phajdan.jr): Check thread after fixing http://crbug.com/167126. |
| 155 g_observers.Get().RemoveObserver(observer); | 155 g_observers.Get().RemoveObserver(observer); |
| 156 } | 156 } |
| 157 | 157 |
| 158 BrowserChildProcessHostImpl::BrowserChildProcessHostImpl( | 158 BrowserChildProcessHostImpl::BrowserChildProcessHostImpl( |
| 159 content::ProcessType process_type, | 159 content::ProcessType process_type, |
| 160 BrowserChildProcessHostDelegate* delegate, | 160 BrowserChildProcessHostDelegate* delegate, |
| 161 const std::string& service_name) | 161 const std::string& service_name) |
| 162 : data_(process_type), | 162 : data_(process_type), |
| 163 delegate_(delegate), | 163 delegate_(delegate), |
| 164 child_token_(mojo::edk::GenerateRandomToken()), | 164 pending_connection_(new mojo::edk::PendingProcessConnection), |
| 165 channel_(nullptr), | 165 channel_(nullptr), |
| 166 is_channel_connected_(false), | 166 is_channel_connected_(false), |
| 167 notify_child_disconnected_(false), | 167 notify_child_disconnected_(false), |
| 168 weak_factory_(this) { | 168 weak_factory_(this) { |
| 169 data_.id = ChildProcessHostImpl::GenerateChildProcessUniqueId(); | 169 data_.id = ChildProcessHostImpl::GenerateChildProcessUniqueId(); |
| 170 | 170 |
| 171 child_process_host_.reset(ChildProcessHost::Create(this)); | 171 child_process_host_.reset(ChildProcessHost::Create(this)); |
| 172 AddFilter(new TraceMessageFilter(data_.id)); | 172 AddFilter(new TraceMessageFilter(data_.id)); |
| 173 AddFilter(new ProfilerMessageFilter(process_type)); | 173 AddFilter(new ProfilerMessageFilter(process_type)); |
| 174 AddFilter(new HistogramMessageFilter); | 174 AddFilter(new HistogramMessageFilter); |
| 175 AddFilter(new MemoryMessageFilter(this, process_type)); | 175 AddFilter(new MemoryMessageFilter(this, process_type)); |
| 176 | 176 |
| 177 g_child_process_list.Get().push_back(this); | 177 g_child_process_list.Get().push_back(this); |
| 178 GetContentClient()->browser()->BrowserChildProcessHostCreated(this); | 178 GetContentClient()->browser()->BrowserChildProcessHostCreated(this); |
| 179 | 179 |
| 180 if (!service_name.empty()) { | 180 if (!service_name.empty()) { |
| 181 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 181 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 182 child_connection_.reset(new ChildConnection( | 182 child_connection_.reset( |
| 183 service_name, base::StringPrintf("%d", data_.id), child_token_, | 183 new ChildConnection(service_name, base::StringPrintf("%d", data_.id), |
| 184 ServiceManagerContext::GetConnectorForIOThread(), | 184 pending_connection_.get(), |
| 185 base::ThreadTaskRunnerHandle::Get())); | 185 ServiceManagerContext::GetConnectorForIOThread(), |
| 186 base::ThreadTaskRunnerHandle::Get())); |
| 186 } | 187 } |
| 187 | 188 |
| 188 // May be null during test execution. | 189 // May be null during test execution. |
| 189 if (ServiceManagerConnection::GetForProcess()) { | 190 if (ServiceManagerConnection::GetForProcess()) { |
| 190 ServiceManagerConnection::GetForProcess()->AddConnectionFilter( | 191 ServiceManagerConnection::GetForProcess()->AddConnectionFilter( |
| 191 base::MakeUnique<ConnectionFilterImpl>()); | 192 base::MakeUnique<ConnectionFilterImpl>()); |
| 192 } | 193 } |
| 193 | 194 |
| 194 // Create a persistent memory segment for subprocess histograms. | 195 // Create a persistent memory segment for subprocess histograms. |
| 195 CreateMetricsAllocator(); | 196 CreateMetricsAllocator(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches, | 250 cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches, |
| 250 arraysize(kForwardSwitches)); | 251 arraysize(kForwardSwitches)); |
| 251 | 252 |
| 252 if (child_connection_) { | 253 if (child_connection_) { |
| 253 cmd_line->AppendSwitchASCII(switches::kServiceRequestChannelToken, | 254 cmd_line->AppendSwitchASCII(switches::kServiceRequestChannelToken, |
| 254 child_connection_->service_token()); | 255 child_connection_->service_token()); |
| 255 } | 256 } |
| 256 | 257 |
| 257 notify_child_disconnected_ = true; | 258 notify_child_disconnected_ = true; |
| 258 child_process_.reset(new ChildProcessLauncher( | 259 child_process_.reset(new ChildProcessLauncher( |
| 259 std::move(delegate), std::move(cmd_line), data_.id, this, child_token_, | 260 std::move(delegate), std::move(cmd_line), data_.id, this, |
| 261 std::move(pending_connection_), |
| 260 base::Bind(&BrowserChildProcessHostImpl::OnMojoError, | 262 base::Bind(&BrowserChildProcessHostImpl::OnMojoError, |
| 261 weak_factory_.GetWeakPtr(), | 263 weak_factory_.GetWeakPtr(), |
| 262 base::ThreadTaskRunnerHandle::Get()), | 264 base::ThreadTaskRunnerHandle::Get()), |
| 263 terminate_on_shutdown)); | 265 terminate_on_shutdown)); |
| 264 } | 266 } |
| 265 | 267 |
| 266 const ChildProcessData& BrowserChildProcessHostImpl::GetData() const { | 268 const ChildProcessData& BrowserChildProcessHostImpl::GetData() const { |
| 267 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 269 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 268 return data_; | 270 return data_; |
| 269 } | 271 } |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 | 613 |
| 612 #if defined(OS_WIN) | 614 #if defined(OS_WIN) |
| 613 | 615 |
| 614 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) { | 616 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) { |
| 615 OnChildDisconnected(); | 617 OnChildDisconnected(); |
| 616 } | 618 } |
| 617 | 619 |
| 618 #endif | 620 #endif |
| 619 | 621 |
| 620 } // namespace content | 622 } // namespace content |
| OLD | NEW |