| 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 15 matching lines...) Expand all Loading... |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef WebPrivatePtr_h | 31 #ifndef WebPrivatePtr_h |
| 32 #define WebPrivatePtr_h | 32 #define WebPrivatePtr_h |
| 33 | 33 |
| 34 #include "WebCommon.h" | 34 #include "WebCommon.h" |
| 35 | 35 |
| 36 #if WEBKIT_IMPLEMENTATION | 36 #if INSIDE_WEBKIT |
| 37 #include <wtf/PassRefPtr.h> | 37 #include <wtf/PassRefPtr.h> |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 namespace WebKit { | 40 namespace WebKit { |
| 41 | 41 |
| 42 // This class is an implementation detail of the WebKit API. It exists | 42 // This class is an implementation detail of the WebKit API. It exists |
| 43 // to help simplify the implementation of WebKit interfaces that merely | 43 // to help simplify the implementation of WebKit interfaces that merely |
| 44 // wrap a reference counted WebCore class. | 44 // wrap a reference counted WebCore class. |
| 45 // | 45 // |
| 46 // A typical implementation of a class which uses WebPrivatePtr might look like | 46 // A typical implementation of a class which uses WebPrivatePtr might look like |
| 47 // this: | 47 // this: |
| 48 // class WebFoo { | 48 // class WebFoo { |
| 49 // public: | 49 // public: |
| 50 // virtual ~WebFoo() { } // Only necessary if WebFoo will be used as a | 50 // virtual ~WebFoo() { } // Only necessary if WebFoo will be used as a |
| 51 // // base class. | 51 // // base class. |
| 52 // WebFoo() { } | 52 // WebFoo() { } |
| 53 // WebFoo(const WebFoo& other) { assign(other); } | 53 // WebFoo(const WebFoo& other) { assign(other); } |
| 54 // WebFoo& operator=(const WebFoo& other) | 54 // WebFoo& operator=(const WebFoo& other) |
| 55 // { | 55 // { |
| 56 // assign(other); | 56 // assign(other); |
| 57 // return *this; | 57 // return *this; |
| 58 // } | 58 // } |
| 59 // WEBKIT_EXPORT void assign(const WebFoo&); // Implemented in the body. | 59 // WEBKIT_EXPORT void assign(const WebFoo&); // Implemented in the body. |
| 60 // | 60 // |
| 61 // // Methods that are exposed to Chromium and which are specific to | 61 // // Methods that are exposed to Chromium and which are specific to |
| 62 // // WebFoo go here. | 62 // // WebFoo go here. |
| 63 // WEBKIT_EXPORT doWebFooThing(); | 63 // WEBKIT_EXPORT doWebFooThing(); |
| 64 // | 64 // |
| 65 // // Methods that are used only by other WebKit/chromium API classes | 65 // // Methods that are used only by other WebKit/chromium API classes |
| 66 // // should only be declared when WEBKIT_IMPLEMENTATION is set. | 66 // // should only be declared when INSIDE_WEBKIT is set. |
| 67 // #if WEBKIT_IMPLEMENTATION | 67 // #if INSIDE_WEBKIT |
| 68 // WebFoo(const WTF::PassRefPtr<WebCore::Foo>&); | 68 // WebFoo(const WTF::PassRefPtr<WebCore::Foo>&); |
| 69 // #endif | 69 // #endif |
| 70 // | 70 // |
| 71 // private: | 71 // private: |
| 72 // WebPrivatePtr<WebCore::Foo> m_private; | 72 // WebPrivatePtr<WebCore::Foo> m_private; |
| 73 // }; | 73 // }; |
| 74 // | 74 // |
| 75 template <typename T> | 75 template <typename T> |
| 76 class WebPrivatePtr { | 76 class WebPrivatePtr { |
| 77 public: | 77 public: |
| 78 WebPrivatePtr() : m_ptr(0) { } | 78 WebPrivatePtr() : m_ptr(0) { } |
| 79 ~WebPrivatePtr() { WEBKIT_ASSERT(!m_ptr); } | 79 ~WebPrivatePtr() { WEBKIT_ASSERT(!m_ptr); } |
| 80 | 80 |
| 81 bool isNull() const { return !m_ptr; } | 81 bool isNull() const { return !m_ptr; } |
| 82 | 82 |
| 83 #if WEBKIT_IMPLEMENTATION | 83 #if INSIDE_WEBKIT |
| 84 WebPrivatePtr(const PassRefPtr<T>& prp) | 84 WebPrivatePtr(const PassRefPtr<T>& prp) |
| 85 : m_ptr(prp.leakRef()) | 85 : m_ptr(prp.leakRef()) |
| 86 { | 86 { |
| 87 } | 87 } |
| 88 | 88 |
| 89 void reset() | 89 void reset() |
| 90 { | 90 { |
| 91 assign(0); | 91 assign(0); |
| 92 } | 92 } |
| 93 | 93 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 112 } | 112 } |
| 113 | 113 |
| 114 T* operator->() const | 114 T* operator->() const |
| 115 { | 115 { |
| 116 ASSERT(m_ptr); | 116 ASSERT(m_ptr); |
| 117 return m_ptr; | 117 return m_ptr; |
| 118 } | 118 } |
| 119 #endif | 119 #endif |
| 120 | 120 |
| 121 private: | 121 private: |
| 122 #if WEBKIT_IMPLEMENTATION | 122 #if INSIDE_WEBKIT |
| 123 void assign(T* p) | 123 void assign(T* p) |
| 124 { | 124 { |
| 125 // p is already ref'd for us by the caller | 125 // p is already ref'd for us by the caller |
| 126 if (m_ptr) | 126 if (m_ptr) |
| 127 m_ptr->deref(); | 127 m_ptr->deref(); |
| 128 m_ptr = p; | 128 m_ptr = p; |
| 129 } | 129 } |
| 130 #else | 130 #else |
| 131 // Disable the assignment operator; we define it above for when | 131 // Disable the assignment operator; we define it above for when |
| 132 // WEBKIT_IMPLEMENTATION is set, but we need to make sure that it is not | 132 // INSIDE_WEBKIT is set, but we need to make sure that it is not |
| 133 // used outside there; the compiler-provided version won't handle reference | 133 // used outside there; the compiler-provided version won't handle reference |
| 134 // counting properly. | 134 // counting properly. |
| 135 WebPrivatePtr<T>& operator=(const WebPrivatePtr<T>& other); | 135 WebPrivatePtr<T>& operator=(const WebPrivatePtr<T>& other); |
| 136 #endif | 136 #endif |
| 137 // Disable the copy constructor; classes that contain a WebPrivatePtr | 137 // Disable the copy constructor; classes that contain a WebPrivatePtr |
| 138 // should implement their copy constructor using assign(). | 138 // should implement their copy constructor using assign(). |
| 139 WebPrivatePtr(const WebPrivatePtr<T>&); | 139 WebPrivatePtr(const WebPrivatePtr<T>&); |
| 140 | 140 |
| 141 T* m_ptr; | 141 T* m_ptr; |
| 142 }; | 142 }; |
| 143 | 143 |
| 144 } // namespace WebKit | 144 } // namespace WebKit |
| 145 | 145 |
| 146 #endif | 146 #endif |
| OLD | NEW |