buffet: Use command schema to define "progress"

According to the GCD specification command progress is dictionary,
defined same way as parameters and results.
Mapping between "done" and "progress" dictionary is not obvious, so patch
removes updates of progress from CommandInstance::Done().

BUG=brillo:915
TEST=FEATURES=test emerge-gizmo buffet

Change-Id: If6f6d52dbc0595a8f1cf0cf949a741675c9e5f3c
Reviewed-on: https://chromium-review.googlesource.com/268352
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/commands/command_instance.cc b/buffet/commands/command_instance.cc
index e62e048..24c7869 100644
--- a/buffet/commands/command_instance.cc
+++ b/buffet/commands/command_instance.cc
@@ -151,10 +151,10 @@
   json->SetString(commands::attributes::kCommand_Name, name_);
   json->Set(commands::attributes::kCommand_Parameters,
             TypedValueToJson(parameters_, nullptr).release());
+  json->Set(commands::attributes::kCommand_Progress,
+            TypedValueToJson(progress_, nullptr).release());
   json->Set(commands::attributes::kCommand_Results,
             TypedValueToJson(results_, nullptr).release());
-  json->Set(commands::attributes::kCommand_Progress,
-            GetProgressJson().release());
   json->SetString(commands::attributes::kCommand_State, status_);
 
   return json;
@@ -175,12 +175,11 @@
   return true;
 }
 
-bool CommandInstance::SetProgress(int progress) {
-  if (progress < 0 || progress > 100)
-    return false;
+bool CommandInstance::SetProgress(const native_types::Object& progress) {
+  // Change status even if progress unchanged, e.g. 0% -> 0%.
+  SetStatus(kStatusInProgress);
   if (progress != progress_) {
     progress_ = progress;
-    SetStatus(kStatusInProgress);
     for (auto& proxy : proxies_) {
       proxy->OnProgressChanged();
     }
@@ -201,7 +200,6 @@
 }
 
 void CommandInstance::Done() {
-  SetProgress(100);
   SetStatus(kStatusDone);
   RemoveFromQueue();
   // The command will be destroyed after that, so do not access any members.
@@ -221,15 +219,4 @@
     queue_->DelayedRemove(GetID());
 }
 
-std::unique_ptr<base::Value> CommandInstance::GetProgressJson() const {
-  // GCD server requires "progress" to be a JSON object. We will just make
-  // an object with a single field, "progress", so the patch request will
-  // look like this: {"progress": {"progress":100}}.
-  std::unique_ptr<base::DictionaryValue> progress_object{
-      new base::DictionaryValue};
-  progress_object->SetInteger(commands::attributes::kCommand_Progress,
-                              progress_);
-  return std::move(progress_object);
-}
-
 }  // namespace buffet