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

Side by Side Diff: content/browser/browser_child_process_host_impl.cc

Issue 2680973006: Mojo EDK: Add safe process connection API (Closed)
Patch Set: Created 3 years, 10 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
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/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
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(new ChildConnection(
183 service_name, base::StringPrintf("%d", data_.id), child_token_, 183 service_name, base::StringPrintf("%d", data_.id), *pending_connection_,
184 ServiceManagerContext::GetConnectorForIOThread(), 184 ServiceManagerContext::GetConnectorForIOThread(),
185 base::ThreadTaskRunnerHandle::Get())); 185 base::ThreadTaskRunnerHandle::Get()));
186 } 186 }
187 187
188 // May be null during test execution. 188 // May be null during test execution.
189 if (ServiceManagerConnection::GetForProcess()) { 189 if (ServiceManagerConnection::GetForProcess()) {
190 ServiceManagerConnection::GetForProcess()->AddConnectionFilter( 190 ServiceManagerConnection::GetForProcess()->AddConnectionFilter(
191 base::MakeUnique<ConnectionFilterImpl>()); 191 base::MakeUnique<ConnectionFilterImpl>());
192 } 192 }
193 193
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches, 249 cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches,
250 arraysize(kForwardSwitches)); 250 arraysize(kForwardSwitches));
251 251
252 if (child_connection_) { 252 if (child_connection_) {
253 cmd_line->AppendSwitchASCII(switches::kServiceRequestChannelToken, 253 cmd_line->AppendSwitchASCII(switches::kServiceRequestChannelToken,
254 child_connection_->service_token()); 254 child_connection_->service_token());
255 } 255 }
256 256
257 notify_child_disconnected_ = true; 257 notify_child_disconnected_ = true;
258 child_process_.reset(new ChildProcessLauncher( 258 child_process_.reset(new ChildProcessLauncher(
259 std::move(delegate), std::move(cmd_line), data_.id, this, child_token_, 259 std::move(delegate), std::move(cmd_line), data_.id, this,
260 std::move(pending_connection_),
260 base::Bind(&BrowserChildProcessHostImpl::OnMojoError, 261 base::Bind(&BrowserChildProcessHostImpl::OnMojoError,
261 weak_factory_.GetWeakPtr(), 262 weak_factory_.GetWeakPtr(),
262 base::ThreadTaskRunnerHandle::Get()), 263 base::ThreadTaskRunnerHandle::Get()),
263 terminate_on_shutdown)); 264 terminate_on_shutdown));
264 } 265 }
265 266
266 const ChildProcessData& BrowserChildProcessHostImpl::GetData() const { 267 const ChildProcessData& BrowserChildProcessHostImpl::GetData() const {
267 DCHECK_CURRENTLY_ON(BrowserThread::IO); 268 DCHECK_CURRENTLY_ON(BrowserThread::IO);
268 return data_; 269 return data_;
269 } 270 }
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 612
612 #if defined(OS_WIN) 613 #if defined(OS_WIN)
613 614
614 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) { 615 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) {
615 OnChildDisconnected(); 616 OnChildDisconnected();
616 } 617 }
617 618
618 #endif 619 #endif
619 620
620 } // namespace content 621 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698