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

Side by Side Diff: base/critical_closure_ios.mm

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: fix some tests -- more to come 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 #include "base/critical_closure.h" 5 #include "base/critical_closure.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/ios/scoped_critical_action.h" 10 #include "base/ios/scoped_critical_action.h"
11 #include "base/memory/ref_counted.h"
12 11
13 namespace { 12 namespace {
14 13
15 // This class wraps a closure so it can continue to run for a period of time 14 // This class wraps a closure so it can continue to run for a period of time
16 // when the application goes to the background by using 15 // when the application goes to the background by using
17 // |base::ios::ScopedCriticalAction|. 16 // |base::ios::ScopedCriticalAction|.
18 class CriticalClosure : public base::RefCountedThreadSafe<CriticalClosure> { 17 template <typename R>
18 class CriticalClosure {
19 public: 19 public:
20 explicit CriticalClosure(base::Closure* closure) : closure_(closure) { 20 explicit CriticalClosure(const base::Callback<R(void)>& closure)
21 } 21 : closure_(closure) {}
22
23 ~CriticalClosure() {}
22 24
23 void Run() { 25 void Run() {
24 closure_->Run(); 26 closure_.Run();
25 } 27 }
26 28
27 private: 29 private:
28 friend class base::RefCountedThreadSafe<CriticalClosure>; 30 base::ios::ScopedCriticalAction critical_action_;
29 31 base::Callback<R(void)> closure_;
30 virtual ~CriticalClosure() {}
31
32 base::ios::ScopedCriticalAction criticial_action_;
33 scoped_ptr<base::Closure> closure_;
34 32
35 DISALLOW_COPY_AND_ASSIGN(CriticalClosure); 33 DISALLOW_COPY_AND_ASSIGN(CriticalClosure);
36 }; 34 };
37 35
38 } // namespace 36 } // namespace
39 37
40 namespace base { 38 namespace base {
41 39
42 base::Closure MakeCriticalClosure(const base::Closure& closure) { 40 template <typename R>
41 Callback<R(void)> MakeCriticalClosure(const Callback<R(void)>& closure) {
43 DCHECK([[UIDevice currentDevice] isMultitaskingSupported]); 42 DCHECK([[UIDevice currentDevice] isMultitaskingSupported]);
44 scoped_refptr<CriticalClosure> critical_closure( 43 return base::Bind(&CriticalClosure<R>::Run,
45 new CriticalClosure(new base::Closure(closure))); 44 Owned(new CriticalClosure<R>(closure)));
46 return base::Bind(&CriticalClosure::Run, critical_closure.get());
47 } 45 }
48 46
49 } // namespace base 47 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698