[M85 Dev][EFL] Fix crashes at webview launch
[platform/framework/web/chromium-efl.git] / base / callback_internal.cc
1 // Copyright (c) 2012 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_internal.h"
6
7 #include "base/check.h"
8 #include "base/notreached.h"
9
10 namespace base {
11 namespace internal {
12
13 namespace {
14
15 bool QueryCancellationTraitsForNonCancellables(
16     const BindStateBase*,
17     BindStateBase::CancellationQueryMode mode) {
18   switch (mode) {
19     case BindStateBase::IS_CANCELLED:
20       return false;
21     case BindStateBase::MAYBE_VALID:
22       return true;
23   }
24   NOTREACHED();
25 }
26
27 }  // namespace
28
29 void BindStateBaseRefCountTraits::Destruct(const BindStateBase* bind_state) {
30   bind_state->destructor_(bind_state);
31 }
32
33 BindStateBase::BindStateBase(InvokeFuncStorage polymorphic_invoke,
34                              void (*destructor)(const BindStateBase*))
35     : BindStateBase(polymorphic_invoke,
36                     destructor,
37                     &QueryCancellationTraitsForNonCancellables) {}
38
39 BindStateBase::BindStateBase(
40     InvokeFuncStorage polymorphic_invoke,
41     void (*destructor)(const BindStateBase*),
42     bool (*query_cancellation_traits)(const BindStateBase*,
43                                       CancellationQueryMode))
44     : polymorphic_invoke_(polymorphic_invoke),
45       destructor_(destructor),
46       query_cancellation_traits_(query_cancellation_traits) {}
47
48 CallbackBase& CallbackBase::operator=(CallbackBase&& c) noexcept = default;
49 CallbackBase::CallbackBase(const CallbackBaseCopyable& c)
50     : bind_state_(c.bind_state_) {}
51
52 CallbackBase& CallbackBase::operator=(const CallbackBaseCopyable& c) {
53   bind_state_ = c.bind_state_;
54   return *this;
55 }
56
57 CallbackBase::CallbackBase(CallbackBaseCopyable&& c) noexcept
58     : bind_state_(std::move(c.bind_state_)) {}
59
60 CallbackBase& CallbackBase::operator=(CallbackBaseCopyable&& c) noexcept {
61   bind_state_ = std::move(c.bind_state_);
62   return *this;
63 }
64
65 void CallbackBase::Reset() {
66   // NULL the bind_state_ last, since it may be holding the last ref to whatever
67   // object owns us, and we may be deleted after that.
68   bind_state_ = nullptr;
69 }
70
71 bool CallbackBase::IsCancelled() const {
72   DCHECK(bind_state_);
73   return bind_state_->IsCancelled();
74 }
75
76 bool CallbackBase::MaybeValid() const {
77   DCHECK(bind_state_);
78   return bind_state_->MaybeValid();
79 }
80
81 bool CallbackBase::EqualsInternal(const CallbackBase& other) const {
82   return bind_state_ == other.bind_state_;
83 }
84
85 CallbackBase::~CallbackBase() = default;
86
87 CallbackBaseCopyable::CallbackBaseCopyable(const CallbackBaseCopyable& c) {
88   bind_state_ = c.bind_state_;
89 }
90
91 CallbackBaseCopyable& CallbackBaseCopyable::operator=(
92     const CallbackBaseCopyable& c) {
93   bind_state_ = c.bind_state_;
94   return *this;
95 }
96
97 CallbackBaseCopyable& CallbackBaseCopyable::operator=(
98     CallbackBaseCopyable&& c) noexcept = default;
99
100 }  // namespace internal
101 }  // namespace base