| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 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 |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_REFCOUNTED_H_ | 5 #ifndef BASE_REFCOUNTED_H_ |
| 6 #define BASE_REFCOUNTED_H_ | 6 #define BASE_REFCOUNTED_H_ |
| 7 | 7 |
| 8 namespace base { | 8 namespace base { |
| 9 | 9 |
| 10 template <typename T> | 10 template <typename T> |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 ~PrivateRefCountedDtorInHeader() {} | 100 ~PrivateRefCountedDtorInHeader() {} |
| 101 friend class base::RefCounted<PrivateRefCountedDtorInHeader>; | 101 friend class base::RefCounted<PrivateRefCountedDtorInHeader>; |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 // Unsafe; A grandchild class ends up exposing their parent and grandparent's | 104 // Unsafe; A grandchild class ends up exposing their parent and grandparent's |
| 105 // destructors. | 105 // destructors. |
| 106 class DerivedProtectedToPublicInHeader | 106 class DerivedProtectedToPublicInHeader |
| 107 : public ProtectedRefCountedVirtualDtorInHeader { | 107 : public ProtectedRefCountedVirtualDtorInHeader { |
| 108 public: | 108 public: |
| 109 DerivedProtectedToPublicInHeader() {} | 109 DerivedProtectedToPublicInHeader() {} |
| 110 ~DerivedProtectedToPublicInHeader() override {} | 110 virtual ~DerivedProtectedToPublicInHeader() {} |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 // Unsafe; A grandchild ends up implicitly exposing their parent and | 113 // Unsafe; A grandchild ends up implicitly exposing their parent and |
| 114 // grantparent's destructors. | 114 // grantparent's destructors. |
| 115 class ImplicitDerivedProtectedToPublicInHeader | 115 class ImplicitDerivedProtectedToPublicInHeader |
| 116 : public ProtectedRefCountedVirtualDtorInHeader { | 116 : public ProtectedRefCountedVirtualDtorInHeader { |
| 117 public: | 117 public: |
| 118 ImplicitDerivedProtectedToPublicInHeader() {} | 118 ImplicitDerivedProtectedToPublicInHeader() {} |
| 119 }; | 119 }; |
| 120 | 120 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 139 virtual ~APublicInterface() {} | 139 virtual ~APublicInterface() {} |
| 140 virtual void DoFoo() = 0; | 140 virtual void DoFoo() = 0; |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 // Unsafe. "ImplementsAPublicInterface* foo" can be deleted via | 143 // Unsafe. "ImplementsAPublicInterface* foo" can be deleted via |
| 144 // "delete (APublicInterface*)foo;". | 144 // "delete (APublicInterface*)foo;". |
| 145 class ImplementsAPublicInterface | 145 class ImplementsAPublicInterface |
| 146 : public APublicInterface, | 146 : public APublicInterface, |
| 147 public base::RefCounted<ImplementsAPublicInterface> { | 147 public base::RefCounted<ImplementsAPublicInterface> { |
| 148 public: | 148 public: |
| 149 void DoFoo() override {} | 149 virtual void DoFoo() override {} |
| 150 | 150 |
| 151 protected: | 151 protected: |
| 152 ~ImplementsAPublicInterface() override {} | 152 virtual ~ImplementsAPublicInterface() {} |
| 153 | 153 |
| 154 private: | 154 private: |
| 155 friend class base::RefCounted<ImplementsAPublicInterface>; | 155 friend class base::RefCounted<ImplementsAPublicInterface>; |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 class AnImplicitInterface { | 158 class AnImplicitInterface { |
| 159 public: | 159 public: |
| 160 virtual void DoBar() {} | 160 virtual void DoBar() {} |
| 161 }; | 161 }; |
| 162 | 162 |
| 163 // Unsafe. | 163 // Unsafe. |
| 164 class ImplementsAnImplicitInterface | 164 class ImplementsAnImplicitInterface |
| 165 : public AnImplicitInterface, | 165 : public AnImplicitInterface, |
| 166 public base::RefCounted<ImplementsAnImplicitInterface> { | 166 public base::RefCounted<ImplementsAnImplicitInterface> { |
| 167 public: | 167 public: |
| 168 void DoBar() override {} | 168 virtual void DoBar() override {} |
| 169 | 169 |
| 170 private: | 170 private: |
| 171 friend class base::RefCounted<ImplementsAnImplicitInterface>; | 171 friend class base::RefCounted<ImplementsAnImplicitInterface>; |
| 172 ~ImplementsAnImplicitInterface() {} | 172 ~ImplementsAnImplicitInterface() {} |
| 173 }; | 173 }; |
| 174 | 174 |
| 175 // Safe. Private inheritance does not expose the base destructor. | 175 // Safe. Private inheritance does not expose the base destructor. |
| 176 class PrivatelyImplementsAPublicInterface | 176 class PrivatelyImplementsAPublicInterface |
| 177 : private APublicInterface, | 177 : private APublicInterface, |
| 178 public base::RefCounted<PrivatelyImplementsAPublicInterface> { | 178 public base::RefCounted<PrivatelyImplementsAPublicInterface> { |
| 179 public: | 179 public: |
| 180 void DoFoo() override {} | 180 virtual void DoFoo() override {} |
| 181 | 181 |
| 182 private: | 182 private: |
| 183 friend class base::RefCounted<PrivatelyImplementsAPublicInterface>; | 183 friend class base::RefCounted<PrivatelyImplementsAPublicInterface>; |
| 184 ~PrivatelyImplementsAPublicInterface() override {} | 184 virtual ~PrivatelyImplementsAPublicInterface() {} |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 // Unsafe. | 187 // Unsafe. |
| 188 class BaseInterface { | 188 class BaseInterface { |
| 189 public: | 189 public: |
| 190 virtual ~BaseInterface() {} | 190 virtual ~BaseInterface() {} |
| 191 virtual void DoFoo() {} | 191 virtual void DoFoo() {} |
| 192 }; | 192 }; |
| 193 class DerivedInterface : public BaseInterface { | 193 class DerivedInterface : public BaseInterface { |
| 194 protected: | 194 protected: |
| 195 ~DerivedInterface() override {} | 195 virtual ~DerivedInterface() {} |
| 196 }; | 196 }; |
| 197 class SomeOtherInterface { | 197 class SomeOtherInterface { |
| 198 public: | 198 public: |
| 199 virtual ~SomeOtherInterface() {} | 199 virtual ~SomeOtherInterface() {} |
| 200 virtual void DoBar() {} | 200 virtual void DoBar() {} |
| 201 }; | 201 }; |
| 202 class RefcountedType : public base::RefCounted<RefcountedType> { | 202 class RefcountedType : public base::RefCounted<RefcountedType> { |
| 203 protected: | 203 protected: |
| 204 ~RefcountedType() {} | 204 ~RefcountedType() {} |
| 205 private: | 205 private: |
| 206 friend class base::RefCounted<RefcountedType>; | 206 friend class base::RefCounted<RefcountedType>; |
| 207 }; | 207 }; |
| 208 class UnsafeInheritanceChain | 208 class UnsafeInheritanceChain |
| 209 : public DerivedInterface, | 209 : public DerivedInterface, |
| 210 public SomeOtherInterface, | 210 public SomeOtherInterface, |
| 211 public RefcountedType { | 211 public RefcountedType { |
| 212 public: | 212 public: |
| 213 // DerivedInterface | 213 // DerivedInterface |
| 214 void DoFoo() override {} | 214 virtual void DoFoo() override {} |
| 215 | 215 |
| 216 // SomeOtherInterface | 216 // SomeOtherInterface |
| 217 void DoBar() override {} | 217 virtual void DoBar() override {} |
| 218 | 218 |
| 219 protected: | 219 protected: |
| 220 ~UnsafeInheritanceChain() override {} | 220 virtual ~UnsafeInheritanceChain() {} |
| 221 }; | 221 }; |
| 222 | 222 |
| 223 #endif // BASE_REFCOUNTED_H_ | 223 #endif // BASE_REFCOUNTED_H_ |
| OLD | NEW |