blob: 90867310c855754f7bb26b74b35e839b698dad03 [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
14ScopedClosureRunner::~ScopedClosureRunner() {
15 if (!closure_.is_null())
tzik398065c2017-08-08 05:19:4016 std::move(closure_).Run();
[email protected]1c232c22013-08-30 02:04:0417}
18
sergeyue4be1912016-06-25 00:51:0919ScopedClosureRunner::ScopedClosureRunner(ScopedClosureRunner&& other)
20 : closure_(other.Release()) {}
21
22ScopedClosureRunner& ScopedClosureRunner::operator=(
23 ScopedClosureRunner&& other) {
sergeyu668613aa2016-07-08 00:34:2724 ReplaceClosure(other.Release());
sergeyue4be1912016-06-25 00:51:0925 return *this;
26}
27
sergeyu668613aa2016-07-08 00:34:2728void ScopedClosureRunner::RunAndReset() {
tzik398065c2017-08-08 05:19:4029 std::move(closure_).Run();
[email protected]1c232c22013-08-30 02:04:0430}
31
tzik398065c2017-08-08 05:19:4032void ScopedClosureRunner::ReplaceClosure(OnceClosure closure) {
33 closure_ = std::move(closure);
[email protected]1c232c22013-08-30 02:04:0434}
35
tzik398065c2017-08-08 05:19:4036OnceClosure ScopedClosureRunner::Release() {
37 return std::move(closure_);
[email protected]1c232c22013-08-30 02:04:0438}
39
40} // namespace base