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

Side by Side Diff: base/critical_closure.h

Issue 257003007: Introduce a new framework for back-and-forth tracked/protected preferences migration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: +cleanup-only tests Created 6 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 | Annotate | Revision Log
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 "base/callback.h" 8 #include "base/callback.h"
9 9
10 #if defined(OS_IOS)
11 #import <UIKit/UIKit.h>
Nico 2014/05/06 03:00:10 wot, why do you need UIKit in base? That's why th
gab 2014/05/06 14:40:35 Oh of course, moved that as-is from the .mm file;
12
13 #include "base/bind.h"
14 #include "base/ios/scoped_critical_action.h"
15 #endif
16
10 namespace base { 17 namespace base {
11 18
12 // Returns a closure that will continue to run for a period of time when the 19 namespace internal {
20
21 #if defined(OS_IOS)
22 // This class wraps a closure so it can continue to run for a period of time
23 // when the application goes to the background by using
24 // |ios::ScopedCriticalAction|.
25 template <typename R>
26 class CriticalClosure {
27 public:
28 explicit CriticalClosure(const Callback<R(void)>& closure)
29 : closure_(closure) {}
30
31 ~CriticalClosure() {}
32
33 void Run() {
34 closure_.Run();
35 }
36
37 private:
38 ios::ScopedCriticalAction critical_action_;
39 Callback<R(void)> closure_;
40
41 DISALLOW_COPY_AND_ASSIGN(CriticalClosure);
42 };
43 #endif // defined(OS_IOS)
44
45 } // namespace internal
46
47 // Returns a closure (which may return a result, but must not require any extra
48 // arguments) that will continue to run for a period of time when the
13 // application goes to the background if possible on platforms where 49 // application goes to the background if possible on platforms where
14 // applications don't execute while backgrounded, otherwise the original task is 50 // applications don't execute while backgrounded, otherwise the original task is
15 // returned. 51 // returned.
16 // 52 //
17 // Example: 53 // Example:
18 // file_message_loop_proxy_->PostTask( 54 // file_message_loop_proxy_->PostTask(
19 // FROM_HERE, 55 // FROM_HERE,
20 // MakeCriticalClosure(base::Bind(&WriteToDiskTask, path_, data))); 56 // MakeCriticalClosure(base::Bind(&WriteToDiskTask, path_, data)));
21 // 57 //
22 // Note new closures might be posted in this closure. If the new closures need 58 // Note new closures might be posted in this closure. If the new closures need
23 // background running time, |MakeCriticalClosure| should be applied on them 59 // background running time, |MakeCriticalClosure| should be applied on them
24 // before posting. 60 // before posting.
25 #if defined(OS_IOS) 61 #if defined(OS_IOS)
26 base::Closure MakeCriticalClosure(const base::Closure& closure); 62 template <typename R>
27 #else 63 Callback<R(void)> MakeCriticalClosure(const Callback<R(void)>& closure) {
28 inline base::Closure MakeCriticalClosure(const base::Closure& closure) { 64 DCHECK([[UIDevice currentDevice] isMultitaskingSupported]);
65 return base::Bind(&internals::CriticalClosure<R>::Run,
66 Owned(new internals::CriticalClosure<R>(closure)));
67 }
68 #else // defined(OS_IOS)
69 template <typename R>
70 inline Callback<R(void)> MakeCriticalClosure(const Callback<R(void)>& closure) {
29 // No-op for platforms where the application does not need to acquire 71 // No-op for platforms where the application does not need to acquire
30 // background time for closures to finish when it goes into the background. 72 // background time for closures to finish when it goes into the background.
31 return closure; 73 return closure;
32 } 74 }
33 #endif // !defined(OS_IOS) 75 #endif // defined(OS_IOS)
34 76
35 } // namespace base 77 } // namespace base
36 78
37 #endif // BASE_CRITICAL_CLOSURE_H_ 79 #endif // BASE_CRITICAL_CLOSURE_H_
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/critical_closure_ios.mm » ('j') | base/prefs/json_pref_store.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698