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

Side by Side Diff: base/critical_closure.h

Issue 2637843002: Migrate base::TaskRunner from Closure to OnceClosure (Closed)
Patch Set: rebase Created 3 years, 8 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 | « no previous file | base/critical_closure_internal_ios.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 8 #include <utility>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 11 matching lines...) Expand all
22 22
23 #if defined(OS_IOS) 23 #if defined(OS_IOS)
24 // Returns true if multi-tasking is supported on this iOS device. 24 // Returns true if multi-tasking is supported on this iOS device.
25 bool IsMultiTaskingSupported(); 25 bool IsMultiTaskingSupported();
26 26
27 // This class wraps a closure so it can continue to run for a period of time 27 // This class wraps a closure so it can continue to run for a period of time
28 // when the application goes to the background by using 28 // when the application goes to the background by using
29 // |ios::ScopedCriticalAction|. 29 // |ios::ScopedCriticalAction|.
30 class CriticalClosure { 30 class CriticalClosure {
31 public: 31 public:
32 explicit CriticalClosure(Closure closure); 32 explicit CriticalClosure(OnceClosure closure);
33 ~CriticalClosure(); 33 ~CriticalClosure();
34 void Run(); 34 void Run();
35 35
36 private: 36 private:
37 ios::ScopedCriticalAction critical_action_; 37 ios::ScopedCriticalAction critical_action_;
38 Closure closure_; 38 OnceClosure closure_;
39 39
40 DISALLOW_COPY_AND_ASSIGN(CriticalClosure); 40 DISALLOW_COPY_AND_ASSIGN(CriticalClosure);
41 }; 41 };
42 #endif // defined(OS_IOS) 42 #endif // defined(OS_IOS)
43 43
44 } // namespace internal 44 } // namespace internal
45 45
46 // Returns a closure that will continue to run for a period of time when the 46 // Returns a closure that will continue to run for a period of time when the
47 // application goes to the background if possible on platforms where 47 // application goes to the background if possible on platforms where
48 // applications don't execute while backgrounded, otherwise the original task is 48 // applications don't execute while backgrounded, otherwise the original task is
49 // returned. 49 // returned.
50 // 50 //
51 // Example: 51 // Example:
52 // file_task_runner_->PostTask( 52 // file_task_runner_->PostTask(
53 // FROM_HERE, 53 // FROM_HERE,
54 // MakeCriticalClosure(base::Bind(&WriteToDiskTask, path_, data))); 54 // MakeCriticalClosure(base::Bind(&WriteToDiskTask, path_, data)));
55 // 55 //
56 // Note new closures might be posted in this closure. If the new closures need 56 // Note new closures might be posted in this closure. If the new closures need
57 // background running time, |MakeCriticalClosure| should be applied on them 57 // background running time, |MakeCriticalClosure| should be applied on them
58 // before posting. 58 // before posting.
59 #if defined(OS_IOS) 59 #if defined(OS_IOS)
60 inline Closure MakeCriticalClosure(Closure closure) { 60 inline OnceClosure MakeCriticalClosure(OnceClosure closure) {
61 DCHECK(internal::IsMultiTaskingSupported()); 61 DCHECK(internal::IsMultiTaskingSupported());
62 return base::Bind(&internal::CriticalClosure::Run, 62 return base::BindOnce(
63 Owned(new internal::CriticalClosure(std::move(closure)))); 63 &internal::CriticalClosure::Run,
64 Owned(new internal::CriticalClosure(std::move(closure))));
64 } 65 }
65 #else // defined(OS_IOS) 66 #else // defined(OS_IOS)
66 inline Closure MakeCriticalClosure(Closure closure) { 67 inline OnceClosure MakeCriticalClosure(OnceClosure closure) {
67 // No-op for platforms where the application does not need to acquire 68 // No-op for platforms where the application does not need to acquire
68 // background time for closures to finish when it goes into the background. 69 // background time for closures to finish when it goes into the background.
69 return closure; 70 return closure;
70 } 71 }
71 #endif // defined(OS_IOS) 72 #endif // defined(OS_IOS)
72 73
73 } // namespace base 74 } // namespace base
74 75
75 #endif // BASE_CRITICAL_CLOSURE_H_ 76 #endif // BASE_CRITICAL_CLOSURE_H_
OLDNEW
« no previous file with comments | « no previous file | base/critical_closure_internal_ios.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698