Revert 246124 "gn: Fix clang plugin on ios."
[chromium-blink-merge.git] / base / critical_closure_ios.mm
blobd605cad0a20a5baf076672f07dd4427f43222220
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.
5 #include "base/critical_closure.h"
7 #import <UIKit/UIKit.h>
9 #include "base/bind.h"
10 #include "base/ios/scoped_critical_action.h"
11 #include "base/memory/ref_counted.h"
13 namespace {
15 // 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
17 // |base::ios::ScopedCriticalAction|.
18 class CriticalClosure : public base::RefCountedThreadSafe<CriticalClosure> {
19  public:
20   explicit CriticalClosure(base::Closure* closure) : closure_(closure) {
21   }
23   void Run() {
24     closure_->Run();
25   }
27  private:
28   friend class base::RefCountedThreadSafe<CriticalClosure>;
30   virtual ~CriticalClosure() {}
32   base::ios::ScopedCriticalAction criticial_action_;
33   scoped_ptr<base::Closure> closure_;
35   DISALLOW_COPY_AND_ASSIGN(CriticalClosure);
38 }  // namespace
40 namespace base {
42 base::Closure MakeCriticalClosure(const base::Closure& closure) {
43   DCHECK([[UIDevice currentDevice] isMultitaskingSupported]);
44   scoped_refptr<CriticalClosure> critical_closure(
45       new CriticalClosure(new base::Closure(closure)));
46   return base::Bind(&CriticalClosure::Run, critical_closure.get());
49 }  // namespace base