Add alias and option to support migration

The main goal of the change is to allow us to change the name of the
blobId while making sure the existing data is still valid during the
migration. Added an alias option which allow us to have two possible
valid blobId and will use the `baseBlobId` to commit the data even if
the current data match the alish ID. This allow us to change the blobId
of the binary store without loosing the data.

Also added an option to revert back to the alias blobId with the
`blobtool` to support backward compatibility when we need to downgrade
to a version without alias support. Created the base service that gets
trigger to start the blob id revert.

Tested:

Tested backward compatibility and working fine. The blob data are not
lost between versions.

Change-Id: I75bcbce3aff20c6ee8a491bef36fac260595d6f7
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/include/binarystore.hpp b/include/binarystore.hpp
index 792de4a..aa83714 100644
--- a/include/binarystore.hpp
+++ b/include/binarystore.hpp
@@ -74,6 +74,7 @@
     BinaryStore& operator=(BinaryStore&&) = default;
 
     std::string getBaseBlobId() const override;
+    bool setBaseBlobId(const std::string& baseBlobId) override;
     std::vector<std::string> getBlobIds() const override;
     bool openOrCreateBlob(const std::string& blobId, uint16_t flags) override;
     bool deleteBlob(const std::string& blobId) override;
@@ -91,10 +92,10 @@
      * @returns unique_ptr to constructed BinaryStore. Caller should take
      *     ownership of the instance.
      */
-    static std::unique_ptr<BinaryStoreInterface>
-        createFromConfig(const std::string& baseBlobId,
-                         std::unique_ptr<SysFile> file,
-                         std::optional<uint32_t> maxSize = std::nullopt);
+    static std::unique_ptr<BinaryStoreInterface> createFromConfig(
+        const std::string& baseBlobId, std::unique_ptr<SysFile> file,
+        std::optional<uint32_t> maxSize = std::nullopt,
+        std::optional<std::string> aliasBlobBaseId = std::nullopt);
 
     /**
      * Helper factory method to create a BinaryStore instance
@@ -111,7 +112,8 @@
   private:
     /* Load the serialized data from sysfile if commit state is dirty.
      * Returns False if encountered error when loading */
-    bool loadSerializedData();
+    bool loadSerializedData(
+        std::optional<std::string> aliasBlobBaseId = std::nullopt);
 
     std::string baseBlobId_;
     binaryblobproto::BinaryBlobBase blob_;