Chromium Code Reviews| Index: content/common/mac/app_nap_activity.mm |
| diff --git a/content/common/mac/app_nap_activity.mm b/content/common/mac/app_nap_activity.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a5960c6b2522473f938140e09e0a015acf3660e7 |
| --- /dev/null |
| +++ b/content/common/mac/app_nap_activity.mm |
| @@ -0,0 +1,49 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/common/mac/app_nap_activity.h" |
| + |
| +#import <Foundation/Foundation.h> |
| + |
| +#include "base/mac/scoped_nsobject.h" |
| + |
| +namespace content { |
| + |
| +namespace { |
| +NSString* const kActivityReason = @"Process foregrounded"; |
| +const NSActivityOptions kActivityOptions = |
| + (NSActivityUserInitiatedAllowingIdleSystemSleep | |
| + NSActivityLatencyCritical) & |
| + ~(NSActivitySuddenTerminationDisabled | |
| + NSActivityAutomaticTerminationDisabled); |
| + |
| +} // namespace |
| + |
| +struct AssertionWrapper { |
| + public: |
|
Robert Sesek
2017/05/31 22:21:56
struct members are public by default, so you can o
lgrey
2017/06/01 15:51:10
Done.
|
| + base::scoped_nsobject<id> obj_; |
|
Robert Sesek
2017/05/31 22:21:56
You can also omit trailing _ on public struct memb
lgrey
2017/06/01 15:51:10
Done.
|
| +}; |
| + |
| +AppNapActivity::AppNapActivity() { |
| + assertion_.reset(new AssertionWrapper()); |
| +}; |
| + |
| +AppNapActivity::~AppNapActivity() { |
| + DCHECK(!assertion_->obj_.get()); |
| +}; |
| + |
| +void AppNapActivity::Begin() { |
| + DCHECK(!assertion_->obj_.get()); |
| + id assertion = |
| + [[NSProcessInfo processInfo] beginActivityWithOptions:kActivityOptions |
| + reason:kActivityReason]; |
| + assertion_->obj_.reset([assertion retain]); |
| +} |
| + |
| +void AppNapActivity::End() { |
| + id assertion = assertion_->obj_.autorelease(); |
| + DCHECK(assertion); |
| + [[NSProcessInfo processInfo] endActivity:assertion]; |
| +} |
|
Robert Sesek
2017/05/31 22:21:56
nit: blank line after
lgrey
2017/06/01 15:51:10
Done.
|
| +} // namespace content |