Revert "components: Replace base::Optional and friends with absl counterparts"

Reason for revert: absl::optional is not available on Chrome OS.

This reverts commit 0f45c2c30d8091905981fec3b8e35425e0bdff12.

BUG=chromium:1271599
BUG=b:204698553
BUG=b:198296022
TEST=cros_run_unit_tests --board=${BOARD} --packages cbor

Change-Id: Ibb30f235947deafe22a581c8c5974bf889889354
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/cbor/+/3309186
Tested-by: Anastasiia N <anastasiian@chromium.org>
Reviewed-by: Tom Hughes <tomhughes@chromium.org>
Reviewed-by: Josie Nordrum <josienordrum@google.com>
Tested-by: Tom Hughes <tomhughes@chromium.org>
Commit-Queue: Anastasiia N <anastasiian@chromium.org>
diff --git a/diagnostic_writer_unittest.cc b/diagnostic_writer_unittest.cc
index 8ae39ef..4569cf7 100644
--- a/diagnostic_writer_unittest.cc
+++ b/diagnostic_writer_unittest.cc
@@ -64,7 +64,7 @@
   static const uint8_t kInvalidUTF8[] = {0x62, 0xe2, 0x80};
   cbor::Reader::Config config;
   config.allow_invalid_utf8 = true;
-  absl::optional<cbor::Value> maybe_value =
+  base::Optional<cbor::Value> maybe_value =
       cbor::Reader::Read(kInvalidUTF8, config);
 
   ASSERT_TRUE(maybe_value);
diff --git a/reader.cc b/reader.cc
index dcfb217..5161fae 100644
--- a/reader.cc
+++ b/reader.cc
@@ -72,7 +72,7 @@
 Reader::~Reader() {}
 
 // static
