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 "base/callback_helpers.h"
9 ScopedClosureRunner::ScopedClosureRunner() = default;
11 ScopedClosureRunner::ScopedClosureRunner(OnceClosure closure)
12 : closure_(std::move(closure)) {}
14 ScopedClosureRunner::~ScopedClosureRunner() {
15 if (!closure_.is_null())
16 std::move(closure_).Run();
19 ScopedClosureRunner::ScopedClosureRunner(ScopedClosureRunner&& other)
20 : closure_(other.Release()) {}
22 ScopedClosureRunner& ScopedClosureRunner::operator=(
23 ScopedClosureRunner&& other) {
24 ReplaceClosure(other.Release());
28 void ScopedClosureRunner::RunAndReset() {
29 std::move(closure_).Run();
32 void ScopedClosureRunner::ReplaceClosure(OnceClosure closure) {
33 closure_ = std::move(closure);
36 OnceClosure ScopedClosureRunner::Release() {
37 return std::move(closure_);