diff options
author | Alex Vakulenko <avakulenko@chromium.org> | 2014-09-03 10:38:09 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-09-05 01:17:16 +0000 |
commit | 90e4ffc22f8eaeb8284b30e22474d77aa1ba1557 (patch) | |
tree | 646eaa7da43830b64e1acf3fbfbaf2fe6a8a2b18 | |
parent | f2418e562d358917b02b53290d5f4b3690d6f5d3 (diff) | |
download | platform_external_libbrillo-90e4ffc22f8eaeb8284b30e22474d77aa1ba1557.tar.gz platform_external_libbrillo-90e4ffc22f8eaeb8284b30e22474d77aa1ba1557.tar.bz2 platform_external_libbrillo-90e4ffc22f8eaeb8284b30e22474d77aa1ba1557.zip |
libchromeos: Add GetDefaultCompletionAction() to AsyncEventSequencer
In many cases the async callback from DBusObject::RegisterAsync()
should do nothing. So, rather than providing a dummy method every
time this is the case, provide a helper on AsyncEventSequencer
class to provide the default (NO-OP) CompletionAction callback.
BUG=None
TEST=FEATURES=test emerge-link libchromeos
Change-Id: Ie17295a32b609254d52adc979ba5fc11b44f4d31
Reviewed-on: https://chromium-review.googlesource.com/216293
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
-rw-r--r-- | chromeos/dbus/async_event_sequencer.cc | 6 | ||||
-rw-r--r-- | chromeos/dbus/async_event_sequencer.h | 4 | ||||
-rw-r--r-- | chromeos/dbus/dbus_object_unittest.cc | 5 | ||||
-rw-r--r-- | chromeos/dbus/exported_object_manager_unittest.cc | 4 | ||||
-rw-r--r-- | chromeos/dbus/exported_property_set_unittest.cc | 5 |
5 files changed, 14 insertions, 10 deletions
diff --git a/chromeos/dbus/async_event_sequencer.cc b/chromeos/dbus/async_event_sequencer.cc index 33cf9ce..0f9c455 100644 --- a/chromeos/dbus/async_event_sequencer.cc +++ b/chromeos/dbus/async_event_sequencer.cc @@ -43,6 +43,7 @@ void AsyncEventSequencer::OnAllTasksCompletedCall( namespace { void IgnoreSuccess(const AsyncEventSequencer::CompletionTask& task, bool /*success*/) { task.Run(); } +void DoNothing(bool success) {} } // namespace AsyncEventSequencer::CompletionAction AsyncEventSequencer::WrapCompletionTask( @@ -50,6 +51,11 @@ AsyncEventSequencer::CompletionAction AsyncEventSequencer::WrapCompletionTask( return base::Bind(&IgnoreSuccess, task); } +AsyncEventSequencer::CompletionAction + AsyncEventSequencer::GetDefaultCompletionAction() { + return base::Bind(&DoNothing); +} + void AsyncEventSequencer::HandleFinish(int registration_number, const std::string& error_message, bool failure_is_fatal, bool success) { diff --git a/chromeos/dbus/async_event_sequencer.h b/chromeos/dbus/async_event_sequencer.h index ee10f28..38e193e 100644 --- a/chromeos/dbus/async_event_sequencer.h +++ b/chromeos/dbus/async_event_sequencer.h @@ -67,7 +67,9 @@ class CHROMEOS_EXPORT AsyncEventSequencer // Wrap a CompletionTask with a function that discards the result. // This CompletionTask retains no references to the AsyncEventSequencer. - CompletionAction WrapCompletionTask(const CompletionTask& task); + static CompletionAction WrapCompletionTask(const CompletionTask& task); + // Create a default CompletionAction that doesn't do anything when called. + static CompletionAction GetDefaultCompletionAction(); private: // We'll partially bind this function before giving it back via diff --git a/chromeos/dbus/dbus_object_unittest.cc b/chromeos/dbus/dbus_object_unittest.cc index f9835ae..ba66e58 100644 --- a/chromeos/dbus/dbus_object_unittest.cc +++ b/chromeos/dbus/dbus_object_unittest.cc @@ -34,8 +34,6 @@ const char kTestMethod_StrLen[] = "StrLen"; const char kTestInterface3[] = "org.chromium.Test.NoOpInterface"; const char kTestMethod_NoOp[] = "NoOp"; -void NoAction(bool all_succeeded) {} - struct Calc { int Add(ErrorPtr* error, int x, int y) { return x + y; } int Negate(ErrorPtr* error, int x) { return -x; } @@ -90,7 +88,8 @@ class DBusObjectTest : public ::testing::Test { base::Callback<void(ErrorPtr*)> noop_callback = base::Bind(NoOp); itf3->AddMethodHandler(kTestMethod_NoOp, noop_callback); - dbus_object_->RegisterAsync(base::Bind(NoAction)); + dbus_object_->RegisterAsync( + AsyncEventSequencer::GetDefaultCompletionAction()); } void ExpectError(dbus::Response* response, const std::string& expected_code) { diff --git a/chromeos/dbus/exported_object_manager_unittest.cc b/chromeos/dbus/exported_object_manager_unittest.cc index 32ecb37..57152fa 100644 --- a/chromeos/dbus/exported_object_manager_unittest.cc +++ b/chromeos/dbus/exported_object_manager_unittest.cc @@ -94,8 +94,6 @@ void VerifyInterfaceDropSignal(dbus::Signal* signal) { EXPECT_EQ(path, kClaimedTestPath); } -void NoAction(bool all_succeeded) {} - } // namespace class ExportedObjectManagerTest: public ::testing::Test { @@ -116,7 +114,7 @@ class ExportedObjectManagerTest: public ::testing::Test { ExportMethod(_, _, _, _)).Times(AnyNumber()); om_.reset(new ExportedObjectManager(bus_.get(), kTestPath)); property_writer_ = base::Bind(&WriteTestPropertyDict); - om_->RegisterAsync(base::Bind(NoAction)); + om_->RegisterAsync(AsyncEventSequencer::GetDefaultCompletionAction()); } void TearDown() override { diff --git a/chromeos/dbus/exported_property_set_unittest.cc b/chromeos/dbus/exported_property_set_unittest.cc index 330cfce..eda6098 100644 --- a/chromeos/dbus/exported_property_set_unittest.cc +++ b/chromeos/dbus/exported_property_set_unittest.cc @@ -53,8 +53,6 @@ const dbus::ObjectPath kMethodsExportedOnPath(std::string("/export")); const dbus::ObjectPath kTestObjectPathInit(std::string("/path_init")); const dbus::ObjectPath kTestObjectPathUpdate(std::string("/path_update")); -void NoAction(bool all_succeeded) {} - } // namespace class ExportedPropertySetTest : public ::testing::Test { @@ -99,7 +97,8 @@ class ExportedPropertySetTest : public ::testing::Test { itf3->AddProperty(kStringListPropName, &stringlist_prop_); itf3->AddProperty(kPathListPropName, &pathlist_prop_); itf3->AddProperty(kUint8ListPropName, &uint8list_prop_); - dbus_object_.RegisterAsync(base::Bind(NoAction)); + dbus_object_.RegisterAsync( + AsyncEventSequencer::GetDefaultCompletionAction()); } virtual ~Properties() {} |