-absl::optional<Value> Reader::Read(base::span<uint8_t const> data,
+base::Optional<Value> Reader::Read(base::span<uint8_t const> data,
                                    DecoderError* error_code_out,
                                    int max_nesting_level) {
   Config config;
@@ -83,7 +83,7 @@
 }
 
 // static
-absl::optional<Value> Reader::Read(base::span<uint8_t const> data,
+base::Optional<Value> Reader::Read(base::span<uint8_t const> data,
                                    size_t* num_bytes_consumed,
                                    DecoderError* error_code_out,
                                    int max_nesting_level) {
@@ -98,10 +98,10 @@
 }
 
 // static
-absl::optional<Value> Reader::Read(base::span<uint8_t const> data,
+base::Optional<Value> Reader::Read(base::span<uint8_t const> data,
                                    const Config& config) {
   Reader reader(data);
-  absl::optional<Value> value =
+  base::Optional<Value> value =
       reader.DecodeCompleteDataItem(config, config.max_nesting_level);
 
   auto error = reader.GetErrorCode();
@@ -123,16 +123,16 @@
   return value;
 }
 
-absl::optional<Value> Reader::DecodeCompleteDataItem(const Config& config,
+base::Optional<Value> Reader::DecodeCompleteDataItem(const Config& config,
                                                      int max_nesting_level) {
   if (max_nesting_level < 0 || max_nesting_level > kCBORMaxDepth) {
     error_code_ = DecoderError::TOO_MUCH_NESTING;
-    return absl::nullopt;
+    return base::nullopt;
   }
 
-  absl::optional<DataItemHeader> header = DecodeDataItemHeader();
+  base::Optional<DataItemHeader> header = DecodeDataItemHeader();
   if (!header.has_value()) {
-    return absl::nullopt;
+    return base::nullopt;
   }
 
   switch (header->type) {
@@ -157,29 +157,29 @@
   }
 
   error_code_ = DecoderError::UNSUPPORTED_MAJOR_TYPE;
-  return absl::nullopt;
+  return base::nullopt;
 }
 
-absl::optional<Reader::DataItemHeader> Reader::DecodeDataItemHeader() {
-  const absl::optional<uint8_t> initial_byte = ReadByte();
+base::Optional<Reader::DataItemHeader> Reader::DecodeDataItemHeader() {
+  const base::Optional<uint8_t> initial_byte = ReadByte();
   if (!initial_byte) {
-    return absl::nullopt;
+    return base::nullopt;
   }
 
   const auto major_type = GetMajorType(initial_byte.value());
   const uint8_t additional_info = GetAdditionalInfo(initial_byte.value());
 
-  absl::optional<uint64_t> value = ReadVariadicLengthInteger(additional_info);
-  return value ? absl::make_optional(
+  base::Optional<uint64_t> value = ReadVariadicLengthInteger(additional_info);
+  return value ? base::make_optional(
                      DataItemHeader{major_type, additional_info, value.value()})
-               : absl::nullopt;
+               : base::nullopt;
 }
 
-absl::optional<uint64_t> Reader::ReadVariadicLengthInteger(
+base::Optional<uint64_t> Reader::ReadVariadicLengthInteger(
     uint8_t additional_info) {
   uint8_t additional_bytes = 0;
   if (additional_info < 24) {
-    return absl::make_optional(additional_info);
+    return base::make_optional(additional_info);
   } else if (additional_info == 24) {
     additional_bytes = 1;
   } else if (additional_info == 25) {
@@ -190,13 +190,13 @@
     additional_bytes = 8;
   } else {
     error_code_ = DecoderError::UNKNOWN_ADDITIONAL_INFO;
-    return absl::nullopt;
+    return base::nullopt;
   }
 
-  const absl::optional<base::span<const uint8_t>> bytes =
+  const base::Optional<base::span<const uint8_t>> bytes =
       ReadBytes(additional_bytes);
   if (!bytes) {
-    return absl::nullopt;
+    return base::nullopt;
   }
 
   uint64_t int_data = 0;
@@ -206,36 +206,36 @@
   }
 
   return IsEncodingMinimal(additional_bytes, int_data)
-             ? absl::make_optional(int_data)
-             : absl::nullopt;
+             ? base::make_optional(int_data)
+             : base::nullopt;
 }
 
-absl::optional<Value> Reader::DecodeValueToNegative(uint64_t value) {
+base::Optional<Value> Reader::DecodeValueToNegative(uint64_t value) {
   auto negative_value = -base::CheckedNumeric<int64_t>(value) - 1;
   if (!negative_value.IsValid()) {
     error_code_ = DecoderError::OUT_OF_RANGE_INTEGER_VALUE;
-    return absl::nullopt;
+    return base::nullopt;
   }
   return Value(negative_value.ValueOrDie());
 }
 
-absl::optional<Value> Reader::DecodeValueToUnsigned(uint64_t value) {
+base::Optional<Value> Reader::DecodeValueToUnsigned(uint64_t value) {
   auto unsigned_value = base::CheckedNumeric<int64_t>(value);
   if (!unsigned_value.IsValid()) {
     error_code_ = DecoderError::OUT_OF_RANGE_INTEGER_VALUE;
-    return absl::nullopt;
+    return base::nullopt;
   }
   return Value(unsigned_value.ValueOrDie());
 }
 
-absl::optional<Value> Reader::DecodeToSimpleValue(
+base::Optional<Value> Reader::DecodeToSimpleValue(
     const DataItemHeader& header) {
   // ReadVariadicLengthInteger provides this bound.
   CHECK_LE(header.additional_info, 27);
   // Floating point numbers are not supported.
   if (header.additional_info > 24) {
     error_code_ = DecoderError::UNSUPPORTED_FLOATING_POINT_VALUE;
-    return absl::nullopt;
+    return base::nullopt;
   }
 
   // Since |header.additional_info| <= 24, ReadVariadicLengthInteger also
@@ -254,16 +254,16 @@
   }
 
   error_code_ = DecoderError::UNSUPPORTED_SIMPLE_VALUE;
-  return absl::nullopt;
+  return base::nullopt;
 }
 
-absl::optional<Value> Reader::ReadStringContent(
+base::Optional<Value> Reader::ReadStringContent(
     const Reader::DataItemHeader& header,
     const Config& config) {
   uint64_t num_bytes = header.value;
-  const absl::optional<base::span<const uint8_t>> bytes = ReadBytes(num_bytes);
+  const base::Optional<base::span<const uint8_t>> bytes = ReadBytes(num_bytes);
   if (!bytes) {
-    return absl::nullopt;
+    return base::nullopt;
   }
 
   std::string cbor_string(bytes->begin(), bytes->end());
@@ -276,22 +276,22 @@
   }
 
   error_code_ = DecoderError::INVALID_UTF8;
-  return absl::nullopt;
+  return base::nullopt;
 }
 
-absl::optional<Value> Reader::ReadByteStringContent(
+base::Optional<Value> Reader::ReadByteStringContent(
     const Reader::DataItemHeader& header) {
   uint64_t num_bytes = header.value;
-  const absl::optional<base::span<const uint8_t>> bytes = ReadBytes(num_bytes);
+  const base::Optional<base::span<const uint8_t>> bytes = ReadBytes(num_bytes);
   if (!bytes) {
-    return absl::nullopt;
+    return base::nullopt;
   }
 
   std::vector<uint8_t> cbor_byte_string(bytes->begin(), bytes->end());
   return Value(std::move(cbor_byte_string));
 }
 
-absl::optional<Value> Reader::ReadArrayContent(
+base::Optional<Value> Reader::ReadArrayContent(
     const Reader::DataItemHeader& header,
     const Config& config,
     int max_nesting_level) {
@@ -299,17 +299,17 @@
 
   Value::ArrayValue cbor_array;
   for (uint64_t i = 0; i < length; ++i) {
-    absl::optional<Value> cbor_element =
+    base::Optional<Value> cbor_element =
         DecodeCompleteDataItem(config, max_nesting_level - 1);
     if (!cbor_element.has_value()) {
-      return absl::nullopt;
+      return base::nullopt;
     }
     cbor_array.push_back(std::move(cbor_element.value()));
   }
   return Value(std::move(cbor_array));
 }
 
-absl::optional<Value> Reader::ReadMapContent(
+base::Optional<Value> Reader::ReadMapContent(
     const Reader::DataItemHeader& header,
     const Config& config,
     int max_nesting_level) {
@@ -317,12 +317,12 @@
 
   std::map<Value, Value, Value::Less> cbor_map;
   for (uint64_t i = 0; i < length; ++i) {
-    absl::optional<Value> key =
+    base::Optional<Value> key =
         DecodeCompleteDataItem(config, max_nesting_level - 1);
-    absl::optional<Value> value =
+    base::Optional<Value> value =
         DecodeCompleteDataItem(config, max_nesting_level - 1);
     if (!key.has_value() || !value.has_value()) {
-      return absl::nullopt;
+      return base::nullopt;
     }
 
     switch (key.value().type()) {
@@ -333,17 +333,17 @@
         break;
       case Value::Type::INVALID_UTF8:
         error_code_ = DecoderError::INVALID_UTF8;
-        return absl::nullopt;
+        return base::nullopt;
       default:
         error_code_ = DecoderError::INCORRECT_MAP_KEY_TYPE;
-        return absl::nullopt;
+        return base::nullopt;
     }
     if (IsDuplicateKey(key.value(), cbor_map))
-      return absl::nullopt;
+      return base::nullopt;
 
     if (!config.allow_and_canonicalize_out_of_order_keys &&
         !IsKeyInOrder(key.value(), cbor_map)) {
-      return absl::nullopt;
+      return base::nullopt;
     }
 
     cbor_map.emplace(std::move(key.value()), std::move(value.value()));
@@ -358,16 +358,16 @@
   return Value(std::move(map));
 }
 
-absl::optional<uint8_t> Reader::ReadByte() {
-  const absl::optional<base::span<const uint8_t>> bytes = ReadBytes(1);
-  return bytes ? absl::make_optional(bytes.value()[0]) : absl::nullopt;
+base::Optional<uint8_t> Reader::ReadByte() {
+  const base::Optional<base::span<const uint8_t>> bytes = ReadBytes(1);
+  return bytes ? base::make_optional(bytes.value()[0]) : base::nullopt;
 }
 
-absl::optional<base::span<const uint8_t>> Reader::ReadBytes(
+base::Optional<base::span<const uint8_t>> Reader::ReadBytes(
     uint64_t num_bytes) {
   if (base::strict_cast<uint64_t>(rest_.size()) < num_bytes) {
     error_code_ = DecoderError::INCOMPLETE_CBOR_DATA;
-    return absl::nullopt;
+    return base::nullopt;
   }
   const base::span<const uint8_t> ret = rest_.first(num_bytes);
   rest_ = rest_.subspan(num_bytes);
diff --git a/reader.h b/reader.h
index 9d0371b..bd9d6d9 100644
--- a/reader.h
+++ b/reader.h
@@ -10,9 +10,9 @@
 #include <map>
 
 #include "base/containers/span.h"
+#include "base/optional.h"
 #include "cbor/cbor_export.h"
 #include "cbor/values.h"
-#include "third_party/abseil-cpp/absl/types/optional.h"
 
 // Concise Binary Object Representation (CBOR) decoder as defined by
 // https://tools.ietf.org/html/rfc7049. This decoder only accepts canonical CBOR
@@ -141,18 +141,18 @@
   //
   // Returns an empty Optional if not all the data was consumed, and sets
   // |error_code_out| to EXTRANEOUS_DATA in this case.
-  static absl::optional<Value> Read(base::span<const uint8_t> input_data,
+  static base::Optional<Value> Read(base::span<const uint8_t> input_data,
                                     DecoderError* error_code_out = nullptr,
                                     int max_nesting_level = kCBORMaxDepth);
 
   // A version of |Read|, above, that takes a |Config| structure to allow
   // additional controls.
-  static absl::optional<Value> Read(base::span<const uint8_t> input_data,
+  static base::Optional<Value> Read(base::span<const uint8_t> input_data,
                                     const Config& config);
 
   // A version of |Read| that takes some fields of |Config| as parameters to
   // avoid having to construct a |Config| object explicitly.
-  static absl::optional<Value> Read(base::span<const uint8_t> input_data,
+  static base::Optional<Value> Read(base::span<const uint8_t> input_data,
                                     size_t* num_bytes_consumed,
                                     DecoderError* error_code_out = nullptr,
                                     int max_nesting_level = kCBORMaxDepth);
@@ -178,24 +178,24 @@
     uint64_t value;
   };
 
-  absl::optional<DataItemHeader> DecodeDataItemHeader();
-  absl::optional<Value> DecodeCompleteDataItem(const Config& config,
+  base::Optional<DataItemHeader> DecodeDataItemHeader();
+  base::Optional<Value> DecodeCompleteDataItem(const Config& config,
                                                int max_nesting_level);
-  absl::optional<Value> DecodeValueToNegative(uint64_t value);
-  absl::optional<Value> DecodeValueToUnsigned(uint64_t value);
-  absl::optional<Value> DecodeToSimpleValue(const DataItemHeader& header);
-  absl::optional<uint64_t> ReadVariadicLengthInteger(uint8_t additional_info);
-  absl::optional<Value> ReadByteStringContent(const DataItemHeader& header);
-  absl::optional<Value> ReadStringContent(const DataItemHeader& header,
+  base::Optional<Value> DecodeValueToNegative(uint64_t value);
+  base::Optional<Value> DecodeValueToUnsigned(uint64_t value);
+  base::Optional<Value> DecodeToSimpleValue(const DataItemHeader& header);
+  base::Optional<uint64_t> ReadVariadicLengthInteger(uint8_t additional_info);
+  base::Optional<Value> ReadByteStringContent(const DataItemHeader& header);
+  base::Optional<Value> ReadStringContent(const DataItemHeader& header,
                                           const Config& config);
-  absl::optional<Value> ReadArrayContent(const DataItemHeader& header,
+  base::Optional<Value> ReadArrayContent(const DataItemHeader& header,
                                          const Config& config,
                                          int max_nesting_level);
-  absl::optional<Value> ReadMapContent(const DataItemHeader& header,
+  base::Optional<Value> ReadMapContent(const DataItemHeader& header,
                                        const Config& config,
                                        int max_nesting_level);
-  absl::optional<uint8_t> ReadByte();
-  absl::optional<base::span<const uint8_t>> ReadBytes(uint64_t num_bytes);
+  base::Optional<uint8_t> ReadByte();
+  base::Optional<base::span<const uint8_t>> ReadBytes(uint64_t num_bytes);
   bool IsKeyInOrder(const Value& new_key,
                     const std::map<Value, Value, Value::Less>& map);
   // Check if `new_key` is a duplicate of a key that already exists in the
diff --git a/reader_fuzzer.cc b/reader_fuzzer.cc
index ae12767..0df3d3f 100644
--- a/reader_fuzzer.cc
+++ b/reader_fuzzer.cc
@@ -13,9 +13,9 @@
 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
   std::vector<uint8_t> input(data, data + size);
 
-  absl::optional<Value> cbor = Reader::Read(input);
+  base::Optional<Value> cbor = Reader::Read(input);
   if (cbor.has_value()) {
-    absl::optional<std::vector<uint8_t>> serialized_cbor =
+    base::Optional<std::vector<uint8_t>> serialized_cbor =
         Writer::Write(cbor.value());
     CHECK(serialized_cbor.has_value());
     if (serialized_cbor.has_value()) {
@@ -27,10 +27,10 @@
 
   Reader::Config config;
   config.allow_and_canonicalize_out_of_order_keys = true;
-  absl::optional<Value> cbor_1 = Reader::Read(input, config);
+  base::Optional<Value> cbor_1 = Reader::Read(input, config);
 
   if (cbor_1.has_value()) {
-    absl::optional<std::vector<uint8_t>> serialized_cbor =
+    base::Optional<std::vector<uint8_t>> serialized_cbor =
         Writer::Write(cbor_1.value());
     CHECK(serialized_cbor.has_value());
     if (serialized_cbor.has_value()) {
diff --git a/reader_unittest.cc b/reader_unittest.cc
index 285c48a..d36e172 100644
--- a/reader_unittest.cc
+++ b/reader_unittest.cc
@@ -52,7 +52,7 @@
   for (const UintTestCase& test_case : kUintTestCases) {
     SCOPED_TRACE(testing::Message() << "testing uint: " << test_case.value);
 
-    absl::optional<Value> cbor = Reader::Read(test_case.cbor_data);
+    base::Optional<Value> cbor = Reader::Read(test_case.cbor_data);
     ASSERT_TRUE(cbor.has_value());
     ASSERT_EQ(cbor.value().type(), Value::Type::UNSIGNED);
     EXPECT_EQ(cbor.value().GetInteger(), test_case.value);
@@ -117,7 +117,7 @@
     SCOPED_TRACE(testing::Message()
                  << "testing element at index : " << test_case_index++);
 
-    absl::optional<Value> cbor = Reader::Read(non_minimal_uint, &error_code);
+    base::Optional<Value> cbor = Reader::Read(non_minimal_uint, &error_code);
     EXPECT_FALSE(cbor.has_value());
     EXPECT_EQ(error_code, Reader::DecoderError::NON_MINIMAL_CBOR_ENCODING);
   }
@@ -144,7 +144,7 @@
     SCOPED_TRACE(testing::Message()
                  << "testing negative int : " << test_case.negative_int);
 
-    absl::optional<Value> cbor = Reader::Read(test_case.cbor_data);
+    base::Optional<Value> cbor = Reader::Read(test_case.cbor_data);
     ASSERT_TRUE(cbor.has_value());
     ASSERT_EQ(cbor.value().type(), Value::Type::NEGATIVE);
     EXPECT_EQ(cbor.value().GetInteger(), test_case.negative_int);
@@ -184,7 +184,7 @@
     SCOPED_TRACE(testing::Message()
                  << "testing string test case at : " << element_index++);
 
-    absl::optional<Value> cbor = Reader::Read(test_case.cbor_data);
+    base::Optional<Value> cbor = Reader::Read(test_case.cbor_data);
     ASSERT_TRUE(cbor.has_value());
     ASSERT_EQ(cbor.value().type(), Value::Type::BYTE_STRING);
     EXPECT_EQ(cbor.value().GetBytestring(), test_case.value);
@@ -226,7 +226,7 @@
     SCOPED_TRACE(testing::Message()
                  << "testing string value : " << test_case.value);
 
-    absl::optional<Value> cbor = Reader::Read(test_case.cbor_data);
+    base::Optional<Value> cbor = Reader::Read(test_case.cbor_data);
     ASSERT_TRUE(cbor.has_value());
     ASSERT_EQ(cbor.value().type(), Value::Type::STRING);
     EXPECT_EQ(cbor.value().GetString(), test_case.value);
@@ -271,7 +271,7 @@
     SCOPED_TRACE(testing::Message()
                  << "testing string with nul bytes :" << test_case.value);
 
-    absl::optional<Value> cbor = Reader::Read(test_case.cbor_data);
+    base::Optional<Value> cbor = Reader::Read(test_case.cbor_data);
     ASSERT_TRUE(cbor.has_value());
     ASSERT_EQ(cbor.value().type(), Value::Type::STRING);
     EXPECT_EQ(cbor.value().GetString(), test_case.value);
@@ -301,7 +301,7 @@
   static const std::vector<uint8_t> string_with_invalid_continuation_byte = {
       0x63, 0x00, 0x00, 0xA6};
   Reader::DecoderError error_code;
-  absl::optional<Value> cbor =
+  base::Optional<Value> cbor =
       Reader::Read(string_with_invalid_continuation_byte, &error_code);
   EXPECT_FALSE(cbor.has_value());
   EXPECT_EQ(error_code, Reader::DecoderError::INVALID_UTF8);
@@ -317,7 +317,7 @@
       // clang-format on
   };
 
-  absl::optional<Value> cbor = Reader::Read(kArrayTestCaseCbor);
+  base::Optional<Value> cbor = Reader::Read(kArrayTestCaseCbor);
   ASSERT_TRUE(cbor.has_value());
   const Value cbor_array = std::move(cbor.value());
   ASSERT_EQ(cbor_array.type(), Value::Type::ARRAY);
@@ -366,7 +366,7 @@
       // clang-format on
   };
 
-  absl::optional<Value> cbor = Reader::Read(kMapTestCaseCbor);
+  base::Optional<Value> cbor = Reader::Read(kMapTestCaseCbor);
   ASSERT_TRUE(cbor.has_value());
   const Value cbor_val = std::move(cbor.value());
   ASSERT_EQ(cbor_val.type(), Value::Type::MAP);
@@ -428,7 +428,7 @@
       // clang-format on
   };
 
-  absl::optional<Value> cbor = Reader::Read(kMapWithIntegerKeyCbor);
+  base::Optional<Value> cbor = Reader::Read(kMapWithIntegerKeyCbor);
   ASSERT_TRUE(cbor.has_value());
   const Value cbor_val = std::move(cbor.value());
   ASSERT_EQ(cbor_val.type(), Value::Type::MAP);
@@ -487,7 +487,7 @@
       // clang-format on
   };
 
-  absl::optional<Value> cbor = Reader::Read(kMapWithIntegerKeyCbor);
+  base::Optional<Value> cbor = Reader::Read(kMapWithIntegerKeyCbor);
   ASSERT_TRUE(cbor.has_value());
   const Value cbor_val = std::move(cbor.value());
   ASSERT_EQ(cbor_val.type(), Value::Type::MAP);
@@ -541,7 +541,7 @@
       // clang-format on
   };
 
-  absl::optional<Value> cbor = Reader::Read(kMapArrayTestCaseCbor);
+  base::Optional<Value> cbor = Reader::Read(kMapArrayTestCaseCbor);
   ASSERT_TRUE(cbor.has_value());
   const Value cbor_val = std::move(cbor.value());
   ASSERT_EQ(cbor_val.type(), Value::Type::MAP);
@@ -594,7 +594,7 @@
   };
 
   Reader::DecoderError error_code;
-  absl::optional<Value> cbor = Reader::Read(kMapTestCase, &error_code);
+  base::Optional<Value> cbor = Reader::Read(kMapTestCase, &error_code);
   ASSERT_TRUE(cbor.has_value());
   ASSERT_EQ(cbor->type(), Value::Type::MAP);
   ASSERT_EQ(cbor->GetMap().size(), 2u);
@@ -637,7 +637,7 @@
   };
 
   Reader::DecoderError error_code;
-  absl::optional<Value> cbor = Reader::Read(kMapTestCase, &error_code);
+  base::Optional<Value> cbor = Reader::Read(kMapTestCase, &error_code);
   ASSERT_TRUE(cbor.has_value());
   ASSERT_EQ(cbor->type(), Value::Type::MAP);
   ASSERT_EQ(cbor->GetMap().size(), 2u);
@@ -710,7 +710,7 @@
   };
 
   Reader::DecoderError error_code;
-  absl::optional<Value> cbor = Reader::Read(kMapTestCase, &error_code);
+  base::Optional<Value> cbor = Reader::Read(kMapTestCase, &error_code);
   ASSERT_TRUE(cbor.has_value());
   ASSERT_EQ(cbor->type(), Value::Type::MAP);
   ASSERT_EQ(cbor->GetMap().size(), 6u);
@@ -763,7 +763,7 @@
       // clang-format on
   };
 
-  absl::optional<Value> cbor = Reader::Read(kNestedMapTestCase);
+  base::Optional<Value> cbor = Reader::Read(kNestedMapTestCase);
   ASSERT_TRUE(cbor.has_value());
   const Value cbor_val = std::move(cbor.value());
   ASSERT_EQ(cbor_val.type(), Value::Type::MAP);
@@ -800,11 +800,11 @@
   static const std::vector<uint8_t> kMinNegativeInt = {
       0x3b, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
 
-  absl::optional<Value> max_positive_int = Reader::Read(kMaxPositiveInt);
+  base::Optional<Value> max_positive_int = Reader::Read(kMaxPositiveInt);
   ASSERT_TRUE(max_positive_int.has_value());
   EXPECT_EQ(max_positive_int.value().GetInteger(), INT64_MAX);
 
-  absl::optional<Value> min_negative_int = Reader::Read(kMinNegativeInt);
+  base::Optional<Value> min_negative_int = Reader::Read(kMinNegativeInt);
   ASSERT_TRUE(min_negative_int.has_value());
   EXPECT_EQ(min_negative_int.value().GetInteger(), INT64_MIN);
 }
@@ -817,12 +817,12 @@
       0x3b, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
 
   Reader::DecoderError error_code;
-  absl::optional<Value> positive_int_out_of_range_cbor =
+  base::Optional<Value> positive_int_out_of_range_cbor =
       Reader::Read(kOutOfRangePositiveInt, &error_code);
   EXPECT_FALSE(positive_int_out_of_range_cbor.has_value());
   EXPECT_EQ(error_code, Reader::DecoderError::OUT_OF_RANGE_INTEGER_VALUE);
 
-  absl::optional<Value> negative_int_out_of_range_cbor =
+  base::Optional<Value> negative_int_out_of_range_cbor =
       Reader::Read(kOutOfRangeNegativeInt, &error_code);
   EXPECT_FALSE(negative_int_out_of_range_cbor.has_value());
   EXPECT_EQ(error_code, Reader::DecoderError::OUT_OF_RANGE_INTEGER_VALUE);
@@ -844,7 +844,7 @@
     SCOPED_TRACE(testing::Message()
                  << "testing simple value at index : " << test_element_index++);
 
-    absl::optional<Value> cbor = Reader::Read(test_case.cbor_data);
+    base::Optional<Value> cbor = Reader::Read(test_case.cbor_data);
     ASSERT_TRUE(cbor.has_value());
     ASSERT_EQ(cbor.value().type(), Value::Type::SIMPLE_VALUE);
     EXPECT_EQ(cbor.value().GetSimpleValue(), test_case.value);
@@ -880,7 +880,7 @@
                  << "testing unsupported floating point : "
                  << testing::PrintToString(unsupported_floating_point));
     Reader::DecoderError error_code;
-    absl::optional<Value> cbor =
+    base::Optional<Value> cbor =
         Reader::Read(unsupported_floating_point, &error_code);
     EXPECT_FALSE(cbor.has_value());
     EXPECT_EQ(error_code,
@@ -925,7 +925,7 @@
                                     << test_element_index++);
 
     Reader::DecoderError error_code;
-    absl::optional<Value> cbor = Reader::Read(incomplete_data, &error_code);
+    base::Optional<Value> cbor = Reader::Read(incomplete_data, &error_code);
     EXPECT_FALSE(cbor.has_value());
     EXPECT_EQ(error_code, Reader::DecoderError::INCOMPLETE_CBOR_DATA);
   }
@@ -947,7 +947,7 @@
   };
 
   Reader::DecoderError error_code;
-  absl::optional<Value> cbor = Reader::Read(kMapWithUintKey, &error_code);
+  base::Optional<Value> cbor = Reader::Read(kMapWithUintKey, &error_code);
   EXPECT_FALSE(cbor.has_value());
   EXPECT_EQ(error_code, Reader::DecoderError::INCORRECT_MAP_KEY_TYPE);
 }
@@ -979,7 +979,7 @@
                  << "testing data at index : " << test_element_index++);
 
     Reader::DecoderError error_code;
-    absl::optional<Value> cbor = Reader::Read(incorrect_cbor, &error_code);
+    base::Optional<Value> cbor = Reader::Read(incorrect_cbor, &error_code);
     EXPECT_FALSE(cbor.has_value());
     EXPECT_EQ(error_code, Reader::DecoderError::UNKNOWN_ADDITIONAL_INFO);
   }
@@ -1004,7 +1004,7 @@
     SCOPED_TRACE(testing::Message()
                  << "testing zero nested data : " << test_element_index++);
     Reader::DecoderError error_code;
-    absl::optional<Value> cbor = Reader::Read(zero_depth_data, &error_code, 0);
+    base::Optional<Value> cbor = Reader::Read(zero_depth_data, &error_code, 0);
     EXPECT_TRUE(cbor.has_value());
     EXPECT_EQ(error_code, Reader::DecoderError::CBOR_NO_ERROR);
   }
@@ -1026,12 +1026,12 @@
   };
 
   Reader::DecoderError error_code;
-  absl::optional<Value> cbor_single_layer_max =
+  base::Optional<Value> cbor_single_layer_max =
       Reader::Read(kNestedCBORData, &error_code, 1);
   EXPECT_FALSE(cbor_single_layer_max.has_value());
   EXPECT_EQ(error_code, Reader::DecoderError::TOO_MUCH_NESTING);
 
-  absl::optional<Value> cbor_double_layer_max =
+  base::Optional<Value> cbor_double_layer_max =
       Reader::Read(kNestedCBORData, &error_code, 2);
   EXPECT_TRUE(cbor_double_layer_max.has_value());
   EXPECT_EQ(error_code, Reader::DecoderError::CBOR_NO_ERROR);
@@ -1089,7 +1089,7 @@
     // Expect `OUT_OF_ORDER_KEY`.
     {
       Reader::DecoderError error_code;
-      absl::optional<Value> cbor =
+      base::Optional<Value> cbor =
           Reader::Read(unsorted_map, &error_code);
       EXPECT_FALSE(cbor.has_value());
       EXPECT_EQ(error_code, Reader::DecoderError::OUT_OF_ORDER_KEY);
@@ -1103,7 +1103,7 @@
       config.error_code_out = &error_code;
       config.allow_and_canonicalize_out_of_order_keys = true;
 
-      absl::optional<Value> cbor =
+      base::Optional<Value> cbor =
           Reader::Read(unsorted_map, config);
       EXPECT_TRUE(cbor);
       EXPECT_EQ(error_code, Reader::DecoderError::CBOR_NO_ERROR);
@@ -1147,7 +1147,7 @@
     // Expect `OUT_OF_ORDER_KEY`.
     {
       Reader::DecoderError error_code;
-      absl::optional<Value> cbor =
+      base::Optional<Value> cbor =
           Reader::Read(unsorted_map, &error_code);
       EXPECT_FALSE(cbor.has_value());
       EXPECT_EQ(error_code, Reader::DecoderError::OUT_OF_ORDER_KEY);
@@ -1161,7 +1161,7 @@
       config.error_code_out = &error_code;
       config.allow_and_canonicalize_out_of_order_keys = true;
 
-      absl::optional<Value> cbor =
+      base::Optional<Value> cbor =
           Reader::Read(unsorted_map, config);
       EXPECT_FALSE(cbor);
       EXPECT_EQ(error_code, Reader::DecoderError::DUPLICATE_KEY);
@@ -1195,7 +1195,7 @@
 
   {
     Reader::DecoderError error_code;
-    absl::optional<Value> cbor =
+    base::Optional<Value> cbor =
         Reader::Read(kMapWithDuplicateKey, &error_code);
     EXPECT_FALSE(cbor.has_value());
     EXPECT_EQ(error_code, Reader::DecoderError::DUPLICATE_KEY);
@@ -1207,7 +1207,7 @@
     config.error_code_out = &error_code;
     config.allow_and_canonicalize_out_of_order_keys = true;
 
-    absl::optional<Value> cbor = Reader::Read(kMapWithDuplicateKey, config);
+    base::Optional<Value> cbor = Reader::Read(kMapWithDuplicateKey, config);
     EXPECT_FALSE(cbor.has_value());
     EXPECT_EQ(error_code, Reader::DecoderError::DUPLICATE_KEY);
   }
@@ -1231,7 +1231,7 @@
     SCOPED_TRACE(testing::Message() << "testing cbor data utf8 encoding : "
                                     << test_element_index++);
 
-    absl::optional<Value> correctly_encoded_cbor =
+    base::Optional<Value> correctly_encoded_cbor =
         Reader::Read(cbor_byte, &error_code);
     EXPECT_TRUE(correctly_encoded_cbor.has_value());
     EXPECT_EQ(error_code, Reader::DecoderError::CBOR_NO_ERROR);
@@ -1239,7 +1239,7 @@
 
   // Incorrect UTF8 encoding referenced by section 3.5.3 of the stress test.
   std::vector<uint8_t> impossible_utf_byte{0x64, 0xfe, 0xfe, 0xff, 0xff};
-  absl::optional<Value> incorrectly_encoded_cbor =
+  base::Optional<Value> incorrectly_encoded_cbor =
       Reader::Read(impossible_utf_byte, &error_code);
   EXPECT_FALSE(incorrectly_encoded_cbor.has_value());
   EXPECT_EQ(error_code, Reader::DecoderError::INVALID_UTF8);
@@ -1265,7 +1265,7 @@
                  << "testing cbor extraneous data : " << test_element_index++);
 
     Reader::DecoderError error_code;
-    absl::optional<Value> cbor =
+    base::Optional<Value> cbor =
         Reader::Read(extraneous_cbor_data, &error_code);
     EXPECT_FALSE(cbor.has_value());
     EXPECT_EQ(error_code, Reader::DecoderError::EXTRANEOUS_DATA);
@@ -1300,7 +1300,7 @@
                  << ::testing::PrintToString(unsupported_simple_val));
 
     Reader::DecoderError error_code;
-    absl::optional<Value> cbor =
+    base::Optional<Value> cbor =
         Reader::Read(unsupported_simple_val, &error_code);
     EXPECT_FALSE(cbor.has_value());
     EXPECT_EQ(error_code, Reader::DecoderError::UNSUPPORTED_SIMPLE_VALUE);
@@ -1316,7 +1316,7 @@
   };
   for (const auto& test_case : kTestCases) {
     Reader::DecoderError error_code;
-    absl::optional<Value> cbor = Reader::Read(test_case, &error_code);
+    base::Optional<Value> cbor = Reader::Read(test_case, &error_code);
     EXPECT_FALSE(cbor.has_value());
     EXPECT_EQ(error_code, Reader::DecoderError::INCOMPLETE_CBOR_DATA);
   }
@@ -1340,7 +1340,7 @@
   Reader::Config config;
   config.error_code_out = &error;
 
-  absl::optional<Value> cbor = Reader::Read(kInvalidUTF8, config);
+  base::Optional<Value> cbor = Reader::Read(kInvalidUTF8, config);
   EXPECT_FALSE(cbor);
   EXPECT_EQ(Reader::DecoderError::INVALID_UTF8, error);
 
diff --git a/writer.cc b/writer.cc
index 2762bb3..1ae21c6 100644
--- a/writer.cc
+++ b/writer.cc
@@ -17,19 +17,19 @@
 Writer::~Writer() {}
 
 // static
-absl::optional<std::vector<uint8_t>> Writer::Write(const Value& node,
+base::Optional<std::vector<uint8_t>> Writer::Write(const Value& node,
                                                    const Config& config) {
   std::vector<uint8_t> cbor;
   Writer writer(&cbor);
   if (!writer.EncodeCBOR(node, config.max_nesting_level,
                          config.allow_invalid_utf8_for_testing)) {
-    return absl::nullopt;
+    return base::nullopt;
   }
   return cbor;
 }
 
 // static
-absl::optional<std::vector<uint8_t>> Writer::Write(const Value& node,
+base::Optional<std::vector<uint8_t>> Writer::Write(const Value& node,
                                                    size_t max_nesting_level) {
   Config config;
   config.max_nesting_level = base::checked_cast<int>(max_nesting_level);
diff --git a/writer.h b/writer.h
index 07ed51d..7a8a02f 100644
--- a/writer.h
+++ b/writer.h
@@ -10,9 +10,9 @@
 
 #include <vector>
 
+#include "base/optional.h"
 #include "cbor/cbor_export.h"
 #include "cbor/values.h"
-#include "third_party/abseil-cpp/absl/types/optional.h"
 
 // A basic Concise Binary Object Representation (CBOR) encoder as defined by
 // https://tools.ietf.org/html/rfc7049. This is a generic encoder that supplies
@@ -80,12 +80,12 @@
   // Returns the CBOR byte string representation of |node|, unless its nesting
   // depth is greater than |max_nesting_level|, in which case an empty optional
   // value is returned.
-  static absl::optional<std::vector<uint8_t>> Write(
+  static base::Optional<std::vector<uint8_t>> Write(
       const Value& node,
       size_t max_nesting_level = kDefaultMaxNestingDepth);
 
   // A version of |Write| above that takes a Config.
-  static absl::optional<std::vector<uint8_t>> Write(const Value& node,
+  static base::Optional<std::vector<uint8_t>> Write(const Value& node,
                                                     const Config& config);
 
  private: