buffet: Make ExportedPropertySet threadsafe

In Chrome, we have both a DBus thread and some main thread (an 'origin'
thread).  Objects related to DBus functionality need to accomodate this
so that we can send this upstream.  This mostly just means that we need
to add assertions that developers are using the API correctly, so that
the use of weak pointers is safe.

BUG=chromium:360831
TEST=Unittests pass.  buffet_BasicDBusAPI still passes.

Change-Id: Ibb48a5e65c7cb02e5edce9cbf85432bed70d7686
Reviewed-on: https://chromium-review.googlesource.com/193505
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Christopher Wiley <wiley@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/exported_property_set.h b/buffet/exported_property_set.h
index 84dbe2a..c464a8b 100644
--- a/buffet/exported_property_set.h
+++ b/buffet/exported_property_set.h
@@ -94,13 +94,17 @@
 
 class ExportedPropertySet {
  public:
-  ExportedPropertySet(dbus::ExportedObject* exported_object);
-  ~ExportedPropertySet();
+  typedef base::Callback<void(bool success)> OnInitFinish;
 
-  // Claims the org.freedesktop.DBus.Properties interface.  This
-  // needs to be done after all properties are initialized to
-  // appropriate values.
-  void ClaimPropertiesInterface();
+  ExportedPropertySet(dbus::Bus* bus, const dbus::ObjectPath& path);
+  virtual ~ExportedPropertySet();
+
+  // Claims the method associated with the org.freedesktop.DBus.Properties
+  // interface.  This needs to be done after all properties are initialized to
+  // appropriate values.  This method will call |cb| when all methods
+  // are exported to the DBus object.  |cb| will be called on the origin
+  // thread.
+  void Init(const OnInitFinish& cb);
 
  protected:
   void RegisterProperty(const std::string& interface_name,
@@ -118,16 +122,11 @@
   // Instead, use setters in exposed interfaces.
   void HandleSet(dbus::MethodCall* method_call,
                  dbus::ExportedObject::ResponseSender response_sender);
+  void HandlePropertyUpdated(const std::string& interface,
+                             const std::string& name,
+                             const ExportedPropertyBase* property);
 
-  virtual void HandlePropertyUpdated(const std::string& interface,
-                                     const std::string& name,
-                                     const ExportedPropertyBase* property);
-
-  void WriteSignalForPropertyUpdate(const std::string& interface,
-                                    const std::string& name,
-                                    const ExportedPropertyBase* property,
-                                    dbus::Signal* signal) const;
-
+  dbus::Bus* bus_;
   dbus::ExportedObject* exported_object_;  // weak; owned by the Bus object.
   // This is a map from interface name -> property name -> pointer to property.
   std::map<std::string,