Index: content/common/mac/activity.mm |
diff --git a/content/common/mac/activity.mm b/content/common/mac/activity.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e85cea94cc253da1b2b5ac1e2546b623a6f0b326 |
--- /dev/null |
+++ b/content/common/mac/activity.mm |
@@ -0,0 +1,48 @@ |
+// 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/activity.h" |
+ |
+#import <Foundation/Foundation.h> |
+ |
+#include "base/mac/scoped_nsobject.h" |
+ |
+static NSString* const kActivityReason = @"Process foregrounded"; |
Robert Sesek
2017/05/31 18:11:27
optional: drop the static and move into the anonym
lgrey
2017/05/31 21:28:12
Done.
|
+static const NSActivityOptions kActivityOptions = |
+ (NSActivityUserInitiatedAllowingIdleSystemSleep | |
+ NSActivityLatencyCritical) & |
+ ~(NSActivitySuddenTerminationDisabled | |
+ NSActivityAutomaticTerminationDisabled); |
+ |
+namespace mac { |
+ |
+class AssertionWrapper { |
Robert Sesek
2017/05/31 18:11:26
I think this could be a simple struct and just exp
lgrey
2017/05/31 21:28:12
Done. Renamed the member |obj_| to avoid awkward "
Robert Sesek
2017/05/31 22:21:56
Nope, I think that's fine. |obj| or |ptr| would be
|
+ public: |
+ id get() { return assertion_.get(); }; |
+ id autorelease() { return assertion_.autorelease(); } |
+ void reset(id obj) { assertion_.reset(obj); }; |
+ |
+ private: |
+ base::scoped_nsobject<id> assertion_; |
+}; |
Robert Sesek
2017/05/31 18:11:26
nit: blank line after
lgrey
2017/05/31 21:28:12
Done.
|
+Activity::Activity() { |
+ assertion_.reset(new AssertionWrapper()); |
+}; |
+ |
+Activity::~Activity(){}; |
Robert Sesek
2017/05/31 18:11:26
DCHECK(!assertion_.get()) ?
lgrey
2017/05/31 21:28:12
Done.
|
+ |
+void Activity::Begin() { |
+ DCHECK(!assertion_->get()); |
+ id assertion = |
+ [[NSProcessInfo processInfo] beginActivityWithOptions:kActivityOptions |
+ reason:kActivityReason]; |
+ assertion_->reset([assertion retain]); |
+} |
+ |
+void Activity::End() { |
+ id assertion = assertion_->autorelease(); |
+ DCHECK(assertion); |
+ [[NSProcessInfo processInfo] endActivity:assertion]; |
+} |
+} // namespace mac |