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

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

Issue 2913883002: [Mac] Wrap NSUserActivity begin/end so that it can be called from common files (Closed)
Patch Set: Actually stage moved files :/ 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
(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/activity.h"
6
7 #import <Foundation/Foundation.h>
8
9 #include "base/mac/scoped_nsobject.h"
10
11 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.
12 static const NSActivityOptions kActivityOptions =
13 (NSActivityUserInitiatedAllowingIdleSystemSleep |
14 NSActivityLatencyCritical) &
15 ~(NSActivitySuddenTerminationDisabled |
16 NSActivityAutomaticTerminationDisabled);
17
18 namespace mac {
19
20 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
21 public:
22 id get() { return assertion_.get(); };
23 id autorelease() { return assertion_.autorelease(); }
24 void reset(id obj) { assertion_.reset(obj); };
25
26 private:
27 base::scoped_nsobject<id> assertion_;
28 };
Robert Sesek 2017/05/31 18:11:26 nit: blank line after
lgrey 2017/05/31 21:28:12 Done.
29 Activity::Activity() {
30 assertion_.reset(new AssertionWrapper());
31 };
32
33 Activity::~Activity(){};
Robert Sesek 2017/05/31 18:11:26 DCHECK(!assertion_.get()) ?
lgrey 2017/05/31 21:28:12 Done.
34
35 void Activity::Begin() {
36 DCHECK(!assertion_->get());
37 id assertion =
38 [[NSProcessInfo processInfo] beginActivityWithOptions:kActivityOptions
39 reason:kActivityReason];
40 assertion_->reset([assertion retain]);
41 }
42
43 void Activity::End() {
44 id assertion = assertion_->autorelease();
45 DCHECK(assertion);
46 [[NSProcessInfo processInfo] endActivity:assertion];
47 }
48 } // namespace mac
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698