1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "content/child/scoped_child_process_reference.h" 6 7 #include "base/bind.h" 8 #include "base/time/time.h" 9 #include "content/child/child_process.h" 10 11 namespace content { 12 ScopedChildProcessReference()13ScopedChildProcessReference::ScopedChildProcessReference() 14 : has_reference_(true) { 15 ChildProcess::current()->AddRefProcess(); 16 } 17 ~ScopedChildProcessReference()18ScopedChildProcessReference::~ScopedChildProcessReference() { 19 if (has_reference_) 20 ChildProcess::current()->ReleaseProcess(); 21 } 22 ReleaseWithDelay(const base::TimeDelta & delay)23void ScopedChildProcessReference::ReleaseWithDelay( 24 const base::TimeDelta& delay) { 25 DCHECK(has_reference_); 26 base::MessageLoop::current()->PostDelayedTask( 27 FROM_HERE, 28 base::Bind(&ChildProcess::ReleaseProcess, 29 base::Unretained(ChildProcess::current())), 30 delay); 31 has_reference_ = false; 32 } 33 34 } // namespace content 35