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

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

Issue 1865913005: Nuke WebPassOwnPtr<T> and replace it with std::unique_ptr<T>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
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 #include <cstddef>
10
11 #if INSIDE_BLINK
12 #include "wtf/PassOwnPtr.h"
13 #else
14 #include <base/memory/scoped_ptr.h>
15 #endif
16
17 namespace blink {
18
19 // WebPassOwnPtr<T> is used to pass a T pointer with ownership from chromium
20 // side to blink side. T's definition must be shared among all users
21 // (especially between chromium and blink).
22 // TODO(yhirano): Migrate to scoped_ptr or std::unique_ptr once the repository
23 // merge is done or C++11 std library is allowed.
24 template <typename T>
25 class WebPassOwnPtr final {
26 public:
27 WebPassOwnPtr() : m_ptr(nullptr) {}
28 WebPassOwnPtr(std::nullptr_t) : m_ptr(nullptr) {}
29 // We need |const| to bind an rvalue. As a result, |m_ptr| needs to be
30 // mutable because we manipulate it.
31 template <typename U>
32 WebPassOwnPtr(const WebPassOwnPtr<U>& o)
33 {
34 m_ptr = o.m_ptr;
35 o.m_ptr = nullptr;
36 }
37 WebPassOwnPtr(const WebPassOwnPtr& o)
38 {
39 m_ptr = o.m_ptr;
40 o.m_ptr = nullptr;
41 }
42 ~WebPassOwnPtr()
43 {
44 delete m_ptr;
45 }
46 WebPassOwnPtr& operator =(const WebPassOwnPtr&) = delete;
47
48 #if INSIDE_BLINK
49 PassOwnPtr<T> release()
50 {
51 T* ptr = m_ptr;
52 m_ptr = nullptr;
53 return adoptPtr(ptr);
54 }
55 #else
56 operator scoped_ptr<T>()
57 {
58 T* ptr = m_ptr;
59 m_ptr = nullptr;
60 return scoped_ptr<T>(ptr);
61 }
62 #endif // INSIDE_BLINK
63
64 template <typename U> friend class WebPassOwnPtr;
65 template <typename U> friend WebPassOwnPtr<U> adoptWebPtr(U*);
66
67 private:
68 explicit WebPassOwnPtr(T* ptr) : m_ptr(ptr) {}
69
70 // See the constructor comment to see why |mutable| is needed.
71 mutable T* m_ptr;
72 };
73
74 template <typename T>
75 WebPassOwnPtr<T> adoptWebPtr(T* p) { return WebPassOwnPtr<T>(p); }
76
77 } // namespace blink
78
79 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698