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

Unified 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, 7 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d2c82e80a8687d31ee4bbf1d4df96694d84facaf
--- /dev/null
+++ b/content/common/mac/app_nap_activity.mm
@@ -0,0 +1,50 @@
+// 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 {
+ base::scoped_nsobject<id> obj;
+};
+
+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];
+}
+
+} // namespace content
« 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