Minimize includes in fx_memory.h and string_data_template.h.

- Forward declare PartitionAllocatorGeneric in fx_memory.h.
- Move StringDataTemplate impl into string_data_template.cpp.
- Then do IWYU to fix the build.

Change-Id: I55b0bc6818780078a15d0ab7c81458613c3a1a3b
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/69050
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_psengine_unittest.cpp b/core/fpdfapi/page/cpdf_psengine_unittest.cpp
index b449ef7..e7a61f7 100644
--- a/core/fpdfapi/page/cpdf_psengine_unittest.cpp
+++ b/core/fpdfapi/page/cpdf_psengine_unittest.cpp
@@ -5,6 +5,7 @@
 #include <limits>
 
 #include "core/fpdfapi/page/cpdf_psengine.h"
+#include "core/fxcrt/fx_memory.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace {
diff --git a/core/fpdfapi/parser/cpdf_array_unittest.cpp b/core/fpdfapi/parser/cpdf_array_unittest.cpp
index aa8287a..171a7e4 100644
--- a/core/fpdfapi/parser/cpdf_array_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_array_unittest.cpp
@@ -10,6 +10,7 @@
 #include "core/fpdfapi/parser/cpdf_boolean.h"
 #include "core/fpdfapi/parser/cpdf_number.h"
 #include "core/fpdfapi/parser/cpdf_reference.h"
+#include "core/fxcrt/fx_memory.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "third_party/base/ptr_util.h"
 
diff --git a/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp
index 5834d77..a8411a3 100644
--- a/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp
@@ -7,6 +7,7 @@
 #include <string>
 
 #include "core/fpdfapi/parser/fpdf_parser_utility.h"
+#include "core/fxcrt/fx_memory.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "testing/test_support.h"
 #include "third_party/base/span.h"
diff --git a/core/fpdfdoc/cpdf_aaction.cpp b/core/fpdfdoc/cpdf_aaction.cpp
index 8284913..300e94a 100644
--- a/core/fpdfdoc/cpdf_aaction.cpp
+++ b/core/fpdfdoc/cpdf_aaction.cpp
@@ -7,6 +7,7 @@
 #include "core/fpdfdoc/cpdf_aaction.h"
 
 #include "core/fpdfapi/parser/cpdf_dictionary.h"
