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

Side by Side Diff: public/platform/WebPassOwnPtr.h

Issue 23455058: WIP: WebLayer::addAnimation should transfer the ownership of WebAnimation instance. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 3 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 | « public/platform/WebLayer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2013 Intel Corporation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #ifndef WebPassOwnPtr_h
27 #define WebPassOwnPtr_h
28
29 #include "WebCommon.h"
30
31 #if INSIDE_WEBKIT
32 #include "wtf/OwnPtr.h"
33 #include "wtf/PassOwnPtr.h"
34 using WTF::EnableIf;
35 using WTF::IsPointerConvertible;
36 #endif
37
38 namespace WebKit {
39
40 // It exists to help transfer the ownership of either OwnPtr or PassOwnPtr from Blink to Chromium.
41 //
42 // A typical usage is as follows:
43 // in Blink side
44 // OwnPtr<WebAnimation> animation;
45 // WebLayer layer;
46 // layer->addAnimation(animation);
47 //
48 // in Chromium side
49 // bool WebAnimation::addAnimation(WebPassOwnPtr<WebAnimation> pop_animation) {
50 // scoped_ptr<WebAnimation> animation(pop_animation.leakPtr());
51 // ...
52 // }
53 template <typename T>
54 class WebPassOwnPtr {
55 public:
56 WebPassOwnPtr() : m_ptr(0) { }
57 ~WebPassOwnPtr() { delete m_ptr; }
jamesr 2013/09/24 17:52:10 you can't do this without ~T(), which will make it
dshwang 2013/09/24 18:23:22 Could you explain why it cannot work in detail or
58 WebPassOwnPtr(const WebPassOwnPtr& o) : m_ptr(o.leakPtr()) { }
59
60 T* leakPtr() const
61 {
62 T* ptr = m_ptr;
63 m_ptr = 0;
64 return ptr;
65 }
66 bool operator!() const { return !m_ptr; }
67
68 #if INSIDE_WEBKIT
69 explicit WebPassOwnPtr(T* ptr)
70 : m_ptr(ptr)
71 {
72 COMPILE_ASSERT(sizeof(T) > 0, TypeMustBeComplete);
73 }
74
75 template<typename U> WebPassOwnPtr(const OwnPtr<U>&, EnsurePtrConvertibleArg Decl(U, T));
76 template<typename U> WebPassOwnPtr(const PassOwnPtr<U>&, EnsurePtrConvertibl eArgDecl(U, T));
77
78 T* get() const { return m_ptr; }
79 T* operator->() const
80 {
81 WEBKIT_ASSERT(m_ptr);
82 return m_ptr;
83 }
84 #endif // INSIDE_WEBKIT
85
86 private:
87 WebPassOwnPtr& operator=(const WebPassOwnPtr&);
88
89 mutable T* m_ptr;
90 };
91
92 #if INSIDE_WEBKIT
93 template<typename T> template<typename U> inline WebPassOwnPtr<T>::WebPassOwnPtr (const OwnPtr<U>& o, EnsurePtrConvertibleArgDefn(U, T))
94 : m_ptr(o.leakPtr())
95 {
96 }
97
98 template<typename T> template<typename U> inline WebPassOwnPtr<T>::WebPassOwnPtr (const PassOwnPtr<U>& o, EnsurePtrConvertibleArgDefn(U, T))
99 : m_ptr(o.leakPtr())
100 {
101 }
102 #endif
103
104 } // namespace WebKit
105
106 #endif
OLDNEW
« no previous file with comments | « public/platform/WebLayer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698