Commit 235834ce authored by Xiaohui Chen's avatar Xiaohui Chen Committed by Commit Bot

assistant: refactor service init flow

* Pass in profile instead of mojom connector, this will guarantee the
  profile and connector always matches

Bug: 908919
Test: locally build and run
Change-Id: Iae0a73524456c108c75e1a21400d28a99afe6cd2
Reviewed-on: https://chromium-review.googlesource.com/c/1352769
Commit-Queue: Xiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611936}
parent b592282e
...@@ -1645,10 +1645,8 @@ bool UserSessionManager::InitializeUserSession(Profile* profile) { ...@@ -1645,10 +1645,8 @@ bool UserSessionManager::InitializeUserSession(Profile* profile) {
if (start_session_type_ == PRIMARY_USER_SESSION) { if (start_session_type_ == PRIMARY_USER_SESSION) {
#if BUILDFLAG(ENABLE_CROS_ASSISTANT) #if BUILDFLAG(ENABLE_CROS_ASSISTANT)
// Initialize Assistant early to be used in post login Oobe steps. // Initialize Assistant early to be used in post login Oobe steps.
if (chromeos::switches::IsAssistantEnabled()) { if (chromeos::switches::IsAssistantEnabled())
AssistantClient::Get()->MaybeInit( AssistantClient::Get()->MaybeInit(profile);
content::BrowserContext::GetConnectorFor(profile));
}
#endif #endif
UserFlow* user_flow = ChromeUserManager::Get()->GetCurrentUserFlow(); UserFlow* user_flow = ChromeUserManager::Get()->GetCurrentUserFlow();
WizardController* oobe_controller = WizardController::default_controller(); WizardController* oobe_controller = WizardController::default_controller();
......
...@@ -38,9 +38,8 @@ AssistantClient::~AssistantClient() { ...@@ -38,9 +38,8 @@ AssistantClient::~AssistantClient() {
g_instance = nullptr; g_instance = nullptr;
} }
void AssistantClient::MaybeInit(service_manager::Connector* connector) { void AssistantClient::MaybeInit(Profile* profile) {
if (arc::IsAssistantAllowedForProfile( if (arc::IsAssistantAllowedForProfile(profile) !=
ProfileManager::GetActiveUserProfile()) !=
ash::mojom::AssistantAllowedState::ALLOWED) { ash::mojom::AssistantAllowedState::ALLOWED) {
return; return;
} }
...@@ -49,6 +48,7 @@ void AssistantClient::MaybeInit(service_manager::Connector* connector) { ...@@ -49,6 +48,7 @@ void AssistantClient::MaybeInit(service_manager::Connector* connector) {
return; return;
initialized_ = true; initialized_ = true;
auto* connector = content::BrowserContext::GetConnectorFor(profile);
connector->BindInterface(chromeos::assistant::mojom::kServiceName, connector->BindInterface(chromeos::assistant::mojom::kServiceName,
&assistant_connection_); &assistant_connection_);
......
...@@ -12,10 +12,7 @@ ...@@ -12,10 +12,7 @@
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h" #include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
namespace service_manager { class Profile;
class Connector;
} // namespace service_manager
class AssistantImageDownloader; class AssistantImageDownloader;
class AssistantSetup; class AssistantSetup;
...@@ -27,7 +24,7 @@ class AssistantClient : chromeos::assistant::mojom::Client { ...@@ -27,7 +24,7 @@ class AssistantClient : chromeos::assistant::mojom::Client {
AssistantClient(); AssistantClient();
~AssistantClient() override; ~AssistantClient() override;
void MaybeInit(service_manager::Connector* connector); void MaybeInit(Profile* profile);
// assistant::mojom::Client overrides: // assistant::mojom::Client overrides:
void OnAssistantStatusChanged(bool running) override; void OnAssistantStatusChanged(bool running) override;
......
...@@ -474,8 +474,7 @@ void SessionControllerClient::OnSessionStateChanged() { ...@@ -474,8 +474,7 @@ void SessionControllerClient::OnSessionStateChanged() {
// Assistant is initialized only once when primary user logs in. // Assistant is initialized only once when primary user logs in.
if (chromeos::switches::IsAssistantEnabled()) { if (chromeos::switches::IsAssistantEnabled()) {
AssistantClient::Get()->MaybeInit( AssistantClient::Get()->MaybeInit(
content::BrowserContext::GetConnectorFor( ProfileManager::GetPrimaryUserProfile());
ProfileManager::GetPrimaryUserProfile()));
} }
#endif #endif
} }
......
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