• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
7 namespace base {
8 
9 ScopedClosureRunner::ScopedClosureRunner() = default;
10 
ScopedClosureRunner(OnceClosure closure)11 ScopedClosureRunner::ScopedClosureRunner(OnceClosure closure)
12     : closure_(std::move(closure)) {}
13 
~ScopedClosureRunner()14 ScopedClosureRunner::~ScopedClosureRunner() {
15   if (!closure_.is_null())
16     std::move(closure_).Run();
17 }
18 
ScopedClosureRunner(ScopedClosureRunner && other)19 ScopedClosureRunner::ScopedClosureRunner(ScopedClosureRunner&& other)
20     : closure_(other.Release()) {}
21 
operator =(ScopedClosureRunner && other)22 ScopedClosureRunner& ScopedClosureRunner::operator=(
23     ScopedClosureRunner&& other) {
24   ReplaceClosure(other.Release());
25   return *this;
26 }
27 
RunAndReset()28 void ScopedClosureRunner::RunAndReset() {
29   std::move(closure_).Run();
30 }
31 
ReplaceClosure(OnceClosure closure)32 void ScopedClosureRunner::ReplaceClosure(OnceClosure closure) {
33   closure_ = std::move(closure);
34 }
35 
Release()36 OnceClosure ScopedClosureRunner::Release() {
37   return std::move(closure_);
38 }
39 
40 }  // namespace base
41