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

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

Issue 2050123002: Remove OwnPtr from Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First attempt to land. Created 4 years, 6 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
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * Copyright (C) 2013 Intel Corporation. All rights reserved. 3 * Copyright (C) 2013 Intel Corporation. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 15 matching lines...) Expand all
26 26
27 #ifndef WebPrivateOwnPtr_h 27 #ifndef WebPrivateOwnPtr_h
28 #define WebPrivateOwnPtr_h 28 #define WebPrivateOwnPtr_h
29 29
30 #include "WebCommon.h" 30 #include "WebCommon.h"
31 #include "WebNonCopyable.h" 31 #include "WebNonCopyable.h"
32 #include "base/logging.h" 32 #include "base/logging.h"
33 #include <cstddef> 33 #include <cstddef>
34 34
35 #if INSIDE_BLINK 35 #if INSIDE_BLINK
36 #include "wtf/PassOwnPtr.h" 36 #include "wtf/PtrUtil.h"
37 #include <memory>
37 #endif 38 #endif
38 39
39 namespace blink { 40 namespace blink {
40 41
41 // 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
42 // to help simplify the implementation of WebKit interfaces that merely 43 // to help simplify the implementation of WebKit interfaces that merely
43 // wrap a pointer to a WebCore class. It's similar to WebPrivatePtr, but it 44 // wrap a pointer to a WebCore class. It's similar to WebPrivatePtr, but it
44 // wraps a naked pointer rather than a reference counted. 45 // wraps a naked pointer rather than a reference counted.
45 // Note: you must call reset(0) on the implementation side in order to delete 46 // Note: you must call reset(0) on the implementation side in order to delete
46 // the WebCore pointer. 47 // the WebCore pointer.
47 template <typename T> 48 template <typename T>
48 class WebPrivateOwnPtr : public WebNonCopyable { 49 class WebPrivateOwnPtr : public WebNonCopyable {
49 public: 50 public:
50 WebPrivateOwnPtr() : m_ptr(nullptr) {} 51 WebPrivateOwnPtr() : m_ptr(nullptr) {}
51 WebPrivateOwnPtr(std::nullptr_t) : m_ptr(nullptr) {} 52 WebPrivateOwnPtr(std::nullptr_t) : m_ptr(nullptr) {}
52 ~WebPrivateOwnPtr() { DCHECK(!m_ptr); } 53 ~WebPrivateOwnPtr() { DCHECK(!m_ptr); }
53 54
54 explicit WebPrivateOwnPtr(T* ptr) 55 explicit WebPrivateOwnPtr(T* ptr)
55 : m_ptr(ptr) 56 : m_ptr(ptr)
56 { 57 {
57 } 58 }
58 59
59 T* get() const { return m_ptr; } 60 T* get() const { return m_ptr; }
60 61
61 #if INSIDE_BLINK 62 #if INSIDE_BLINK
62 template <typename U> 63 template <typename U>
63 WebPrivateOwnPtr(PassOwnPtr<U>, EnsurePtrConvertibleArgDecl(U, T)); 64 WebPrivateOwnPtr(std::unique_ptr<U>, EnsurePtrConvertibleArgDecl(U, T));
64 65
65 void reset(T* ptr) 66 void reset(T* ptr)
66 { 67 {
67 delete m_ptr; 68 delete m_ptr;
68 m_ptr = ptr; 69 m_ptr = ptr;
69 } 70 }
70 71
71 void reset(PassOwnPtr<T> o) 72 void reset(std::unique_ptr<T> o)
72 { 73 {
73 reset(o.leakPtr()); 74 reset(o.release());
74 } 75 }
75 76
76 PassOwnPtr<T> release() 77 std::unique_ptr<T> release()
77 { 78 {
78 T* ptr = m_ptr; 79 T* ptr = m_ptr;
79 m_ptr = nullptr; 80 m_ptr = nullptr;
80 return adoptPtr(ptr); 81 return wrapUnique(ptr);
81 } 82 }
82 83
83 T& operator*() const 84 T& operator*() const
84 { 85 {
85 DCHECK(m_ptr); 86 DCHECK(m_ptr);
86 return *m_ptr; 87 return *m_ptr;
87 } 88 }
88 89
89 T* operator->() const 90 T* operator->() const
90 { 91 {
91 DCHECK(m_ptr); 92 DCHECK(m_ptr);
92 return m_ptr; 93 return m_ptr;
93 } 94 }
94 #endif // INSIDE_BLINK 95 #endif // INSIDE_BLINK
95 96
96 private: 97 private:
97 T* m_ptr; 98 T* m_ptr;
98 }; 99 };
99 100
100 #if INSIDE_BLINK 101 #if INSIDE_BLINK
101 template <typename T> 102 template <typename T>
102 template <typename U> 103 template <typename U>
103 inline WebPrivateOwnPtr<T>::WebPrivateOwnPtr(PassOwnPtr<U> o, EnsurePtrConvertib leArgDefn(U, T)) 104 inline WebPrivateOwnPtr<T>::WebPrivateOwnPtr(std::unique_ptr<U> o, EnsurePtrConv ertibleArgDefn(U, T))
104 : m_ptr(o.leakPtr()) 105 : m_ptr(o.release())
105 { 106 {
106 static_assert(!std::is_array<T>::value, "Pointers to array must never be con verted"); 107 static_assert(!std::is_array<T>::value, "Pointers to array must never be con verted");
107 } 108 }
108 #endif 109 #endif
109 110
110 } // namespace blink 111 } // namespace blink
111 112
112 #endif 113 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/public/platform/WebFileSystemCallbacks.h ('k') | third_party/WebKit/public/platform/WebScrollbar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698