Index: base/memory/ptr_util.h |
diff --git a/base/memory/ptr_util.h b/base/memory/ptr_util.h |
index 04f2c0258929e74c0bcca89d4433fa6f647a0d28..2c8db5e11893b7f41ee429ffade92ef0bde8fa02 100644 |
--- a/base/memory/ptr_util.h |
+++ b/base/memory/ptr_util.h |
@@ -7,6 +7,31 @@ |
#include <memory> |
+// A function to convert T* into scoped_ptr<T> |
+// Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation |
+// for scoped_ptr<FooBarBaz<type>>(new FooBarBaz<type>(arg)) |
+// |
+// Why doesn't this just return a scoped_ptr? |
+// |
+// make_scoped_ptr is currently being migrated out of scoped_ptr.h, so we can |
+// globally rename make_scoped_ptr to WrapUnique without breaking the build. |
+// Doing so without breaking intermediate builds involves several steps: |
+// |
+// 1. Move make_scoped_ptr into ptr_util.h and include ptr_util.h from |
+// scoped_ptr.h. |
+// 2. Add an #include for ptr_util.h to every file that references |
+// make_scoped_ptr. |
+// 3. Remove ptr_util.h include from scoped_ptr.h. |
+// 4. Global rewrite everything. |
+// |
+// Unfortunately, step 1 introduces an awkward cycle of dependencies between |
+// ptr_util.h and scoped_ptr.h To break that cycle, we exploit the fact that |
+// scoped_ptr is really just a type alias for std::unique_ptr. |
+template <typename T> |
+std::unique_ptr<T> make_scoped_ptr(T* ptr) { |
+ return std::unique_ptr<T>(ptr); |
+} |
+ |
namespace base { |
// Helper to transfer ownership of a raw pointer to a std::unique_ptr<T>. |