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

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 "public/platform/WebCommon.h"
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 // TODO(yhirano): Migrate to scoped_ptr or std::unique_ptr once the repository
21 // merge is done or C++11 std library is allowed.
22 template <typename T>
23 class WebPassOwnPtr final {
24 public:
25 WebPassOwnPtr() : m_ptr(nullptr) {}
26 WebPassOwnPtr(decltype(nullptr)) : m_ptr(nullptr) {}
27 // We need |const| to bind an rvalue. As a result, |m_ptr| needs to be
28 // mutable because we manipulate it.
29 template <typename U>
30 WebPassOwnPtr(const WebPassOwnPtr<U>& o)
31 {
32 m_ptr = o.m_ptr;
33 o.m_ptr = nullptr;
34 }
35 ~WebPassOwnPtr()
36 {
37 #if INSIDE_BLINK
38 release();
39 #endif
40 BLINK_ASSERT(!m_ptr);
41 }
42 WebPassOwnPtr& operator =(const WebPassOwnPtr&) = delete;
43
44 #if INSIDE_BLINK
45 PassOwnPtr<T> release()
46 {
47 T* ptr = m_ptr;
48 m_ptr = nullptr;
49 return adoptPtr(ptr);
50 }
51 #endif // INSIDE_BLINK
52
53 template <typename U> friend class WebPassOwnPtr;
54 template <typename U> friend WebPassOwnPtr<U> adoptWebPtr(U*);
55
56 private:
57 explicit WebPassOwnPtr(T* ptr) : m_ptr(ptr) {}
58
59 // See the constructor comment to see why |mutable| is needed.
60 mutable T* m_ptr;
61 };
62
63 template <typename T>
64 WebPassOwnPtr<T> adoptWebPtr(T* p) { return WebPassOwnPtr<T>(p); }
65
66 } // namespace blink
67
68 #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