aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSonny Sasaka <sonnysasaka@chromium.org>2018-03-22 00:21:58 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-03-24 12:31:30 -0700
commitc879ed39a320c7e245355d81bc31d837bdda24c0 (patch)
tree0cc7cc44e47f3757aa1f9f520e96aed059715be5
parent2b61f16f86b773f88ba69a7a15b6a33e132c3a58 (diff)
downloadplatform_external_libbrillo-c879ed39a320c7e245355d81bc31d837bdda24c0.tar.gz
platform_external_libbrillo-c879ed39a320c7e245355d81bc31d837bdda24c0.tar.bz2
platform_external_libbrillo-c879ed39a320c7e245355d81bc31d837bdda24c0.zip
libbrillo: Resets property update callback on UnregisterProperty
BUG=chromium:812468 TEST=Unit test added Change-Id: I797852ffc456894d845b388feff1de56b922e49b Reviewed-on: https://chromium-review.googlesource.com/974907 Commit-Ready: Sonny Sasaka <sonnysasaka@chromium.org> Tested-by: Sonny Sasaka <sonnysasaka@chromium.org> Reviewed-by: Ben Chan <benchan@chromium.org>
-rw-r--r--brillo/dbus/exported_property_set.cc5
-rw-r--r--brillo/dbus/exported_property_set.h3
-rw-r--r--brillo/dbus/exported_property_set_unittest.cc4
3 files changed, 12 insertions, 0 deletions
diff --git a/brillo/dbus/exported_property_set.cc b/brillo/dbus/exported_property_set.cc
index 31a99be..018843e 100644
--- a/brillo/dbus/exported_property_set.cc
+++ b/brillo/dbus/exported_property_set.cc
@@ -61,6 +61,7 @@ void ExportedPropertySet::UnregisterProperty(const std::string& interface_name,
auto prop_iter = prop_map.find(property_name);
CHECK(prop_iter != prop_map.end())
<< "Property '" << property_name << "' doesn't exist";
+ prop_iter->second->ClearUpdateCallback();
prop_map.erase(prop_iter);
}
@@ -170,6 +171,10 @@ void ExportedPropertyBase::SetUpdateCallback(const OnUpdateCallback& cb) {
on_update_callback_ = cb;
}
+void ExportedPropertyBase::ClearUpdateCallback() {
+ on_update_callback_.Reset();
+}
+
void ExportedPropertyBase::SetAccessMode(
ExportedPropertyBase::Access access_mode) {
access_mode_ = access_mode;
diff --git a/brillo/dbus/exported_property_set.h b/brillo/dbus/exported_property_set.h
index 3d4b14b..61ea08a 100644
--- a/brillo/dbus/exported_property_set.h
+++ b/brillo/dbus/exported_property_set.h
@@ -71,6 +71,9 @@ class BRILLO_EXPORT ExportedPropertyBase {
// interface of the exported object.
virtual void SetUpdateCallback(const OnUpdateCallback& cb);
+ // Clears the update callback that was previously set with SetUpdateCallback.
+ virtual void ClearUpdateCallback();
+
// Returns the contained value as Any.
virtual brillo::Any GetValue() const = 0;
diff --git a/brillo/dbus/exported_property_set_unittest.cc b/brillo/dbus/exported_property_set_unittest.cc
index 4c03aef..93aceb4 100644
--- a/brillo/dbus/exported_property_set_unittest.cc
+++ b/brillo/dbus/exported_property_set_unittest.cc
@@ -342,6 +342,10 @@ TEST_F(ExportedPropertySetTest, GetRemovedProperty) {
auto response = GetPropertyOnInterface(kTestInterface1, kBoolPropName);
ASSERT_EQ(DBUS_ERROR_UNKNOWN_PROPERTY, response->GetErrorName());
+
+ // Signal should not be emitted for removed property.
+ EXPECT_CALL(*mock_exported_object_, SendSignal(_)).Times(0);
+ p_->bool_prop_.SetValue(true);
}
TEST_F(ExportedPropertySetTest, GetWorksWithBool) {