Update googleurl from upstream

This updates googleurl to use the Chromium upstream version
70f03f8a864da80522f06826d9a985af57699b5e from
Wed Feb 8 00:23:59 2023 +0000.

Change-Id: I951d632f26d01f3226d2f2a34487804f5592ea8f
diff --git a/AUTHORS b/AUTHORS
index a2016b0..ac46f9f 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -232,7 +232,6 @@
 Charles Vaughn <cvaughn@gmail.com>
 Cheng Zhao <zcbenz@gmail.com>
 Cheng Yu <yuzichengcode@gmail.com>
-Cheung Ho <uioptt24@gmail.com>
 Choongwoo Han <cwhan.tunz@gmail.com>
 Choudhury M. Shamsujjoha <choudhury.s@samsung.com>
 Chris Greene <cwgreene@amazon.com>
@@ -278,6 +277,7 @@
 Dániel Bátyai <dbatyai@inf.u-szeged.hu>
 Dániel Vince <vinced@inf.u-szeged.hu>
 Daniil Suvorov <severecloud@gmail.com>
+Danny Weiss <danny.weiss.fr@gmail.com>
 Daoming Qiu <daoming.qiu@intel.com>
 Darik Harter <darik.harter@gmail.com>
 Darshan Sen <raisinten@gmail.com>
@@ -377,6 +377,7 @@
 Felipe Erias Morandeira <felipeerias@gmail.com>
 Felix H. Dahlke <fhd@ubercode.de>
 Felix Weilbach <feweilbach@gmail.com>
+Feng Shengyuan <fengshengyuan@agora.io>
 Feng Yu <f3n67u@gmail.com>
 Fengrong Fang <fr.fang@samsung.com>
 Fernando Jiménez Moreno <ferjmoreno@gmail.com>
@@ -449,8 +450,10 @@
 Henrique de Carvalho <decarv.henrique@gmail.com>
 Henrique Limas <henrique.ramos.limas@gmail.com>
 Himanshu Joshi <h.joshi@samsung.com>
+Himanshu Nayak <himanshu.nayak@amd.corp-partner.google.com>
 Hiroki Oshima <hiroki.oshima@gmail.com>
 Hiroyuki Matsuda <gsittyz@gmail.com>
+Ho Cheung <uioptt24@gmail.com>
 Hodol Han <bab6ting@gmail.com>
 Holger Kraus <kraush@amazon.com>
 Hong Zheng <hong.zheng@intel.com>
@@ -604,6 +607,7 @@
 John Yani <vanuan@gmail.com>
 John Yoo <nearbyh13@gmail.com>
 Johnson Lin <johnson.lin@intel.com>
+Jon Jensen <jonj@netflix.com>
 Jonathan Frazer <listedegarde@gmail.com>
 Jonathan Garbee <jonathan@garbee.me>
 Jonathan Hacker <jhacker@arcanefour.com>
@@ -718,6 +722,7 @@
 Kyungsun Lee <kyungsuny.lee@gmail.com>
 Kyungtae Kim <ktf.kim@samsung.com>
 Kyungyoung Heo <bbvch13531@gmail.com>
+Kyutae Lee <gorisanson@gmail.com>
 Lalit Chandivade <lalit.chandivade@einfochips.com>
 Lam Lu <lamlu@amazon.com>
 Laszlo Gombos <l.gombos@samsung.com>
@@ -760,7 +765,7 @@
 Luke Zarko <lukezarko@gmail.com>
 Luoxi Pan <l.panpax@gmail.com>
 Lu Yahan <yahan@iscas.ac.cn>
-Ma Aiguo <maaiguo@uniontech.com>
+Ma Aiguo <imaiguo@gmail.com>
 Maarten Lankhorst <m.b.lankhorst@gmail.com>
 Maciej Pawlowski <m.pawlowski@eyeo.com>
 Magnus Danielsson <fuzzac@gmail.com>
@@ -855,6 +860,7 @@
 Mingeun Park <mindal99546@gmail.com>
 Minggang Wang <minggang.wang@intel.com>
 Mingmin Xie <melvinxie@gmail.com>
+Mingming Xu <mingming1.xu@intel.com>
 Minjeong Kim <deoxyribonucleicacid150@gmail.com>
 Minjeong Lee <apenr1234@gmail.com>
 Minseok Koo <kei98301@gmail.com>
