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

Side by Side Diff: third_party/WebKit/Source/platform/mojo/MojoHelper.h

Issue 1981233003: Finish migration from sameThreadBindForMojo to createBaseCallback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/Source/modules/vr/VRController.cpp ('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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MojoHelper_h 5 #ifndef MojoHelper_h
6 #define MojoHelper_h 6 #define MojoHelper_h
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "mojo/public/cpp/bindings/callback.h" 9 #include "mojo/public/cpp/bindings/callback.h"
10 #include "mojo/public/cpp/bindings/wtf_array.h" 10 #include "mojo/public/cpp/bindings/wtf_array.h"
11 #include "platform/heap/HeapAllocator.h" 11 #include "platform/heap/HeapAllocator.h"
12 #include <utility> 12 #include <utility>
13 13
14 namespace blink { 14 namespace blink {
15 15
16 namespace internal { 16 namespace internal {
17 17
18 template <typename R, typename... Args> 18 template <typename R, typename... Args>
19 R CallWTFFunction(Function<R(Args...)>* functor, Args... args) 19 R CallWTFFunction(Function<R(Args...)>* functor, Args... args)
20 { 20 {
21 return (*functor)(std::forward<Args>(args)...); 21 return (*functor)(std::forward<Args>(args)...);
22 } 22 }
23 23
24 } 24 }
25 25
26 // Binds an instance of a class to its member function. Does not bind anything
27 // else. Provides limited access to base::Bind() function. base::Bind() could
28 // be dangerous if it's used across threads, so we don't want to allow general
29 // use of base::Bind(). See also "platform/ThreadSafeFunctional.h".
30 template <typename Class, typename ReturnType, typename... Args>
31 mojo::Callback<ReturnType(Args...)>
32 sameThreadBindForMojo(ReturnType (Class::*method)(Args...), Class* instance)
33 {
34 return base::Bind(method, base::Unretained(instance));
35 }
36
37 template <typename R, typename... Args> 26 template <typename R, typename... Args>
38 base::Callback<R(Args...)> createBaseCallback(PassOwnPtr<Function<R(Args...)>> f unctor) 27 base::Callback<R(Args...)> createBaseCallback(PassOwnPtr<Function<R(Args...)>> f unctor)
39 { 28 {
40 return base::Bind(&internal::CallWTFFunction<R, Args...>, base::Owned(functo r.leakPtr())); 29 return base::Bind(&internal::CallWTFFunction<R, Args...>, base::Owned(functo r.leakPtr()));
41 } 30 }
42 31
43 template <typename R, typename... Args> 32 template <typename R, typename... Args>
44 base::Callback<R(Args...)> createBaseCallback(std::unique_ptr<Function<R(Args... )>> functor) 33 base::Callback<R(Args...)> createBaseCallback(std::unique_ptr<Function<R(Args... )>> functor)
45 { 34 {
46 return base::Bind(&internal::CallWTFFunction<R, Args...>, base::Owned(functo r.release())); 35 return base::Bind(&internal::CallWTFFunction<R, Args...>, base::Owned(functo r.release()));
(...skipping 13 matching lines...) Expand all
60 WTFArray<T> result(input.size()); 49 WTFArray<T> result(input.size());
61 for (size_t i = 0; i < input.size(); ++i) 50 for (size_t i = 0; i < input.size(); ++i)
62 result[i] = TypeConverter<T, E>::Convert(input[i]); 51 result[i] = TypeConverter<T, E>::Convert(input[i]);
63 return std::move(result); 52 return std::move(result);
64 } 53 }
65 }; 54 };
66 55
67 } // namespace mojo 56 } // namespace mojo
68 57
69 #endif // MojoHelper_h 58 #endif // MojoHelper_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/vr/VRController.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698