Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9b5ab5fc authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Make sure task_runner is valid when we call PostTask on it"

parents 1bc74c5e 7122d837
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -553,13 +553,19 @@ void bta_sys_sendmsg(void* p_msg) {
void do_in_bta_thread(const tracked_objects::Location& from_here,
                      const base::Closure& task) {
  base::MessageLoop* bta_message_loop = get_message_loop();

  if (!bta_message_loop || !bta_message_loop->task_runner().get()) {
  if (!bta_message_loop) {
    APPL_TRACE_ERROR("%s: MessageLooper not initialized", __func__);
    return;
  }

  bta_message_loop->task_runner()->PostTask(from_here, task);
  scoped_refptr<base::SingleThreadTaskRunner> task_runner =
      bta_message_loop->task_runner();
  if (!task_runner.get()) {
    APPL_TRACE_ERROR("%s: task runner is dead", __func__);
    return;
  }

  task_runner->PostTask(from_here, task);
}

/*******************************************************************************
+9 −3
Original line number Diff line number Diff line
@@ -225,14 +225,20 @@ bt_status_t btif_transfer_context(tBTIF_CBACK* p_cback, uint16_t event,
 **/
bt_status_t do_in_jni_thread(const tracked_objects::Location& from_here,
                             const base::Closure& task) {
  if (!message_loop_ || !message_loop_->task_runner().get()) {
  if (!message_loop_) {
    BTIF_TRACE_WARNING("%s: Dropped message, message_loop not initialized yet!",
                       __func__);
    return BT_STATUS_FAIL;
  }

  if (message_loop_->task_runner()->PostTask(from_here, task))
    return BT_STATUS_SUCCESS;
  scoped_refptr<base::SingleThreadTaskRunner> task_runner =
      message_loop_->task_runner();
  if (!task_runner.get()) {
    BTIF_TRACE_WARNING("%s: task runner is dead", __func__);
    return BT_STATUS_FAIL;
  }

  if (task_runner->PostTask(from_here, task)) return BT_STATUS_SUCCESS;

  BTIF_TRACE_ERROR("%s: Post task to task runner failed!", __func__);
  return BT_STATUS_FAIL;