@@ -1196,6 +1202,7 @@
 Suyash Sengar <suyash.s@samsung.com>
 Swarali Raut <swarali.sr@samsung.com>
 Swati Jaiswal <swa.jaiswal@samsung.com>
+Syed Wajid <syed.wajid@samsung.com>
 Sylvain Zimmer <sylvinus@gmail.com>
 Sylvestre Ledru <sylvestre.ledru@gmail.com>
 Synthia Islam <synthia.is@samsung.com>
@@ -1327,7 +1334,9 @@
 Yang Liu <jd9668954@gmail.com>
 Yannic Bonenberger <yannic.bonenberger@gmail.com>
 Yarin Kaul <yarin.kaul@gmail.com>
+Yash Joshi <yashjoshimail@gmail.com>
 Yash Vempati <vempatiy@amazon.com>
+Yash Vinayak <yash.vinayak@samsung.com>
 Ye Liu <cbakgly@gmail.com>
 Yeol Park <peary2@gmail.com>
 Yeonwoo Jo <yeonwoo.jo.92@gmail.com>
@@ -1378,6 +1387,7 @@
 Zeqin Chen <talonchen@tencent.com>
 Zhang Hao <zhanghao.m@bytedance.com>
 Zhang Hao <15686357310a@gmail.com>
+Zhaoming Jiang <zhaoming.jiang@intel.com>
 Zhaoze Zhou <zhaoze.zhou@partner.samsung.com>
 Zheda Chen <zheda.chen@intel.com>
 Zheng Chuang <zhengchuangscu@gmail.com>
diff --git a/base/compiler_specific.h b/base/compiler_specific.h
index 0174b6d..8085338 100644
--- a/base/compiler_specific.h
+++ b/base/compiler_specific.h
@@ -64,7 +64,7 @@
 // folding of multiple identical caller functions into a single signature. To
 // prevent code folding, see NO_CODE_FOLDING() in base/debug/alias.h.
 // Use like:
-//   void NOT_TAIL_CALLED FooBar();
+//   NOT_TAIL_CALLED void FooBar();
 #if defined(__clang__) && HAS_ATTRIBUTE(not_tail_called)
 #define NOT_TAIL_CALLED __attribute__((not_tail_called))
 #else
diff --git a/base/containers/checked_iterators.h b/base/containers/checked_iterators.h
index dc8d2ba..0cd2832 100644
--- a/base/containers/checked_iterators.h
+++ b/base/containers/checked_iterators.h
@@ -11,6 +11,7 @@
 
 #include "polyfills/base/check_op.h"
 #include "base/containers/util.h"
+#include "polyfills/base/memory/raw_ptr_exclusion.h"
 #include "build/build_config.h"
 
 namespace gurl_base {
@@ -207,9 +208,15 @@
     GURL_CHECK_EQ(end_, other.end_);
   }
 
-  const T* start_ = nullptr;
-  T* current_ = nullptr;
-  const T* end_ = nullptr;
+  // This field is not a raw_ptr<> because it was filtered by the rewriter for:
+  // #union, #constexpr-ctor-field-initializer
+  RAW_PTR_EXCLUSION const T* start_ = nullptr;
+  // This field is not a raw_ptr<> because it was filtered by the rewriter for:
+  // #union, #constexpr-ctor-field-initializer
+  RAW_PTR_EXCLUSION T* current_ = nullptr;
+  // This field is not a raw_ptr<> because it was filtered by the rewriter for:
+  // #union, #constexpr-ctor-field-initializer
+  RAW_PTR_EXCLUSION const T* end_ = nullptr;
 };
 
 template <typename T>
diff --git a/base/containers/span.h b/base/containers/span.h
index 40e325f..1496611 100644
--- a/base/containers/span.h
+++ b/base/containers/span.h
@@ -18,6 +18,7 @@
 #include "base/containers/checked_iterators.h"
 #include "base/containers/contiguous_iterator.h"
 #include "base/cxx20_to_address.h"
