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

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

Issue 2143323002: Remove WebPrivateOwnPtr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 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
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * Copyright (C) 2013 Intel Corporation. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 #ifndef WebPrivateOwnPtr_h
28 #define WebPrivateOwnPtr_h
29
30 #include "WebCommon.h"
31 #include "WebNonCopyable.h"
32 #include "base/logging.h"
33 #include <cstddef>
34
35 #if INSIDE_BLINK
36 #include "wtf/PtrUtil.h"
37 #include <memory>
38 #endif
39
40 namespace blink {
41
42 // This class is an implementation detail of the WebKit API. It exists
43 // to help simplify the implementation of WebKit interfaces that merely
44 // wrap a pointer to a WebCore class. It's similar to WebPrivatePtr, but it
45 // wraps a naked pointer rather than a reference counted.
46 // Note: you must call reset(0) on the implementation side in order to delete
47 // the WebCore pointer.
48 template <typename T>
49 class WebPrivateOwnPtr : public WebNonCopyable {
50 public:
51 WebPrivateOwnPtr() : m_ptr(nullptr) {}
52 WebPrivateOwnPtr(std::nullptr_t) : m_ptr(nullptr) {}
53 ~WebPrivateOwnPtr() { DCHECK(!m_ptr); }
54
55 explicit WebPrivateOwnPtr(T* ptr)
56 : m_ptr(ptr)
57 {
58 }
59
60 T* get() const { return m_ptr; }
61
62 #if INSIDE_BLINK
63 template <typename U>
64 WebPrivateOwnPtr(std::unique_ptr<U>, EnsurePtrConvertibleArgDecl(U, T));
65
66 void reset(T* ptr)
67 {
68 delete m_ptr;
69 m_ptr = ptr;
70 }
71
72 void reset(std::unique_ptr<T> o)
73 {
74 reset(o.release());
75 }
76
77 std::unique_ptr<T> release()
78 {
79 T* ptr = m_ptr;
80 m_ptr = nullptr;
81 return wrapUnique(ptr);
82 }
83
84 T& operator*() const
85 {
86 DCHECK(m_ptr);
87 return *m_ptr;
88 }
89
90 T* operator->() const
91 {
92 DCHECK(m_ptr);
93 return m_ptr;
94 }
95 #endif // INSIDE_BLINK
96
97 private:
98 T* m_ptr;
99 };
100
101 #if INSIDE_BLINK
102 template <typename T>
103 template <typename U>
104 inline WebPrivateOwnPtr<T>::WebPrivateOwnPtr(std::unique_ptr<U> o, EnsurePtrConv ertibleArgDefn(U, T))
105 : m_ptr(o.release())
106 {
107 static_assert(!std::is_array<T>::value, "Pointers to array must never be con verted");
108 }
109 #endif
110
111 } // namespace blink
112
113 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/public/platform/WebLayerTreeView.h ('k') | third_party/WebKit/public/platform/WebURLResponse.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698