OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 BASE_CRITICAL_CLOSURE_H_ | 5 #ifndef BASE_CRITICAL_CLOSURE_H_ |
6 #define BASE_CRITICAL_CLOSURE_H_ | 6 #define BASE_CRITICAL_CLOSURE_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 | 9 |
10 #if defined(OS_IOS) | 10 #if defined(OS_IOS) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 } // namespace internal | 46 } // namespace internal |
47 | 47 |
48 // Returns a closure (which may return a result, but must not require any extra | 48 // Returns a closure (which may return a result, but must not require any extra |
49 // arguments) that will continue to run for a period of time when the | 49 // arguments) that will continue to run for a period of time when the |
50 // application goes to the background if possible on platforms where | 50 // application goes to the background if possible on platforms where |
51 // applications don't execute while backgrounded, otherwise the original task is | 51 // applications don't execute while backgrounded, otherwise the original task is |
52 // returned. | 52 // returned. |
53 // | 53 // |
54 // Example: | 54 // Example: |
55 // file_message_loop_proxy_->PostTask( | 55 // file_task_runner_->PostTask( |
56 // FROM_HERE, | 56 // FROM_HERE, |
57 // MakeCriticalClosure(base::Bind(&WriteToDiskTask, path_, data))); | 57 // MakeCriticalClosure(base::Bind(&WriteToDiskTask, path_, data))); |
58 // | 58 // |
59 // Note new closures might be posted in this closure. If the new closures need | 59 // Note new closures might be posted in this closure. If the new closures need |
60 // background running time, |MakeCriticalClosure| should be applied on them | 60 // background running time, |MakeCriticalClosure| should be applied on them |
61 // before posting. | 61 // before posting. |
62 #if defined(OS_IOS) | 62 #if defined(OS_IOS) |
63 template <typename R> | 63 template <typename R> |
64 Callback<R(void)> MakeCriticalClosure(const Callback<R(void)>& closure) { | 64 Callback<R(void)> MakeCriticalClosure(const Callback<R(void)>& closure) { |
65 DCHECK(internal::IsMultiTaskingSupported()); | 65 DCHECK(internal::IsMultiTaskingSupported()); |
66 return base::Bind(&internal::CriticalClosure<R>::Run, | 66 return base::Bind(&internal::CriticalClosure<R>::Run, |
67 Owned(new internal::CriticalClosure<R>(closure))); | 67 Owned(new internal::CriticalClosure<R>(closure))); |
68 } | 68 } |
69 #else // defined(OS_IOS) | 69 #else // defined(OS_IOS) |
70 template <typename R> | 70 template <typename R> |
71 inline Callback<R(void)> MakeCriticalClosure(const Callback<R(void)>& closure) { | 71 inline Callback<R(void)> MakeCriticalClosure(const Callback<R(void)>& closure) { |
72 // No-op for platforms where the application does not need to acquire | 72 // No-op for platforms where the application does not need to acquire |
73 // background time for closures to finish when it goes into the background. | 73 // background time for closures to finish when it goes into the background. |
74 return closure; | 74 return closure; |
75 } | 75 } |
76 #endif // defined(OS_IOS) | 76 #endif // defined(OS_IOS) |
77 | 77 |
78 } // namespace base | 78 } // namespace base |
79 | 79 |
80 #endif // BASE_CRITICAL_CLOSURE_H_ | 80 #endif // BASE_CRITICAL_CLOSURE_H_ |
OLD | NEW |