+#include "base/numerics/safe_math.h"
 
 namespace gurl_base {
 
@@ -256,16 +257,16 @@
 
   template <typename It,
             typename = internal::EnableIfCompatibleContiguousIterator<It, T>>
-  constexpr span(It first, size_t count) noexcept
+  constexpr span(It first, StrictNumeric<size_t> count) noexcept
       : ExtentStorage(count),
         // The use of to_address() here is to handle the case where the iterator
         // `first` is pointing to the container's `end()`. In that case we can
         // not use the address returned from the iterator, or dereference it
-        // through the iterator's `operator*`, but we can store it. We must assume
-        // in this case that `count` is 0, since the iterator does not point to
-        // valid data. Future hardening of iterators may disallow pulling the
-        // address from `end()`, as demonstrated by asserts() in libstdc++:
-        // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93960.
+        // through the iterator's `operator*`, but we can store it. We must
+        // assume in this case that `count` is 0, since the iterator does not
+        // point to valid data. Future hardening of iterators may disallow
+        // pulling the address from `end()`, as demonstrated by asserts() in
+        // libstdc++: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93960.
         //
         // The span API dictates that the `data()` is accessible when size is 0,
         // since the pointer may be valid, so we cannot prevent storing and
@@ -473,7 +474,7 @@
 
 // Type-deducing helpers for constructing a span.
 template <int&... ExplicitArgumentBarrier, typename It>
-constexpr auto make_span(It it, size_t size) noexcept {
+constexpr auto make_span(It it, StrictNumeric<size_t> size) noexcept {
   using T = std::remove_reference_t<iter_reference_t<It>>;
   return span<T>(it, size);
 }
@@ -508,7 +509,7 @@
 //
 // Usage: auto static_span = gurl_base::make_span<N>(...);
 template <size_t N, int&... ExplicitArgumentBarrier, typename It>
-constexpr auto make_span(It it, size_t size) noexcept {
+constexpr auto make_span(It it, StrictNumeric<size_t> size) noexcept {
   using T = std::remove_reference_t<iter_reference_t<It>>;
   return span<T, N>(it, size);
 }
diff --git a/base/cxx17_backports.h b/base/cxx17_backports.h
index ce59af0..a784f84 100644
--- a/base/cxx17_backports.h
+++ b/base/cxx17_backports.h
@@ -5,27 +5,13 @@
 #ifndef BASE_CXX17_BACKPORTS_H_
 #define BASE_CXX17_BACKPORTS_H_
 
-#include <functional>
-
-#include "polyfills/base/check.h"
+#include <algorithm>
 
 namespace gurl_base {
 
-// C++14 implementation of C++17's std::clamp():
-// https://en.cppreference.com/w/cpp/algorithm/clamp
-// Please note that the C++ spec makes it undefined behavior to call std::clamp
-// with a value of `lo` that compares greater than the value of `hi`. This
-// implementation uses a GURL_CHECK to enforce this as a hard restriction.
-template <typename T, typename Compare>
-constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp) {
-  GURL_CHECK(!comp(hi, lo));
-  return comp(v, lo) ? lo : comp(hi, v) ? hi : v;
-}
-
-template <typename T>
-constexpr const T& clamp(const T& v, const T& lo, const T& hi) {
-  return gurl_base::clamp(v, lo, hi, std::less<T>{});
-}
+// TODO(crbug.com/1373621): Rewrite all uses of gurl_base::clamp as std::clamp and
+// remove this file.
+using std::clamp;
 
 }  // namespace base
 
diff --git a/base/memory/raw_ptr_exclusion.h b/base/memory/raw_ptr_exclusion.h
index 2a30e26..3ce1d60 100644
--- a/base/memory/raw_ptr_exclusion.h
+++ b/base/memory/raw_ptr_exclusion.h
@@ -1,27 +1,13 @@
-// Copyright 2022 The Chromium Authors
+// Copyright 2023 The Chromium Authors
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
 #ifndef BASE_MEMORY_RAW_PTR_EXCLUSION_H_
 #define BASE_MEMORY_RAW_PTR_EXCLUSION_H_
 
-#include "polyfills/base/allocator/buildflags.h"
-#include "base/compiler_specific.h"
-#include "build/build_config.h"
-
-#if HAS_ATTRIBUTE(annotate)
-#if defined(OFFICIAL_BUILD) && !BUILDFLAG(FORCE_ENABLE_RAW_PTR_EXCLUSION)
-// The annotation changed compiler output and increased binary size so disable
-// for official builds.
-// TODO(crbug.com/1320670): Remove when issue is resolved.
-#define RAW_PTR_EXCLUSION
-#else
-// Marks a field as excluded from the raw_ptr usage enforcement clang plugin.
-// Example: RAW_PTR_EXCLUSION Foo* foo_;
-#define RAW_PTR_EXCLUSION __attribute__((annotate("raw_ptr_exclusion")))
-#endif
-#else
-#define RAW_PTR_EXCLUSION
-#endif
+// Although `raw_ptr` is part of the standalone PA distribution, it is
+// easier to use the shorter path in `//base/memory`. We retain this
+// facade header for ease of typing.
+#include "base/allocator/partition_allocator/pointers/raw_ptr_exclusion.h"  // IWYU pragma: export
 
 #endif  // BASE_MEMORY_RAW_PTR_EXCLUSION_H_
diff --git a/base/numerics/safe_conversions.h b/base/numerics/safe_conversions.h
index 4a9494e..3e04bf4 100644
--- a/base/numerics/safe_conversions.h
+++ b/base/numerics/safe_conversions.h
@@ -20,10 +20,6 @@
 #define BASE_HAS_OPTIMIZED_SAFE_CONVERSIONS (0)
 #endif
 
-#if !BASE_NUMERICS_DISABLE_OSTREAM_OPERATORS
-#include <ostream>
-#endif
-
 namespace gurl_base {
 namespace internal {
 
diff --git a/base/strings/safe_sprintf.cc b/base/strings/safe_sprintf.cc
index 0b53dff..f30360b 100644
--- a/base/strings/safe_sprintf.cc
+++ b/base/strings/safe_sprintf.cc
@@ -418,18 +418,19 @@
     }
   } while (num || padding || (reverse_prefix > prefix));
 
-  // Conversion to ASCII actually resulted in the digits being in reverse
-  // order. We can't easily generate them in forward order, as we can't tell
-  // the number of characters needed until we are done converting.
-  // So, now, we reverse the string (except for the possible '-' sign).
-  char* front = buffer_ + start;
-  char* back = GetInsertionPoint();
-  while (--back > front) {
-    char ch = *back;
-    *back = *front;
-    *front++ = ch;
+  if (start < size_) {
+    // Conversion to ASCII actually resulted in the digits being in reverse
+    // order. We can't easily generate them in forward order, as we can't tell
+    // the number of characters needed until we are done converting.
+    // So, now, we reverse the string (except for the possible '-' sign).
+    char* front = buffer_ + start;
+    char* back = GetInsertionPoint();
+    while (--back > front) {
+      char ch = *back;
+      *back = *front;
+      *front++ = ch;
+    }
   }
-
   IncrementCount(discarded);
   return !discarded;
 }
diff --git a/base/strings/safe_sprintf.h b/base/strings/safe_sprintf.h
index de4f06a..2948712 100644
--- a/base/strings/safe_sprintf.h
+++ b/base/strings/safe_sprintf.h
@@ -9,6 +9,7 @@
 #include <stdint.h>
 #include <stdlib.h>
 
+#include "polyfills/base/memory/raw_ptr_exclusion.h"
 #include "build/build_config.h"
 
 #if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
@@ -197,7 +198,9 @@
     const char* str;
 
     // A pointer to an arbitrary object.
-    const void* ptr;
+    // This field is not a raw_ptr<> because it was filtered by the rewriter
+    // for: #union
+    RAW_PTR_EXCLUSION const void* ptr;
   };
   const enum Type type;
 };
