Commit 66c4d794 authored by Xiaohui Chen's avatar Xiaohui Chen Committed by Commit Bot

assistant: move shutdown a little bit early

Moving libassistant shutdown a little bit earlier in the
shutdown process to help it finish shutdown.

Bug: 950146
Test: locally run and logout/shutdown
Change-Id: Ic0d3b2ca0bf0cc06702c71fb02659854540a0863
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2036256
Commit-Queue: Xiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738355}
parent 5bd86acd
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "ash/public/cpp/assistant/assistant_interface_binder.h" #include "ash/public/cpp/assistant/assistant_interface_binder.h"
#include "ash/public/cpp/network_config_service.h" #include "ash/public/cpp/network_config_service.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/assistant/assistant_util.h" #include "chrome/browser/chromeos/assistant/assistant_util.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
...@@ -28,6 +29,8 @@ ...@@ -28,6 +29,8 @@
#include "content/public/browser/device_service.h" #include "content/public/browser/device_service.h"
#include "content/public/browser/media_session_service.h" #include "content/public/browser/media_session_service.h"
#include "content/public/browser/network_service_instance.h" #include "content/public/browser/network_service_instance.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/service_process_host.h" #include "content/public/browser/service_process_host.h"
#include "services/identity/public/mojom/identity_service.mojom.h" #include "services/identity/public/mojom/identity_service.mojom.h"
...@@ -37,6 +40,9 @@ AssistantClientImpl::AssistantClientImpl() { ...@@ -37,6 +40,9 @@ AssistantClientImpl::AssistantClientImpl() {
// Otherwise, it will not get OnUserProfileLoaded notification. // Otherwise, it will not get OnUserProfileLoaded notification.
DCHECK(session_manager->sessions().empty()); DCHECK(session_manager->sessions().empty());
session_manager->AddObserver(this); session_manager->AddObserver(this);
notification_registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
content::NotificationService::AllSources());
} }
AssistantClientImpl::~AssistantClientImpl() { AssistantClientImpl::~AssistantClientImpl() {
...@@ -107,6 +113,16 @@ void AssistantClientImpl::BindAssistant( ...@@ -107,6 +113,16 @@ void AssistantClientImpl::BindAssistant(
std::move(receiver)); std::move(receiver));
} }
void AssistantClientImpl::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK_EQ(chrome::NOTIFICATION_APP_TERMINATING, type);
if (!initialized_)
return;
AssistantServiceConnection::GetForProfile(profile_)->service()->Shutdown();
}
void AssistantClientImpl::OnAssistantStatusChanged( void AssistantClientImpl::OnAssistantStatusChanged(
ash::mojom::AssistantState new_state) { ash::mojom::AssistantState new_state) {
ash::AssistantState::Get()->NotifyStatusChanged(new_state); ash::AssistantState::Get()->NotifyStatusChanged(new_state);
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h" #include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
#include "components/session_manager/core/session_manager_observer.h" #include "components/session_manager/core/session_manager_observer.h"
#include "components/signin/public/identity_manager/identity_manager.h" #include "components/signin/public/identity_manager/identity_manager.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
...@@ -29,6 +31,7 @@ class Profile; ...@@ -29,6 +31,7 @@ class Profile;
// Class to handle all Assistant in-browser-process functionalities. // Class to handle all Assistant in-browser-process functionalities.
class AssistantClientImpl : public ash::AssistantClient, class AssistantClientImpl : public ash::AssistantClient,
public chromeos::assistant::mojom::Client, public chromeos::assistant::mojom::Client,
public content::NotificationObserver,
public signin::IdentityManager::Observer, public signin::IdentityManager::Observer,
public session_manager::SessionManagerObserver { public session_manager::SessionManagerObserver {
public: public:
...@@ -43,6 +46,11 @@ class AssistantClientImpl : public ash::AssistantClient, ...@@ -43,6 +46,11 @@ class AssistantClientImpl : public ash::AssistantClient,
mojo::PendingReceiver<chromeos::assistant::mojom::Assistant> receiver) mojo::PendingReceiver<chromeos::assistant::mojom::Assistant> receiver)
override; override;
// content::NotificationObserver overrides:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
// assistant::mojom::Client overrides: // assistant::mojom::Client overrides:
void OnAssistantStatusChanged(ash::mojom::AssistantState new_state) override; void OnAssistantStatusChanged(ash::mojom::AssistantState new_state) override;
void RequestAssistantStructure( void RequestAssistantStructure(
...@@ -119,6 +127,8 @@ class AssistantClientImpl : public ash::AssistantClient, ...@@ -119,6 +127,8 @@ class AssistantClientImpl : public ash::AssistantClient,
bool initialized_ = false; bool initialized_ = false;
content::NotificationRegistrar notification_registrar_;
// Non-owning pointers. // Non-owning pointers.
Profile* profile_ = nullptr; Profile* profile_ = nullptr;
signin::IdentityManager* identity_manager_ = nullptr; signin::IdentityManager* identity_manager_ = nullptr;
......
...@@ -35,6 +35,9 @@ interface AssistantService { ...@@ -35,6 +35,9 @@ interface AssistantService {
// Binds an interface to control assistant settings. // Binds an interface to control assistant settings.
BindSettingsManager(pending_receiver<AssistantSettingsManager> receiver); BindSettingsManager(pending_receiver<AssistantSettingsManager> receiver);
// Signals system shutdown, the service could start cleaning up if needed.
Shutdown();
}; };
// Interface whose implementation is owned by Shell in Ash. This is used // Interface whose implementation is owned by Shell in Ash. This is used
......
...@@ -258,6 +258,13 @@ void Service::BindSettingsManager( ...@@ -258,6 +258,13 @@ void Service::BindSettingsManager(
std::move(receiver)); std::move(receiver));
} }
void Service::Shutdown() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (assistant_manager_service_)
StopAssistantManagerService();
}
void Service::PowerChanged(const power_manager::PowerSupplyProperties& prop) { void Service::PowerChanged(const power_manager::PowerSupplyProperties& prop) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const bool power_source_connected = const bool power_source_connected =
......
...@@ -106,6 +106,7 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) Service ...@@ -106,6 +106,7 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) Service
void BindAssistant(mojo::PendingReceiver<mojom::Assistant> receiver) override; void BindAssistant(mojo::PendingReceiver<mojom::Assistant> receiver) override;
void BindSettingsManager( void BindSettingsManager(
mojo::PendingReceiver<mojom::AssistantSettingsManager> receiver) override; mojo::PendingReceiver<mojom::AssistantSettingsManager> receiver) override;
void Shutdown() override;
// chromeos::PowerManagerClient::Observer overrides: // chromeos::PowerManagerClient::Observer overrides:
void PowerChanged(const power_manager::PowerSupplyProperties& prop) override; void PowerChanged(const power_manager::PowerSupplyProperties& prop) override;
......
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