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

Side by Side Diff: chrome/browser/mac/scoped_authorizationref.h

Issue 9764013: Move authorization_util files into base/mac. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix license headers Created 8 years, 9 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 | « chrome/browser/mac/keystone_promote_preflight.sh ('k') | chrome/chrome_browser.gypi » ('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 (c) 2011 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 #ifndef CHROME_BROWSER_MAC_SCOPED_AUTHORIZATIONREF_H_
6 #define CHROME_BROWSER_MAC_SCOPED_AUTHORIZATIONREF_H_
7 #pragma once
8
9 #include <Security/Authorization.h>
10
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13
14 // ScopedAuthorizationRef maintains ownership of an AuthorizationRef. It is
15 // patterned after the scoped_ptr interface.
16
17 class ScopedAuthorizationRef {
18 public:
19 explicit ScopedAuthorizationRef(AuthorizationRef authorization = NULL)
20 : authorization_(authorization) {
21 }
22
23 ~ScopedAuthorizationRef() {
24 if (authorization_) {
25 AuthorizationFree(authorization_, kAuthorizationFlagDestroyRights);
26 }
27 }
28
29 void reset(AuthorizationRef authorization = NULL) {
30 if (authorization_ != authorization) {
31 if (authorization_) {
32 AuthorizationFree(authorization_, kAuthorizationFlagDestroyRights);
33 }
34 authorization_ = authorization;
35 }
36 }
37
38 bool operator==(AuthorizationRef that) const {
39 return authorization_ == that;
40 }
41
42 bool operator!=(AuthorizationRef that) const {
43 return authorization_ != that;
44 }
45
46 operator AuthorizationRef() const {
47 return authorization_;
48 }
49
50 AuthorizationRef* operator&() {
51 return &authorization_;
52 }
53
54 AuthorizationRef get() const {
55 return authorization_;
56 }
57
58 void swap(ScopedAuthorizationRef& that) {
59 AuthorizationRef temp = that.authorization_;
60 that.authorization_ = authorization_;
61 authorization_ = temp;
62 }
63
64 // ScopedAuthorizationRef::release() is like scoped_ptr<>::release. It is
65 // NOT a wrapper for AuthorizationFree(). To force a
66 // ScopedAuthorizationRef object to call AuthorizationFree(), use
67 // ScopedAuthorizationRef::reset().
68 AuthorizationRef release() WARN_UNUSED_RESULT {
69 AuthorizationRef temp = authorization_;
70 authorization_ = NULL;
71 return temp;
72 }
73
74 private:
75 AuthorizationRef authorization_;
76
77 DISALLOW_COPY_AND_ASSIGN(ScopedAuthorizationRef);
78 };
79
80 #endif // CHROME_BROWSER_MAC_SCOPED_AUTHORIZATIONREF_H_
OLDNEW
« no previous file with comments | « chrome/browser/mac/keystone_promote_preflight.sh ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698