Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: third_party/WebKit/public/platform/callback/WebClosure.h

Issue 1830033003: Make lost context callback a base::Closure thru the WGC3DProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lostcontext-webclosure: nocomment Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 m_closure = base::Bind(&RunAndDelete, base::Passed(make_scoped_ptr(c.lea kPtr())));
35 }
36 #endif
37
38 // TODO(danakj): These could be =default with MSVC 2015.
39 WebClosure(WebClosure&& other) { *this = std::move(other); }
40 WebClosure& operator=(WebClosure&& other)
41 {
42 m_haveClosure = other.m_haveClosure;
43 other.m_haveClosure = false;
esprehn 2016/03/25 01:05:06 ditto, guard the m_haveClosure code with debug ifd
danakj 2016/03/25 01:41:53 Done.
44 m_closure = std::move(other.m_closure);
45 return *this;
46 }
47
48 #if !BLINK_IMPLEMENTATION
49 // TODO(danakj): This could be rvalue-ref-qualified.
50 base::Closure ToBaseClosure()
51 {
52 // Don't call this more than once!
53 DCHECK(m_haveClosure);
54 m_haveClosure = false;
55 return std::move(m_closure);
56 }
57 #endif
58
59 private:
60 #if BLINK_IMPLEMENTATION
61 static void RunAndDelete(scoped_ptr<SameThreadClosure> c) { (*c)(); }
62 #endif
63
64 bool m_haveClosure = true;
esprehn 2016/03/25 01:05:05 ifdef this to debug only, the boolean is only used
danakj 2016/03/25 01:41:53 Done, to DCHECK_IS_ON().
65 base::Closure m_closure;
66
67 DISALLOW_COPY_AND_ASSIGN(WebClosure);
68 };
69
70 } // namespace blink
71
72 #endif // WebClosure_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698