OLD | NEW |
---|---|
(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/ios/scoped_critical_action.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/synchronization/lock.h" | |
9 | |
10 #import <UIKit/UIKit.h> | |
Mark Mentovai
2012/07/31 23:16:33
C system includes before project includes, with th
Chen Yu
2012/08/01 11:26:13
Done.
| |
11 | |
12 namespace base { | |
13 namespace ios { | |
14 | |
15 // This implementation calls |beginBackgroundTaskWithExpirationHandler:| when | |
16 // instantiated and |endBackgroundTask:| when destroyed, creating a scope whose | |
17 // execution will continue (temporarily) even after the app is backgrounded. | |
18 ScopedCriticalAction::ScopedCriticalAction() { | |
19 background_task_id_ = [[UIApplication sharedApplication] | |
Mark Mentovai
2012/07/31 23:16:33
This function returns a UIBackgroundTaskIdentifier
stuartmorgan
2012/08/01 04:31:55
Except it isn't, which is why we did this. It make
Mark Mentovai
2012/08/01 13:50:42
stuartmorgan wrote:
| |
20 beginBackgroundTaskWithExpirationHandler:^{ | |
21 DLOG(WARNING) << "Background task with id " << background_task_id_ | |
22 << " expired."; | |
23 // Note if |endBackgroundTask:| is not called for each task before time | |
24 // expires, the system kills the application. | |
25 EndBackgroundTask(); | |
26 }]; | |
27 VLOG(3) << "Beginning background task with id " << background_task_id_; | |
Mark Mentovai
2012/07/31 23:16:33
The docs say something about UIBackgroundTaskInval
Chen Yu
2012/08/01 11:26:13
There is no much we can do in this case; a warning
| |
28 } | |
29 | |
30 ScopedCriticalAction::~ScopedCriticalAction() { | |
31 EndBackgroundTask(); | |
32 } | |
33 | |
34 void ScopedCriticalAction::EndBackgroundTask() { | |
35 UIBackgroundTaskIdentifier task_id; | |
36 { | |
37 AutoLock lockScope(id_lock_); | |
38 task_id = background_task_id_; | |
39 background_task_id_ = UIBackgroundTaskInvalid; | |
40 } | |
41 if (task_id == UIBackgroundTaskInvalid) | |
42 return; | |
43 | |
44 VLOG(3) << "Ending background task with id " << task_id; | |
45 [[UIApplication sharedApplication] endBackgroundTask:task_id]; | |
46 } | |
47 | |
48 } // namespace ios | |
49 } // namespace base | |
OLD | NEW |