From cfc13ca576d64b695a7e6eef087afe9b19922e04 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Mon, 17 Oct 2022 11:03:50 -0700 Subject: [PATCH] Remove SessionProfile leftover completely --- browser/profiles/BUILD.gn | 9 - browser/profiles/brave_profile_impl.cc | 58 ------ browser/profiles/brave_profile_impl.h | 38 ---- browser/profiles/brave_profile_manager.cc | 11 -- browser/profiles/brave_profile_manager.h | 1 - .../brave_profile_shortcut_manager_win.cc | 41 ----- .../brave_profile_shortcut_manager_win.h | 30 ---- browser/profiles/profile_util.cc | 166 ------------------ browser/profiles/profile_util.h | 37 ---- .../host_content_settings_map_factory.cc | 10 -- .../profiles/pref_service_builder_utils.cc | 49 ------ .../chrome/browser/profiles/profile_impl.cc | 1 - .../chrome/browser/profiles/profile_impl.h | 20 --- .../profiles/profile_shortcut_manager_win.cc | 8 - ...upervised_user_settings_service_factory.cc | 16 -- .../chrome/browser/ui/browser_navigator.cc | 42 +---- ...host_content_settings_map_factory.cc.patch | 12 -- ...ome-browser-profiles-profile_impl.cc.patch | 13 -- ...rome-browser-profiles-profile_impl.h.patch | 12 -- ...iles-profile_shortcut_manager_win.cc.patch | 13 -- ...sed_user_settings_service_factory.cc.patch | 12 -- test/base/brave_testing_profile.cc | 10 +- 22 files changed, 3 insertions(+), 606 deletions(-) delete mode 100644 browser/profiles/brave_profile_impl.cc delete mode 100644 browser/profiles/brave_profile_impl.h delete mode 100644 browser/profiles/brave_profile_shortcut_manager_win.cc delete mode 100644 browser/profiles/brave_profile_shortcut_manager_win.h delete mode 100644 chromium_src/chrome/browser/content_settings/host_content_settings_map_factory.cc delete mode 100644 chromium_src/chrome/browser/profiles/profile_impl.h delete mode 100644 chromium_src/chrome/browser/profiles/profile_shortcut_manager_win.cc delete mode 100644 chromium_src/chrome/browser/supervised_user/supervised_user_settings_service_factory.cc delete mode 100644 patches/chrome-browser-content_settings-host_content_settings_map_factory.cc.patch delete mode 100644 patches/chrome-browser-profiles-profile_impl.cc.patch delete mode 100644 patches/chrome-browser-profiles-profile_impl.h.patch delete mode 100644 patches/chrome-browser-profiles-profile_shortcut_manager_win.cc.patch delete mode 100644 patches/chrome-browser-supervised_user-supervised_user_settings_service_factory.cc.patch diff --git a/browser/profiles/BUILD.gn b/browser/profiles/BUILD.gn index 479598b7cdd4..8d86019dfa51 100644 --- a/browser/profiles/BUILD.gn +++ b/browser/profiles/BUILD.gn @@ -9,8 +9,6 @@ source_set("profiles") { "brave_bookmark_model_loaded_observer.h", "brave_profile_avatar_downloader.cc", "brave_profile_avatar_downloader.h", - "brave_profile_impl.cc", - "brave_profile_impl.h", "brave_profile_manager.cc", "brave_profile_manager.h", "brave_renderer_updater.cc", @@ -19,13 +17,6 @@ source_set("profiles") { "brave_renderer_updater_factory.h", ] - if (is_win) { - sources += [ - "brave_profile_shortcut_manager_win.cc", - "brave_profile_shortcut_manager_win.h", - ] - } - public_deps = [ ":util" ] deps = [ diff --git a/browser/profiles/brave_profile_impl.cc b/browser/profiles/brave_profile_impl.cc deleted file mode 100644 index a7168dc3abbc..000000000000 --- a/browser/profiles/brave_profile_impl.cc +++ /dev/null @@ -1,58 +0,0 @@ -/* Copyright (c) 2019 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/. */ - -#include "brave/browser/profiles/brave_profile_impl.h" - -#include "brave/browser/profiles/profile_util.h" -#include "brave/components/constants/pref_names.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/profiles/profile_manager.h" -#include "content/public/browser/browser_task_traits.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/notification_source.h" - -BraveProfileImpl::BraveProfileImpl( - const base::FilePath& path, - Delegate* delegate, - CreateMode create_mode, - base::Time creation_time, - scoped_refptr io_task_runner) - : ProfileImpl(path, delegate, create_mode, creation_time, io_task_runner), - weak_ptr_factory_(this) { - // In sessions profiles, prefs are created from the original profile like how - // incognito profile works. By the time chromium start to observe prefs - // initialization in ProfileImpl constructor for the async creation case, - // prefs are already initialized and it's too late for the observer to get - // the notification, so we manually trigger the OnPrefsLoaded here. For the - // sync cases, OnPrefsLoaded will always be called at the end of ProfileImpl - // constructor, so there is no need to trigger it here. - // - // This need to be posted instead of running directly here because we need to - // finish the construction and register this profile first in ProfileManager - // before OnPrefsLoaded is called, otherwise we would hit a DCHECK in - // ProfileManager::OnProfileCreated which is called inside OnPrefsLoaded and - // is expecting the profile_info is already added then. - if (brave::IsSessionProfilePath(path) && - create_mode == CREATE_MODE_ASYNCHRONOUS) { - auto* parent_profile = brave::CreateParentProfileData(this); - parent_observation_.Observe(parent_profile); - - content::GetUIThreadTaskRunner({})->PostTaskAndReply( - FROM_HERE, base::DoNothing(), - base::BindOnce(&ProfileImpl::OnPrefsLoaded, - weak_ptr_factory_.GetWeakPtr(), create_mode, true)); - } -} - -BraveProfileImpl::~BraveProfileImpl() = default; - -void BraveProfileImpl::OnProfileWillBeDestroyed(Profile* profile) { - // this only happens when a profile is deleted because the profile manager - // ensures that session profiles are destroyed before their parents - // passing false for `success` removes the profile from the info cache - g_browser_process->profile_manager()->OnProfileCreationFinished( - this, Profile::CREATE_MODE_ASYNCHRONOUS, false, false); -} diff --git a/browser/profiles/brave_profile_impl.h b/browser/profiles/brave_profile_impl.h deleted file mode 100644 index 9e9cc61f8019..000000000000 --- a/browser/profiles/brave_profile_impl.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright (c) 2019 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/. */ - -#ifndef BRAVE_BROWSER_PROFILES_BRAVE_PROFILE_IMPL_H_ -#define BRAVE_BROWSER_PROFILES_BRAVE_PROFILE_IMPL_H_ - -#include "chrome/browser/profiles/profile_impl.h" - -#include "base/memory/weak_ptr.h" -#include "base/scoped_observation.h" -#include "chrome/browser/profiles/profile_observer.h" - -class PrefStore; - -class BraveProfileImpl : public ProfileImpl, public ProfileObserver { - public: - BraveProfileImpl(const base::FilePath& path, - Delegate* delegate, - CreateMode create_mode, - base::Time creation_time, - scoped_refptr io_task_runner); - BraveProfileImpl(const BraveProfileImpl&) = delete; - BraveProfileImpl& operator=(const BraveProfileImpl&) = delete; - ~BraveProfileImpl() override; - - // ProfileObserver: - void OnProfileWillBeDestroyed(Profile* profile) override; - - private: - // Listens for parent profile destruction. - base::ScopedObservation parent_observation_{this}; - - base::WeakPtrFactory weak_ptr_factory_; -}; - -#endif // BRAVE_BROWSER_PROFILES_BRAVE_PROFILE_IMPL_H_ diff --git a/browser/profiles/brave_profile_manager.cc b/browser/profiles/brave_profile_manager.cc index b5b09f877743..a78ad2ef656e 100644 --- a/browser/profiles/brave_profile_manager.cc +++ b/browser/profiles/brave_profile_manager.cc @@ -54,17 +54,6 @@ BraveProfileManager::BraveProfileManager(const base::FilePath& user_data_dir) MigrateProfileNames(); } -BraveProfileManager::~BraveProfileManager() { - std::vector profiles = GetLoadedProfiles(); - for (Profile* profile : profiles) { - if (brave::IsSessionProfile(profile)) { - // passing false for `success` removes the profile from the info cache - OnProfileCreationFinished(profile, Profile::CREATE_MODE_ASYNCHRONOUS, - false, false); - } - } -} - void BraveProfileManager::InitProfileUserPrefs(Profile* profile) { // migrate obsolete plugin prefs to temporary migration pref because otherwise // they get deleteed by PrefProvider before we can migrate them in diff --git a/browser/profiles/brave_profile_manager.h b/browser/profiles/brave_profile_manager.h index fe6dfb8e7b9b..9114d7571af6 100644 --- a/browser/profiles/brave_profile_manager.h +++ b/browser/profiles/brave_profile_manager.h @@ -15,7 +15,6 @@ class BraveProfileManager : public ProfileManager { explicit BraveProfileManager(const base::FilePath& user_data_dir); BraveProfileManager(const BraveProfileManager&) = delete; BraveProfileManager& operator=(const BraveProfileManager&) = delete; - ~BraveProfileManager() override; void InitProfileUserPrefs(Profile* profile) override; void SetNonPersonalProfilePrefs(Profile* profile) override; diff --git a/browser/profiles/brave_profile_shortcut_manager_win.cc b/browser/profiles/brave_profile_shortcut_manager_win.cc deleted file mode 100644 index e9a053ec9c4d..000000000000 --- a/browser/profiles/brave_profile_shortcut_manager_win.cc +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright (c) 2019 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/. */ - -#include "brave/browser/profiles/brave_profile_shortcut_manager_win.h" - -#include "brave/browser/profiles/profile_util.h" -#include "chrome/browser/profiles/profile_attributes_storage.h" -#include "chrome/browser/profiles/profile_manager.h" - -BraveProfileShortcutManagerWin::BraveProfileShortcutManagerWin( - ProfileManager* manager) - : ProfileShortcutManagerWin(manager), - profile_manager_(manager) {} - -void BraveProfileShortcutManagerWin::GetShortcutProperties( - const base::FilePath& profile_path, - base::CommandLine* command_line, - std::wstring* name, - base::FilePath* icon_path) { - // Session profiles are currently not added into storage because they will - // return early in ProfileManager::AddProfileToStorage because of the profile - // path is not directly under user_data_dir. To avoid DCHECK(has_entry) in - // chromium's GetShortcutProperties and invalid access to the entry, return - // early here when entry cannot be found. - // - // TODO(jocelyn): Properly add session profiles into the storage and remove - // this override. - if (brave::IsSessionProfilePath(profile_path)) { - ProfileAttributesStorage& storage = - profile_manager_->GetProfileAttributesStorage(); - if (!storage.GetProfileAttributesWithPath(profile_path)) - return; - } - - ProfileShortcutManagerWin::GetShortcutProperties(profile_path, - command_line, - name, - icon_path); -} diff --git a/browser/profiles/brave_profile_shortcut_manager_win.h b/browser/profiles/brave_profile_shortcut_manager_win.h deleted file mode 100644 index 469ae1d73017..000000000000 --- a/browser/profiles/brave_profile_shortcut_manager_win.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (c) 2019 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/. */ - -#ifndef BRAVE_BROWSER_PROFILES_BRAVE_PROFILE_SHORTCUT_MANAGER_WIN_H_ -#define BRAVE_BROWSER_PROFILES_BRAVE_PROFILE_SHORTCUT_MANAGER_WIN_H_ - -#include "base/memory/raw_ptr.h" -#include "chrome/browser/profiles/profile_shortcut_manager_win.h" - -class BraveProfileShortcutManagerWin : public ProfileShortcutManagerWin { - public: - explicit BraveProfileShortcutManagerWin(ProfileManager* manager); - BraveProfileShortcutManagerWin(const BraveProfileShortcutManagerWin&) = - delete; - BraveProfileShortcutManagerWin& operator=( - const BraveProfileShortcutManagerWin&) = delete; - ~BraveProfileShortcutManagerWin() override = default; - - void GetShortcutProperties(const base::FilePath& profile_path, - base::CommandLine* command_line, - std::wstring* name, - base::FilePath* icon_path) override; - - private: - raw_ptr profile_manager_ = nullptr; -}; - -#endif // BRAVE_BROWSER_PROFILES_BRAVE_PROFILE_SHORTCUT_MANAGER_WIN_H_ diff --git a/browser/profiles/profile_util.cc b/browser/profiles/profile_util.cc index 000db7ead2e1..34ed83c1c798 100644 --- a/browser/profiles/profile_util.cc +++ b/browser/profiles/profile_util.cc @@ -9,22 +9,16 @@ #include #include -#include "base/files/file_path.h" -#include "base/memory/ptr_util.h" #include "base/memory/raw_ptr.h" #include "base/metrics/histogram_macros.h" -#include "base/no_destructor.h" #include "brave/components/brave_shields/browser/brave_shields_p3a.h" #include "brave/components/constants/brave_constants.h" #include "brave/components/constants/pref_names.h" #include "brave/components/ntp_background_images/common/pref_names.h" #include "brave/components/search_engines/brave_prepopulated_engines.h" #include "brave/components/tor/buildflags/buildflags.h" -#include "chrome/browser/browser_process.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_key.h" -#include "chrome/browser/profiles/profile_manager.h" #include "components/content_settings/core/browser/cookie_settings.h" #include "components/content_settings/core/common/pref_names.h" #include "components/prefs/pref_service.h" @@ -39,153 +33,6 @@ using ntp_background_images::prefs::kNewTabPageShowSponsoredImagesBackgroundImag namespace brave { -namespace { - -using PathMap = std::map; - -PathMap* GetPathMap() { - static base::NoDestructor provider; - return provider.get(); -} - -Profile* GetFromPath(const base::FilePath& key) { - auto mapping = *GetPathMap(); - const auto& it = mapping.find(key); - if (it == mapping.end()) { - DCHECK(false); - return nullptr; - } - - return it->second; -} - -class ParentProfileData : public base::SupportsUserData::Data { - public: - ParentProfileData(const ParentProfileData&) = delete; - ParentProfileData& operator=(const ParentProfileData&) = delete; - ~ParentProfileData() override; - static void CreateForProfile(content::BrowserContext* context); - static ParentProfileData* FromProfile(content::BrowserContext* context); - static const ParentProfileData* FromProfile( - const content::BrowserContext* context); - static const ParentProfileData* FromPath(const base::FilePath& path); - - Profile* profile() const; - - std::unique_ptr Clone() override; - - private: - static const void* const kUserDataKey; - static const void* UserDataKey(); - - explicit ParentProfileData(Profile* profile); - - raw_ptr profile_ = nullptr; - base::FilePath path_; -}; - -const void* const ParentProfileData::kUserDataKey = &kUserDataKey; - -// static -void ParentProfileData::CreateForProfile(content::BrowserContext* context) { - DCHECK(context); - if (FromProfile(context)) - return; - - auto* profile = Profile::FromBrowserContext(context); - auto* profile_manager = g_browser_process->profile_manager(); - DCHECK(profile_manager); - - auto* parent_profile = - profile_manager->GetProfileByPath(GetParentProfilePath(profile)); - DCHECK(parent_profile); - DCHECK(parent_profile != profile); - - profile->SetUserData(UserDataKey(), - base::WrapUnique(new ParentProfileData(parent_profile))); - - GetPathMap()->insert( - std::pair(profile->GetPath(), profile)); -} - -// static -ParentProfileData* ParentProfileData::FromProfile( - content::BrowserContext* context) { - DCHECK(context); - auto* profile = Profile::FromBrowserContext(context); - return static_cast( - profile->GetOriginalProfile()->GetUserData(UserDataKey())); -} - -// static -const ParentProfileData* ParentProfileData::FromProfile( - const content::BrowserContext* context) { - DCHECK(context); - const auto* profile = static_cast(context); - return static_cast( - profile->GetOriginalProfile()->GetUserData(UserDataKey())); -} - -// static -const ParentProfileData* ParentProfileData::FromPath( - const base::FilePath& path) { - auto* profile = GetFromPath(path); - DCHECK(profile); - return FromProfile(profile); -} - -Profile* ParentProfileData::profile() const { - return profile_; -} - -std::unique_ptr ParentProfileData::Clone() { - return base::WrapUnique(new ParentProfileData(profile_)); -} - -const void* ParentProfileData::UserDataKey() { - return &kUserDataKey; -} - -ParentProfileData::ParentProfileData(Profile* profile) - : profile_(profile), path_(profile->GetPath()) {} - -ParentProfileData::~ParentProfileData() { - GetPathMap()->erase(path_); -} - -} // namespace - -Profile* CreateParentProfileData(content::BrowserContext* context) { - ParentProfileData::CreateForProfile(context); - return ParentProfileData::FromProfile(context)->profile(); -} - -base::FilePath GetParentProfilePath(content::BrowserContext* context) { - return GetParentProfilePath(context->GetPath()); -} - -base::FilePath GetParentProfilePath(const base::FilePath& path) { - return path.DirName().DirName(); -} - -bool IsSessionProfile(content::BrowserContext* context) { - DCHECK(context); - return ParentProfileData::FromProfile(context) != nullptr; -} - -bool IsSessionProfilePath(const base::FilePath& path) { - return path.DirName().BaseName() == base::FilePath(kSessionProfileDir); -} - -Profile* GetParentProfile(content::BrowserContext* context) { - DCHECK(context); - return ParentProfileData::FromProfile(context)->profile(); -} - -Profile* GetParentProfile(const base::FilePath& path) { - return ParentProfileData::FromPath(path)->profile(); -} - bool IsGuestProfile(content::BrowserContext* context) { DCHECK(context); return Profile::FromBrowserContext(context) @@ -254,16 +101,3 @@ void SetDefaultThirdPartyCookieBlockValue(Profile* profile) { } } // namespace brave - -namespace chrome { - -// Get the correct profile for keyed services that use -// GetBrowserContextRedirectedInIncognito or equivalent -content::BrowserContext* GetBrowserContextRedirectedInIncognitoOverride( - content::BrowserContext* context) { - if (brave::IsSessionProfile(context)) - context = brave::GetParentProfile(context); - return chrome::GetBrowserContextRedirectedInIncognito(context); -} - -} // namespace chrome diff --git a/browser/profiles/profile_util.h b/browser/profiles/profile_util.h index 86857a7b982b..3f373820fe35 100644 --- a/browser/profiles/profile_util.h +++ b/browser/profiles/profile_util.h @@ -6,29 +6,11 @@ #ifndef BRAVE_BROWSER_PROFILES_PROFILE_UTIL_H_ #define BRAVE_BROWSER_PROFILES_PROFILE_UTIL_H_ -#include "base/files/file_path.h" -#include "base/supports_user_data.h" -// this needs to be here so we don't accidentally override the real method -#include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/profile.h" #include "content/public/browser/browser_context.h" namespace brave { -Profile* CreateParentProfileData(content::BrowserContext* context); - -base::FilePath GetParentProfilePath(content::BrowserContext* context); - -base::FilePath GetParentProfilePath(const base::FilePath& file_path); - -bool IsSessionProfile(content::BrowserContext* context); - -bool IsSessionProfilePath(const base::FilePath& path); - -Profile* GetParentProfile(content::BrowserContext* context); - -Profile* GetParentProfile(const base::FilePath& path); - // This function is similar to Profile::IsGuestSession. It is used to get // around the bug(?) in OffTheRecordProfileImpl::Init() code that calls // set_is_guest_profile on off-the-record profile only after calling @@ -66,23 +48,4 @@ void SetDefaultThirdPartyCookieBlockValue(Profile* profile); } // namespace brave -namespace chrome { - -// Get the correct profile for keyed services that use -// GetBrowserContextRedirectedInIncognito or equivalent -content::BrowserContext* GetBrowserContextRedirectedInIncognitoOverride( - content::BrowserContext* context); - -} // namespace chrome - -// Get the correct profile for keyed services that do NOT use -// GetBrowserContextRedirectedInIncognito or equivalent -#define BRAVE_GET_BROWSER_CONTEXT_TO_USE_WITHOUT_REDIRECT \ - if (brave::IsSessionProfile(context)) { \ - auto* parent = brave::GetParentProfile(context); \ - context = context->IsOffTheRecord() \ - ? parent->GetPrimaryOTRProfile(/*create_if_needed=*/true) \ - : parent; \ - } - #endif // BRAVE_BROWSER_PROFILES_PROFILE_UTIL_H_ diff --git a/chromium_src/chrome/browser/content_settings/host_content_settings_map_factory.cc b/chromium_src/chrome/browser/content_settings/host_content_settings_map_factory.cc deleted file mode 100644 index d2521622bed9..000000000000 --- a/chromium_src/chrome/browser/content_settings/host_content_settings_map_factory.cc +++ /dev/null @@ -1,10 +0,0 @@ -/* Copyright (c) 2019 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/. */ - -#include "brave/browser/profiles/profile_util.h" - -#define BRAVE_BUILD_SERVICE_INSTANCE_FOR brave::IsSessionProfile(profile) || -#include "src/chrome/browser/content_settings/host_content_settings_map_factory.cc" -#undef BRAVE_BUILD_SERVICE_INSTANCE_FOR diff --git a/chromium_src/chrome/browser/profiles/pref_service_builder_utils.cc b/chromium_src/chrome/browser/profiles/pref_service_builder_utils.cc index 403da92a96aa..16a6b9f04ca0 100644 --- a/chromium_src/chrome/browser/profiles/pref_service_builder_utils.cc +++ b/chromium_src/chrome/browser/profiles/pref_service_builder_utils.cc @@ -6,30 +6,16 @@ #include "chrome/browser/profiles/pref_service_builder_utils.h" #include "brave/browser/brave_profile_prefs.h" -#include "brave/browser/profiles/brave_profile_impl.h" -#include "brave/browser/profiles/profile_util.h" #include "brave/components/brave_ads/browser/ads_service.h" #include "brave/components/brave_rewards/browser/rewards_service.h" #include "brave/components/constants/pref_names.h" -#include "brave/components/tor/buildflags/buildflags.h" #include "build/build_config.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/prefs/pref_service_syncable_util.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/pref_names.h" #include "components/spellcheck/browser/pref_names.h" #include "ui/color/system_theme.h" -#if BUILDFLAG(ENABLE_EXTENSIONS) -#include "extensions/browser/extension_pref_store.h" -#include "extensions/browser/extension_pref_value_map_factory.h" -#endif - -#define CreatePrefService CreatePrefService_ChromiumImpl #define RegisterProfilePrefs RegisterProfilePrefs_ChromiumImpl #include "src/chrome/browser/profiles/pref_service_builder_utils.cc" -#undef CreatePrefService #undef RegisterProfilePrefs // Prefs for KeyedService @@ -56,38 +42,3 @@ void RegisterProfilePrefs(bool is_signin_profile, base::Value(static_cast(ui::SystemTheme::kDefault))); #endif } - -std::unique_ptr CreatePrefService( - scoped_refptr pref_registry, - PrefStore* extension_pref_store, - policy::PolicyService* policy_service, - policy::ChromeBrowserPolicyConnector* browser_policy_connector, - mojo::PendingRemote - pref_validation_delegate, - scoped_refptr io_task_runner, - SimpleFactoryKey* key, - const base::FilePath& path, - bool async_prefs) { - // Create prefs using the same approach that chromium used when creating an - // off-the-record profile from its original profile. - if (brave::IsSessionProfilePath(path)) { - base::FilePath original_path = brave::GetParentProfilePath(path); - Profile* original_profile = - g_browser_process->profile_manager()->GetProfileByPath(original_path); - DCHECK(original_profile); - PrefStore* local_extension_pref_store = nullptr; -#if BUILDFLAG(ENABLE_EXTENSIONS) - local_extension_pref_store = new ExtensionPrefStore( - ExtensionPrefValueMapFactory::GetForBrowserContext(original_profile), - true); -#endif - return CreateIncognitoPrefServiceSyncable( - PrefServiceSyncableFromProfile(original_profile), - local_extension_pref_store); - } - - return CreatePrefService_ChromiumImpl( - pref_registry, extension_pref_store, policy_service, - browser_policy_connector, std::move(pref_validation_delegate), - io_task_runner, key, path, async_prefs); -} diff --git a/chromium_src/chrome/browser/profiles/profile_impl.cc b/chromium_src/chrome/browser/profiles/profile_impl.cc index 2f3743b7d1db..d27b2d1194cf 100644 --- a/chromium_src/chrome/browser/profiles/profile_impl.cc +++ b/chromium_src/chrome/browser/profiles/profile_impl.cc @@ -4,7 +4,6 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "brave/browser/profiles/brave_bookmark_model_loaded_observer.h" -#include "brave/browser/profiles/brave_profile_impl.h" #define BookmarkModelLoadedObserver BraveBookmarkModelLoadedObserver #define ChromeBrowsingDataRemoverDelegate BraveBrowsingDataRemoverDelegate #include "src/chrome/browser/profiles/profile_impl.cc" diff --git a/chromium_src/chrome/browser/profiles/profile_impl.h b/chromium_src/chrome/browser/profiles/profile_impl.h deleted file mode 100644 index 97da8687575a..000000000000 --- a/chromium_src/chrome/browser/profiles/profile_impl.h +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright (c) 2019 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/. */ - -#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_ -#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_ - -#define BRAVE_PROFILE_IMPL_H_ \ - private: \ - friend class BraveProfileImpl; \ - \ - public: -// define BRAVE_PROFILE_IMPL_H_ - -#include "src/chrome/browser/profiles/profile_impl.h" - -#undef BRAVE_PROFILE_IMPL_H_ - -#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_ diff --git a/chromium_src/chrome/browser/profiles/profile_shortcut_manager_win.cc b/chromium_src/chrome/browser/profiles/profile_shortcut_manager_win.cc deleted file mode 100644 index 95ddeece168a..000000000000 --- a/chromium_src/chrome/browser/profiles/profile_shortcut_manager_win.cc +++ /dev/null @@ -1,8 +0,0 @@ -/* Copyright (c) 2019 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/. */ - -#include "brave/browser/profiles/brave_profile_shortcut_manager_win.h" - -#include "src/chrome/browser/profiles/profile_shortcut_manager_win.cc" diff --git a/chromium_src/chrome/browser/supervised_user/supervised_user_settings_service_factory.cc b/chromium_src/chrome/browser/supervised_user/supervised_user_settings_service_factory.cc deleted file mode 100644 index 6785ac8ed162..000000000000 --- a/chromium_src/chrome/browser/supervised_user/supervised_user_settings_service_factory.cc +++ /dev/null @@ -1,16 +0,0 @@ -/* Copyright (c) 2019 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 "brave/browser/profiles/profile_util.h" - -// Use the same SupervisedUserSettingsService, which handles a part of -// preferences, as its parent profile. Chromium's incognito profile also shares -// it with its original profile. -#define BRAVE_GET_KEY_TO_USE \ - if (brave::IsSessionProfilePath(key->GetPath())) { \ - return brave::GetParentProfile(key->GetPath())->GetProfileKey(); \ - } - -#include "src/chrome/browser/supervised_user/supervised_user_settings_service_factory.cc" diff --git a/chromium_src/chrome/browser/ui/browser_navigator.cc b/chromium_src/chrome/browser/ui/browser_navigator.cc index 9af8a42f7379..4786376e47b9 100644 --- a/chromium_src/chrome/browser/ui/browser_navigator.cc +++ b/chromium_src/chrome/browser/ui/browser_navigator.cc @@ -3,34 +3,14 @@ * 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/. */ -#include "brave/browser/profiles/profile_util.h" #include "brave/components/constants/webui_url_constants.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_navigator_params.h" #include "chrome/common/webui_url_constants.h" #include "url/gurl.h" namespace { -bool HandleURLInParent(NavigateParams* params, Profile* profile) { - if (profile->IsTor() && - !params->browser->profile()->IsOffTheRecord()) { - return true; - } - - return false; -} - -// GetOrCreateBrowser is not accessible here -Browser* BraveGetOrCreateBrowser(Profile* profile, bool user_gesture) { - Browser* browser = chrome::FindTabbedBrowser(profile, false); - return browser - ? browser - : Browser::Create(Browser::CreateParams(profile, user_gesture)); -} - void UpdateBraveScheme(NavigateParams* params) { if (params->url.SchemeIs(content::kBraveUIScheme)) { GURL::Replacements replacements; @@ -39,22 +19,6 @@ void UpdateBraveScheme(NavigateParams* params) { } } -void MaybeHandleInParent(NavigateParams* params, bool allow_in_incognito) { - auto& profile = params->initiating_profile; - if (brave::IsSessionProfile(profile)) { - if (!allow_in_incognito) { - params->initiating_profile = - profile->IsOffTheRecord() - ? brave::GetParentProfile(profile)->GetPrimaryOTRProfile( - /*create_if_needed=*/true) - : brave::GetParentProfile(profile); - } else if (HandleURLInParent(params, profile)) { - params->browser = BraveGetOrCreateBrowser( - brave::GetParentProfile(profile), params->user_gesture); - } - } -} - bool IsHostAllowedInIncognitoBraveImpl(const base::StringPiece& host) { if (host == kWalletPageHost || host == kWalletPanelHost || host == kRewardsPageHost || host == chrome::kChromeUISyncInternalsHost || @@ -67,10 +31,6 @@ bool IsHostAllowedInIncognitoBraveImpl(const base::StringPiece& host) { } // namespace -#define BRAVE_ADJUST_NAVIGATE_PARAMS_FOR_URL \ - UpdateBraveScheme(params); \ - MaybeHandleInParent(params, IsURLAllowedInIncognito( \ - params->url, params->initiating_profile)); - +#define BRAVE_ADJUST_NAVIGATE_PARAMS_FOR_URL UpdateBraveScheme(params); #include "src/chrome/browser/ui/browser_navigator.cc" #undef BRAVE_ADJUST_NAVIGATE_PARAMS_FOR_URL diff --git a/patches/chrome-browser-content_settings-host_content_settings_map_factory.cc.patch b/patches/chrome-browser-content_settings-host_content_settings_map_factory.cc.patch deleted file mode 100644 index 18ee0057b5dc..000000000000 --- a/patches/chrome-browser-content_settings-host_content_settings_map_factory.cc.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/chrome/browser/content_settings/host_content_settings_map_factory.cc b/chrome/browser/content_settings/host_content_settings_map_factory.cc -index 09e166d182eedb33c6d4c32fa51e211e75611136..48a3693139ca3b67800ea041bdf0918ed1882daf 100644 ---- a/chrome/browser/content_settings/host_content_settings_map_factory.cc -+++ b/chrome/browser/content_settings/host_content_settings_map_factory.cc -@@ -97,6 +97,7 @@ scoped_refptr - - scoped_refptr settings_map(new HostContentSettingsMap( - profile->GetPrefs(), -+ BRAVE_BUILD_SERVICE_INSTANCE_FOR - profile->IsOffTheRecord() || profile->IsGuestSession(), - /*store_last_modified=*/true, - profile->ShouldRestoreOldSessionCookies())); diff --git a/patches/chrome-browser-profiles-profile_impl.cc.patch b/patches/chrome-browser-profiles-profile_impl.cc.patch deleted file mode 100644 index b0867d63bc4c..000000000000 --- a/patches/chrome-browser-profiles-profile_impl.cc.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc -index 9f2ccdfbc8e5504f47f689060809b9ccc69fea18..0ed04f56f043d7a2493e31a42d03bab03724ba33 100644 ---- a/chrome/browser/profiles/profile_impl.cc -+++ b/chrome/browser/profiles/profile_impl.cc -@@ -365,7 +365,7 @@ std::unique_ptr Profile::CreateProfile(const base::FilePath& path, - NOTREACHED(); - } - -- std::unique_ptr profile = base::WrapUnique(new ProfileImpl( -+ std::unique_ptr profile = base::WrapUnique(new BraveProfileImpl( - path, delegate, create_mode, creation_time, io_task_runner)); - return profile; - } diff --git a/patches/chrome-browser-profiles-profile_impl.h.patch b/patches/chrome-browser-profiles-profile_impl.h.patch deleted file mode 100644 index c7470b7fd5ed..000000000000 --- a/patches/chrome-browser-profiles-profile_impl.h.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h -index fa114390c0b08a7538f2c52f7c69477519efb874..88c5aaec5dc4921c6e10d68fa70afab794ce2c23 100644 ---- a/chrome/browser/profiles/profile_impl.h -+++ b/chrome/browser/profiles/profile_impl.h -@@ -165,6 +165,7 @@ class ProfileImpl : public Profile { - void OnLogin() override; - void InitChromeOSPreferences() override; - #endif // BUILDFLAG(IS_CHROMEOS_ASH) -+ BRAVE_PROFILE_IMPL_H_ - - bool IsNewProfile() const override; - diff --git a/patches/chrome-browser-profiles-profile_shortcut_manager_win.cc.patch b/patches/chrome-browser-profiles-profile_shortcut_manager_win.cc.patch deleted file mode 100644 index 6d3a420e2ed1..000000000000 --- a/patches/chrome-browser-profiles-profile_shortcut_manager_win.cc.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/chrome/browser/profiles/profile_shortcut_manager_win.cc b/chrome/browser/profiles/profile_shortcut_manager_win.cc -index 6d08c9ab2f15d61772adcb3f0dde42eb4fcbeacb..0811ce28db7ceabb9331a6f66c7a04835665641b 100644 ---- a/chrome/browser/profiles/profile_shortcut_manager_win.cc -+++ b/chrome/browser/profiles/profile_shortcut_manager_win.cc -@@ -859,7 +859,7 @@ bool ProfileShortcutManager::IsFeatureEnabled() { - // static - std::unique_ptr ProfileShortcutManager::Create( - ProfileManager* manager) { -- return std::make_unique(manager); -+ return std::make_unique(manager); - } - - ProfileShortcutManagerWin::ProfileShortcutManagerWin(ProfileManager* manager) diff --git a/patches/chrome-browser-supervised_user-supervised_user_settings_service_factory.cc.patch b/patches/chrome-browser-supervised_user-supervised_user_settings_service_factory.cc.patch deleted file mode 100644 index 50a1ada39cae..000000000000 --- a/patches/chrome-browser-supervised_user-supervised_user_settings_service_factory.cc.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/chrome/browser/supervised_user/supervised_user_settings_service_factory.cc b/chrome/browser/supervised_user/supervised_user_settings_service_factory.cc -index d0979bc67c47ad2fb163c09151d9a8079247543c..916e24c7458f86d9e0267cbcd5cef8b40edebc44 100644 ---- a/chrome/browser/supervised_user/supervised_user_settings_service_factory.cc -+++ b/chrome/browser/supervised_user/supervised_user_settings_service_factory.cc -@@ -36,6 +36,7 @@ SupervisedUserSettingsServiceFactory::BuildServiceInstanceFor( - - SimpleFactoryKey* SupervisedUserSettingsServiceFactory::GetKeyToUse( - SimpleFactoryKey* key) const { -+ BRAVE_GET_KEY_TO_USE - ProfileKey* profile_key = ProfileKey::FromSimpleFactoryKey(key); - return profile_key->GetOriginalKey(); - } diff --git a/test/base/brave_testing_profile.cc b/test/base/brave_testing_profile.cc index f8bad7faecea..5d02a0d93c82 100644 --- a/test/base/brave_testing_profile.cc +++ b/test/base/brave_testing_profile.cc @@ -5,21 +5,15 @@ #include "brave/test/base/brave_testing_profile.h" -#include "brave/browser/profiles/profile_util.h" #include "brave/components/constants/pref_names.h" #include "components/gcm_driver/gcm_buildflags.h" #include "components/prefs/pref_service.h" BraveTestingProfile::BraveTestingProfile(const base::FilePath& path, Delegate* delegate) - : TestingProfile(path, delegate) { - if (brave::IsSessionProfilePath(path)) { - brave::CreateParentProfileData(this); - } -} + : TestingProfile(path, delegate) {} -BraveTestingProfile::BraveTestingProfile() - : TestingProfile() { +BraveTestingProfile::BraveTestingProfile() : TestingProfile() { #if !BUILDFLAG(USE_GCM_FROM_PLATFORM) GetPrefs()->SetBoolean(kBraveGCMChannelStatus, true); #endif