diff --git a/base/strings/safe_sprintf_unittest.cc b/base/strings/safe_sprintf_unittest.cc
index 76d72b2..af52d1c 100644
--- a/base/strings/safe_sprintf_unittest.cc
+++ b/base/strings/safe_sprintf_unittest.cc
@@ -483,14 +483,7 @@
 
 }  // anonymous namespace
 
-// TODO(crbug.com/1369007): Fails when OOB protection is turned on.
-#if BUILDFLAG(ENABLE_BACKUP_REF_PTR_SUPPORT) || \
-    BUILDFLAG(ENABLE_MTE_CHECKED_PTR_SUPPORT)
-#define MAYBE_Truncation DISABLED_Truncation
-#else
-#define MAYBE_Truncation Truncation
-#endif
-TEST(SafeSPrintfTest, MAYBE_Truncation) {
+TEST(SafeSPrintfTest, Truncation) {
   // We use PrintLongString() to print a complex long string and then
   // truncate to all possible lengths. This ends up exercising a lot of
   // different code paths in SafeSPrintf() and IToASCII(), as truncation can
diff --git a/base/strings/string_util.cc b/base/strings/string_util.cc
index f92029f..f345244 100644
--- a/base/strings/string_util.cc
+++ b/base/strings/string_util.cc
@@ -29,6 +29,7 @@
 #include "base/strings/utf_string_conversions.h"
 #include "base/third_party/icu/icu_utf.h"
 #include "build/build_config.h"
+#include "absl/types/optional.h"
 
 namespace gurl_base {
 
@@ -391,13 +392,29 @@
     StringPiece16 format_string,
     const std::vector<std::u16string>& subst,
     std::vector<size_t>* offsets) {
-  return internal::DoReplaceStringPlaceholders(format_string, subst, offsets);
+  absl::optional<std::u16string> replacement =
+      internal::DoReplaceStringPlaceholders(
+          format_string, subst,
+          /*placeholder_prefix*/ u'$',
+          /*should_escape_multiple_placeholder_prefixes*/ true,
+          /*is_strict_mode*/ false, offsets);
+
+  GURL_DCHECK(replacement);
+  return replacement.value();
 }
 
 std::string ReplaceStringPlaceholders(StringPiece format_string,
                                       const std::vector<std::string>& subst,
                                       std::vector<size_t>* offsets) {
-  return internal::DoReplaceStringPlaceholders(format_string, subst, offsets);
+  absl::optional<std::string> replacement =
+      internal::DoReplaceStringPlaceholders(
+          format_string, subst,
+          /*placeholder_prefix*/ '$',
+          /*should_escape_multiple_placeholder_prefixes*/ true,
+          /*is_strict_mode*/ false, offsets);
+
+  GURL_DCHECK(replacement);
+  return replacement.value();
 }
 
 std::u16string ReplaceStringPlaceholders(const std::u16string& format_string,
diff --git a/base/strings/string_util_impl_helpers.h b/base/strings/string_util_impl_helpers.h
index 4cd9a3b..9578477 100644
--- a/base/strings/string_util_impl_helpers.h
+++ b/base/strings/string_util_impl_helpers.h
@@ -14,6 +14,7 @@
 #include "base/ranges/algorithm.h"
 #include "base/strings/string_piece.h"
 #include "base/third_party/icu/icu_utf.h"
+#include "absl/types/optional.h"
 
 namespace gurl_base::internal {
 
@@ -494,56 +495,90 @@
   return result;
 }
 
+// Replaces placeholders in `format_string` with values from `subst`.
+// * `placeholder_prefix`: Allows using a specific character as the placeholder
+// prefix. `gurl_base::ReplaceStringPlaceholders` uses '$'.
+// * `should_escape_multiple_placeholder_prefixes`:
+//   * If this parameter is `true`, which is the case with
+//   `gurl_base::ReplaceStringPlaceholders`, `placeholder_prefix` characters are
+//   replaced by that number less one. Eg $$->$, $$$->$$, etc.
+//   * If this parameter is `false`, each literal `placeholder_prefix` character
+//   in `format_string` is escaped with another `placeholder_prefix`. For
+//   instance, with `%` as the `placeholder_prefix`: %%->%, %%%%->%%, etc.
+// * `is_strict_mode`:
+//   * If this parameter is `true`, error handling is stricter. The function
+//   returns `absl::nullopt` if:
+//     * a placeholder %N is encountered where N > substitutions.size().
+//     * a literal `%` is not escaped with a `%`.
 template <typename T, typename CharT = typename T::value_type>
-std::basic_string<CharT> DoReplaceStringPlaceholders(
+absl::optional<std::basic_string<CharT>> DoReplaceStringPlaceholders(
     T format_string,
     const std::vector<std::basic_string<CharT>>& subst,
+    const CharT placeholder_prefix,
+    const bool should_escape_multiple_placeholder_prefixes,
+    const bool is_strict_mode,
     std::vector<size_t>* offsets) {
   size_t substitutions = subst.size();
   GURL_DCHECK_LT(substitutions, 11U);
 
   size_t sub_length = 0;
-  for (const auto& cur : subst)
+  for (const auto& cur : subst) {
     sub_length += cur.length();
+  }
 
   std::basic_string<CharT> formatted;
   formatted.reserve(format_string.length() + sub_length);
 
   std::vector<ReplacementOffset> r_offsets;
   for (auto i = format_string.begin(); i != format_string.end(); ++i) {
-    if ('$' == *i) {
+    if (placeholder_prefix == *i) {
       if (i + 1 != format_string.end()) {
         ++i;
-        if ('$' == *i) {
-          while (i != format_string.end() && '$' == *i) {
-            formatted.push_back('$');
+        if (placeholder_prefix == *i) {
+          do {
+            formatted.push_back(placeholder_prefix);
             ++i;
-          }
+          } while (should_escape_multiple_placeholder_prefixes &&
+                   i != format_string.end() && placeholder_prefix == *i);
           --i;
         } else {
           if (*i < '1' || *i > '9') {
-            GURL_DLOG(ERROR) << "Invalid placeholder: $"
-                        << std::basic_string<CharT>(1, *i);
+            if (is_strict_mode) {
+              GURL_DLOG(ERROR) << "Invalid placeholder after placeholder prefix: "
+                          << std::basic_string<CharT>(1, placeholder_prefix)
+                          << std::basic_string<CharT>(1, *i);
+              return absl::nullopt;
+            }
+
             continue;
           }
-          size_t index = static_cast<size_t>(*i - '1');
+          const size_t index = static_cast<size_t>(*i - '1');
           if (offsets) {
             ReplacementOffset r_offset(index, formatted.size());
             r_offsets.insert(
                 ranges::upper_bound(r_offsets, r_offset, &CompareParameter),
                 r_offset);
           }
-          if (index < substitutions)
+          if (index < substitutions) {
             formatted.append(subst.at(index));
+          } else if (is_strict_mode) {
+            GURL_DLOG(ERROR) << "index out of range: " << index << ": "
+                        << substitutions;
+            return absl::nullopt;
+          }
         }
+      } else if (is_strict_mode) {
+        GURL_DLOG(ERROR) << "unexpected placeholder prefix at end of string";
+        return absl::nullopt;
       }
     } else {
       formatted.push_back(*i);
     }
   }
   if (offsets) {
-    for (const auto& cur : r_offsets)
+    for (const auto& cur : r_offsets) {
       offsets->push_back(cur.offset);
+    }
   }
   return formatted;
 }
diff --git a/base/strings/string_util_win.cc b/base/strings/string_util_win.cc
index c3569b3..ea84d0b 100644
--- a/base/strings/string_util_win.cc
+++ b/base/strings/string_util_win.cc
@@ -6,6 +6,7 @@
 
 #include "base/ranges/algorithm.h"
 #include "base/strings/string_util_impl_helpers.h"
+#include "absl/types/optional.h"
 
 namespace gurl_base {
 
@@ -128,7 +129,15 @@
 std::wstring ReplaceStringPlaceholders(WStringPiece format_string,
                                        const std::vector<std::wstring>& subst,
                                        std::vector<size_t>* offsets) {
-  return internal::DoReplaceStringPlaceholders(format_string, subst, offsets);
+  absl::optional<std::wstring> replacement =
+      internal::DoReplaceStringPlaceholders(
+          format_string, subst,
+          /*placeholder_prefix*/ L'$',
+          /*should_escape_multiple_placeholder_prefixes*/ true,
+          /*is_strict_mode*/ false, offsets);
+
+  GURL_DCHECK(replacement);
+  return replacement.value();
 }
 
 }  // namespace base
diff --git a/build/build_config.h b/build/build_config.h
index 6811872..6db5d9b 100644
--- a/build/build_config.h
+++ b/build/build_config.h
@@ -26,6 +26,9 @@
 
 // This file also adds defines specific to the platform, architecture etc.
 //
+//  Platform:
+//    IS_OZONE
+//
 //  Compiler:
 //    COMPILER_MSVC / COMPILER_GCC
 //
diff --git a/copy.bara.sky b/copy.bara.sky
index a586cea..6c374ad 100644
--- a/copy.bara.sky
+++ b/copy.bara.sky
@@ -21,7 +21,7 @@
         "base/containers/util.h",
         "base/cxx17_backports.h",
         "base/cxx20_to_address.h",
-	"base/cxx20_is_constant_evaluated.h",
+        "base/cxx20_is_constant_evaluated.h",
         "base/debug/crash_logging.cc",
         "base/debug/crash_logging.h",
         "base/debug/leak_annotations.h",
@@ -69,7 +69,7 @@
 # Those headers are pulled from //polyfill instead of copied from Chromium.
 # Should be in sync with //polyfill/BUILD.
 polyfilled_headers = [
-    "base/allocator/buildflags.h",
+    #"base/allocator/buildflags.h",
     "base/base_export.h",
     "base/check.h",
     "base/check_op.h",
@@ -81,6 +81,7 @@
     "base/feature_list.h",
     "base/logging.h",
     "base/memory/raw_ptr.h",
+    "base/memory/raw_ptr_exclusion.h",
     "base/notreached.h",
     "base/trace_event/memory_usage_estimator.h",
     "third_party/perfetto/include/perfetto/tracing/traced_value.h",
@@ -109,7 +110,6 @@
 
     # Fix some Perfetto includes.
     core.replace("perfetto/tracing/traced_value_forward.h", "perfetto/tracing/traced_value.h"),
-
     core.replace("#include \"base/strings/string_number_conversions_win.h\"", ""),
     core.replace("#include \"base/allocator/partition_allocator/partition_alloc_config.h\"", ""),
 
diff --git a/polyfills/BUILD b/polyfills/BUILD
index 7e887e3..6bd0565 100644
--- a/polyfills/BUILD
+++ b/polyfills/BUILD
@@ -18,6 +18,7 @@
         "base/feature_list.h",
         "base/logging.h",
         "base/memory/raw_ptr.h",
+        "base/memory/raw_ptr_exclusion.h",
         "base/metrics/histogram_macros.h",
         "base/notreached.h",
         "base/trace_event/memory_usage_estimator.h",
diff --git a/polyfills/base/memory/raw_ptr_exclusion.h b/polyfills/base/memory/raw_ptr_exclusion.h
new file mode 100644
index 0000000..2ef3a8b
--- /dev/null
+++ b/polyfills/base/memory/raw_ptr_exclusion.h
@@ -0,0 +1,10 @@
+// Copyright 2022 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef POLYFILLS_BASE_MEMORY_RAW_PTR_EXCLUSION_H_
+#define POLYFILLS_BASE_MEMORY_RAW_PTR_EXCLUSION_H_
+
+#define RAW_PTR_EXCLUSION
+
+#endif  // POLYFILLS_BASE_MEMORY_RAW_PTR_EXCLUSION_H_
diff --git a/url/gurl.cc b/url/gurl.cc
index c5e3f19..87097a9 100644
--- a/url/gurl.cc
+++ b/url/gurl.cc
@@ -362,7 +362,7 @@
 }
 
 bool GURL::SchemeIsHTTPOrHTTPS() const {
-  return SchemeIs(url::kHttpScheme) || SchemeIs(url::kHttpsScheme);
+  return SchemeIs(url::kHttpsScheme) || SchemeIs(url::kHttpScheme);
 }
 
 bool GURL::SchemeIsWSOrWSS() const {
diff --git a/url/origin.cc b/url/origin.cc
index 1b416a9..b16d3df 100644
--- a/url/origin.cc
+++ b/url/origin.cc
@@ -375,11 +375,13 @@
   if (!reader.ReadUInt64(&nonce_low))
     return absl::nullopt;
 
+  absl::optional<gurl_base::UnguessableToken> nonce_token =
+      gurl_base::UnguessableToken::Deserialize(nonce_high, nonce_low);
+
   Origin::Nonce nonce;
-  if (nonce_high != 0 && nonce_low != 0) {
+  if (nonce_token.has_value()) {
     // The serialized nonce wasn't empty, so copy it here.
-    nonce = Origin::Nonce(
-        gurl_base::UnguessableToken::Deserialize(nonce_high, nonce_low));
+    nonce = Origin::Nonce(nonce_token.value());
   }
   Origin origin;
   origin.nonce_ = std::move(nonce);
diff --git a/url/origin.h b/url/origin.h
index 5da5d84..292d8d4 100644
--- a/url/origin.h
+++ b/url/origin.h
@@ -13,6 +13,7 @@
 #include "polyfills/base/component_export.h"
 #include "polyfills/base/debug/alias.h"
 #include "base/debug/crash_logging.h"
+#include "base/gtest_prod_util.h"
 #include "base/strings/string_piece_forward.h"
 #include "base/strings/string_util.h"
 #include "base/unguessable_token.h"
@@ -40,6 +41,8 @@
 namespace blink {
 class SecurityOrigin;
 class SecurityOriginTest;
+class StorageKey;
+class StorageKeyTest;
 }  // namespace blink
 
 namespace IPC {
@@ -329,6 +332,7 @@
  private:
   friend class blink::SecurityOrigin;
   friend class blink::SecurityOriginTest;
+  friend class blink::StorageKey;
   // SchemefulSite needs access to the serialization/deserialization logic which
   // includes the nonce.
   friend class net::SchemefulSite;
@@ -339,6 +343,7 @@
   friend IPC::ParamTraits<url::Origin>;
   friend COMPONENT_EXPORT(URL) std::ostream& operator<<(std::ostream& out,
                                                         const Origin& origin);
+  friend class blink::StorageKeyTest;
 
   // Origin::Nonce is a wrapper around gurl_base::UnguessableToken that generates
   // the random value only when the value is first accessed. The lazy generation
diff --git a/url/run_all_perftests.cc b/url/run_all_perftests.cc
index 47aeae2..7560e83 100644
--- a/url/run_all_perftests.cc
+++ b/url/run_all_perftests.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "base/bind.h"
+#include "base/functional/bind.h"
 #include "base/test/launcher/unit_test_launcher.h"
 #include "base/test/perf_test_suite.h"
 
diff --git a/url/run_all_unittests.cc b/url/run_all_unittests.cc
index 0e339bd..159e236 100644
--- a/url/run_all_unittests.cc
+++ b/url/run_all_unittests.cc
@@ -4,7 +4,7 @@
 
 #include <memory>
 
-#include "base/bind.h"
+#include "base/functional/bind.h"
 #include "base/test/launcher/unit_test_launcher.h"
 #include "base/test/test_io_thread.h"
 #include "base/test/test_suite.h"
diff --git a/url/url_canon.h b/url/url_canon.h
index 1eed379..bb90c4a 100644
--- a/url/url_canon.h
+++ b/url/url_canon.h
@@ -10,7 +10,7 @@
 
 #include "polyfills/base/component_export.h"
 #include "polyfills/base/export_template.h"
-#include "base/memory/raw_ptr_exclusion.h"
+#include "polyfills/base/memory/raw_ptr_exclusion.h"
 #include "base/numerics/clamped_math.h"
 #include "url/third_party/mozilla/url_parse.h"
 
diff --git a/url/url_canon_icu_unittest.cc b/url/url_canon_icu_unittest.cc
index fc3fb67..46b7ae0 100644
--- a/url/url_canon_icu_unittest.cc
+++ b/url/url_canon_icu_unittest.cc
@@ -32,7 +32,7 @@
 
   ~UConvScoper() {
     if (converter_)
-      ucnv_close(converter_);
+      ucnv_close(converter_.ExtractAsDangling());
   }
 
   // Returns the converter object, may be NULL.
diff --git a/url/url_canon_stdstring.h b/url/url_canon_stdstring.h
index c9e2a1b..c8f9500 100644
--- a/url/url_canon_stdstring.h
+++ b/url/url_canon_stdstring.h
@@ -13,7 +13,7 @@
 
 #include "base/compiler_specific.h"
 #include "polyfills/base/component_export.h"
-#include "base/memory/raw_ptr_exclusion.h"
+#include "polyfills/base/memory/raw_ptr_exclusion.h"
 #include "base/strings/string_piece.h"
 #include "url/url_canon.h"