Revert "Make CPDF_IndirectObjectHolder use unique_ptr to objects"

This reverts commit c8544d634a1993e2592e41458be215fcd0956031.

TBR=dsinclair@chromium.org

Review URL: https://codereview.chromium.org/2355683002 .
diff --git a/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp b/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
index 36f6226..cab99ec 100644
--- a/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
+++ b/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
@@ -1365,7 +1365,7 @@
   FX_BOOL bNoOriginal = (m_dwFlags & FPDFCREATE_NO_ORIGINAL) != 0;
   for (const auto& pair : *m_pDocument) {
     const uint32_t objnum = pair.first;
-    const CPDF_Object* pObj = pair.second.get();
+    const CPDF_Object* pObj = pair.second;
     if (bIncremental || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum)
       continue;
     if (m_pParser && m_pParser->IsValidObjectNumber(objnum) &&
diff --git a/core/fpdfapi/fpdf_parser/cfdf_document.cpp b/core/fpdfapi/fpdf_parser/cfdf_document.cpp
index 92b20ca..0182948 100644
--- a/core/fpdfapi/fpdf_parser/cfdf_document.cpp
+++ b/core/fpdfapi/fpdf_parser/cfdf_document.cpp
@@ -90,8 +90,7 @@
 
   buf << "%FDF-1.2\r\n";
   for (const auto& pair : *this)
-    buf << pair.first << " 0 obj\r\n"
-        << pair.second.get() << "\r\nendobj\r\n\r\n";
+    buf << pair.first << " 0 obj\r\n" << pair.second << "\r\nendobj\r\n\r\n";
 
   buf << "trailer\r\n<</Root " << m_pRootDict->GetObjNum()
       << " 0 R>>\r\n%%EOF\r\n";
diff --git a/core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp b/core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp
index 800e34b..dc639fe 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp
@@ -11,12 +11,15 @@
 
 CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder() : m_LastObjNum(0) {}
 
-CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() {}
+CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() {
+  for (const auto& pair : m_IndirectObjs)
+    delete pair.second;
+}
 
 CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject(
     uint32_t objnum) const {
   auto it = m_IndirectObjs.find(objnum);
-  return it != m_IndirectObjs.end() ? it->second.get() : nullptr;
+  return it != m_IndirectObjs.end() ? it->second : nullptr;
 }
 
 CPDF_Object* CPDF_IndirectObjectHolder::GetOrParseIndirectObject(
@@ -34,7 +37,10 @@
 
   pObj->m_ObjNum = objnum;
   m_LastObjNum = std::max(m_LastObjNum, objnum);
-  m_IndirectObjs[objnum].reset(pObj);
+  if (m_IndirectObjs[objnum])
+    delete m_IndirectObjs[objnum];
+
+  m_IndirectObjs[objnum] = pObj;
   return pObj;
 }
 
@@ -47,7 +53,7 @@
     return pObj->m_ObjNum;
 
   m_LastObjNum++;
-  m_IndirectObjs[m_LastObjNum].reset(pObj);
+  m_IndirectObjs[m_LastObjNum] = pObj;
   pObj->m_ObjNum = m_LastObjNum;
   return m_LastObjNum;
 }
@@ -59,12 +65,15 @@
     return false;
 
   CPDF_Object* pOldObj = GetIndirectObject(objnum);
-  if (pOldObj && pObj->GetGenNum() <= pOldObj->GetGenNum()) {
-    delete pObj;
-    return false;
+  if (pOldObj) {
+    if (pObj->GetGenNum() <= pOldObj->GetGenNum()) {
+      delete pObj;
+      return false;
+    }
+    delete pOldObj;
   }
   pObj->m_ObjNum = objnum;
-  m_IndirectObjs[objnum].reset(pObj);
+  m_IndirectObjs[objnum] = pObj;
   m_LastObjNum = std::max(m_LastObjNum, objnum);
   return true;
 }
@@ -74,5 +83,6 @@
   if (!pObj || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum)
     return;
 
+  delete pObj;
   m_IndirectObjs.erase(objnum);
 }
diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h b/core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h
index 2abbda2..57dafb0 100644
--- a/core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h
+++ b/core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h
@@ -8,7 +8,6 @@
 #define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_INDIRECT_OBJECT_HOLDER_H_
 
 #include <map>
-#include <memory>
 
 #include "core/fxcrt/include/fx_system.h"
 
@@ -16,8 +15,8 @@
 
 class CPDF_IndirectObjectHolder {
  public:
-  using const_iterator =
-      std::map<uint32_t, std::unique_ptr<CPDF_Object>>::const_iterator;
+  using iterator = std::map<uint32_t, CPDF_Object*>::iterator;
+  using const_iterator = std::map<uint32_t, CPDF_Object*>::const_iterator;
 
   CPDF_IndirectObjectHolder();
   virtual ~CPDF_IndirectObjectHolder();
@@ -34,7 +33,9 @@
   uint32_t GetLastObjNum() const { return m_LastObjNum; }
   void SetLastObjNum(uint32_t objnum) { m_LastObjNum = objnum; }
 
+  iterator begin() { return m_IndirectObjs.begin(); }
   const_iterator begin() const { return m_IndirectObjs.begin(); }
+  iterator end() { return m_IndirectObjs.end(); }
   const_iterator end() const { return m_IndirectObjs.end(); }
 
  protected:
@@ -42,7 +43,7 @@
 
  private:
   uint32_t m_LastObjNum;
-  std::map<uint32_t, std::unique_ptr<CPDF_Object>> m_IndirectObjs;
+  std::map<uint32_t, CPDF_Object*> m_IndirectObjs;
 };
 
 #endif  // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_INDIRECT_OBJECT_HOLDER_H_
diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_object.h b/core/fpdfapi/fpdf_parser/include/cpdf_object.h
index de14503..115ce02 100644
--- a/core/fpdfapi/fpdf_parser/include/cpdf_object.h
+++ b/core/fpdfapi/fpdf_parser/include/cpdf_object.h
@@ -7,7 +7,6 @@
 #ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_OBJECT_H_
 #define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_OBJECT_H_
 
-#include <memory>
 #include <set>
 
 #include "core/fxcrt/include/fx_string.h"
@@ -93,7 +92,6 @@
   friend class CPDF_Parser;
   friend class CPDF_Reference;
   friend class CPDF_Stream;
-  friend struct std::default_delete<CPDF_Object>;
 
   CPDF_Object() : m_ObjNum(0), m_GenNum(0) {}
   virtual ~CPDF_Object();