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

Side by Side Diff: content/common/mac/app_nap_activity.mm

Issue 2913883002: [Mac] Wrap NSUserActivity begin/end so that it can be called from common files (Closed)
Patch Set: Whitespace Created 3 years, 6 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
« no previous file with comments | « content/common/mac/app_nap_activity.h ('k') | content/common/mac/app_nap_activity_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « content/common/mac/app_nap_activity.h ('k') | content/common/mac/app_nap_activity_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698