summaryrefslogtreecommitdiffstats
path: root/dbus
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-14 22:10:24 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-14 22:10:24 +0000
commitdf159b2125d12fcc957c53d0c9822995dfcc8bfd (patch)
treed9a268376675f5416e92c15319c948fc524b21c1 /dbus
parente941828154d023ebedfbc90197efb80b092c5856 (diff)
downloadchromium_src-df159b2125d12fcc957c53d0c9822995dfcc8bfd.zip
chromium_src-df159b2125d12fcc957c53d0c9822995dfcc8bfd.tar.gz
chromium_src-df159b2125d12fcc957c53d0c9822995dfcc8bfd.tar.bz2
Stop restricting the sender object path for incoming signals.
Restricting the sender path makes it impossible to test signal handling with dbus-send --type=signal, as it uses "/" as the sender object path. For now, let's remove the restriction. We can make this restriction customizable when it becomes necessary. This is for http://codereview.chromium.org/7862020/ TEST=dbus_unittests BUG=none Review URL: http://codereview.chromium.org/7845029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101171 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus')
-rw-r--r--dbus/end_to_end_async_unittest.cc11
-rw-r--r--dbus/object_proxy.cc14
-rw-r--r--dbus/test_service.cc20
-rw-r--r--dbus/test_service.h7
4 files changed, 46 insertions, 6 deletions
diff --git a/dbus/end_to_end_async_unittest.cc b/dbus/end_to_end_async_unittest.cc
index f04f9a7..7d52130 100644
--- a/dbus/end_to_end_async_unittest.cc
+++ b/dbus/end_to_end_async_unittest.cc
@@ -234,3 +234,14 @@ TEST_F(EndToEndAsyncTest, TestSignal) {
WaitForTestSignal();
ASSERT_EQ(kMessage, test_signal_string_);
}
+
+TEST_F(EndToEndAsyncTest, TestSignalFromRoot) {
+ const char kMessage[] = "hello, world";
+ // Send the test signal from the root object path, to see if we can
+ // handle signals sent from "/", like dbus-send does.
+ test_service_->SendTestSignalFromRoot(kMessage);
+ // Receive the signal with the object proxy. The signal is handled in
+ // EndToEndAsyncTest::OnTestSignal() in the main thread.
+ WaitForTestSignal();
+ ASSERT_EQ(kMessage, test_signal_string_);
+}
diff --git a/dbus/object_proxy.cc b/dbus/object_proxy.cc
index faeee0e..863bef5 100644
--- a/dbus/object_proxy.cc
+++ b/dbus/object_proxy.cc
@@ -291,10 +291,14 @@ void ObjectProxy::ConnectToSignalInternal(
filter_added_ = true;
}
// Add a match rule so the signal goes through HandleMessage().
+ //
+ // We don't restrict the sender object path to be |object_path_| here,
+ // to make it easy to test D-Bus signal handling with dbus-send, that
+ // uses "/" as the sender object path. We can make the object path
+ // restriction customizable when it becomes necessary.
const std::string match_rule =
- base::StringPrintf("type='signal', interface='%s', path='%s'",
- interface_name.c_str(),
- object_path_.c_str());
+ base::StringPrintf("type='signal', interface='%s'",
+ interface_name.c_str());
ScopedDBusError error;
bus_->AddMatch(match_rule, error.get());;
if (error.is_set()) {
@@ -341,9 +345,7 @@ DBusHandlerResult ObjectProxy::HandleMessage(
scoped_ptr<Signal> signal(
Signal::FromRawMessage(raw_message));
- // The signal is not coming from the remote object we are attaching to.
- if (signal->GetPath() != object_path_)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ VLOG(1) << "Signal received: " << signal->ToString();
const std::string interface = signal->GetInterface();
const std::string member = signal->GetMember();
diff --git a/dbus/test_service.cc b/dbus/test_service.cc
index bc4ec86d..ca0eea3 100644
--- a/dbus/test_service.cc
+++ b/dbus/test_service.cc
@@ -72,6 +72,14 @@ void TestService::SendTestSignal(const std::string& message) {
message));
}
+void TestService::SendTestSignalFromRoot(const std::string& message) {
+ message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&TestService::SendTestSignalFromRootInternal,
+ base::Unretained(this),
+ message));
+}
+
void TestService::SendTestSignalInternal(const std::string& message) {
dbus::Signal signal("org.chromium.TestInterface", "Test");
dbus::MessageWriter writer(&signal);
@@ -79,6 +87,18 @@ void TestService::SendTestSignalInternal(const std::string& message) {
exported_object_->SendSignal(&signal);
}
+void TestService::SendTestSignalFromRootInternal(const std::string& message) {
+ dbus::Signal signal("org.chromium.TestInterface", "Test");
+ dbus::MessageWriter writer(&signal);
+ writer.AppendString(message);
+
+ // Use "/" just like dbus-send does.
+ ExportedObject* root_object =
+ bus_->GetExportedObject("org.chromium.TestService",
+ "/");
+ root_object->SendSignal(&signal);
+}
+
void TestService::OnExported(const std::string& interface_name,
const std::string& method_name,
bool success) {
diff --git a/dbus/test_service.h b/dbus/test_service.h
index f4a8a84..3ea40db 100644
--- a/dbus/test_service.h
+++ b/dbus/test_service.h
@@ -62,10 +62,17 @@ class TestService : public base::Thread {
// Sends "Test" signal with the given message from the exported object.
void SendTestSignal(const std::string& message);
+ // Sends "Test" signal with the given message from the root object ("/").
+ // This function emulates dbus-send's behavior.
+ void SendTestSignalFromRoot(const std::string& message);
+
private:
// Helper function for SendTestSignal().
void SendTestSignalInternal(const std::string& message);
+ // Helper function for SendTestSignalFromRoot.
+ void SendTestSignalFromRootInternal(const std::string& message);
+
// Helper function for ShutdownAndBlock().
void ShutdownAndBlockInternal();