buffet: Send modelManifestId with device registration

modelManifestId is ID of manifest with useful information
that can be used by device clients.
modelManifestId is the same value as modelId from /privet/info.

CQ-DEPEND=CL:251381
BUG=brillo:295
TEST=unittests

Change-Id: Ic847c30badd9aa8b97f3deb7939813cc95195f02
Reviewed-on: https://chromium-review.googlesource.com/251141
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/device_registration_info.cc b/buffet/device_registration_info.cc
index 01ff4fc..5851f04 100644
--- a/buffet/device_registration_info.cc
+++ b/buffet/device_registration_info.cc
@@ -50,6 +50,8 @@
 const char kDisplayName[]   = "display_name";
 const char kDescription[]   = "description";
 const char kLocation[]      = "location";
+const char kModelId[]       = "model_id";
+
 
 }  // namespace storage_keys
 }  // namespace buffet
@@ -230,6 +232,11 @@
   if (!dict->GetString(storage_keys::kLocation, &location))
     return false;
 
+  // Temporarily tolerate missing modelId. Older registrations will not have a
+  // modelId in their state files.
+  // TODO(vitalybuka): Add result check back. Should be safe starting Mar 2015.
+  dict->GetString(storage_keys::kModelId, &model_id_);
+
   client_id_            = client_id;
   client_secret_        = client_secret;
   api_key_              = api_key;
@@ -243,6 +250,7 @@
   display_name_         = display_name;
   description_          = description;
   location_             = location;
+
   return true;
 }
 
@@ -261,6 +269,7 @@
   dict.SetString(storage_keys::kDisplayName,  display_name_);
   dict.SetString(storage_keys::kDescription,  description_);
   dict.SetString(storage_keys::kLocation,     location_);
+  dict.SetString(storage_keys::kModelId,      model_id_);
 
   return storage_->Save(&dict);
 }
@@ -387,6 +396,8 @@
     resource->SetString("description", description_);
   if (!location_.empty())
     resource->SetString("location", location_);
+  if (!model_id_.empty())
+    resource->SetString("modelManifestId", model_id_);
   resource->SetString("channel.supportedType", "xmpp");
   resource->Set("commandDefs", commands.release());
   resource->Set("state", state.release());
@@ -425,17 +436,18 @@
       !GetParamValue(params, storage_keys::kClientSecret, &client_secret_,
                      error) ||
       !GetParamValue(params, storage_keys::kApiKey, &api_key_, error) ||
-      !GetParamValue(params, storage_keys::kDeviceKind, &device_kind_,
-                     error) ||
+      !GetParamValue(params, storage_keys::kDeviceKind, &device_kind_, error) ||
       !GetParamValue(params, storage_keys::kName, &name_, error) ||
       !GetParamValue(params, storage_keys::kDisplayName, &display_name_,
                      error) ||
       !GetParamValue(params, storage_keys::kDescription, &description_,
                      error) ||
       !GetParamValue(params, storage_keys::kLocation, &location_, error) ||
+      !GetParamValue(params, storage_keys::kModelId, &model_id_, error) ||
       !GetParamValue(params, storage_keys::kOAuthURL, &oauth_url_, error) ||
-      !GetParamValue(params, storage_keys::kServiceURL, &service_url_, error))
+      !GetParamValue(params, storage_keys::kServiceURL, &service_url_, error)) {
     return std::string();
+  }
 
   std::unique_ptr<base::DictionaryValue> device_draft =
       BuildDeviceResource(error);