Commit 2ef7d0ed authored by derat's avatar derat Committed by Commit bot

dbus: Make ObjectManager get objects after service is ready.

Make dbus::ObjectManager automatically fetch managed objects
after the remote service becomes available. Also remove
Bus::GetManagedObjects(), which produces a large amount of
log spam due to some services not yet being ready. (It was
called by chromeos::DBusThreadManager and
bluez::BluezDBusManager at startup.)

BUG=636554

Review-Url: https://codereview.chromium.org/2239123002
Cr-Commit-Position: refs/heads/master@{#417405}
parent 04803b42
...@@ -216,11 +216,6 @@ void DBusThreadManager::InitializeClients() { ...@@ -216,11 +216,6 @@ void DBusThreadManager::InitializeClients() {
GetSystemClockClient()->Init(GetSystemBus()); GetSystemClockClient()->Init(GetSystemBus());
GetUpdateEngineClient()->Init(GetSystemBus()); GetUpdateEngineClient()->Init(GetSystemBus());
// This must be called after the list of clients so they've each had a
// chance to register with their object g_dbus_thread_managers.
if (GetSystemBus())
GetSystemBus()->GetManagedObjects();
client_bundle_->SetupDefaultEnvironment(); client_bundle_->SetupDefaultEnvironment();
} }
......
...@@ -400,13 +400,6 @@ void Bus::RemoveObjectManagerInternalHelper( ...@@ -400,13 +400,6 @@ void Bus::RemoveObjectManagerInternalHelper(
callback.Run(); callback.Run();
} }
void Bus::GetManagedObjects() {
for (ObjectManagerTable::iterator iter = object_manager_table_.begin();
iter != object_manager_table_.end(); ++iter) {
iter->second->GetManagedObjects();
}
}
bool Bus::Connect() { bool Bus::Connect() {
// dbus_bus_get_private() and dbus_bus_get() are blocking calls. // dbus_bus_get_private() and dbus_bus_get() are blocking calls.
AssertOnDBusThread(); AssertOnDBusThread();
......
...@@ -360,12 +360,6 @@ class CHROME_DBUS_EXPORT Bus : public base::RefCountedThreadSafe<Bus> { ...@@ -360,12 +360,6 @@ class CHROME_DBUS_EXPORT Bus : public base::RefCountedThreadSafe<Bus> {
const ObjectPath& object_path, const ObjectPath& object_path,
const base::Closure& callback); const base::Closure& callback);
// Instructs all registered object managers to retrieve their set of managed
// objects from their respective remote objects. There is no need to call this
// manually, this is called automatically by the D-Bus thread manager once
// implementation classes are registered.
virtual void GetManagedObjects();
// Shuts down the bus and blocks until it's done. More specifically, this // Shuts down the bus and blocks until it's done. More specifically, this
// function does the following: // function does the following:
// //
......
...@@ -31,7 +31,6 @@ class MockObjectManager : public ObjectManager { ...@@ -31,7 +31,6 @@ class MockObjectManager : public ObjectManager {
MOCK_METHOD1(GetObjectProxy, ObjectProxy*(const ObjectPath&)); MOCK_METHOD1(GetObjectProxy, ObjectProxy*(const ObjectPath&));
MOCK_METHOD2(GetProperties, PropertySet*(const ObjectPath&, MOCK_METHOD2(GetProperties, PropertySet*(const ObjectPath&,
const std::string&)); const std::string&));
MOCK_METHOD0(GetManagedObjects, void());
protected: protected:
virtual ~MockObjectManager(); virtual ~MockObjectManager();
......
...@@ -167,35 +167,6 @@ void ObjectManager::CleanUp() { ...@@ -167,35 +167,6 @@ void ObjectManager::CleanUp() {
match_rule_.clear(); match_rule_.clear();
} }
void ObjectManager::InitializeObjects() {
DCHECK(bus_);
DCHECK(object_proxy_);
DCHECK(setup_success_);
// |object_proxy_| is no longer valid if the Bus was shut down before this
// call. Don't initiate any other action from the origin thread.
if (cleanup_called_)
return;
object_proxy_->ConnectToSignal(
kObjectManagerInterface,
kObjectManagerInterfacesAdded,
base::Bind(&ObjectManager::InterfacesAddedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::Bind(&ObjectManager::InterfacesAddedConnected,
weak_ptr_factory_.GetWeakPtr()));
object_proxy_->ConnectToSignal(
kObjectManagerInterface,
kObjectManagerInterfacesRemoved,
base::Bind(&ObjectManager::InterfacesRemovedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::Bind(&ObjectManager::InterfacesRemovedConnected,
weak_ptr_factory_.GetWeakPtr()));
GetManagedObjects();
}
bool ObjectManager::SetupMatchRuleAndFilter() { bool ObjectManager::SetupMatchRuleAndFilter() {
DCHECK(bus_); DCHECK(bus_);
DCHECK(!setup_success_); DCHECK(!setup_success_);
...@@ -235,10 +206,39 @@ bool ObjectManager::SetupMatchRuleAndFilter() { ...@@ -235,10 +206,39 @@ bool ObjectManager::SetupMatchRuleAndFilter() {
} }
void ObjectManager::OnSetupMatchRuleAndFilterComplete(bool success) { void ObjectManager::OnSetupMatchRuleAndFilterComplete(bool success) {
LOG_IF(WARNING, !success) << service_name_ << " " << object_path_.value() if (!success) {
<< ": Failed to set up match rule."; LOG(WARNING) << service_name_ << " " << object_path_.value()
if (success) << ": Failed to set up match rule.";
InitializeObjects(); return;
}
DCHECK(bus_);
DCHECK(object_proxy_);
DCHECK(setup_success_);
// |object_proxy_| is no longer valid if the Bus was shut down before this
// call. Don't initiate any other action from the origin thread.
if (cleanup_called_)
return;
object_proxy_->ConnectToSignal(
kObjectManagerInterface,
kObjectManagerInterfacesAdded,
base::Bind(&ObjectManager::InterfacesAddedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::Bind(&ObjectManager::InterfacesAddedConnected,
weak_ptr_factory_.GetWeakPtr()));
object_proxy_->ConnectToSignal(
kObjectManagerInterface,
kObjectManagerInterfacesRemoved,
base::Bind(&ObjectManager::InterfacesRemovedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::Bind(&ObjectManager::InterfacesRemovedConnected,
weak_ptr_factory_.GetWeakPtr()));
if (!service_name_owner_.empty())
GetManagedObjects();
} }
// static // static
......
...@@ -71,8 +71,9 @@ ...@@ -71,8 +71,9 @@
// object_manager_->UnregisterInterface(kInterface); // object_manager_->UnregisterInterface(kInterface);
// } // }
// //
// The D-Bus thread manager takes care of issuing the necessary call to // This class calls GetManagedObjects() asynchronously after the remote service
// GetManagedObjects() after the implementation classes have been set up. // becomes available and additionally refreshes managed objects after the
// service stops or restarts.
// //
// The object manager interface class has one abstract method that must be // The object manager interface class has one abstract method that must be
// implemented by the class to create Properties structures on demand. As well // implemented by the class to create Properties structures on demand. As well
...@@ -238,17 +239,14 @@ public: ...@@ -238,17 +239,14 @@ public:
private: private:
friend class base::RefCountedThreadSafe<ObjectManager>; friend class base::RefCountedThreadSafe<ObjectManager>;
// Connects the InterfacesAdded and InterfacesRemoved signals and calls
// GetManagedObjects. Called from OnSetupMatchRuleAndFilterComplete.
void InitializeObjects();
// Called from the constructor to add a match rule for PropertiesChanged // Called from the constructor to add a match rule for PropertiesChanged
// signals on the DBus thread and set up a corresponding filter function. // signals on the D-Bus thread and set up a corresponding filter function.
bool SetupMatchRuleAndFilter(); bool SetupMatchRuleAndFilter();
// Called on the origin thread once the match rule and filter have been set // Called on the origin thread once the match rule and filter have been set
// up. |success| is false, if an error occurred during set up; it's true // up. Connects the InterfacesAdded and InterfacesRemoved signals and
// otherwise. // refreshes objects if the service is available. |success| is false if an
// error occurred during setup and true otherwise.
void OnSetupMatchRuleAndFilterComplete(bool success); void OnSetupMatchRuleAndFilterComplete(bool success);
// Called by dbus:: when a message is received. This is used to filter // Called by dbus:: when a message is received. This is used to filter
......
...@@ -195,11 +195,6 @@ void BluezDBusManager::InitializeClients() { ...@@ -195,11 +195,6 @@ void BluezDBusManager::InitializeClients() {
client_bundle_->bluetooth_media_client()->Init(GetSystemBus()); client_bundle_->bluetooth_media_client()->Init(GetSystemBus());
client_bundle_->bluetooth_media_transport_client()->Init(GetSystemBus()); client_bundle_->bluetooth_media_transport_client()->Init(GetSystemBus());
client_bundle_->bluetooth_profile_manager_client()->Init(GetSystemBus()); client_bundle_->bluetooth_profile_manager_client()->Init(GetSystemBus());
// This must be called after the list of clients so they've each had a
// chance to register with their object g_dbus_thread_managers.
if (GetSystemBus())
GetSystemBus()->GetManagedObjects();
} }
// static // static
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment