Skip to content

Commit

Permalink
assistant: fix crash when register fallback media handler
Browse files Browse the repository at this point in the history
It is possible that the callback from libassistant comes right after
assistant_manager is stopped/reset.  Let's guard this case.

Bug: 879390
Test: locally build
Change-Id: Iea2fe174a02627e6d61406a1319d172470028afd
Reviewed-on: https://chromium-review.googlesource.com/1198105
Reviewed-by: Muyuan Li <[email protected]>
Commit-Queue: Xiaohui Chen <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#587879}(cherry picked from commit c3a7b6f)
Reviewed-on: https://chromium-review.googlesource.com/1207930
Reviewed-by: Xiaohui Chen <[email protected]>
Cr-Commit-Position: refs/branch-heads/3538@{#58}
Cr-Branched-From: 79f7c91-refs/heads/master@{#587811}
  • Loading branch information
Xiaohui Chen authored and Xiaohui Chen committed Sep 5, 2018
1 parent b5260c8 commit 951cf45
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion chromeos/services/assistant/assistant_manager_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "chromeos/services/assistant/assistant_manager_service_impl.h"

#include <algorithm>
#include <utility>

#include "ash/public/interfaces/constants.mojom.h"
Expand Down Expand Up @@ -133,6 +134,12 @@ void AssistantManagerServiceImpl::SetAccessToken(
}

void AssistantManagerServiceImpl::RegisterFallbackMediaHandler() {
// This is a callback from LibAssistant, it is async from LibAssistant thread.
// It is possible that when it reaches here, the assistant_manager_ has
// been stopped.
if (!assistant_manager_internal_)
return;

// Register handler for media actions.
assistant_manager_internal_->RegisterFallbackMediaHandler(
[this](std::string play_media_args_proto) {
Expand Down Expand Up @@ -735,8 +742,13 @@ void AssistantManagerServiceImpl::HandleUpdateSettingsResponse(
callback.Run(result);
}

// assistant_client::DeviceStateListener overrides
// Run on LibAssistant threads
void AssistantManagerServiceImpl::OnStartFinished() {
RegisterFallbackMediaHandler();
main_thread_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&AssistantManagerServiceImpl::RegisterFallbackMediaHandler,
weak_factory_.GetWeakPtr()));
}

void AssistantManagerServiceImpl::OnTimerSoundingStarted() {
Expand Down

0 comments on commit 951cf45

Please sign in to comment.