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

Side by Side Diff: media/base/bind_to_current_loop.h

Issue 2352853002: Disallow redundant Bind calls. (Closed)
Patch Set: static_assert message tweak Created 4 years, 2 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
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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 MEDIA_BASE_BIND_TO_CURRENT_LOOP_H_ 5 #ifndef MEDIA_BASE_BIND_TO_CURRENT_LOOP_H_
6 #define MEDIA_BASE_BIND_TO_CURRENT_LOOP_H_ 6 #define MEDIA_BASE_BIND_TO_CURRENT_LOOP_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 template <typename T> 43 template <typename T>
44 base::internal::PassedWrapper<ScopedVector<T> > TrampolineForward( 44 base::internal::PassedWrapper<ScopedVector<T> > TrampolineForward(
45 ScopedVector<T>& p) { return base::Passed(&p); } 45 ScopedVector<T>& p) { return base::Passed(&p); }
46 46
47 // First, tell the compiler TrampolineHelper is a struct template with one 47 // First, tell the compiler TrampolineHelper is a struct template with one
48 // type parameter. Then define specializations where the type is a function 48 // type parameter. Then define specializations where the type is a function
49 // returning void and taking zero or more arguments. 49 // returning void and taking zero or more arguments.
50 template <typename Sig> struct TrampolineHelper; 50 template <typename Sig> struct TrampolineHelper;
51 51
52 template <>
53 struct TrampolineHelper<void()> {
54 static void Run(
55 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
56 const base::Closure& cb) {
57 task_runner->PostTask(FROM_HERE, cb);
58 }
59 };
60
52 template <typename... Args> 61 template <typename... Args>
53 struct TrampolineHelper<void(Args...)> { 62 struct TrampolineHelper<void(Args...)> {
54 static void Run( 63 static void Run(
55 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 64 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
56 const base::Callback<void(Args...)>& cb, 65 const base::Callback<void(Args...)>& cb,
57 Args... args) { 66 Args... args) {
58 task_runner->PostTask(FROM_HERE, 67 task_runner->PostTask(FROM_HERE,
59 base::Bind(cb, TrampolineForward(args)...)); 68 base::Bind(cb, TrampolineForward(args)...));
60 } 69 }
61 }; 70 };
62 71
63 } // namespace internal 72 } // namespace internal
64 73
65 template<typename T> 74 template<typename T>
66 static base::Callback<T> BindToCurrentLoop( 75 static base::Callback<T> BindToCurrentLoop(
67 const base::Callback<T>& cb) { 76 const base::Callback<T>& cb) {
68 return base::Bind(&internal::TrampolineHelper<T>::Run, 77 return base::Bind(&internal::TrampolineHelper<T>::Run,
69 base::ThreadTaskRunnerHandle::Get(), cb); 78 base::ThreadTaskRunnerHandle::Get(), cb);
70 } 79 }
71 80
72 } // namespace media 81 } // namespace media
73 82
74 #endif // MEDIA_BASE_BIND_TO_CURRENT_LOOP_H_ 83 #endif // MEDIA_BASE_BIND_TO_CURRENT_LOOP_H_
OLDNEW
« no previous file with comments | « media/audio/android/audio_manager_android.cc ('k') | remoting/host/host_change_notification_listener_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698