Chromium Code Reviews| 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/scoped_ptr.h" | |
| 13 #include "public/platform/WebCommon.h" | |
| 14 | |
| 15 #include <utility> | |
| 16 | |
| 17 #if BLINK_IMPLEMENTATION | |
| 18 #include "wtf/Functional.h" | |
| 19 #else | |
| 20 #include "base/logging.h" | |
| 21 #endif | |
| 22 | |
| 23 namespace blink { | |
| 24 | |
| 25 // Conversion from WTF closures to base closures to pass a callback out of | |
| 26 // blink. | |
| 27 class WebClosure { | |
| 28 public: | |
| 29 #if BLINK_IMPLEMENTATION | |
| 30 WebClosure() {} | |
| 31 | |
| 32 explicit WebClosure(PassOwnPtr<SameThreadClosure> c) | |
| 33 { | |
| 34 auto run_and_delete = +[](scoped_ptr<SameThreadClosure> c) | |
|
Ken Russell (switch to Gerrit)
2016/03/24 18:29:04
Is the "+" strictly needed to avoid compile errors
danakj
2016/03/24 18:36:50
The + let's bind work. Bind won't let you use a la
danakj
2016/03/24 18:38:09
But apparently does not work in MSVC. Cool.
| |
| 35 { | |
| 36 (*c)(); | |
| 37 }; | |
| 38 m_closure = base::Bind(run_and_delete, base::Passed(make_scoped_ptr(c.le akPtr()))); | |
| 39 } | |
| 40 #endif | |
| 41 | |
| 42 // TODO(danakj): These could be =default with MSVC 2015. | |
| 43 WebClosure(WebClosure&& other) { *this = std::move(other); } | |
| 44 WebClosure& operator=(WebClosure&& other) | |
| 45 { | |
| 46 m_haveClosure = other.m_haveClosure; | |
| 47 other.m_haveClosure = false; | |
| 48 m_closure = std::move(other.m_closure); | |
| 49 return *this; | |
| 50 } | |
| 51 | |
| 52 #if !BLINK_IMPLEMENTATION | |
| 53 // TODO(danakj): This could be rvalue-ref-qualified. | |
| 54 base::Closure ToBaseClosure() | |
| 55 { | |
| 56 // Don't call this more than once! | |
| 57 DCHECK(m_haveClosure); | |
| 58 m_haveClosure = false; | |
| 59 return std::move(m_closure); | |
| 60 } | |
| 61 #endif | |
| 62 | |
| 63 private: | |
| 64 bool m_haveClosure = true; | |
| 65 base::Closure m_closure; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(WebClosure); | |
| 68 }; | |
| 69 | |
| 70 } // namespace blink | |
| 71 | |
| 72 #endif // WebClosure_h | |
| OLD | NEW |