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

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: public-review 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
« no previous file with comments | « third_party/WebKit/public/platform/callback/DEPS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #if DCHECK_IS_ON()
43 m_haveClosure = other.m_haveClosure;
44 other.m_haveClosure = false;
45 #endif
46 m_closure = std::move(other.m_closure);
47 return *this;
48 }
49
50 #if !BLINK_IMPLEMENTATION
51 // TODO(danakj): This could be rvalue-ref-qualified.
52 base::Closure TakeBaseClosure()
53 {
54 #if DCHECK_IS_ON()
55 // Don't call this more than once!
56 DCHECK(m_haveClosure);
57 m_haveClosure = false;
58 #endif
59 return std::move(m_closure);
60 }
61 #endif
62
63 private:
64 #if BLINK_IMPLEMENTATION
65 static void RunAndDelete(scoped_ptr<SameThreadClosure> c) { (*c)(); }
66 #endif
67
68 #if DCHECK_IS_ON()
69 bool m_haveClosure = true;
70 #endif
71 base::Closure m_closure;
72
73 DISALLOW_COPY_AND_ASSIGN(WebClosure);
74 };
75
76 } // namespace blink
77
78 #endif // WebClosure_h
OLDNEW
« no previous file with comments | « third_party/WebKit/public/platform/callback/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698