fixup! [M120 Migration] Notify media device state to webbrowser
[platform/framework/web/chromium-efl.git] / base / callback_list.cc
1 // Copyright 2020 The Chromium Authors
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_list.h"
6
7 #include <utility>
8
9 #include "base/functional/callback.h"
10
11 namespace base {
12
13 CallbackListSubscription::CallbackListSubscription() = default;
14
15 CallbackListSubscription::CallbackListSubscription(base::OnceClosure closure)
16     : closure_(std::move(closure)) {}
17
18 CallbackListSubscription::CallbackListSubscription(
19     CallbackListSubscription&& subscription)
20     : closure_(std::move(subscription.closure_)) {}
21
22 CallbackListSubscription& CallbackListSubscription::operator=(
23     CallbackListSubscription&& subscription) {
24   // Note: This still works properly for self-assignment.
25   Run();
26   closure_ = std::move(subscription.closure_);
27   return *this;
28 }
29
30 CallbackListSubscription::~CallbackListSubscription() {
31   Run();
32 }
33
34 void CallbackListSubscription::Run() {
35   if (closure_)
36     std::move(closure_).Run();
37 }
38
39 }  // namespace base