diff --git a/browser/perf/brave_perf_features_processor.cc b/browser/perf/brave_perf_features_processor.cc index 8db5c796b13..14b5b15eca3 100644 --- a/browser/perf/brave_perf_features_processor.cc +++ b/browser/perf/brave_perf_features_processor.cc @@ -53,7 +53,7 @@ void EnableAdblockCookieList(base::WeakPtr profile) { namespace perf { -void MaybeEnableBraveFeatureForPerfTesting(Profile* profile) { +void MaybeEnableBraveFeaturesPrefsForPerfTesting(Profile* profile) { auto* cmd = base::CommandLine::ForCurrentProcess(); if (!cmd->HasSwitch(switches::kEnableBraveFeaturesForPerfTesting) || !cmd->HasSwitch(::switches::kUserDataDir)) { @@ -64,11 +64,6 @@ void MaybeEnableBraveFeatureForPerfTesting(Profile* profile) { profile->GetPrefs()->SetBoolean(brave_ads::prefs::kOptedInToNotificationAds, true); - // Rewards - auto* rewards_service = - brave_rewards::RewardsServiceFactory::GetForProfile(profile); - rewards_service->CreateRewardsWallet("US", base::BindOnce(&FakeCallback)); - // Brave news profile->GetPrefs()->SetBoolean(brave_news::prefs::kNewTabPageShowToday, true); @@ -86,6 +81,20 @@ void MaybeEnableBraveFeatureForPerfTesting(Profile* profile) { base::Time::Now()); profile->GetPrefs()->SetBoolean( ai_chat::prefs::kBraveChatAutocompleteProviderEnabled, true); +} + +void MaybeEnableBraveFeaturesServicesAndComponentsForPerfTesting( + Profile* profile) { + auto* cmd = base::CommandLine::ForCurrentProcess(); + if (!cmd->HasSwitch(switches::kEnableBraveFeaturesForPerfTesting) || + !cmd->HasSwitch(::switches::kUserDataDir)) { + return; + } + + // Rewards + auto* rewards_service = + brave_rewards::RewardsServiceFactory::GetForProfile(profile); + rewards_service->CreateRewardsWallet("US", base::BindOnce(&FakeCallback)); // Adblock EnableAdblockCookieList(profile->GetWeakPtr()); diff --git a/browser/perf/brave_perf_features_processor.h b/browser/perf/brave_perf_features_processor.h index d2f8ca9a3d0..01b268427cb 100644 --- a/browser/perf/brave_perf_features_processor.h +++ b/browser/perf/brave_perf_features_processor.h @@ -10,8 +10,16 @@ class Profile; namespace perf { -// A handler for --enable-brave-features-for-perf-testing switch. -void MaybeEnableBraveFeatureForPerfTesting(Profile* profile); +// Handlers for --enable-brave-features-for-perf-testing switch. +// They are split into two because the first is invoked from +// BraveProfileManager::InitProfileUserPrefs and cannot instantiate services +// that rely on identity manager because ProfileImpl::OnLocaleReady expects +// identity manager not to be initialized before browser context services are +// created. The second one is invoked from +// BraveProfileManager::DoFinalInitForServices. +void MaybeEnableBraveFeaturesPrefsForPerfTesting(Profile* profile); +void MaybeEnableBraveFeaturesServicesAndComponentsForPerfTesting( + Profile* profile); } // namespace perf diff --git a/browser/profiles/brave_profile_manager.cc b/browser/profiles/brave_profile_manager.cc index 90ae5b62348..5ea5fc9bed9 100644 --- a/browser/profiles/brave_profile_manager.cc +++ b/browser/profiles/brave_profile_manager.cc @@ -107,8 +107,7 @@ void RecordInitialP3AValues(Profile* profile) { } // namespace BraveProfileManager::BraveProfileManager(const base::FilePath& user_data_dir) - : ProfileManager(user_data_dir) { -} + : ProfileManager(user_data_dir) {} size_t BraveProfileManager::GetNumberOfProfiles() { size_t count = ProfileManager::GetNumberOfProfiles(); @@ -157,7 +156,7 @@ void BraveProfileManager::InitProfileUserPrefs(Profile* profile) { RecordInitialP3AValues(profile); brave::SetDefaultSearchVersion(profile, profile->IsNewProfile()); brave::SetDefaultThirdPartyCookieBlockValue(profile); - perf::MaybeEnableBraveFeatureForPerfTesting(profile); + perf::MaybeEnableBraveFeaturesPrefsForPerfTesting(profile); MigrateHttpsUpgradeSettings(profile); } @@ -166,6 +165,7 @@ void BraveProfileManager::DoFinalInitForServices(Profile* profile, ProfileManager::DoFinalInitForServices(profile, go_off_the_record); if (!do_final_services_init_) return; + perf::MaybeEnableBraveFeaturesServicesAndComponentsForPerfTesting(profile); brave_ads::AdsServiceFactory::GetForProfile(profile); brave_rewards::RewardsServiceFactory::GetForProfile(profile); brave_wallet::BraveWalletServiceFactory::GetServiceForContext(profile); @@ -230,7 +230,6 @@ void BraveProfileManager::SetNonPersonalProfilePrefs(Profile* profile) { prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false); } - BraveProfileManagerWithoutInit::BraveProfileManagerWithoutInit( const base::FilePath& user_data_dir) : BraveProfileManager(user_data_dir) {