OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 template <typename T, | 90 template <typename T, |
91 WebPrivatePtrDestruction crossThreadDestruction, | 91 WebPrivatePtrDestruction crossThreadDestruction, |
92 WebPrivatePtrStrength strongOrWeak> | 92 WebPrivatePtrStrength strongOrWeak> |
93 class PtrStorageImpl<T, | 93 class PtrStorageImpl<T, |
94 crossThreadDestruction, | 94 crossThreadDestruction, |
95 strongOrWeak, | 95 strongOrWeak, |
96 kRefCountedLifetime> { | 96 kRefCountedLifetime> { |
97 public: | 97 public: |
98 typedef PassRefPtr<T> BlinkPtrType; | 98 typedef PassRefPtr<T> BlinkPtrType; |
99 | 99 |
100 void Assign(const BlinkPtrType& val) { | 100 void Assign(BlinkPtrType&& val) { |
101 static_assert( | 101 static_assert( |
102 crossThreadDestruction == kWebPrivatePtrDestructionSameThread || | 102 crossThreadDestruction == kWebPrivatePtrDestructionSameThread || |
103 WTF::IsSubclassOfTemplate<T, WTF::ThreadSafeRefCounted>::value, | 103 WTF::IsSubclassOfTemplate<T, WTF::ThreadSafeRefCounted>::value, |
104 "Cross thread destructible class must derive from " | 104 "Cross thread destructible class must derive from " |
105 "ThreadSafeRefCounted<>"); | 105 "ThreadSafeRefCounted<>"); |
106 static_assert( | 106 static_assert( |
107 strongOrWeak == WebPrivatePtrStrength::kNormal, | 107 strongOrWeak == WebPrivatePtrStrength::kNormal, |
108 "Ref-counted classes do not support weak WebPrivatePtr<> references"); | 108 "Ref-counted classes do not support weak WebPrivatePtr<> references"); |
109 Release(); | 109 Release(); |
110 ptr_ = val.LeakRef(); | 110 ptr_ = val.LeakRef(); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 // want to expose destructors of core classes to embedders. We should | 278 // want to expose destructors of core classes to embedders. We should |
279 // call reset() manually in destructors of classes with WebPrivatePtr | 279 // call reset() manually in destructors of classes with WebPrivatePtr |
280 // members. | 280 // members. |
281 DCHECK(!storage_); | 281 DCHECK(!storage_); |
282 } | 282 } |
283 | 283 |
284 bool IsNull() const { return !storage_; } | 284 bool IsNull() const { return !storage_; } |
285 | 285 |
286 #if INSIDE_BLINK | 286 #if INSIDE_BLINK |
287 template <typename U> | 287 template <typename U> |
288 WebPrivatePtr(const U& ptr) : storage_(0) { | 288 WebPrivatePtr(U&& ptr) : storage_(0) { |
289 Storage().Assign(ptr); | 289 Storage().Assign(std::forward<U>(ptr)); |
290 } | 290 } |
291 | 291 |
292 void Reset() { Storage().Release(); } | 292 void Reset() { Storage().Release(); } |
293 | 293 |
294 WebPrivatePtr& operator=(const WebPrivatePtr& other) { | 294 WebPrivatePtr& operator=(const WebPrivatePtr& other) { |
295 Storage().Assign(other.Storage()); | 295 Storage().Assign(other.Storage()); |
296 return *this; | 296 return *this; |
297 } | 297 } |
298 | 298 |
299 template <typename U> | 299 template <typename U> |
300 WebPrivatePtr& operator=(const U& ptr) { | 300 WebPrivatePtr& operator=(U&& ptr) { |
301 Storage().Assign(ptr); | 301 Storage().Assign(std::forward<U>(ptr)); |
302 return *this; | 302 return *this; |
303 } | 303 } |
304 | 304 |
305 T* Get() const { return Storage().Get(); } | 305 T* Get() const { return Storage().Get(); } |
306 | 306 |
307 T& operator*() const { | 307 T& operator*() const { |
308 DCHECK(storage_); | 308 DCHECK(storage_); |
309 return *Get(); | 309 return *Get(); |
310 } | 310 } |
311 | 311 |
(...skipping 23 matching lines...) Expand all Loading... |
335 // Disable the copy constructor; classes that contain a WebPrivatePtr | 335 // Disable the copy constructor; classes that contain a WebPrivatePtr |
336 // should implement their copy constructor using assign(). | 336 // should implement their copy constructor using assign(). |
337 WebPrivatePtr(const WebPrivatePtr&) = delete; | 337 WebPrivatePtr(const WebPrivatePtr&) = delete; |
338 | 338 |
339 void* storage_; | 339 void* storage_; |
340 }; | 340 }; |
341 | 341 |
342 } // namespace blink | 342 } // namespace blink |
343 | 343 |
344 #endif // WebPrivatePtr_h | 344 #endif // WebPrivatePtr_h |
OLD | NEW |