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/manager.h b/buffet/manager.h
index cc65868..95d0548 100644
--- a/buffet/manager.h
+++ b/buffet/manager.h
@@ -8,6 +8,7 @@
 #include <base/basictypes.h>
 #include <base/memory/scoped_ptr.h>
 #include <dbus/message.h>
+#include <dbus/object_path.h>
 
 #include "buffet/dbus_constants.h"
 #include "buffet/exported_property_set.h"
@@ -21,15 +22,19 @@
 // device state.
 class Manager {
  public:
-  Manager(DBusManager* dbus_manager);
+  typedef base::Callback<void(bool success)> OnInitFinish;
+
+  Manager(dbus::Bus* bus);
   ~Manager();
+  void Init(const OnInitFinish& cb);
 
  private:
   struct Properties: public dbus_utils::ExportedPropertySet {
    public:
     dbus_utils::ExportedProperty<std::string> state_;
-    Properties(dbus::ExportedObject *manager_object)
-        : dbus_utils::ExportedPropertySet(manager_object) {
+    Properties(dbus::Bus* bus)
+        : dbus_utils::ExportedPropertySet(
+              bus, dbus::ObjectPath(dbus_constants::kManagerServicePath)) {
       RegisterProperty(dbus_constants::kManagerInterface, "State", &state_);
     }
     virtual ~Properties() {}
@@ -42,7 +47,8 @@
   scoped_ptr<dbus::Response> HandleUpdateState(
       dbus::MethodCall* method_call);
 
-  DBusManager* dbus_manager_;  // Weak;  DBusManager should outlive Manager.
+  dbus::Bus* bus_;
+  dbus::ExportedObject* exported_object_;  // weak; owned by the Bus object.
   scoped_ptr<Properties> properties_;
 
   DISALLOW_COPY_AND_ASSIGN(Manager);