diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-06 00:20:53 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-06 00:20:53 +0000 |
commit | 12e2599805235b139796ffee9598e8c95768b21a (patch) | |
tree | ac743b9e174698ebdeb96f8ffaba3e356db71cc3 /dbus/bus.cc | |
parent | b1e2d361992fb4dfed9422df35f161442850909a (diff) | |
download | chromium_src-12e2599805235b139796ffee9598e8c95768b21a.zip chromium_src-12e2599805235b139796ffee9598e8c95768b21a.tar.gz chromium_src-12e2599805235b139796ffee9598e8c95768b21a.tar.bz2 |
Fix a bug in dbus::Bus::AddFilterFunction().
We should not reject the same function if it's associated with different data.
BUG=99258
TEST=adde a unit test and confirmed it passed.
Review URL: http://codereview.chromium.org/8161005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104208 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus/bus.cc')
-rw-r--r-- | dbus/bus.cc | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/dbus/bus.cc b/dbus/bus.cc index 89918e0..87fe9c7 100644 --- a/dbus/bus.cc +++ b/dbus/bus.cc @@ -439,37 +439,45 @@ void Bus::Send(DBusMessage* request, uint32* serial) { CHECK(success) << "Unable to allocate memory"; } -void Bus::AddFilterFunction(DBusHandleMessageFunction filter_function, +bool Bus::AddFilterFunction(DBusHandleMessageFunction filter_function, void* user_data) { DCHECK(connection_); AssertOnDBusThread(); - if (filter_functions_added_.find(filter_function) != + std::pair<DBusHandleMessageFunction, void*> filter_data_pair = + std::make_pair(filter_function, user_data); + if (filter_functions_added_.find(filter_data_pair) != filter_functions_added_.end()) { - LOG(ERROR) << "Filter function already exists: " << filter_function; - return; + VLOG(1) << "Filter function already exists: " << filter_function + << " with associated data: " << user_data; + return false; } const bool success = dbus_connection_add_filter( connection_, filter_function, user_data, NULL); CHECK(success) << "Unable to allocate memory"; - filter_functions_added_.insert(filter_function); + filter_functions_added_.insert(filter_data_pair); + return true; } -void Bus::RemoveFilterFunction(DBusHandleMessageFunction filter_function, +bool Bus::RemoveFilterFunction(DBusHandleMessageFunction filter_function, void* user_data) { DCHECK(connection_); AssertOnDBusThread(); - if (filter_functions_added_.find(filter_function) == + std::pair<DBusHandleMessageFunction, void*> filter_data_pair = + std::make_pair(filter_function, user_data); + if (filter_functions_added_.find(filter_data_pair) == filter_functions_added_.end()) { - LOG(ERROR) << "Requested to remove an unknown filter function: " - << filter_function; - return; + VLOG(1) << "Requested to remove an unknown filter function: " + << filter_function + << " with associated data: " << user_data; + return false; } dbus_connection_remove_filter(connection_, filter_function, user_data); - filter_functions_added_.erase(filter_function); + filter_functions_added_.erase(filter_data_pair); + return true; } void Bus::AddMatch(const std::string& match_rule, DBusError* error) { |