+#include "core/fxcrt/fx_memory.h"
 
 namespace {
 
diff --git a/core/fpdfdoc/cpdf_defaultappearance_unittest.cpp b/core/fpdfdoc/cpdf_defaultappearance_unittest.cpp
index 6f6c525..252d37e 100644
--- a/core/fpdfdoc/cpdf_defaultappearance_unittest.cpp
+++ b/core/fpdfdoc/cpdf_defaultappearance_unittest.cpp
@@ -4,6 +4,7 @@
 
 #include "core/fpdfdoc/cpdf_defaultappearance.h"
 
+#include "core/fxcrt/fx_memory.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "testing/test_support.h"
 #include "third_party/base/span.h"
diff --git a/core/fpdfdoc/cpdf_dest.cpp b/core/fpdfdoc/cpdf_dest.cpp
index e815c02..47f149b 100644
--- a/core/fpdfdoc/cpdf_dest.cpp
+++ b/core/fpdfdoc/cpdf_dest.cpp
@@ -13,6 +13,7 @@
 #include "core/fpdfapi/parser/cpdf_name.h"
 #include "core/fpdfapi/parser/cpdf_number.h"
 #include "core/fpdfdoc/cpdf_nametree.h"
+#include "core/fxcrt/fx_memory.h"
 
 namespace {
 
diff --git a/core/fpdftext/cpdf_linkextract_unittest.cpp b/core/fpdftext/cpdf_linkextract_unittest.cpp
index f4bd197..014bedb 100644
--- a/core/fpdftext/cpdf_linkextract_unittest.cpp
+++ b/core/fpdftext/cpdf_linkextract_unittest.cpp
@@ -4,6 +4,7 @@
 
 #include "core/fpdftext/cpdf_linkextract.h"
 
+#include "core/fxcrt/fx_memory.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 // Class to help test functions in CPDF_LinkExtract class.
diff --git a/core/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp b/core/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp
index 0d09b31..d006e74 100644
--- a/core/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp
+++ b/core/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp
@@ -9,6 +9,7 @@
 #include <vector>
 
 #include "core/fxcrt/fx_memory.h"
+#include "third_party/base/numerics/safe_math.h"
 
 namespace {
 
diff --git a/core/fxcodec/jpx/jpx_unittest.cpp b/core/fxcodec/jpx/jpx_unittest.cpp
index def5065..7ae60a5 100644
--- a/core/fxcodec/jpx/jpx_unittest.cpp
+++ b/core/fxcodec/jpx/jpx_unittest.cpp
@@ -2,6 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+#include <limits.h>
 #include <stdint.h>
 
 #include <limits>
diff --git a/core/fxcrt/BUILD.gn b/core/fxcrt/BUILD.gn
index b3ea3e1..23d3e78 100644
--- a/core/fxcrt/BUILD.gn
+++ b/core/fxcrt/BUILD.gn
@@ -62,6 +62,7 @@
     "retain_ptr.h",
     "retained_tree_node.h",
     "shared_copy_on_write.h",
+    "string_data_template.cpp",
     "string_data_template.h",
     "string_pool_template.h",
     "string_view_template.h",
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp
index f76df5f..7afd9f3 100644
--- a/core/fxcrt/fx_coordinates.cpp
+++ b/core/fxcrt/fx_coordinates.cpp
@@ -10,6 +10,7 @@
 
 #include "build/build_config.h"
 #include "core/fxcrt/fx_extension.h"
+#include "core/fxcrt/fx_memory.h"
 #include "core/fxcrt/fx_safe_types.h"
 #include "third_party/base/numerics/safe_conversions.h"
 
diff --git a/core/fxcrt/fx_extension_unittest.cpp b/core/fxcrt/fx_extension_unittest.cpp
index 2d265c7..d4163d3 100644
--- a/core/fxcrt/fx_extension_unittest.cpp
+++ b/core/fxcrt/fx_extension_unittest.cpp
@@ -6,6 +6,7 @@
 
 #include <limits>
 
+#include "core/fxcrt/fx_memory.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 TEST(fxcrt, FXSYS_IsLowerASCII) {
diff --git a/core/fxcrt/fx_memory.cpp b/core/fxcrt/fx_memory.cpp
index f2b47f0..22862b2 100644
--- a/core/fxcrt/fx_memory.cpp
+++ b/core/fxcrt/fx_memory.cpp
@@ -12,6 +12,7 @@
 
 #include "build/build_config.h"
 #include "core/fxcrt/fx_safe_types.h"
+#include "third_party/base/allocator/partition_allocator/partition_alloc.h"
 #include "third_party/base/debug/alias.h"
 
 pdfium::base::PartitionAllocatorGeneric& GetArrayBufferPartitionAllocator() {
diff --git a/core/fxcrt/fx_memory.h b/core/fxcrt/fx_memory.h
index 63efd08..b2f582f 100644
--- a/core/fxcrt/fx_memory.h
+++ b/core/fxcrt/fx_memory.h
@@ -22,7 +22,13 @@
 #ifdef __cplusplus
 }  // extern "C"
 
-#include "third_party/base/allocator/partition_allocator/partition_alloc.h"
+#include "third_party/base/compiler_specific.h"
+
+namespace pdfium {
+namespace base {
+class PartitionAllocatorGeneric;
+}  // namespace base
+}  // namespace pdfium
 
 pdfium::base::PartitionAllocatorGeneric& GetArrayBufferPartitionAllocator();
 pdfium::base::PartitionAllocatorGeneric& GetGeneralPartitionAllocator();
diff --git a/core/fxcrt/fx_system_unittest.cpp b/core/fxcrt/fx_system_unittest.cpp
index bc5dbba..63bebc1 100644
--- a/core/fxcrt/fx_system_unittest.cpp
+++ b/core/fxcrt/fx_system_unittest.cpp
@@ -5,6 +5,7 @@
 #include <limits>
 
 #include "build/build_config.h"
+#include "core/fxcrt/fx_memory.h"
 #include "core/fxcrt/fx_string.h"
 #include "core/fxcrt/fx_system.h"
 #include "testing/gtest/include/gtest/gtest.h"
diff --git a/core/fxcrt/string_data_template.cpp b/core/fxcrt/string_data_template.cpp
new file mode 100644
index 0000000..a7cafd2
--- /dev/null
+++ b/core/fxcrt/string_data_template.cpp
@@ -0,0 +1,101 @@
+// Copyright 2020 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fxcrt/string_data_template.h"
+
+#include "core/fxcrt/fx_memory.h"
+#include "third_party/base/allocator/partition_allocator/partition_alloc.h"
+#include "third_party/base/numerics/safe_math.h"
+
+namespace fxcrt {
+
+// static
+template <typename CharType>
+StringDataTemplate<CharType>* StringDataTemplate<CharType>::Create(
+    size_t nLen) {
+  ASSERT(nLen > 0);
+
+  // Calculate space needed for the fixed portion of the struct plus the
+  // NUL char that is not included in |m_nAllocLength|.
+  int overhead = offsetof(StringDataTemplate, m_String) + sizeof(CharType);
+  pdfium::base::CheckedNumeric<size_t> nSize = nLen;
+  nSize *= sizeof(CharType);
+  nSize += overhead;
+
+  // Now round to an 8-byte boundary. We'd expect that this is the minimum
+  // granularity of any of the underlying allocators, so there may be cases
+  // where we can save a re-alloc when adding a few characters to a string
+  // by using this otherwise wasted space.
+  nSize += 7;
+  nSize &= ~7;
+  size_t totalSize = nSize.ValueOrDie();
+  size_t usableLen = (totalSize - overhead) / sizeof(CharType);
+  ASSERT(usableLen >= nLen);
+
+  void* pData = GetStringPartitionAllocator().root()->Alloc(
+      totalSize, "StringDataTemplate");
+  return new (pData) StringDataTemplate(nLen, usableLen);
+}
+
+// static
+template <typename CharType>
+StringDataTemplate<CharType>* StringDataTemplate<CharType>::Create(
+    const CharType* pStr,
+    size_t nLen) {
+  StringDataTemplate* result = Create(nLen);
+  result->CopyContents(pStr, nLen);
+  return result;
+}
+
+template <typename CharType>
+void StringDataTemplate<CharType>::Release() {
+  if (--m_nRefs <= 0)
+    GetStringPartitionAllocator().root()->Free(this);
+}
+
+template <typename CharType>
+void StringDataTemplate<CharType>::CopyContents(
+    const StringDataTemplate& other) {
+  ASSERT(other.m_nDataLength <= m_nAllocLength);
+  memcpy(m_String, other.m_String,
+         (other.m_nDataLength + 1) * sizeof(CharType));
+}
+
+template <typename CharType>
+void StringDataTemplate<CharType>::CopyContents(const CharType* pStr,
+                                                size_t nLen) {
+  ASSERT(nLen >= 0);
+  ASSERT(nLen <= m_nAllocLength);
+
+  memcpy(m_String, pStr, nLen * sizeof(CharType));
+  m_String[nLen] = 0;
+}
+
+template <typename CharType>
+void StringDataTemplate<CharType>::CopyContentsAt(size_t offset,
+                                                  const CharType* pStr,
+                                                  size_t nLen) {
+  ASSERT(offset >= 0);
+  ASSERT(nLen >= 0);
+  ASSERT(offset + nLen <= m_nAllocLength);
+
+  memcpy(m_String + offset, pStr, nLen * sizeof(CharType));
+  m_String[offset + nLen] = 0;
+}
+
+template <typename CharType>
+StringDataTemplate<CharType>::StringDataTemplate(size_t dataLen,
+                                                 size_t allocLen)
+    : m_nRefs(0), m_nDataLength(dataLen), m_nAllocLength(allocLen) {
+  ASSERT(dataLen >= 0);
+  ASSERT(dataLen <= allocLen);
+  m_String[dataLen] = 0;
+}
+
+template class StringDataTemplate<char>;
+template class StringDataTemplate<wchar_t>;
+
+}  // namespace fxcrt
diff --git a/core/fxcrt/string_data_template.h b/core/fxcrt/string_data_template.h
index cda41e0..da471af 100644
--- a/core/fxcrt/string_data_template.h
+++ b/core/fxcrt/string_data_template.h
@@ -7,78 +7,26 @@
 #ifndef CORE_FXCRT_STRING_DATA_TEMPLATE_H_
 #define CORE_FXCRT_STRING_DATA_TEMPLATE_H_
 
-#include "core/fxcrt/fx_memory.h"
 #include "core/fxcrt/fx_system.h"
-#include "third_party/base/numerics/safe_math.h"
 
 namespace fxcrt {
 
 template <typename CharType>
 class StringDataTemplate {
  public:
-  static StringDataTemplate* Create(size_t nLen) {
-    ASSERT(nLen > 0);
-
-    // Calculate space needed for the fixed portion of the struct plus the
-    // NUL char that is not included in |m_nAllocLength|.
-    int overhead = offsetof(StringDataTemplate, m_String) + sizeof(CharType);
-    pdfium::base::CheckedNumeric<size_t> nSize = nLen;
-    nSize *= sizeof(CharType);
-    nSize += overhead;
-
-    // Now round to an 8-byte boundary. We'd expect that this is the minimum
-    // granularity of any of the underlying allocators, so there may be cases
-    // where we can save a re-alloc when adding a few characters to a string
-    // by using this otherwise wasted space.
-    nSize += 7;
-    nSize &= ~7;
-    size_t totalSize = nSize.ValueOrDie();
-    size_t usableLen = (totalSize - overhead) / sizeof(CharType);
-    ASSERT(usableLen >= nLen);
-
-    void* pData = GetStringPartitionAllocator().root()->Alloc(
-        totalSize, "StringDataTemplate");
-    return new (pData) StringDataTemplate(nLen, usableLen);
-  }
-
-  static StringDataTemplate* Create(const CharType* pStr, size_t nLen) {
-    StringDataTemplate* result = Create(nLen);
-    result->CopyContents(pStr, nLen);
-    return result;
-  }
+  static StringDataTemplate* Create(size_t nLen);
+  static StringDataTemplate* Create(const CharType* pStr, size_t nLen);
 
   void Retain() { ++m_nRefs; }
-  void Release() {
-    if (--m_nRefs <= 0)
-      GetStringPartitionAllocator().root()->Free(this);
-  }
+  void Release();
 
   bool CanOperateInPlace(size_t nTotalLen) const {
     return m_nRefs <= 1 && nTotalLen <= m_nAllocLength;
   }
 
-  void CopyContents(const StringDataTemplate& other) {
-    ASSERT(other.m_nDataLength <= m_nAllocLength);
-    memcpy(m_String, other.m_String,
-           (other.m_nDataLength + 1) * sizeof(CharType));
-  }
-
-  void CopyContents(const CharType* pStr, size_t nLen) {
-    ASSERT(nLen >= 0);
-    ASSERT(nLen <= m_nAllocLength);
-
-    memcpy(m_String, pStr, nLen * sizeof(CharType));
-    m_String[nLen] = 0;
-  }
-
-  void CopyContentsAt(size_t offset, const CharType* pStr, size_t nLen) {
-    ASSERT(offset >= 0);
-    ASSERT(nLen >= 0);
-    ASSERT(offset + nLen <= m_nAllocLength);
-
-    memcpy(m_String + offset, pStr, nLen * sizeof(CharType));
-    m_String[offset + nLen] = 0;
-  }
+  void CopyContents(const StringDataTemplate& other);
+  void CopyContents(const CharType* pStr, size_t nLen);
+  void CopyContentsAt(size_t offset, const CharType* pStr, size_t nLen);
 
   // To ensure ref counts do not overflow, consider the worst possible case:
   // the entire address space contains nothing but pointers to this object.
@@ -97,19 +45,10 @@
   CharType m_String[1];
 
  private:
-  StringDataTemplate(size_t dataLen, size_t allocLen)
-      : m_nRefs(0), m_nDataLength(dataLen), m_nAllocLength(allocLen) {
-    ASSERT(dataLen >= 0);
-    ASSERT(dataLen <= allocLen);
-    m_String[dataLen] = 0;
-  }
-
+  StringDataTemplate(size_t dataLen, size_t allocLen);
   ~StringDataTemplate() = delete;
 };
 
-extern template class StringDataTemplate<char>;
-extern template class StringDataTemplate<wchar_t>;
-
 }  // namespace fxcrt
 
 using fxcrt::StringDataTemplate;
diff --git a/core/fxcrt/widestring_unittest.cpp b/core/fxcrt/widestring_unittest.cpp
index 1043b5d..08d061f 100644
--- a/core/fxcrt/widestring_unittest.cpp
+++ b/core/fxcrt/widestring_unittest.cpp
@@ -9,6 +9,7 @@
 #include <vector>
 
 #include "build/build_config.h"
+#include "core/fxcrt/fx_memory.h"
 #include "core/fxcrt/fx_string.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "third_party/base/span.h"
diff --git a/fpdfsdk/fpdf_annot_embeddertest.cpp b/fpdfsdk/fpdf_annot_embeddertest.cpp
index 0fb5084..5438519 100644
--- a/fpdfsdk/fpdf_annot_embeddertest.cpp
+++ b/fpdfsdk/fpdf_annot_embeddertest.cpp
@@ -23,6 +23,7 @@
 #include "testing/gtest/include/gtest/gtest.h"
 #include "testing/utils/hash.h"
 #include "third_party/base/span.h"
+#include "third_party/base/stl_util.h"
 
 namespace {
 
diff --git a/fpdfsdk/fpdf_formfill_embeddertest.cpp b/fpdfsdk/fpdf_formfill_embeddertest.cpp
index 59928a9..aef5c61 100644
--- a/fpdfsdk/fpdf_formfill_embeddertest.cpp
+++ b/fpdfsdk/fpdf_formfill_embeddertest.cpp
@@ -8,6 +8,7 @@
 
 #include "build/build_config.h"
 #include "core/fxcrt/fx_coordinates.h"
+#include "core/fxcrt/fx_memory.h"
 #include "core/fxcrt/fx_string.h"
 #include "core/fxcrt/fx_system.h"
 #include "public/cpp/fpdf_scopers.h"
diff --git a/fpdfsdk/fpdf_structtree_embeddertest.cpp b/fpdfsdk/fpdf_structtree_embeddertest.cpp
index f527877..f44fdd1 100644
--- a/fpdfsdk/fpdf_structtree_embeddertest.cpp
+++ b/fpdfsdk/fpdf_structtree_embeddertest.cpp
@@ -2,6 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+#include "core/fxcrt/fx_memory.h"
 #include "core/fxcrt/fx_string.h"
 #include "public/fpdf_structtree.h"
 #include "testing/embedder_test.h"
diff --git a/fpdfsdk/pwl/cpwl_scroll_bar.cpp b/fpdfsdk/pwl/cpwl_scroll_bar.cpp
index 35b0a55..8fb7f58 100644
--- a/fpdfsdk/pwl/cpwl_scroll_bar.cpp
+++ b/fpdfsdk/pwl/cpwl_scroll_bar.cpp
@@ -11,6 +11,7 @@
 #include <utility>
 #include <vector>
 
+#include "core/fxcrt/fx_memory.h"
 #include "core/fxge/cfx_pathdata.h"
 #include "core/fxge/cfx_renderdevice.h"
 #include "fpdfsdk/pwl/cpwl_wnd.h"
diff --git a/fxbarcode/datamatrix/BC_C40Encoder.cpp b/fxbarcode/datamatrix/BC_C40Encoder.cpp
index 9e18a76..0ee471b 100644
--- a/fxbarcode/datamatrix/BC_C40Encoder.cpp
+++ b/fxbarcode/datamatrix/BC_C40Encoder.cpp
@@ -23,6 +23,7 @@
 #include "fxbarcode/datamatrix/BC_C40Encoder.h"
 
 #include "core/fxcrt/fx_extension.h"
+#include "core/fxcrt/fx_memory.h"
 #include "fxbarcode/common/BC_CommonBitMatrix.h"
 #include "fxbarcode/datamatrix/BC_Encoder.h"
 #include "fxbarcode/datamatrix/BC_EncoderContext.h"
diff --git a/fxbarcode/oned/BC_OnedCodaBarWriter.cpp b/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
index d87125f..2021a8a 100644
--- a/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
+++ b/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
@@ -23,6 +23,7 @@
 #include "fxbarcode/oned/BC_OnedCodaBarWriter.h"
 
 #include "core/fxcrt/fx_extension.h"
+#include "core/fxcrt/fx_memory.h"
 #include "fxbarcode/BC_Writer.h"
 #include "fxbarcode/common/BC_CommonBitMatrix.h"
 #include "fxbarcode/oned/BC_OneDimWriter.h"
diff --git a/fxbarcode/oned/BC_OnedCodaBarWriter_unittest.cpp b/fxbarcode/oned/BC_OnedCodaBarWriter_unittest.cpp
index 89b0ac8..600959c 100644
--- a/fxbarcode/oned/BC_OnedCodaBarWriter_unittest.cpp
+++ b/fxbarcode/oned/BC_OnedCodaBarWriter_unittest.cpp
@@ -4,6 +4,7 @@
 
 #include "fxbarcode/oned/BC_OnedCodaBarWriter.h"
 
+#include "core/fxcrt/fx_memory.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace {
diff --git a/fxbarcode/oned/BC_OnedCode128Writer_unittest.cpp b/fxbarcode/oned/BC_OnedCode128Writer_unittest.cpp
index c85cdfd..3de3b60 100644
--- a/fxbarcode/oned/BC_OnedCode128Writer_unittest.cpp
+++ b/fxbarcode/oned/BC_OnedCode128Writer_unittest.cpp
@@ -4,6 +4,7 @@
 
 #include "fxbarcode/oned/BC_OnedCode128Writer.h"
 
+#include "core/fxcrt/fx_memory.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace {
diff --git a/fxbarcode/oned/BC_OnedCode39Writer_unittest.cpp b/fxbarcode/oned/BC_OnedCode39Writer_unittest.cpp
index e263d59..7bf17a4 100644
--- a/fxbarcode/oned/BC_OnedCode39Writer_unittest.cpp
+++ b/fxbarcode/oned/BC_OnedCode39Writer_unittest.cpp
@@ -6,6 +6,7 @@
 
 #include <cstring>
 
+#include "core/fxcrt/fx_memory.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace {
diff --git a/fxbarcode/oned/BC_OnedEAN13Writer_unittest.cpp b/fxbarcode/oned/BC_OnedEAN13Writer_unittest.cpp
index 55746ba..09bf296 100644
--- a/fxbarcode/oned/BC_OnedEAN13Writer_unittest.cpp
+++ b/fxbarcode/oned/BC_OnedEAN13Writer_unittest.cpp
@@ -4,6 +4,7 @@
 
 #include "fxbarcode/oned/BC_OnedEAN13Writer.h"
 
+#include "core/fxcrt/fx_memory.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace {
diff --git a/fxbarcode/oned/BC_OnedEAN8Writer_unittest.cpp b/fxbarcode/oned/BC_OnedEAN8Writer_unittest.cpp
index ae1b823..c537919 100644
--- a/fxbarcode/oned/BC_OnedEAN8Writer_unittest.cpp
+++ b/fxbarcode/oned/BC_OnedEAN8Writer_unittest.cpp
@@ -4,6 +4,7 @@
 
 #include "fxbarcode/oned/BC_OnedEAN8Writer.h"
 
+#include "core/fxcrt/fx_memory.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace {
diff --git a/fxbarcode/oned/BC_OnedUPCAWriter_unittest.cpp b/fxbarcode/oned/BC_OnedUPCAWriter_unittest.cpp
index c5acd23..8f11072 100644
--- a/fxbarcode/oned/BC_OnedUPCAWriter_unittest.cpp
+++ b/fxbarcode/oned/BC_OnedUPCAWriter_unittest.cpp
@@ -4,6 +4,7 @@
 
 #include "fxbarcode/oned/BC_OnedUPCAWriter.h"
 
+#include "core/fxcrt/fx_memory.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace {
diff --git a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp
index 4ca5c8b..822f376 100644
--- a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp
+++ b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp
@@ -4,6 +4,9 @@
 
 #include "fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h"
 
+#include <vector>
+
+#include "core/fxcrt/fx_memory.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 TEST(PDF417HighLevelEncoderTest, EncodeHighLevel) {
diff --git a/fxjs/cjs_globalarrays.cpp b/fxjs/cjs_globalarrays.cpp
index 9cf540e..b95861d 100644
--- a/fxjs/cjs_globalarrays.cpp
+++ b/fxjs/cjs_globalarrays.cpp
@@ -6,6 +6,8 @@
 
 #include "fxjs/cjs_globalarrays.h"
 
+#include "core/fxcrt/fx_memory.h"
+
 #define GLOBAL_ARRAY(rt, name, ...)                                          \
   {                                                                          \
     static const wchar_t* const values[] = {__VA_ARGS__};                    \
diff --git a/fxjs/cjs_publicmethods_unittest.cpp b/fxjs/cjs_publicmethods_unittest.cpp
index 1d72418..739c031 100644
--- a/fxjs/cjs_publicmethods_unittest.cpp
+++ b/fxjs/cjs_publicmethods_unittest.cpp
@@ -4,6 +4,7 @@
 
 #include "fxjs/cjs_publicmethods.h"
 
+#include "core/fxcrt/fx_memory.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 TEST(CJS_PublicMethods, IsNumber) {
diff --git a/fxjs/cjs_util.cpp b/fxjs/cjs_util.cpp
index 1f95c31..2f174fa 100644
--- a/fxjs/cjs_util.cpp
+++ b/fxjs/cjs_util.cpp
@@ -15,6 +15,7 @@
 
 #include "build/build_config.h"
 #include "core/fxcrt/fx_extension.h"
+#include "core/fxcrt/fx_memory.h"
 #include "fxjs/cjs_event_context.h"
 #include "fxjs/cjs_eventrecorder.h"
 #include "fxjs/cjs_object.h"
diff --git a/fxjs/cjs_util_unittest.cpp b/fxjs/cjs_util_unittest.cpp
index d405746..7c10571 100644
--- a/fxjs/cjs_util_unittest.cpp
+++ b/fxjs/cjs_util_unittest.cpp
@@ -4,6 +4,7 @@
 
 #include "fxjs/cjs_util.h"
 
+#include "core/fxcrt/fx_memory.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 TEST(CJS_Util, ParseDataType) {
diff --git a/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp b/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp
index 19fc730..7ac25c0 100644
--- a/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp
+++ b/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp
@@ -2,6 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+#include "core/fxcrt/fx_memory.h"
 #include "fxjs/xfa/cfxjse_engine.h"
 #include "fxjs/xfa/cfxjse_value.h"
 #include "testing/gtest/include/gtest/gtest.h"
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index 64006b3..e62ad86 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -10,6 +10,7 @@
 #include <tuple>
 
 #include "core/fxcrt/fx_extension.h"
+#include "core/fxcrt/fx_memory.h"
 #include "core/fxcrt/xml/cfx_xmlelement.h"
 #include "core/fxcrt/xml/cfx_xmltext.h"
 #include "fxjs/cjs_result.h"
diff --git a/xfa/fgas/crt/cfgas_stringformatter.cpp b/xfa/fgas/crt/cfgas_stringformatter.cpp
index 1c640b9..1f01f73 100644
--- a/xfa/fgas/crt/cfgas_stringformatter.cpp
+++ b/xfa/fgas/crt/cfgas_stringformatter.cpp
@@ -12,6 +12,7 @@
 #include <vector>
 
 #include "core/fxcrt/fx_extension.h"
+#include "core/fxcrt/fx_memory.h"
 #include "core/fxcrt/fx_safe_types.h"
 #include "third_party/base/stl_util.h"
 #include "xfa/fgas/crt/cfgas_decimal.h"
diff --git a/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp b/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp
index 8a9e60c..0c8fbd4 100644
--- a/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp
+++ b/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp
@@ -12,6 +12,7 @@
 
 #include "build/build_config.h"
 #include "core/fpdfapi/page/cpdf_pagemodule.h"
+#include "core/fxcrt/fx_memory.h"
 #include "testing/fx_string_testhelpers.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "third_party/base/ptr_util.h"
diff --git a/xfa/fgas/font/fgas_fontutils.cpp b/xfa/fgas/font/fgas_fontutils.cpp
index cc6c922..a733583 100644
--- a/xfa/fgas/font/fgas_fontutils.cpp
+++ b/xfa/fgas/font/fgas_fontutils.cpp
@@ -9,6 +9,7 @@
 #include "build/build_config.h"
 #include "core/fxcrt/fx_codepage.h"
 #include "core/fxcrt/fx_extension.h"
+#include "core/fxcrt/fx_memory.h"
 #include "xfa/fgas/font/cfgas_fontmgr.h"
 
 namespace {
diff --git a/xfa/fgas/layout/cfx_char.cpp b/xfa/fgas/layout/cfx_char.cpp
index 311aff4..13f1cc9 100644
--- a/xfa/fgas/layout/cfx_char.cpp
+++ b/xfa/fgas/layout/cfx_char.cpp
@@ -9,6 +9,7 @@
 #include <algorithm>
 
 #include "core/fxcrt/fx_extension.h"
+#include "core/fxcrt/fx_memory.h"
 
 namespace {
 
diff --git a/xfa/fwl/theme/cfwl_widgettp.cpp b/xfa/fwl/theme/cfwl_widgettp.cpp
index 27caf99..677f6b8 100644
--- a/xfa/fwl/theme/cfwl_widgettp.cpp
+++ b/xfa/fwl/theme/cfwl_widgettp.cpp
@@ -9,6 +9,7 @@
 #include <algorithm>
 #include <utility>
 
+#include "core/fxcrt/fx_memory.h"
 #include "core/fxge/render_defines.h"
 #include "third_party/base/ptr_util.h"
 #include "xfa/fde/cfde_textout.h"
diff --git a/xfa/fxfa/cxfa_fffield.cpp b/xfa/fxfa/cxfa_fffield.cpp
index 4f5bf56..1b7afeb 100644
--- a/xfa/fxfa/cxfa_fffield.cpp
+++ b/xfa/fxfa/cxfa_fffield.cpp
@@ -9,6 +9,7 @@
 #include <algorithm>
 #include <utility>
 
+#include "core/fxcrt/fx_memory.h"
 #include "core/fxge/render_defines.h"
 #include "third_party/base/ptr_util.h"
 #include "xfa/fwl/cfwl_edit.h"
diff --git a/xfa/fxfa/cxfa_fwltheme.cpp b/xfa/fxfa/cxfa_fwltheme.cpp
index 4c2c8da..dd35664 100644
--- a/xfa/fxfa/cxfa_fwltheme.cpp
+++ b/xfa/fxfa/cxfa_fwltheme.cpp
@@ -7,6 +7,7 @@
 #include "xfa/fxfa/cxfa_fwltheme.h"
 
 #include "core/fxcrt/fx_codepage.h"
+#include "core/fxcrt/fx_memory.h"
 #include "third_party/base/ptr_util.h"
 #include "xfa/fde/cfde_textout.h"
 #include "xfa/fgas/font/cfgas_gefont.h"
diff --git a/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp b/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp
index 3627e15..1ce0493 100644
--- a/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp
@@ -6,6 +6,7 @@
 
 #include <vector>
 
+#include "core/fxcrt/fx_memory.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "third_party/base/ptr_util.h"
 
diff --git a/xfa/fxfa/parser/cxfa_stroke.cpp b/xfa/fxfa/parser/cxfa_stroke.cpp
index 65301c0..894ea1a 100644
--- a/xfa/fxfa/parser/cxfa_stroke.cpp
+++ b/xfa/fxfa/parser/cxfa_stroke.cpp
@@ -8,6 +8,7 @@
 
 #include <utility>
 
+#include "core/fxcrt/fx_memory.h"
 #include "fxjs/xfa/cjx_object.h"
 #include "xfa/fxfa/cxfa_ffwidget.h"
 #include "xfa/fxfa/parser/cxfa_color.h"
diff --git a/xfa/fxfa/parser/xfa_utils_unittest.cpp b/xfa/fxfa/parser/xfa_utils_unittest.cpp
index e4d6cb8..77f21bc 100644
--- a/xfa/fxfa/parser/xfa_utils_unittest.cpp
+++ b/xfa/fxfa/parser/xfa_utils_unittest.cpp
@@ -4,6 +4,7 @@
 
 #include "xfa/fxfa/parser/xfa_utils.h"
 
+#include "core/fxcrt/fx_memory.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 TEST(XfaUtilsImpTest, XFA_MapRotation) {