• 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 "include/base/cef_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(ScopedClosureRunner && other)14 ScopedClosureRunner::ScopedClosureRunner(ScopedClosureRunner&& other)
15     : closure_(other.Release()) {}
16 
operator =(ScopedClosureRunner && other)17 ScopedClosureRunner& ScopedClosureRunner::operator=(
18     ScopedClosureRunner&& other) {
19   if (this != &other) {
20     RunAndReset();
21     ReplaceClosure(other.Release());
22   }
23   return *this;
24 }
25 
~ScopedClosureRunner()26 ScopedClosureRunner::~ScopedClosureRunner() {
27   RunAndReset();
28 }
29 
RunAndReset()30 void ScopedClosureRunner::RunAndReset() {
31   if (closure_)
32     std::move(closure_).Run();
33 }
34 
ReplaceClosure(OnceClosure closure)35 void ScopedClosureRunner::ReplaceClosure(OnceClosure closure) {
36   closure_ = std::move(closure);
37 }
38 
Release()39 OnceClosure ScopedClosureRunner::Release() {
40   return std::move(closure_);
41 }
42 
43 }  // namespace base
44