Skip to content

Commit

Permalink
more feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
gaaclarke committed Nov 24, 2022
1 parent 9782710 commit f887d1c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 34 deletions.
19 changes: 1 addition & 18 deletions shell/platform/linux/fl_binary_messenger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,7 @@ static void set_message_handler_on_channel(
}
}

static gboolean has_message_handler_on_channel(FlBinaryMessenger* messenger,
const gchar* channel) {
FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(messenger);
return g_hash_table_contains(self->platform_message_handlers, channel);
}

gboolean do_unref(gpointer value) {
static gboolean do_unref(gpointer value) {
g_object_unref(value);
return G_SOURCE_REMOVE;
}
Expand Down Expand Up @@ -328,7 +322,6 @@ static void fl_binary_messenger_impl_class_init(
static void fl_binary_messenger_impl_iface_init(
FlBinaryMessengerInterface* iface) {
iface->set_message_handler_on_channel = set_message_handler_on_channel;
iface->has_message_handler_on_channel = has_message_handler_on_channel;
iface->send_response = send_response;
iface->send_on_channel = send_on_channel;
iface->send_on_channel_finish = send_on_channel_finish;
Expand Down Expand Up @@ -370,16 +363,6 @@ G_MODULE_EXPORT void fl_binary_messenger_set_message_handler_on_channel(
self, channel, handler, user_data, destroy_notify);
}

G_MODULE_EXPORT gboolean
fl_binary_messenger_has_message_handler_on_channel(FlBinaryMessenger* self,
const gchar* channel) {
g_return_val_if_fail(FL_IS_BINARY_MESSENGER(self), FALSE);
g_return_val_if_fail(channel != nullptr, FALSE);

return FL_BINARY_MESSENGER_GET_IFACE(self)->has_message_handler_on_channel(
self, channel);
}

// Note: This function can be called from any thread.
G_MODULE_EXPORT gboolean fl_binary_messenger_send_response(
FlBinaryMessenger* self,
Expand Down
4 changes: 0 additions & 4 deletions shell/platform/linux/fl_binary_messenger_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ G_BEGIN_DECLS
*/
FlBinaryMessenger* fl_binary_messenger_new(FlEngine* engine);

gboolean fl_binary_messenger_has_message_handler_on_channel(
FlBinaryMessenger* messenger,
const gchar* channel);

G_END_DECLS

#endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_BINARY_MESSENGER_PRIVATE_H_
19 changes: 10 additions & 9 deletions shell/platform/linux/fl_binary_messenger_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -461,20 +461,21 @@ TEST(FlBinaryMessengerTest, RespondOnBackgroundThread) {
g_main_loop_run(loop);
}

static void kill_handler_notify_cb(gpointer was_called) {
*static_cast<gboolean*>(was_called) = TRUE;
}

TEST(FlBinaryMessengerTest, DeletingEngineClearsHandlers) {
FlEngine* engine = make_mock_engine();
g_autoptr(FlBinaryMessenger) messenger = fl_binary_messenger_new(engine);
gboolean was_killed = FALSE;

// Listen for messages from the engine.
fl_binary_messenger_set_message_handler_on_channel(
messenger, "test/messages", message_cb, nullptr, nullptr);

ASSERT_TRUE(fl_binary_messenger_has_message_handler_on_channel(
messenger, "test/messages"));
fl_binary_messenger_set_message_handler_on_channel(messenger, "test/messages",
message_cb, &was_killed,
kill_handler_notify_cb);

g_object_unref(engine);
engine = nullptr;
g_clear_object(&engine);

ASSERT_FALSE(fl_binary_messenger_has_message_handler_on_channel(
messenger, "test/messages"));
ASSERT_TRUE(was_killed);
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ struct _FlBinaryMessengerInterface {
gpointer user_data,
GDestroyNotify destroy_notify);

gboolean (*has_message_handler_on_channel)(FlBinaryMessenger* messenger,
const gchar* channel);

gboolean (*send_response)(FlBinaryMessenger* messenger,
FlBinaryMessengerResponseHandle* response_handle,
GBytes* response,
Expand Down

0 comments on commit f887d1c

Please sign in to comment.