[email protected] | 1c232c2 | 2013-08-30 02:04:04 | [diff] [blame] | 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 "base/callback_helpers.h" | ||||
6 | |||||
[email protected] | 1c232c2 | 2013-08-30 02:04:04 | [diff] [blame] | 7 | namespace base { |
8 | |||||
Chris Watkins | bb7211c | 2017-11-29 07:16:38 | [diff] [blame] | 9 | ScopedClosureRunner::ScopedClosureRunner() = default; |
[email protected] | 1c232c2 | 2013-08-30 02:04:04 | [diff] [blame] | 10 | |
tzik | 398065c | 2017-08-08 05:19:40 | [diff] [blame] | 11 | ScopedClosureRunner::ScopedClosureRunner(OnceClosure closure) |
12 | : closure_(std::move(closure)) {} | ||||
[email protected] | 1c232c2 | 2013-08-30 02:04:04 | [diff] [blame] | 13 | |
14 | ScopedClosureRunner::~ScopedClosureRunner() { | ||||
15 | if (!closure_.is_null()) | ||||
tzik | 398065c | 2017-08-08 05:19:40 | [diff] [blame] | 16 | std::move(closure_).Run(); |
[email protected] | 1c232c2 | 2013-08-30 02:04:04 | [diff] [blame] | 17 | } |
18 | |||||
sergeyu | e4be191 | 2016-06-25 00:51:09 | [diff] [blame] | 19 | ScopedClosureRunner::ScopedClosureRunner(ScopedClosureRunner&& other) |
20 | : closure_(other.Release()) {} | ||||
21 | |||||
22 | ScopedClosureRunner& ScopedClosureRunner::operator=( | ||||
23 | ScopedClosureRunner&& other) { | ||||
sergeyu | 668613aa | 2016-07-08 00:34:27 | [diff] [blame] | 24 | ReplaceClosure(other.Release()); |
sergeyu | e4be191 | 2016-06-25 00:51:09 | [diff] [blame] | 25 | return *this; |
26 | } | ||||
27 | |||||
sergeyu | 668613aa | 2016-07-08 00:34:27 | [diff] [blame] | 28 | void ScopedClosureRunner::RunAndReset() { |
tzik | 398065c | 2017-08-08 05:19:40 | [diff] [blame] | 29 | std::move(closure_).Run(); |
[email protected] | 1c232c2 | 2013-08-30 02:04:04 | [diff] [blame] | 30 | } |
31 | |||||
tzik | 398065c | 2017-08-08 05:19:40 | [diff] [blame] | 32 | void ScopedClosureRunner::ReplaceClosure(OnceClosure closure) { |
33 | closure_ = std::move(closure); | ||||
[email protected] | 1c232c2 | 2013-08-30 02:04:04 | [diff] [blame] | 34 | } |
35 | |||||
tzik | 398065c | 2017-08-08 05:19:40 | [diff] [blame] | 36 | OnceClosure ScopedClosureRunner::Release() { |
37 | return std::move(closure_); | ||||
[email protected] | 1c232c2 | 2013-08-30 02:04:04 | [diff] [blame] | 38 | } |
39 | |||||
40 | } // namespace base |