blob: d779869b0a1eb392221897b78ce7c07fb3e2327f [file] [log] [blame]
[email protected]1c232c22013-08-30 02:04:041// 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 "base/callback_helpers.h"
6
[email protected]1c232c22013-08-30 02:04:047namespace base {
8
Chris Watkinsbb7211c2017-11-29 07:16:389ScopedClosureRunner::ScopedClosureRunner() = default;
[email protected]1c232c22013-08-30 02:04:0410
tzik398065c2017-08-08 05:19:4011ScopedClosureRunner::ScopedClosureRunner(OnceClosure closure)
12 : closure_(std::move(closure)) {}
[email protected]1c232c22013-08-30 02:04:0413
sergeyue4be1912016-06-25 00:51:0914ScopedClosureRunner::ScopedClosureRunner(ScopedClosureRunner&& other)
15 : closure_(other.Release()) {}
16
17ScopedClosureRunner& ScopedClosureRunner::operator=(
18 ScopedClosureRunner&& other) {
Peter Kasting323ccc82020-11-14 01:41:2419 if (this != &other) {
20 RunAndReset();
21 ReplaceClosure(other.Release());
22 }
sergeyue4be1912016-06-25 00:51:0923 return *this;
24}
25
Peter Kasting323ccc82020-11-14 01:41:2426ScopedClosureRunner::~ScopedClosureRunner() {
27 RunAndReset();
28}
29
sergeyu668613aa2016-07-08 00:34:2730void ScopedClosureRunner::RunAndReset() {
Peter Kasting323ccc82020-11-14 01:41:2431 if (closure_)
32 std::move(closure_).Run();
[email protected]1c232c22013-08-30 02:04:0433}
34
tzik398065c2017-08-08 05:19:4035void ScopedClosureRunner::ReplaceClosure(OnceClosure closure) {
36 closure_ = std::move(closure);
[email protected]1c232c22013-08-30 02:04:0437}
38
tzik398065c2017-08-08 05:19:4039OnceClosure ScopedClosureRunner::Release() {
40 return std::move(closure_);
[email protected]1c232c22013-08-30 02:04:0441}
42
43} // namespace base