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

Side by Side Diff: core/fxcrt/cfx_retain_ptr.h

Issue 2583093003: Add CFX_RetainPtr Leak() and Unleak() methods (Closed)
Patch Set: Reduce scope of change Created 4 years 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
« no previous file with comments | « no previous file | core/fxcrt/cfx_retain_ptr_unittest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CORE_FXCRT_CFX_RETAIN_PTR_H_ 5 #ifndef CORE_FXCRT_CFX_RETAIN_PTR_H_
6 #define CORE_FXCRT_CFX_RETAIN_PTR_H_ 6 #define CORE_FXCRT_CFX_RETAIN_PTR_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 19 matching lines...) Expand all
30 30
31 void Reset(T* obj = nullptr) { 31 void Reset(T* obj = nullptr) {
32 if (obj) 32 if (obj)
33 obj->Retain(); 33 obj->Retain();
34 m_pObj.reset(obj); 34 m_pObj.reset(obj);
35 } 35 }
36 36
37 T* Get() const { return m_pObj.get(); } 37 T* Get() const { return m_pObj.get(); }
38 void Swap(CFX_RetainPtr& that) { m_pObj.swap(that.m_pObj); } 38 void Swap(CFX_RetainPtr& that) { m_pObj.swap(that.m_pObj); }
39 39
40 // TODO(tsepez): temporary scaffolding, to be removed.
41 T* Leak() { return m_pObj.release(); }
42 void Unleak(T* ptr) { m_pObj.reset(ptr); }
Wei Li 2016/12/28 19:35:04 I don't quite understand the needs for these funct
43
40 CFX_RetainPtr& operator=(const CFX_RetainPtr& that) { 44 CFX_RetainPtr& operator=(const CFX_RetainPtr& that) {
41 if (*this != that) 45 if (*this != that)
42 Reset(that.Get()); 46 Reset(that.Get());
43 return *this; 47 return *this;
44 } 48 }
45 49
46 bool operator==(const CFX_RetainPtr& that) const { 50 bool operator==(const CFX_RetainPtr& that) const {
47 return Get() == that.Get(); 51 return Get() == that.Get();
48 } 52 }
49 53
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // Classes managed by CFX_RetainPtr should have protected (or private) 92 // Classes managed by CFX_RetainPtr should have protected (or private)
89 // constructors, and should friend this function. 93 // constructors, and should friend this function.
90 template <typename T, typename... Args> 94 template <typename T, typename... Args>
91 CFX_RetainPtr<T> MakeRetain(Args&&... args) { 95 CFX_RetainPtr<T> MakeRetain(Args&&... args) {
92 return CFX_RetainPtr<T>(new T(std::forward<Args>(args)...)); 96 return CFX_RetainPtr<T>(new T(std::forward<Args>(args)...));
93 } 97 }
94 98
95 } // namespace pdfium 99 } // namespace pdfium
96 100
97 #endif // CORE_FXCRT_CFX_RETAIN_PTR_H_ 101 #endif // CORE_FXCRT_CFX_RETAIN_PTR_H_
OLDNEW
« no previous file with comments | « no previous file | core/fxcrt/cfx_retain_ptr_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698