From 2bb9f1f18f4030df40585dae1a7534eed29f0470 Mon Sep 17 00:00:00 2001 From: Emerick Rogul Date: Thu, 2 Jan 2025 09:34:48 -0500 Subject: [PATCH] Revert "[DanglingPtr] Remove patching for `AutocompleteMatch` (#26606)" This reverts commit b8941519ee3bbe41e358aef7d807c07ab4a1aa4c. --- .../render_view_context_menu.cc | 16 +++++++-------- .../render_view_context_menu_unittest.cc | 20 ------------------- .../brave_history_quick_provider_unittest.cc | 4 ++-- ...omnibox-browser-autocomplete_match.h.patch | 13 ++++++++++++ 4 files changed, 23 insertions(+), 30 deletions(-) delete mode 100644 chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu_unittest.cc create mode 100644 patches/components-omnibox-browser-autocomplete_match.h.patch diff --git a/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc b/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc index cd52c7117673..a2cf59ffa78f 100644 --- a/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc +++ b/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc @@ -22,7 +22,6 @@ #include "brave/components/ai_rewriter/common/buildflags/buildflags.h" #include "brave/components/tor/buildflags/buildflags.h" #include "brave/grit/brave_theme_resources.h" -#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser_list.h" @@ -73,14 +72,15 @@ namespace { AutocompleteMatch GetAutocompleteMatchForText(Profile* profile, const std::u16string& text) { - // `AutocompleteClassifierFactory` ultimately instantiates a - // `BraveAutocompleteSchemeClassifier` instance, as the substitution gets - // applied on the header for `ChromeAutocompleteSchemeClassifier`. - auto* classifier = AutocompleteClassifierFactory::GetForProfile(profile); - CHECK(classifier); AutocompleteMatch match; - classifier->Classify(text, false, false, - metrics::OmniboxEventProto::INVALID_SPEC, &match, NULL); + AutocompleteClassifier classifier( + std::make_unique( + std::make_unique(profile), + AutocompleteClassifier::DefaultOmniboxProviders()), + std::make_unique(profile)); + classifier.Classify(text, false, false, + metrics::OmniboxEventProto::INVALID_SPEC, &match, NULL); + classifier.Shutdown(); return match; } diff --git a/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu_unittest.cc b/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu_unittest.cc deleted file mode 100644 index c93f1cfdde3c..000000000000 --- a/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu_unittest.cc +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright (c) 2018 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at https://mozilla.org/MPL/2.0/. */ - -#include "chrome/browser/renderer_context_menu/render_view_context_menu.h" - -#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" -#include "chrome/browser/download/download_core_service_factory.h" - -// It is necessary to add this factory to these tests, as the existing overrides -// for `BraveRenderViewContextMenu` may instantiate the -// `BraveAutocompleteSchemeClassifier` using this factory. -#define DownloadCoreServiceFactory \ - AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( \ - profile(), \ - base::BindRepeating(&AutocompleteClassifierFactory::BuildInstanceFor)); \ - DownloadCoreServiceFactory -#include "src/chrome/browser/renderer_context_menu/render_view_context_menu_unittest.cc" -#undef DownloadCoreServiceFactory diff --git a/components/omnibox/browser/brave_history_quick_provider_unittest.cc b/components/omnibox/browser/brave_history_quick_provider_unittest.cc index b068967f9b8d..bcc459966c26 100644 --- a/components/omnibox/browser/brave_history_quick_provider_unittest.cc +++ b/components/omnibox/browser/brave_history_quick_provider_unittest.cc @@ -115,7 +115,6 @@ class BraveHistoryQuickProviderTest : public testing::Test { } void TearDown() override { - ac_matches_.clear(); provider_ = nullptr; client_.reset(); } @@ -243,8 +242,9 @@ class BraveHistoryQuickProviderTest : public testing::Test { base::ScopedTempDir history_dir_; std::unique_ptr client_; - scoped_refptr provider_; ACMatches ac_matches_; // The resulting matches after running RunTest. + + scoped_refptr provider_; }; BraveHistoryQuickProviderTest::SetShouldContain::SetShouldContain( diff --git a/patches/components-omnibox-browser-autocomplete_match.h.patch b/patches/components-omnibox-browser-autocomplete_match.h.patch new file mode 100644 index 000000000000..cf8117057f6c --- /dev/null +++ b/patches/components-omnibox-browser-autocomplete_match.h.patch @@ -0,0 +1,13 @@ +diff --git a/components/omnibox/browser/autocomplete_match.h b/components/omnibox/browser/autocomplete_match.h +index 804afdcf39427df21c501b3d20ccf455886a2876..97b0cb227db751c359eaf0e1abcbaefd078c4b19 100644 +--- a/components/omnibox/browser/autocomplete_match.h ++++ b/components/omnibox/browser/autocomplete_match.h +@@ -717,7 +717,7 @@ struct AutocompleteMatch { + // The provider of this match, used to remember which provider the user had + // selected when the input changes. This may be NULL, in which case there is + // no provider (or memory of the user's selection). +- raw_ptr provider = nullptr; ++ raw_ptr provider = nullptr; + + // The relevance of this match. See table in autocomplete_provider.h for + // scores returned by various providers. This is used to rank matches among