[ledger] Remove ObjectDigestView

This is in preparation for switching ObjectDigest to a class distinct
from std::string.

Tested: compiles, ledger_tests still pass
Change-Id: Iacf27e704abbd02b672894e39e5ac43795fa08e6
diff --git a/bin/ledger/storage/impl/db_serialization.cc b/bin/ledger/storage/impl/db_serialization.cc
index d51c103..effe831 100644
--- a/bin/ledger/storage/impl/db_serialization.cc
+++ b/bin/ledger/storage/impl/db_serialization.cc
@@ -32,7 +32,7 @@
 
 constexpr fxl::StringView ObjectRow::kPrefix;
 
-std::string ObjectRow::GetKeyFor(ObjectDigestView object_digest) {
+std::string ObjectRow::GetKeyFor(const ObjectDigest& object_digest) {
   return fxl::Concatenate({kPrefix, object_digest});
 }
 
diff --git a/bin/ledger/storage/impl/db_serialization.h b/bin/ledger/storage/impl/db_serialization.h
index 31991e7..ee2c49e 100644
--- a/bin/ledger/storage/impl/db_serialization.h
+++ b/bin/ledger/storage/impl/db_serialization.h
@@ -31,7 +31,7 @@
  public:
   static constexpr fxl::StringView kPrefix = "objects/";
 
-  static std::string GetKeyFor(ObjectDigestView object_digest);
+  static std::string GetKeyFor(const ObjectDigest& object_digest);
 };
 
 class UnsyncedCommitRow {
diff --git a/bin/ledger/storage/impl/object_digest.cc b/bin/ledger/storage/impl/object_digest.cc
index f555ec8..07eb2dc 100644
--- a/bin/ledger/storage/impl/object_digest.cc
+++ b/bin/ledger/storage/impl/object_digest.cc
@@ -29,7 +29,7 @@
 
 }  // namespace
 
