Commit aef92a57 authored by Jeroen Dhollander's avatar Jeroen Dhollander Committed by Chromium LUCI CQ

Fix crash in AssistantManagerServiceImpl::OnStartFinished

The |Service::Context| object is used by |AssistantManagerServiceImpl|
but it was destructed first during teardown, causing a use-after-free
error.

Bug: 1162128
Test: compiled
Change-Id: I44a6a52387879602d67057dafc482a50d482d265
Cq-Include-Trybots: luci.chrome.try:linux-chromeos-chrome
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2605578
Commit-Queue: Tao Wu <wutao@chromium.org>
Auto-Submit: Jeroen Dhollander <jeroendh@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839633}
parent d2a9782d
......@@ -216,10 +216,10 @@ class Service::Context : public ServiceContext {
Service::Service(std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_url_loader_factory,
signin::IdentityManager* identity_manager)
: identity_manager_(identity_manager),
: context_(std::make_unique<Context>(this)),
identity_manager_(identity_manager),
token_refresh_timer_(std::make_unique<base::OneShotTimer>()),
main_task_runner_(base::SequencedTaskRunnerHandle::Get()),
context_(std::make_unique<Context>(this)),
pending_url_loader_factory_(std::move(pending_url_loader_factory)) {
DCHECK(identity_manager_);
chromeos::PowerManagerClient* power_manager_client =
......
......@@ -154,6 +154,12 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) Service
// for the device.
bool ShouldEnableHotword();
// |ServiceContext| object passed to child classes so they can access some of
// our functionality without depending on us.
// Note: this is used by the other members here, so it must be defined first
// so it is destroyed last.
std::unique_ptr<ServiceContext> context_;
signin::IdentityManager* const identity_manager_;
std::unique_ptr<ScopedAshSessionObserver> scoped_ash_session_observer_;
ScopedObserver<ash::AmbientUiModel, ash::AmbientUiModelObserver>
......@@ -183,10 +189,6 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) Service
base::Optional<std::string> access_token_;
// |ServiceContext| object passed to child classes so they can access some of
// our functionality without depending on us.
std::unique_ptr<ServiceContext> context_;
// non-null until |assistant_manager_service_| is created.
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_url_loader_factory_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment