libbrillo: factor out Properties interface setup

This code is copy-pasted in the async and sync init functions.
Factor it out into its own function for brevity.

BUG=None
TEST=unit tests

Change-Id: I2c3c4f18df708065bebf77792a9d2d4c85022de4
Reviewed-on: https://chromium-review.googlesource.com/512984
Commit-Ready: Eric Caruso <ejcaruso@chromium.org>
Tested-by: Eric Caruso <ejcaruso@chromium.org>
Reviewed-by: Dan Erat <derat@chromium.org>
diff --git a/brillo/dbus/dbus_object.cc b/brillo/dbus/dbus_object.cc
index 95cccdd..5172dc6 100644
--- a/brillo/dbus/dbus_object.cc
+++ b/brillo/dbus/dbus_object.cc
@@ -190,21 +190,7 @@
   scoped_refptr<AsyncEventSequencer> sequencer(new AsyncEventSequencer());
   exported_object_ = bus_->GetExportedObject(object_path_);
 
-  // Add the org.freedesktop.DBus.Properties interface to the object.
-  DBusInterface* prop_interface = AddOrGetInterface(dbus::kPropertiesInterface);
-  prop_interface->AddSimpleMethodHandler(
-      dbus::kPropertiesGetAll,
-      base::Unretained(&property_set_),
-      &ExportedPropertySet::HandleGetAll);
-  prop_interface->AddSimpleMethodHandlerWithError(
-      dbus::kPropertiesGet,
-      base::Unretained(&property_set_),
-      &ExportedPropertySet::HandleGet);
-  prop_interface->AddSimpleMethodHandlerWithError(
-      dbus::kPropertiesSet,
-      base::Unretained(&property_set_),
-      &ExportedPropertySet::HandleSet);
-  property_set_.OnPropertiesInterfaceExported(prop_interface);
+  RegisterPropertiesInterface();
 
   // Export interface methods
   for (const auto& pair : interfaces_) {
@@ -225,21 +211,7 @@
   CHECK(exported_object_ == nullptr) << "Object already registered.";
   exported_object_ = bus_->GetExportedObject(object_path_);
 
-  // Add the org.freedesktop.DBus.Properties interface to the object.
-  DBusInterface* prop_interface = AddOrGetInterface(dbus::kPropertiesInterface);
-  prop_interface->AddSimpleMethodHandler(
-      dbus::kPropertiesGetAll,
-      base::Unretained(&property_set_),
-      &ExportedPropertySet::HandleGetAll);
-  prop_interface->AddSimpleMethodHandlerWithError(
-      dbus::kPropertiesGet,
-      base::Unretained(&property_set_),
-      &ExportedPropertySet::HandleGet);
-  prop_interface->AddSimpleMethodHandlerWithError(
-      dbus::kPropertiesSet,
-      base::Unretained(&property_set_),
-      &ExportedPropertySet::HandleSet);
-  property_set_.OnPropertiesInterfaceExported(prop_interface);
+  RegisterPropertiesInterface();
 
   // Export interface methods
   for (const auto& pair : interfaces_) {
@@ -275,5 +247,22 @@
   return false;
 }
 
+void DBusObject::RegisterPropertiesInterface() {
+  DBusInterface* prop_interface = AddOrGetInterface(dbus::kPropertiesInterface);
+  prop_interface->AddSimpleMethodHandler(
+      dbus::kPropertiesGetAll,
+      base::Unretained(&property_set_),
+      &ExportedPropertySet::HandleGetAll);
+  prop_interface->AddSimpleMethodHandlerWithError(
+      dbus::kPropertiesGet,
+      base::Unretained(&property_set_),
+      &ExportedPropertySet::HandleGet);
+  prop_interface->AddSimpleMethodHandlerWithError(
+      dbus::kPropertiesSet,
+      base::Unretained(&property_set_),
+      &ExportedPropertySet::HandleSet);
+  property_set_.OnPropertiesInterfaceExported(prop_interface);
+}
+
 }  // namespace dbus_utils
 }  // namespace brillo
diff --git a/brillo/dbus/dbus_object.h b/brillo/dbus/dbus_object.h
index 6cd34dd..e7c59e3 100644
--- a/brillo/dbus/dbus_object.h
+++ b/brillo/dbus/dbus_object.h
@@ -555,6 +555,9 @@
   scoped_refptr<dbus::Bus> GetBus() { return bus_; }
 
  private:
+  // Add the org.freedesktop.DBus.Properties interface to the object.
+  void RegisterPropertiesInterface();
+
   // A map of all the interfaces added to this object.
   std::map<std::string, std::unique_ptr<DBusInterface>> interfaces_;
   // Exported property set for properties registered with the interfaces