WebApp: Redesign RegisterApp and UnregisterApp methods.

Support creation and deletion of apps as a part of single update.

RegisterApp, UnregisterApp and UnregisterAll methods now can be expressed
within one WebAppRegistryUpdate (one transaction).

Report kWriteDataFailed in InstallFinalizer if commit fails.

WebAppRegistryUpdate CreateApp/UpdateApp/DeleteApp is now the only
writable database API (as in Database CRUD: Create/Update/Delete).

Bug: 860583
Change-Id: Ia2e23a4d4a0d47e62b815abd55803616a204e813
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1824043
Reviewed-by: Alan Cutter <[email protected]>
Commit-Queue: Alexey Baskakov <[email protected]>
Cr-Commit-Position: refs/heads/master@{#700088}
diff --git a/chrome/browser/web_applications/web_app_database.h b/chrome/browser/web_applications/web_app_database.h
index 9ef4edf..881cd7c2 100644
--- a/chrome/browser/web_applications/web_app_database.h
+++ b/chrome/browser/web_applications/web_app_database.h
@@ -8,7 +8,6 @@
 #include <memory>
 
 #include "base/callback_forward.h"
-#include "base/containers/flat_set.h"
 #include "base/macros.h"
 #include "base/memory/weak_ptr.h"
 #include "base/optional.h"
@@ -26,6 +25,7 @@
 class AbstractWebAppDatabaseFactory;
 class WebApp;
 class WebAppProto;
+struct RegistryUpdateData;
 
 // Exclusively used from the UI thread.
 class WebAppDatabase {
@@ -34,13 +34,15 @@
   ~WebAppDatabase();
 
   using RegistryOpenedCallback = base::OnceCallback<void(Registry registry)>;
-  using CompletionCallback = base::OnceCallback<void(bool success)>;
-  using AppsToWrite = base::flat_set<const WebApp*>;
-
   // Open existing or create new DB. Read all data and return it via callback.
   void OpenDatabase(RegistryOpenedCallback callback);
-  void WriteWebApps(AppsToWrite apps, CompletionCallback callback);
-  void DeleteWebApps(std::vector<AppId> app_ids, CompletionCallback callback);
+
+  using CompletionCallback = base::OnceCallback<void(bool success)>;
+  // There can be only 1 transaction at a time.
+  void BeginTransaction();
+  void CommitTransaction(const RegistryUpdateData& update_data,
+                         CompletionCallback callback);
+  void CancelTransaction();
 
   // Exposed for testing.
   static std::unique_ptr<WebAppProto> CreateWebAppProto(const WebApp& web_app);
@@ -63,9 +65,6 @@
   void OnDataWritten(CompletionCallback callback,
                      const base::Optional<syncer::ModelError>& error);
 
-  void BeginTransaction();
-  void CommitTransaction(CompletionCallback callback);
-
   std::unique_ptr<syncer::ModelTypeStore> store_;
   std::unique_ptr<syncer::ModelTypeStore::WriteBatch> write_batch_;
   AbstractWebAppDatabaseFactory* database_factory_;