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

Side by Side Diff: base/critical_closure_ios.mm

Issue 10835032: Add APIs to protect critical tasks on iOS. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address review comments Created 8 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/critical_closure.h"
6
7 #import <UIKit/UIKit.h>
8
9 #include "base/bind.h"
10 #include "base/ios/scoped_critical_action.h"
11 #include "base/memory/ref_counted.h"
12
13 namespace {
14
15 // This class wraps a closure to protect it when the application goes to the
16 // background by using |base::ios::ScopedCriticalAction|.
17 class CriticalClosure : public base::RefCountedThreadSafe<CriticalClosure> {
18 public:
19 explicit CriticalClosure(base::Closure* closure) : closure_(closure) {
20 background_scope_.reset(new base::ios::ScopedCriticalAction());
21 }
22
23 void Run() {
24 closure_->Run();
25
26 background_scope_.reset();
27 }
28
29 private:
30 friend class base::RefCountedThreadSafe<CriticalClosure>;
31
32 virtual ~CriticalClosure() {}
33
34 scoped_ptr<base::Closure> closure_;
35 scoped_ptr<base::ios::ScopedCriticalAction> background_scope_;
36
37 DISALLOW_COPY_AND_ASSIGN(CriticalClosure);
38 };
39
40 } // namespace
41
42 namespace base {
43
44 base::Closure MakeCriticalClosure(const base::Closure& closure) {
45 DCHECK([[UIDevice currentDevice] isMultitaskingSupported]);
46 scoped_refptr<CriticalClosure> critical_closure(
47 new CriticalClosure(new base::Closure(closure)));
48 return base::Bind(&CriticalClosure::Run, critical_closure.get());
49 }
50
51 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698