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.
5 #include "content/child/scoped_child_process_reference.h"
8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "base/time/time.h"
12 #include "content/child/child_process.h"
16 ScopedChildProcessReference::ScopedChildProcessReference()
17 : has_reference_(true) {
18 ChildProcess::current()->AddRefProcess();
21 ScopedChildProcessReference::~ScopedChildProcessReference() {
23 ChildProcess::current()->ReleaseProcess();
26 void ScopedChildProcessReference::ReleaseWithDelay(
27 const base::TimeDelta
& delay
) {
28 DCHECK(has_reference_
);
29 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
30 FROM_HERE
, base::Bind(&ChildProcess::ReleaseProcess
,
31 base::Unretained(ChildProcess::current())),
33 has_reference_
= false;
36 } // namespace content