buffet: Simplify dbus::Bus propagation via ExportedObjectManager
Since ExportedObjectManager already stores a reference to dbus::Bus,
there is no reason to pass both of them around between different
objects. Added a method to retrieve the Bus from the ExpObjMgr.
BUG=chromium:374864
TEST=USE=buffet P2_TEST_FILTER="buffet::*" FEATURES=test emerge-link platform2
Change-Id: I01c1b890c1e126ede691d0c0be7fd3733143691b
Reviewed-on: https://chromium-review.googlesource.com/211661
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/exported_object_manager.h b/buffet/exported_object_manager.h
index 212609e..978c84e 100644
--- a/buffet/exported_object_manager.h
+++ b/buffet/exported_object_manager.h
@@ -94,13 +94,15 @@
void ReleaseInterface(const dbus::ObjectPath& path,
const std::string& interface_name);
+ const scoped_refptr<dbus::Bus>& GetBus() const { return bus_; }
+
private:
void HandleGetManagedObjects(
dbus::MethodCall* method_call,
dbus::ExportedObject::ResponseSender response_sender) const;
- // Both |bus_| and |exported_object_| outlive *this.
- dbus::Bus* const bus_;
+ scoped_refptr<dbus::Bus> bus_;
+ // |exported_object_| outlives *this.
dbus::ExportedObject* const exported_object_;
// Tracks all objects currently known to the ExportedObjectManager.
std::map<dbus::ObjectPath, InterfaceProperties> registered_objects_;
diff --git a/buffet/main.cc b/buffet/main.cc
index eb25d13..b70421b 100644
--- a/buffet/main.cc
+++ b/buffet/main.cc
@@ -78,7 +78,7 @@
logging::InitLogging(settings);
}
-void TakeServiceOwnership(scoped_refptr<dbus::Bus> bus, bool success) {
+void TakeServiceOwnership(const scoped_refptr<dbus::Bus>& bus, bool success) {
// Success should always be true since we've said that failures are
// fatal.
CHECK(success) << "Init of one or more objects has failed.";
@@ -88,11 +88,11 @@
}
void EnterMainLoop(base::MessageLoopForIO* message_loop,
- scoped_refptr<dbus::Bus> bus) {
+ const scoped_refptr<dbus::Bus>& bus) {
scoped_refptr<AsyncEventSequencer> sequencer(new AsyncEventSequencer());
ExportedObjectManager object_manager(
bus, dbus::ObjectPath(buffet::dbus_constants::kRootServicePath));
- buffet::Manager manager(bus, object_manager.AsWeakPtr());
+ buffet::Manager manager(object_manager.AsWeakPtr());
object_manager.Init(
sequencer->GetHandler("ObjectManager.Init() failed.", true));
manager.Init(sequencer->GetHandler("Manager.Init() failed.", true));
diff --git a/buffet/manager.cc b/buffet/manager.cc
index 39ccf7d..1cb0da2 100644
--- a/buffet/manager.cc
+++ b/buffet/manager.cc
@@ -29,10 +29,8 @@
namespace buffet {
Manager::Manager(
- scoped_refptr<dbus::Bus> bus,
- base::WeakPtr<dbus_utils::ExportedObjectManager> object_manager)
- : bus_(bus),
- exported_object_(bus->GetExportedObject(
+ const base::WeakPtr<dbus_utils::ExportedObjectManager>& object_manager)
+ : exported_object_(object_manager->GetBus()->GetExportedObject(
dbus::ObjectPath(dbus_constants::kManagerServicePath))),
object_manager_(object_manager) { }
@@ -116,7 +114,7 @@
dbus_constants::kManagerInterface, dbus_constants::kManagerTestMethod,
"Failed exporting TestMethod method",
true));
- properties_.reset(new Properties(bus_));
+ properties_.reset(new Properties(object_manager_->GetBus()));
// TODO(wiley): Initialize all properties appropriately before claiming
// the properties interface.
properties_->state_.SetValue("{}");
diff --git a/buffet/manager.h b/buffet/manager.h
index 08e7656..6bfccd0 100644
--- a/buffet/manager.h
+++ b/buffet/manager.h
@@ -35,8 +35,8 @@
public:
typedef base::Callback<void(bool success)> OnInitFinish;
- Manager(scoped_refptr<dbus::Bus> bus,
- base::WeakPtr<dbus_utils::ExportedObjectManager> object_manager);
+ Manager(
+ const base::WeakPtr<dbus_utils::ExportedObjectManager>& object_manager);
~Manager();
void Init(const OnInitFinish& cb);
@@ -71,7 +71,6 @@
scoped_ptr<::dbus::Response> HandleTestMethod(
::dbus::MethodCall* method_call);
- scoped_refptr<dbus::Bus> bus_;
dbus::ExportedObject* exported_object_; // weak; owned by the Bus object.
base::WeakPtr<dbus_utils::ExportedObjectManager> object_manager_;
scoped_ptr<Properties> properties_;