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

Side by Side Diff: base/mac/scoped_cftyperef.h

Issue 10388108: Implement media::VideoDecodeAccelerator on Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review comments Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
Ami GONE FROM CHROMIUM 2012/05/17 21:44:47 Copyright year needs updating.
Ami GONE FROM CHROMIUM 2012/05/17 21:44:47 My comments on this file are purely FYI; you'll ne
sail 2012/05/23 23:02:29 Done.
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
Ami GONE FROM CHROMIUM 2012/05/17 21:44:47 ...BUT, that said, this change seems not worth it
sail 2012/05/23 23:02:29 The other thing I need here is the copy constructo
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_MAC_SCOPED_CFTYPEREF_H_ 5 #ifndef BASE_MAC_SCOPED_CFTYPEREF_H_
6 #define BASE_MAC_SCOPED_CFTYPEREF_H_ 6 #define BASE_MAC_SCOPED_CFTYPEREF_H_
7 #pragma once 7 #pragma once
8 8
9 #include <CoreFoundation/CoreFoundation.h> 9 #include <CoreFoundation/CoreFoundation.h>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 13
14 namespace base { 14 namespace base {
15 namespace mac { 15 namespace mac {
16 16
17 enum OwnershipPolicy {
Ami GONE FROM CHROMIUM 2012/05/17 21:44:47 Any reason not to live inside ScopedCFTypeRef? (in
sail 2012/05/23 23:02:29 Moving this would make the calling code look like
18 ASSUME,
19 RETAIN
20 };
21
17 // ScopedCFTypeRef<> is patterned after scoped_ptr<>, but maintains ownership 22 // ScopedCFTypeRef<> is patterned after scoped_ptr<>, but maintains ownership
18 // of a CoreFoundation object: any object that can be represented as a 23 // of a CoreFoundation object: any object that can be represented as a
19 // CFTypeRef. Style deviations here are solely for compatibility with 24 // CFTypeRef. Style deviations here are solely for compatibility with
20 // scoped_ptr<>'s interface, with which everyone is already familiar. 25 // scoped_ptr<>'s interface, with which everyone is already familiar.
21 // 26 //
22 // When ScopedCFTypeRef<> takes ownership of an object (in the constructor or 27 // When ScopedCFTypeRef<> takes ownership of an object (in the constructor or
23 // in reset()), it takes over the caller's existing ownership claim. The 28 // in reset()), it takes over the caller's existing ownership claim. The
24 // caller must own the object it gives to ScopedCFTypeRef<>, and relinquishes 29 // caller must own the object it gives to ScopedCFTypeRef<>, and relinquishes
25 // an ownership claim to that object. ScopedCFTypeRef<> does not call 30 // an ownership claim to that object. ScopedCFTypeRef<> does not call
26 // CFRetain(). 31 // CFRetain().
Ami GONE FROM CHROMIUM 2012/05/17 21:44:47 This paragraph seems like the doco for ASSUME and
sail 2012/05/23 23:02:29 Done.
27 template<typename CFT> 32 template<typename CFT>
28 class ScopedCFTypeRef { 33 class ScopedCFTypeRef {
29 public: 34 public:
30 typedef CFT element_type; 35 typedef CFT element_type;
31 36
32 explicit ScopedCFTypeRef(CFT object = NULL) 37 explicit ScopedCFTypeRef(CFT object = NULL,
38 OwnershipPolicy policy = ASSUME)
Ami GONE FROM CHROMIUM 2012/05/17 21:44:47 I don't know that this style-guide violation (defa
sail 2012/05/23 23:02:29 This matches the scoped_nsprotocol constructor. If
Ami GONE FROM CHROMIUM 2012/05/24 21:30:29 Like I said, my opinions about this file are low-p
33 : object_(object) { 39 : object_(object) {
40 if (object_ && policy == RETAIN)
41 CFRetain(object_);
42 }
43
44 ScopedCFTypeRef(const ScopedCFTypeRef<CFT>& that)
45 : object_(that.object_) {
46 if (object_)
47 CFRetain(object_);
34 } 48 }
35 49
36 ~ScopedCFTypeRef() { 50 ~ScopedCFTypeRef() {
37 if (object_) 51 if (object_)
38 CFRelease(object_); 52 CFRelease(object_);
39 } 53 }
40 54
41 void reset(CFT object = NULL) { 55 ScopedCFTypeRef& operator=(const ScopedCFTypeRef<CFT>& that) {
56 reset(that.get(), RETAIN);
57 return *this;
58 }
59
60 void reset(CFT object = NULL,
61 OwnershipPolicy policy = ASSUME) {
62 if (object && policy == RETAIN)
63 CFRetain(object);
42 if (object_) 64 if (object_)
43 CFRelease(object_); 65 CFRelease(object_);
44 object_ = object; 66 object_ = object;
45 } 67 }
46 68
47 bool operator==(CFT that) const { 69 bool operator==(CFT that) const {
48 return object_ == that; 70 return object_ == that;
49 } 71 }
50 72
51 bool operator!=(CFT that) const { 73 bool operator!=(CFT that) const {
(...skipping 18 matching lines...) Expand all
70 // a wrapper for CFRelease(). To force a ScopedCFTypeRef<> object to call 92 // a wrapper for CFRelease(). To force a ScopedCFTypeRef<> object to call
71 // CFRelease(), use ScopedCFTypeRef<>::reset(). 93 // CFRelease(), use ScopedCFTypeRef<>::reset().
72 CFT release() WARN_UNUSED_RESULT { 94 CFT release() WARN_UNUSED_RESULT {
73 CFT temp = object_; 95 CFT temp = object_;
74 object_ = NULL; 96 object_ = NULL;
75 return temp; 97 return temp;
76 } 98 }
77 99
78 private: 100 private:
79 CFT object_; 101 CFT object_;
80
81 DISALLOW_COPY_AND_ASSIGN(ScopedCFTypeRef);
82 }; 102 };
83 103
84 } // namespace mac 104 } // namespace mac
85 } // namespace base 105 } // namespace base
86 106
87 #endif // BASE_MAC_SCOPED_CFTYPEREF_H_ 107 #endif // BASE_MAC_SCOPED_CFTYPEREF_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698