Workflow manager: edit and delete workflows

This CL adds the ability to view/edit and delete workflows in the
workflow manager. With this, the workflow manager initial prototype is
complete, since it allows the user to fully manage their workflows, even
if the UI might be subject to change to further improve it in the
future.

Bug: twpowertools:74
Change-Id: I4f8d1b7ab54dcc600dbd10fcb8e605bcb61d36bb
diff --git a/src/workflows/workflowsStorage.js b/src/workflows/workflowsStorage.js
index e692209..95b3583 100644
--- a/src/workflows/workflowsStorage.js
+++ b/src/workflows/workflowsStorage.js
@@ -47,12 +47,30 @@
   }
 
   static add(workflow) {
-    const binaryWorkflow = workflow.serializeBinary();
-    return arrayBufferToBase64(binaryWorkflow).then(data => {
+    return this._proto2Base64(workflow).then(data => {
       return this.addRaw(data);
     });
   }
 
+  static updateRaw(uuid, base64Workflow) {
+    return this.getAll().then(workflows => {
+      workflows.map(w => {
+        if (w.uuid !== uuid) return w;
+        w.data = base64Workflow;
+        return w;
+      });
+      const items = {};
+      items[kWorkflowsDataKey] = workflows;
+      chrome.storage.local.set(items);
+    });
+  }
+
+  static update(uuid, workflow) {
+    return this._proto2Base64(workflow).then(data => {
+      return this.updateRaw(uuid, data);
+    });
+  }
+
   static remove(uuid) {
     return this.getAll().then(workflows => {
       const items = {};
@@ -60,4 +78,9 @@
       chrome.storage.local.set(items);
     });
   }
+
+  static _proto2Base64(workflow) {
+    const binaryWorkflow = workflow.serializeBinary();
+    return arrayBufferToBase64(binaryWorkflow);
+  }
 }