From e2b9acd9684274d01571167056a27b6835a2a478 Mon Sep 17 00:00:00 2001 From: Jay Harris Date: Wed, 11 Dec 2024 09:10:34 +1300 Subject: [PATCH] Changes for PR --- browser/ai_chat/android/ai_chat_utils_android.cc | 4 ++-- browser/ui/webui/ai_chat/ai_chat_ui_page_handler.cc | 12 ------------ browser/ui/webui/ai_chat/ai_chat_ui_page_handler.h | 2 -- components/ai_chat/core/browser/ai_chat_service.cc | 11 +++++++++++ components/ai_chat/core/browser/ai_chat_service.h | 3 ++- components/ai_chat/core/common/mojom/ai_chat.mojom | 10 +++++----- components/ai_chat/resources/page/api/index.ts | 2 +- .../resources/page/state/active_chat_context.tsx | 2 +- 8 files changed, 22 insertions(+), 24 deletions(-) diff --git a/browser/ai_chat/android/ai_chat_utils_android.cc b/browser/ai_chat/android/ai_chat_utils_android.cc index d08b1b83dbdf..880fde1bef6d 100644 --- a/browser/ai_chat/android/ai_chat_utils_android.cc +++ b/browser/ai_chat/android/ai_chat_utils_android.cc @@ -27,7 +27,7 @@ static void JNI_BraveLeoUtils_OpenLeoQuery( content::WebContents::FromJavaWebContents(jweb_contents); AIChatService* ai_chat_service = AIChatServiceFactory::GetForBrowserContext( web_contents->GetBrowserContext()); - DCHECK(ai_chat_service); + CHECK(ai_chat_service); auto conversation_uuid_str = base::android::ConvertJavaStringToUTF8(conversation_uuid); // This function is either targeted at a specific conversation @@ -58,7 +58,7 @@ static void JNI_BraveLeoUtils_OpenLeoQuery( GURL(base::StrCat({kChatUIURL, conversation->get_conversation_uuid()})), content::Referrer(), WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_FROM_API, false); - CHECK(web_contents->OpenURL(params, {})); + web_contents->OpenURL(params, {}); } static void JNI_BraveLeoUtils_OpenLeoUrlForTab( diff --git a/browser/ui/webui/ai_chat/ai_chat_ui_page_handler.cc b/browser/ui/webui/ai_chat/ai_chat_ui_page_handler.cc index 96c114adb5f9..8bafa8354685 100644 --- a/browser/ui/webui/ai_chat/ai_chat_ui_page_handler.cc +++ b/browser/ui/webui/ai_chat/ai_chat_ui_page_handler.cc @@ -91,18 +91,6 @@ void AIChatUIPageHandler::HandleVoiceRecognition( #endif } -void AIChatUIPageHandler::ConversationExists( - const std::string& conversation_uuid, - ConversationExistsCallback callback) { - AIChatServiceFactory::GetForBrowserContext(profile_)->GetConversation( - conversation_uuid, base::BindOnce( - [](ConversationExistsCallback callback, - ConversationHandler* conversation) { - std::move(callback).Run(conversation != nullptr); - }, - std::move(callback))); -} - void AIChatUIPageHandler::OpenAIChatSettings() { content::WebContents* contents_to_navigate = (active_chat_tab_helper_) ? active_chat_tab_helper_->web_contents() diff --git a/browser/ui/webui/ai_chat/ai_chat_ui_page_handler.h b/browser/ui/webui/ai_chat/ai_chat_ui_page_handler.h index 6559c6ef5b78..4dc28747bba5 100644 --- a/browser/ui/webui/ai_chat/ai_chat_ui_page_handler.h +++ b/browser/ui/webui/ai_chat/ai_chat_ui_page_handler.h @@ -53,8 +53,6 @@ class AIChatUIPageHandler : public mojom::AIChatUIHandler, void RefreshPremiumSession() override; void ManagePremium() override; void HandleVoiceRecognition(const std::string& conversation_uuid) override; - void ConversationExists(const std::string& conversation_uuid, - ConversationExistsCallback callback) override; void CloseUI() override; void SetChatUI(mojo::PendingRemote chat_ui, SetChatUICallback callback) override; diff --git a/components/ai_chat/core/browser/ai_chat_service.cc b/components/ai_chat/core/browser/ai_chat_service.cc index e45a02b043c8..beca1821dbb1 100644 --- a/components/ai_chat/core/browser/ai_chat_service.cc +++ b/components/ai_chat/core/browser/ai_chat_service.cc @@ -608,6 +608,17 @@ void AIChatService::RenameConversation(const std::string& id, OnConversationTitleChanged(conversation_handler, new_name); } +void AIChatService::ConversationExists(const std::string& conversation_uuid, + ConversationExistsCallback callback) { + GetConversation(conversation_uuid, + base::BindOnce( + [](ConversationExistsCallback callback, + ConversationHandler* conversation) { + std::move(callback).Run(conversation != nullptr); + }, + std::move(callback))); +} + void AIChatService::OnPremiumStatusReceived(GetPremiumStatusCallback callback, mojom::PremiumStatus status, mojom::PremiumInfoPtr info) { diff --git a/components/ai_chat/core/browser/ai_chat_service.h b/components/ai_chat/core/browser/ai_chat_service.h index c452ee04e794..e81f7cc4f697 100644 --- a/components/ai_chat/core/browser/ai_chat_service.h +++ b/components/ai_chat/core/browser/ai_chat_service.h @@ -148,7 +148,8 @@ class AIChatService : public KeyedService, void DeleteConversation(const std::string& id) override; void RenameConversation(const std::string& id, const std::string& new_name) override; - + void ConversationExists(const std::string& conversation_uuid, + ConversationExistsCallback callback) override; void BindConversation( const std::string& uuid, mojo::PendingReceiver receiver, diff --git a/components/ai_chat/core/common/mojom/ai_chat.mojom b/components/ai_chat/core/common/mojom/ai_chat.mojom index 0a1b3b0aa004..a10a1be1713c 100644 --- a/components/ai_chat/core/common/mojom/ai_chat.mojom +++ b/components/ai_chat/core/common/mojom/ai_chat.mojom @@ -327,6 +327,11 @@ interface Service { DeleteConversation(string id); RenameConversation(string id, string new_name); + // Determines whether a conversation exists - we need this so we can determine + // whether a URL is bogus (i.e. made up) or if it corresponds to a + // not-visible-in-sidebar conversation. + ConversationExists(string conversation_uuid) => (bool exists); + // Bind ability to send events to the UI and receive current state BindObserver(pending_remote ui) => (ServiceState state); @@ -354,11 +359,6 @@ interface AIChatUIHandler { // so that we can use [EnableIfNot=is_android] here. OpenConversationFullPage(string conversation_uuid); - // Determines whether a conversation exists - we need this so we can determine - // whether a URL is bogus (i.e. made up) or if it corresponds to a - // not-visible-in-sidebar conversation. - ConversationExists(string conversation_uuid) => (bool exists); - OpenURL(url.mojom.Url url); OpenLearnMoreAboutBraveSearchWithLeo(); OpenModelSupportUrl(); diff --git a/components/ai_chat/resources/page/api/index.ts b/components/ai_chat/resources/page/api/index.ts index 82aa28c9e513..55f8ae900aed 100644 --- a/components/ai_chat/resources/page/api/index.ts +++ b/components/ai_chat/resources/page/api/index.ts @@ -32,7 +32,7 @@ export const defaultUIState: State = { isPremiumUserDisconnected: false, isStorageNoticeDismissed: false, canShowPremiumPrompt: false, - isMobile: true,// loadTimeData.getBoolean('isMobile'), + isMobile: loadTimeData.getBoolean('isMobile'), isHistoryFeatureEnabled: loadTimeData.getBoolean('isHistoryEnabled'), allActions: [], } diff --git a/components/ai_chat/resources/page/state/active_chat_context.tsx b/components/ai_chat/resources/page/state/active_chat_context.tsx index dc29e3b03837..548b0261ab0f 100644 --- a/components/ai_chat/resources/page/state/active_chat_context.tsx +++ b/components/ai_chat/resources/page/state/active_chat_context.tsx @@ -115,7 +115,7 @@ function ActiveChatProvider({ children, selectedConversationId, updateSelectedCo // If this isn't a visible conversation, it could be an empty tab bound // conversation. let cancelled = false - getAPI().uiHandler.conversationExists(selectedConversationId).then(({ exists }) => { + getAPI().service.conversationExists(selectedConversationId).then(({ exists }) => { if (cancelled) return if (exists) return updateSelectedConversationId(undefined)