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

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

Issue 2914913002: [Mac] Enable AppNap for renderers (Closed)
Patch Set: Clean up 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/mac/app_nap_activity.h" 5 #include "content/common/mac/app_nap_activity.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 8
9 #include "base/mac/scoped_nsobject.h" 9 #include "base/mac/scoped_nsobject.h"
10 10
11 extern "C" {
12 void __CFRunLoopSetOptionsReason(uint64_t options,
13 NSString* reason,
14 int unused);
15 }
16
11 namespace content { 17 namespace content {
12 18
13 namespace { 19 namespace {
14 20
15 NSString* const kActivityReason = @"Process foregrounded"; 21 NSString* const kActivityReason = @"Process foregrounded";
16 const NSActivityOptions kActivityOptions = 22 const NSActivityOptions kActivityOptions =
17 (NSActivityUserInitiatedAllowingIdleSystemSleep | 23 (NSActivityUserInitiatedAllowingIdleSystemSleep |
18 NSActivityLatencyCritical) & 24 NSActivityLatencyCritical) &
19 ~(NSActivitySuddenTerminationDisabled | 25 ~(NSActivitySuddenTerminationDisabled |
20 NSActivityAutomaticTerminationDisabled); 26 NSActivityAutomaticTerminationDisabled);
21 27
22 } // namespace 28 } // namespace
23 29
24 struct AssertionWrapper { 30 struct AssertionWrapper {
25 base::scoped_nsobject<id> obj; 31 base::scoped_nsobject<id> obj;
26 }; 32 };
27 33
28 AppNapActivity::AppNapActivity() { 34 AppNapActivity::AppNapActivity() {
29 assertion_.reset(new AssertionWrapper()); 35 assertion_.reset(new AssertionWrapper());
30 }; 36 };
31 37
32 AppNapActivity::~AppNapActivity() { 38 AppNapActivity::~AppNapActivity() {
33 DCHECK(!assertion_->obj.get()); 39 DCHECK(!assertion_->obj.get());
34 }; 40 };
35 41
42 void AppNapActivity::InitializeAppNapSupport() {
43 // Reason strings are the same as
44 // what macOS sends in the corresponding call.
45 //
46 // Normally happens during launch services check-in.
47 __CFRunLoopSetOptionsReason(
48 1, @"Finished checking in as application - waiting for events", 0);
49 // Normally happens in a dispatch_once in the NSApplication event loop.
50 __CFRunLoopSetOptionsReason(
51 0x3b000000, @"Finished delay after app launch and bundle check", 0);
shrike 2017/06/02 19:57:53 Can 0x3b000000 be defined as a constant with a rea
lgrey 2017/06/05 14:49:43 It's magic to us, unfortunately (as is the "1" in
shrike 2017/06/05 15:29:36 So is it an "or" of NSActivity flags? If so, can y
52 }
53
36 void AppNapActivity::Begin() { 54 void AppNapActivity::Begin() {
37 DCHECK(!assertion_->obj.get()); 55 DCHECK(!assertion_->obj.get());
38 id assertion = 56 id assertion =
39 [[NSProcessInfo processInfo] beginActivityWithOptions:kActivityOptions 57 [[NSProcessInfo processInfo] beginActivityWithOptions:kActivityOptions
40 reason:kActivityReason]; 58 reason:kActivityReason];
41 assertion_->obj.reset([assertion retain]); 59 assertion_->obj.reset([assertion retain]);
42 } 60 }
43 61
44 void AppNapActivity::End() { 62 void AppNapActivity::End() {
45 id assertion = assertion_->obj.autorelease(); 63 id assertion = assertion_->obj.autorelease();
46 DCHECK(assertion); 64 DCHECK(assertion);
47 [[NSProcessInfo processInfo] endActivity:assertion]; 65 [[NSProcessInfo processInfo] endActivity:assertion];
48 } 66 }
49 67
50 } // namespace content 68 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698