| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 #ifndef WebClosure_h | |
| 6 #define WebClosure_h | |
| 7 | |
| 8 #include "base/bind.h" | |
| 9 #include "base/callback.h" | |
| 10 #include "base/callback_helpers.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/ptr_util.h" | |
| 13 #include "public/platform/WebCommon.h" | |
| 14 | |
| 15 #include <memory> | |
| 16 #include <utility> | |
| 17 | |
| 18 #if BLINK_IMPLEMENTATION | |
| 19 #include "wtf/Functional.h" | |
| 20 #else | |
| 21 #include "base/logging.h" | |
| 22 #endif | |
| 23 | |
| 24 namespace blink { | |
| 25 | |
| 26 // Conversion from WTF closures to base closures to pass a callback out of | |
| 27 // blink. | |
| 28 class WebClosure { | |
| 29 public: | |
| 30 #if BLINK_IMPLEMENTATION | |
| 31 WebClosure() {} | |
| 32 | |
| 33 explicit WebClosure(PassOwnPtr<SameThreadClosure> c) | |
| 34 { | |
| 35 m_closure = base::Bind(&RunAndDelete, base::Passed(base::WrapUnique(c.le
akPtr()))); | |
| 36 } | |
| 37 #endif | |
| 38 | |
| 39 // TODO(danakj): These could be =default with MSVC 2015. | |
| 40 WebClosure(WebClosure&& other) { *this = std::move(other); } | |
| 41 WebClosure& operator=(WebClosure&& other) | |
| 42 { | |
| 43 #if DCHECK_IS_ON() | |
| 44 m_haveClosure = other.m_haveClosure; | |
| 45 other.m_haveClosure = false; | |
| 46 #endif | |
| 47 m_closure = std::move(other.m_closure); | |
| 48 return *this; | |
| 49 } | |
| 50 | |
| 51 #if !BLINK_IMPLEMENTATION | |
| 52 // TODO(danakj): This could be rvalue-ref-qualified. | |
| 53 base::Closure TakeBaseClosure() | |
| 54 { | |
| 55 #if DCHECK_IS_ON() | |
| 56 // Don't call this more than once! | |
| 57 DCHECK(m_haveClosure); | |
| 58 m_haveClosure = false; | |
| 59 #endif | |
| 60 return std::move(m_closure); | |
| 61 } | |
| 62 #endif | |
| 63 | |
| 64 private: | |
| 65 #if BLINK_IMPLEMENTATION | |
| 66 static void RunAndDelete(std::unique_ptr<SameThreadClosure> c) { (*c)(); } | |
| 67 #endif | |
| 68 | |
| 69 #if DCHECK_IS_ON() | |
| 70 bool m_haveClosure = true; | |
| 71 #endif | |
| 72 base::Closure m_closure; | |
| 73 | |
| 74 DISALLOW_COPY_AND_ASSIGN(WebClosure); | |
| 75 }; | |
| 76 | |
| 77 } // namespace blink | |
| 78 | |
| 79 #endif // WebClosure_h | |
| OLD | NEW |