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 blink . | |
| 26 class WebClosure { | |
| 27 public: | |
| 28 #if BLINK_IMPLEMENTATION | |
| 29 WebClosure() {} | |
| 30 | |
| 31 explicit WebClosure(PassOwnPtr<SameThreadClosure> c) | |
| 32 { | |
| 33 auto run_and_delete = +[](scoped_ptr<SameThreadClosure> c) | |
| 34 { | |
| 35 (*c)(); | |
| 36 }; | |
| 37 m_closure = base::Bind(run_and_delete, base::Passed(make_scoped_ptr(c.le akPtr()))); | |
| 38 } | |
| 39 #endif | |
| 40 | |
| 41 // TODO(danakj): These could be =default with MSVC 2015. | |
| 42 WebClosure(WebClosure&& other) { *this = std::move(other); } | |
| 43 WebClosure& operator=(WebClosure&& other) | |
| 44 { | |
| 45 m_haveClosure = other.m_haveClosure; | |
|
dcheng
2016/03/24 15:53:56
Should m_have closure be set to false?
danakj
2016/03/24 17:53:51
But what if the |other| had a closure, now this on
dcheng
2016/03/24 18:00:18
Sorry, to clarify, I meant other.m_haveClosure sho
danakj
2016/03/24 18:03:16
Oh oh ok!
| |
| 46 m_closure = base::ResetAndReturn(&other.m_closure); | |
|
dcheng
2016/03/24 15:53:56
std::move() this too?
danakj
2016/03/24 17:53:51
But it's an rvalue no?
dcheng
2016/03/24 18:00:18
Not sure what you mean. I believe that
m_closure
danakj
2016/03/24 18:03:16
OOh, I see. Does callback null itself when you mov
danakj
2016/03/24 18:06:04
It totes does. Done.
| |
| 47 return *this; | |
| 48 } | |
| 49 | |
| 50 #if !BLINK_IMPLEMENTATION | |
| 51 // TODO(danakj): This could be rvalue-ref-qualified. | |
| 52 base::Closure ToBaseClosure() | |
| 53 { | |
| 54 // Don't call this more than once! | |
| 55 DCHECK(m_haveClosure); | |
| 56 m_haveClosure = false; | |
| 57 return std::move(m_closure); | |
| 58 } | |
| 59 #endif | |
| 60 | |
| 61 private: | |
| 62 bool m_haveClosure = true; | |
| 63 base::Closure m_closure; | |
| 64 | |
| 65 DISALLOW_COPY_AND_ASSIGN(WebClosure); | |
| 66 }; | |
| 67 | |
| 68 } // namespace blink | |
| 69 | |
| 70 #endif // WebClosure_h | |
| OLD | NEW |