OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 "content/common/mac/app_nap_activity.h" |
| 6 |
| 7 #import <Foundation/Foundation.h> |
| 8 |
| 9 #include "base/mac/scoped_nsobject.h" |
| 10 |
| 11 namespace content { |
| 12 |
| 13 namespace { |
| 14 |
| 15 NSString* const kActivityReason = @"Process foregrounded"; |
| 16 const NSActivityOptions kActivityOptions = |
| 17 (NSActivityUserInitiatedAllowingIdleSystemSleep | |
| 18 NSActivityLatencyCritical) & |
| 19 ~(NSActivitySuddenTerminationDisabled | |
| 20 NSActivityAutomaticTerminationDisabled); |
| 21 |
| 22 } // namespace |
| 23 |
| 24 struct AssertionWrapper { |
| 25 base::scoped_nsobject<id> obj; |
| 26 }; |
| 27 |
| 28 AppNapActivity::AppNapActivity() { |
| 29 assertion_.reset(new AssertionWrapper()); |
| 30 }; |
| 31 |
| 32 AppNapActivity::~AppNapActivity() { |
| 33 DCHECK(!assertion_->obj.get()); |
| 34 }; |
| 35 |
| 36 void AppNapActivity::Begin() { |
| 37 DCHECK(!assertion_->obj.get()); |
| 38 id assertion = |
| 39 [[NSProcessInfo processInfo] beginActivityWithOptions:kActivityOptions |
| 40 reason:kActivityReason]; |
| 41 assertion_->obj.reset([assertion retain]); |
| 42 } |
| 43 |
| 44 void AppNapActivity::End() { |
| 45 id assertion = assertion_->obj.autorelease(); |
| 46 DCHECK(assertion); |
| 47 [[NSProcessInfo processInfo] endActivity:assertion]; |
| 48 } |
| 49 |
| 50 } // namespace content |
OLD | NEW |