-bool IsDigestValid(ObjectDigestView object_digest) {
+bool IsDigestValid(const ObjectDigest& object_digest) {
   if (object_digest.size() <= kStorageHashSize) {
     // |object_digest| is of type inline.
     return true;
@@ -48,7 +48,7 @@
   return false;
 }
 
-ObjectDigestType GetObjectDigestType(ObjectDigestView object_digest) {
+ObjectDigestType GetObjectDigestType(const ObjectDigest& object_digest) {
   FXL_DCHECK(IsDigestValid(object_digest));
 
   if (object_digest.size() <= kStorageHashSize) {
@@ -77,7 +77,7 @@
   }
 }
 
-fxl::StringView ExtractObjectDigestData(ObjectDigestView object_digest) {
+fxl::StringView ExtractObjectDigestData(const ObjectDigest& object_digest) {
   FXL_DCHECK(IsDigestValid(object_digest));
 
   if (object_digest.size() <= kStorageHashSize) {
diff --git a/bin/ledger/storage/impl/object_digest.h b/bin/ledger/storage/impl/object_digest.h
index 1eca2fa..5660f2d 100644
--- a/bin/ledger/storage/impl/object_digest.h
+++ b/bin/ledger/storage/impl/object_digest.h
@@ -24,10 +24,10 @@
 };
 
 // Returns whether the given digest is valid.
-bool IsDigestValid(ObjectDigestView object_digest);
+bool IsDigestValid(const ObjectDigest& object_digest);
 
 // Returns the type of |object_digest|.
-ObjectDigestType GetObjectDigestType(ObjectDigestView object_digest);
+ObjectDigestType GetObjectDigestType(const ObjectDigest& object_digest);
 
 // Returns the object type associated to an object id type.
 ObjectType GetObjectType(ObjectDigestType digest_type);
@@ -35,7 +35,7 @@
 // Extracts the data from |object_digest|. If |object_digest| type is |INLINE|,
 // the returned data is the content of the object, otherwise, it is the hash of
 // the object.
-fxl::StringView ExtractObjectDigestData(ObjectDigestView object_digest);
+fxl::StringView ExtractObjectDigestData(const ObjectDigest& object_digest);
 
 // Computes the id of the object of the given |type| with the given |content|.
 ObjectDigest ComputeObjectDigest(ObjectType type,
diff --git a/bin/ledger/storage/impl/object_identifier_encoding.cc b/bin/ledger/storage/impl/object_identifier_encoding.cc
index 19d41b1..8b12be5 100644
--- a/bin/ledger/storage/impl/object_identifier_encoding.cc
+++ b/bin/ledger/storage/impl/object_identifier_encoding.cc
@@ -9,7 +9,6 @@
 #include "peridot/bin/ledger/storage/impl/object_digest.h"
 
 namespace storage {
-
 ObjectIdentifier ToObjectIdentifier(
     const ObjectIdentifierStorage* object_identifier_storage) {
   return {object_identifier_storage->key_index(),
@@ -42,10 +41,12 @@
   }
   const ObjectIdentifierStorage* storage = GetObjectIdentifierStorage(
       reinterpret_cast<const unsigned char*>(data.data()));
-  if (!IsDigestValid(storage->object_digest())) {
+  ObjectDigest object_digest = convert::ToString(storage->object_digest());
+  if (!IsDigestValid(object_digest)) {
     return false;
   }
-  *object_identifier = ToObjectIdentifier(storage);
+  *object_identifier = {storage->key_index(), storage->deletion_scope_id(),
+                        std::move(object_digest)};
   return true;
 }
 
diff --git a/bin/ledger/storage/impl/page_db.h b/bin/ledger/storage/impl/page_db.h
index 1b1feb5..c840196 100644
--- a/bin/ledger/storage/impl/page_db.h
+++ b/bin/ledger/storage/impl/page_db.h
@@ -214,7 +214,7 @@
   // Checks whether the object with the given |object_digest| is stored in the
   // database.
   FXL_WARN_UNUSED_RESULT virtual Status HasObject(
-      coroutine::CoroutineHandler* handler, ObjectDigestView object_digest,
+      coroutine::CoroutineHandler* handler, const ObjectDigest& object_digest,
       bool* has_object) = 0;
 
   // Returns the status of the object with the given id.
diff --git a/bin/ledger/storage/impl/page_db_batch_impl.cc b/bin/ledger/storage/impl/page_db_batch_impl.cc
index d19a601..20a132c 100644
--- a/bin/ledger/storage/impl/page_db_batch_impl.cc
+++ b/bin/ledger/storage/impl/page_db_batch_impl.cc
@@ -185,7 +185,7 @@
 }
 
 Status PageDbBatchImpl::DCheckHasObject(CoroutineHandler* handler,
-                                        convert::ExtendedStringView key) {
+                                        const ObjectDigest& key) {
 #ifdef NDEBUG
   return Status::OK;
 #else
diff --git a/bin/ledger/storage/impl/page_db_batch_impl.h b/bin/ledger/storage/impl/page_db_batch_impl.h
index f1306ea..5550959 100644
--- a/bin/ledger/storage/impl/page_db_batch_impl.h
+++ b/bin/ledger/storage/impl/page_db_batch_impl.h
@@ -78,7 +78,7 @@
 
  private:
   Status DCheckHasObject(coroutine::CoroutineHandler* handler,
-                         convert::ExtendedStringView key);
+                         const ObjectDigest& key);
 
   rng::Random* const random_;
   std::unique_ptr<Db::Batch> batch_;
diff --git a/bin/ledger/storage/impl/page_db_empty_impl.cc b/bin/ledger/storage/impl/page_db_empty_impl.cc
index 1a1db0c..5c84ba8 100644
--- a/bin/ledger/storage/impl/page_db_empty_impl.cc
+++ b/bin/ledger/storage/impl/page_db_empty_impl.cc
@@ -42,7 +42,7 @@
   return Status::NOT_IMPLEMENTED;
 }
 Status PageDbEmptyImpl::HasObject(CoroutineHandler* /*handler*/,
-                                  ObjectDigestView /*object_digest*/,
+                                  const ObjectDigest& /*object_digest*/,
                                   bool* /*has_object*/) {
   return Status::NOT_IMPLEMENTED;
 }
diff --git a/bin/ledger/storage/impl/page_db_empty_impl.h b/bin/ledger/storage/impl/page_db_empty_impl.h
index aa4f331..bb7e48e 100644
--- a/bin/ledger/storage/impl/page_db_empty_impl.h
+++ b/bin/ledger/storage/impl/page_db_empty_impl.h
@@ -37,7 +37,8 @@
                     ObjectIdentifier object_identifier,
                     std::unique_ptr<const Object>* object) override;
   Status HasObject(coroutine::CoroutineHandler* handler,
-                   ObjectDigestView object_digest, bool* has_object) override;
+                   const ObjectDigest& object_digest,
+                   bool* has_object) override;
   Status GetUnsyncedCommitIds(coroutine::CoroutineHandler* handler,
                               std::vector<CommitId>* commit_ids) override;
   Status IsCommitSynced(coroutine::CoroutineHandler* handler,
diff --git a/bin/ledger/storage/impl/page_db_impl.cc b/bin/ledger/storage/impl/page_db_impl.cc
index 2eaaaa9..ca2bca0 100644
--- a/bin/ledger/storage/impl/page_db_impl.cc
+++ b/bin/ledger/storage/impl/page_db_impl.cc
@@ -194,7 +194,8 @@
 }
 
 Status PageDbImpl::HasObject(CoroutineHandler* handler,
-                             ObjectDigestView object_digest, bool* has_object) {
+                             const ObjectDigest& object_digest,
+                             bool* has_object) {
   return db_->HasKey(handler, ObjectRow::GetKeyFor(object_digest), has_object);
 }
 
diff --git a/bin/ledger/storage/impl/page_db_impl.h b/bin/ledger/storage/impl/page_db_impl.h
index 4212398..79016c0 100644
--- a/bin/ledger/storage/impl/page_db_impl.h
+++ b/bin/ledger/storage/impl/page_db_impl.h
@@ -46,7 +46,8 @@
                     ObjectIdentifier object_identifier,
                     std::unique_ptr<const Object>* object) override;
   Status HasObject(coroutine::CoroutineHandler* handler,
-                   ObjectDigestView object_digest, bool* has_object) override;
+                   const ObjectDigest& object_digest,
+                   bool* has_object) override;
   Status GetUnsyncedCommitIds(coroutine::CoroutineHandler* handler,
                               std::vector<CommitId>* commit_ids) override;
   Status IsCommitSynced(coroutine::CoroutineHandler* handler,
diff --git a/bin/ledger/storage/impl/page_storage_impl.cc b/bin/ledger/storage/impl/page_storage_impl.cc
index 20af7a4..2ab74cb 100644
--- a/bin/ledger/storage/impl/page_storage_impl.cc
+++ b/bin/ledger/storage/impl/page_storage_impl.cc
@@ -762,10 +762,10 @@
       object_identifiers.reserve(object_identifiers.size() +
                                  file_index->children()->size());
       for (const auto* child : *file_index->children()) {
-        if (GetObjectDigestType(child->object_identifier()->object_digest()) !=
+        ObjectIdentifier new_object_identifier =
+            ToObjectIdentifier(child->object_identifier());
+        if (GetObjectDigestType(new_object_identifier.object_digest()) !=
             ObjectDigestType::INLINE) {
-          ObjectIdentifier new_object_identifier =
-              ToObjectIdentifier(child->object_identifier());
           if (!seen_identifiers.count(new_object_identifier)) {
             object_identifiers.push_back(std::move(new_object_identifier));
           }
diff --git a/bin/ledger/storage/public/types.h b/bin/ledger/storage/public/types.h
index 71bcf60..30bf43e 100644
--- a/bin/ledger/storage/public/types.h
+++ b/bin/ledger/storage/public/types.h
@@ -19,7 +19,6 @@
 using CommitId = std::string;
 using CommitIdView = convert::ExtendedStringView;
 using ObjectDigest = std::string;
-using ObjectDigestView = convert::ExtendedStringView;
 using JournalId = std::string;
 using JournalIdView = convert::ExtendedStringView;