diff --git a/browser/brave_profile_prefs.cc b/browser/brave_profile_prefs.cc index 05cb7d84e5a2..9d827bcccc04 100644 --- a/browser/brave_profile_prefs.cc +++ b/browser/brave_profile_prefs.cc @@ -126,6 +126,11 @@ void RegisterProfilePrefsForMigration( // Restore "Other Bookmarks" migration registry->RegisterBooleanPref(kOtherBookmarksMigrated, false); + + // Added 04/2021 + registry->RegisterIntegerPref( + kAlternativeSearchEngineProviderInTor, + TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_INVALID); } void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { diff --git a/browser/search_engines/search_engine_provider_service_factory.cc b/browser/search_engines/search_engine_provider_service_factory.cc index 0933d0e1db8d..eef5bd64f4c5 100644 --- a/browser/search_engines/search_engine_provider_service_factory.cc +++ b/browser/search_engines/search_engine_provider_service_factory.cc @@ -100,7 +100,4 @@ SearchEngineProviderServiceFactory::ServiceIsCreatedWithBrowserContext() const { void SearchEngineProviderServiceFactory::RegisterProfilePrefs( user_prefs::PrefRegistrySyncable* registry) { registry->RegisterBooleanPref(kUseAlternativeSearchEngineProvider, false); - registry->RegisterIntegerPref( - kAlternativeSearchEngineProviderInTor, - TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_INVALID); } diff --git a/browser/search_engines/tor_window_search_engine_provider_service.cc b/browser/search_engines/tor_window_search_engine_provider_service.cc index 062a777812a9..438585ddfa4e 100644 --- a/browser/search_engines/tor_window_search_engine_provider_service.cc +++ b/browser/search_engines/tor_window_search_engine_provider_service.cc @@ -5,8 +5,6 @@ #include "brave/browser/search_engines/tor_window_search_engine_provider_service.h" -#include "brave/browser/search_engines/search_engine_provider_util.h" -#include "brave/common/pref_names.h" #include "brave/components/search_engines/brave_prepopulated_engines.h" #include "chrome/browser/profiles/profile.h" #include "components/search_engines/template_url_prepopulate_data.h" @@ -16,69 +14,39 @@ TorWindowSearchEngineProviderService:: TorWindowSearchEngineProviderService(Profile* otr_profile) : SearchEngineProviderService(otr_profile) { DCHECK(otr_profile->IsTor()); - DCHECK(otr_profile->IsOffTheRecord()); - alternative_search_engine_provider_in_tor_.Init( - kAlternativeSearchEngineProviderInTor, - otr_profile->GetOriginalProfile()->GetPrefs()); - - // Configure previously used provider because effective tor profile is - // off the recored profile. + // Config default provider for tor window. auto provider_data = GetInitialSearchEngineProvider(otr_profile->GetPrefs()); TemplateURL provider_url(*provider_data); otr_template_url_service_->SetUserSelectedDefaultSearchProvider( &provider_url); - - // Monitor otr(off the record) profile's search engine changing to caching - // in original profile. - otr_template_url_service_->AddObserver(this); } -TorWindowSearchEngineProviderService:: -~TorWindowSearchEngineProviderService() { - otr_template_url_service_->RemoveObserver(this); -} - -void TorWindowSearchEngineProviderService::OnTemplateURLServiceChanged() { - alternative_search_engine_provider_in_tor_.SetValue( - otr_template_url_service_->GetDefaultSearchProvider()-> - data().prepopulate_id); -} +TorWindowSearchEngineProviderService::~TorWindowSearchEngineProviderService() = + default; std::unique_ptr TorWindowSearchEngineProviderService::GetInitialSearchEngineProvider( PrefService* prefs) const { - std::unique_ptr provider_data = nullptr; - int initial_id = alternative_search_engine_provider_in_tor_.GetValue(); - if (initial_id != - TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_INVALID) { - provider_data = - TemplateURLPrepopulateData::GetPrepopulatedEngine(prefs, initial_id); - } - - // If this is first run, |initial_id| is invalid. Then, use qwant or ddg - // depends on default prepopulate data. If not, check that the initial_id - // returned data. - if (!provider_data) { - initial_id = TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch( - otr_profile_->GetPrefs()) - ->prepopulate_id; - switch (initial_id) { - case TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_QWANT: - case TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_DUCKDUCKGO: - case TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_DUCKDUCKGO_DE: - case TemplateURLPrepopulateData:: - PREPOPULATED_ENGINE_ID_DUCKDUCKGO_AU_NZ_IE: - break; - - default: - initial_id = - TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_DUCKDUCKGO; - break; - } - provider_data = - TemplateURLPrepopulateData::GetPrepopulatedEngine(prefs, initial_id); + std::unique_ptr provider_data; + + int initial_id = TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch( + otr_profile_->GetPrefs()) + ->prepopulate_id; + switch (initial_id) { + case TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_QWANT: + case TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_DUCKDUCKGO: + case TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_DUCKDUCKGO_DE: + case TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_DUCKDUCKGO_AU_NZ_IE: + break; + + default: + initial_id = + TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_DUCKDUCKGO; + break; } + provider_data = + TemplateURLPrepopulateData::GetPrepopulatedEngine(prefs, initial_id); DCHECK(provider_data); return provider_data; diff --git a/browser/search_engines/tor_window_search_engine_provider_service.h b/browser/search_engines/tor_window_search_engine_provider_service.h index 7727ba7de51a..32396d49fa92 100644 --- a/browser/search_engines/tor_window_search_engine_provider_service.h +++ b/browser/search_engines/tor_window_search_engine_provider_service.h @@ -7,9 +7,8 @@ #define BRAVE_BROWSER_SEARCH_ENGINES_TOR_WINDOW_SEARCH_ENGINE_PROVIDER_SERVICE_H_ #include + #include "brave/browser/search_engines/search_engine_provider_service.h" -#include "components/prefs/pref_member.h" -#include "components/search_engines/template_url_service_observer.h" class PrefService; struct TemplateURLData; @@ -18,21 +17,15 @@ struct TemplateURLData; // provider persist across the sessions. // Also, BraveProfileManager::SetNonPersonalProfilePrefs() overrides for it. class TorWindowSearchEngineProviderService - : public SearchEngineProviderService, - public TemplateURLServiceObserver { + : public SearchEngineProviderService { public: explicit TorWindowSearchEngineProviderService(Profile* otr_profile); ~TorWindowSearchEngineProviderService() override; private: - // TemplateURLServiceObserver overrides: - void OnTemplateURLServiceChanged() override; - std::unique_ptr GetInitialSearchEngineProvider( PrefService* prefs) const; - IntegerPrefMember alternative_search_engine_provider_in_tor_; - DISALLOW_COPY_AND_ASSIGN(TorWindowSearchEngineProviderService); }; diff --git a/browser/sources.gni b/browser/sources.gni index e6860abc311f..bb3a0edffa88 100644 --- a/browser/sources.gni +++ b/browser/sources.gni @@ -8,6 +8,7 @@ import("//brave/browser/importer/sources.gni") import("//brave/browser/new_tab/sources.gni") import("//brave/browser/signin/sources.gni") import("//brave/browser/themes/sources.gni") +import("//brave/chromium_src/chrome/browser/prefs/sources.gni") brave_chrome_browser_sources = [] brave_chrome_browser_sources += brave_browser_themes_sources @@ -22,6 +23,7 @@ brave_chrome_browser_deps += brave_browser_wallet_deps brave_chrome_browser_deps += brave_chrome_browser_importer_deps brave_chrome_browser_deps += brave_browser_new_tab_deps brave_chrome_browser_deps += brave_browser_signin_deps +brave_chrome_browser_deps += brave_chromium_src_chrome_browser_prefs_deps brave_chrome_browser_public_deps = [ "//brave/components/brave_sync:constants", diff --git a/build/config/brave_build.gni b/build/config/brave_build.gni index dc96a5948550..b904b55d8cde 100644 --- a/build/config/brave_build.gni +++ b/build/config/brave_build.gni @@ -5,7 +5,6 @@ import("//brave/brave_repack_locales.gni") import("//brave/browser/extensions/resources.gni") import("//brave/browser/resources/extensions/sources.gni") import("//brave/browser/resources/settings/sources.gni") -import("//brave/browser/sources.gni") import("//brave/build/config/compiler.gni") import("//brave/build/features.gni") import("//brave/build/mac/config.gni") diff --git a/chromium_src/chrome/browser/prefs/browser_prefs.cc b/chromium_src/chrome/browser/prefs/browser_prefs.cc index 1c9db5e42c55..96bc7c6a54c0 100644 --- a/chromium_src/chrome/browser/prefs/browser_prefs.cc +++ b/chromium_src/chrome/browser/prefs/browser_prefs.cc @@ -7,6 +7,7 @@ #include "brave/browser/brave_profile_prefs.h" #include "brave/browser/search/ntp_utils.h" #include "brave/browser/themes/brave_dark_mode_utils.h" +#include "brave/common/pref_names.h" #include "brave/components/brave_sync/brave_sync_prefs.h" #include "chrome/browser/profiles/profile.h" #include "components/gcm_driver/gcm_buildflags.h" @@ -51,6 +52,9 @@ void MigrateObsoleteProfilePrefs(Profile* profile) { #if !defined(OS_ANDROID) new_tab_page::MigrateNewTabPagePrefs(profile); #endif + + // Added 04/2021 + profile->GetPrefs()->ClearPref(kAlternativeSearchEngineProviderInTor); } // This method should be periodically pruned of year+ old migrations. diff --git a/chromium_src/chrome/browser/prefs/sources.gni b/chromium_src/chrome/browser/prefs/sources.gni new file mode 100644 index 000000000000..c965504b031b --- /dev/null +++ b/chromium_src/chrome/browser/prefs/sources.gni @@ -0,0 +1,24 @@ +# Copyright (c) 2021 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 http://mozilla.org/MPL/2.0/. + +import("//components/gcm_driver/config.gni") +import("//third_party/widevine/cdm/widevine.gni") + +brave_chromium_src_chrome_browser_prefs_deps = [ + "//brave/common:pref_names", + "//brave/components/brave_sync", + "//chrome/browser/profiles:profile", + "//components/gcm_driver:gcm_buildflags", + "//third_party/widevine/cdm:buildflags", +] + +if (enable_widevine) { + brave_chromium_src_chrome_browser_prefs_deps += [ "//brave/browser/widevine" ] +} + +if (!use_gcm_from_platform) { + brave_chromium_src_chrome_browser_prefs_deps += + [ "//brave/browser/gcm_driver" ] +} diff --git a/patches/chrome-browser-BUILD.gn.patch b/patches/chrome-browser-BUILD.gn.patch index e7bd44c9158a..035074c996e7 100644 --- a/patches/chrome-browser-BUILD.gn.patch +++ b/patches/chrome-browser-BUILD.gn.patch @@ -1,12 +1,12 @@ diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn -index 60acfefd43e4a8a74ae45f86fcef13b56b286e8e..d825fd35ddb17aca21740066a87907c2673dfa99 100644 +index 60acfefd43e4a8a74ae45f86fcef13b56b286e8e..20f3dc3b6c81ced082d15ab971569e18e5bb975c 100644 --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn @@ -2501,6 +2501,7 @@ static_library("browser") { "performance_monitor/metric_evaluator_helper_posix.h", ] } -+ sources += brave_chrome_browser_sources deps += brave_chrome_browser_deps public_deps += brave_chrome_browser_public_deps ++ import("//brave/browser/sources.gni") sources += brave_chrome_browser_sources deps += brave_chrome_browser_deps public_deps += brave_chrome_browser_public_deps if (is_android) { sources += [