WebApp: Implement initialization for WebAppSyncBridge.

This code is disabled by default behind kDesktopPWAsWithoutExtensions base feature.

- Implement WebAppSyncBridge::GetClientTag and GetStorageKey
to infer them from launch_url.

On Init, pass sync metadata from WebAppDatabase to WebAppSyncBridge's
change_processor.

Read WebAppRegistrar apps data to implement WebAppSyncBridge::GetData
(GetData is the sync "view" for our model data).

Unit tests and browser tests will be added later in a follow up CL.
An MVP implementation of the bridge needed first.

This CL follows
"Implementing ModelTypeSyncBridge: Initialization"
section described here:
https://chromium.googlesource.com/chromium/src/+/HEAD/docs/sync/model_api.md#Initialization

In next CLs:
Implement: MergeSyncData, ApplySyncChanges, "Local changes" sections.

Sync-initiated installs/uninstalls will be an interesting case.

Bug: 860583
Change-Id: If8c6e78e48031f4caf9eb39ef68f9de65ec65c6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1797824
Reviewed-by: Alan Cutter <[email protected]>
Reviewed-by: Marc Treib <[email protected]>
Commit-Queue: Alexey Baskakov <[email protected]>
Cr-Commit-Position: refs/heads/master@{#701420}
diff --git a/chrome/browser/web_applications/web_app_database.h b/chrome/browser/web_applications/web_app_database.h
index 881cd7c2..bca34a5 100644
--- a/chrome/browser/web_applications/web_app_database.h
+++ b/chrome/browser/web_applications/web_app_database.h
@@ -18,6 +18,7 @@
 
 namespace syncer {
 class ModelError;
+class MetadataBatch;
 }  // namespace syncer
 
 namespace web_app {
@@ -30,10 +31,16 @@
 // Exclusively used from the UI thread.
 class WebAppDatabase {
  public:
-  explicit WebAppDatabase(AbstractWebAppDatabaseFactory* database_factory);
+  using ReportErrorCallback =
+      base::RepeatingCallback<void(const syncer::ModelError&)>;
+
+  WebAppDatabase(AbstractWebAppDatabaseFactory* database_factory,
+                 ReportErrorCallback error_callback);
   ~WebAppDatabase();
 
-  using RegistryOpenedCallback = base::OnceCallback<void(Registry registry)>;
+  using RegistryOpenedCallback = base::OnceCallback<void(
+      Registry registry,
+      std::unique_ptr<syncer::MetadataBatch> metadata_batch)>;
   // Open existing or create new DB. Read all data and return it via callback.
   void OpenDatabase(RegistryOpenedCallback callback);
 
@@ -61,6 +68,11 @@
       RegistryOpenedCallback callback,
       const base::Optional<syncer::ModelError>& error,
       std::unique_ptr<syncer::ModelTypeStore::RecordList> data_records);
+  void OnAllMetadataRead(
+      std::unique_ptr<syncer::ModelTypeStore::RecordList> data_records,
+      RegistryOpenedCallback callback,
+      const base::Optional<syncer::ModelError>& error,
+      std::unique_ptr<syncer::MetadataBatch> metadata_batch);
 
   void OnDataWritten(CompletionCallback callback,
                      const base::Optional<syncer::ModelError>& error);
@@ -68,6 +80,7 @@
   std::unique_ptr<syncer::ModelTypeStore> store_;
   std::unique_ptr<syncer::ModelTypeStore::WriteBatch> write_batch_;
   AbstractWebAppDatabaseFactory* database_factory_;
+  ReportErrorCallback error_callback_;
 
   // Database is opened if store is created and all data read.
   bool opened_ = false;