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

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

Issue 1232033004: Introduce WebPassOwnPtr. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 5 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
« no previous file with comments | « no previous file | 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 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef WebPassOwnPtr_h
6 #define WebPassOwnPtr_h
7
8 #include "WebCommon.h"
tkent 2015/07/16 08:17:50 should be "public/platform/WebCommon.h"
yhirano 2015/07/16 08:32:21 Done.
9
10 #if INSIDE_BLINK
11 #include "wtf/PassOwnPtr.h"
12 #endif
13
14 namespace blink {
15
16 // WebPassOwnPtr<T> is used to pass a T pointer with ownership from chromium
17 // side to blink side.
18 // WebPassOwnPtr<T> is destructible on chromium side only when it contains
19 // nullptr.
20 template <typename T>
21 class WebPassOwnPtr final {
22 public:
23 WebPassOwnPtr() : m_ptr(nullptr) {}
24 WebPassOwnPtr(decltype(nullptr)) : m_ptr(nullptr) {}
25 template <typename U>
26 WebPassOwnPtr(const WebPassOwnPtr<U>& o)
27 {
28 m_ptr = o.m_ptr;
29 o.m_ptr = nullptr;
30 }
31 ~WebPassOwnPtr()
32 {
33 #if INSIDE_BLINK
34 release();
35 #endif
36 BLINK_ASSERT(!m_ptr);
37 }
38 WebPassOwnPtr& operator =(const WebPassOwnPtr&) = delete;
39
40 #if INSIDE_BLINK
41 PassOwnPtr<T> release()
42 {
43 T* ptr = m_ptr;
44 m_ptr = nullptr;
45 return adoptPtr(ptr);
46 }
47 #endif // INSIDE_BLINK
48
49 template <typename U> friend class WebPassOwnPtr;
50 template <typename U> friend WebPassOwnPtr<U> adoptWebPtr(U*);
51
52 private:
53 explicit WebPassOwnPtr(T* ptr) : m_ptr(ptr) {}
54
55 mutable T* m_ptr;
tkent 2015/07/16 08:17:50 Please add a comment about the reason of mutable.
yhirano 2015/07/16 08:32:21 Done.
56 };
57
58 template <typename T>
59 WebPassOwnPtr<T> adoptWebPtr(T* p) { return WebPassOwnPtr<T>(p); }
60
61 } // namespace blink
62
63 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698