Skip to content

Commit

Permalink
Fixes BraveRendererUpdater to mimic upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyZhukovsky committed Jun 27, 2024
1 parent 50af8e0 commit 233cae0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
7 changes: 6 additions & 1 deletion browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,12 @@ void BraveContentBrowserClient::BrowserURLHandlerCreated(
void BraveContentBrowserClient::RenderProcessWillLaunch(
content::RenderProcessHost* host) {
Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
BraveRendererUpdaterFactory::GetForProfile(profile)->InitializeRenderer(host);
// The BraveRendererUpdater might be null for some irregular profiles, e.g.
// the System Profile.
if (BraveRendererUpdater* service =
BraveRendererUpdaterFactory::GetForProfile(profile)) {
service->InitializeRenderer(host);
}

ChromeContentBrowserClient::RenderProcessWillLaunch(host);
}
Expand Down
23 changes: 10 additions & 13 deletions browser/profiles/brave_renderer_updater_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
#include "brave/browser/profiles/brave_renderer_updater.h"
#include "brave/components/brave_wallet/browser/brave_wallet_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"

BraveRendererUpdaterFactory::BraveRendererUpdaterFactory()
: BrowserContextKeyedServiceFactory(
: ProfileKeyedServiceFactory(
"BraveRendererUpdater",
BrowserContextDependencyManager::GetInstance()) {
ProfileSelections::Builder()
.WithRegular(ProfileSelection::kOwnInstance)
.WithGuest(ProfileSelection::kOwnInstance)
.Build()) {
DependsOn(brave_wallet::BraveWalletServiceFactory::GetInstance());
}

Expand All @@ -36,23 +37,19 @@ BraveRendererUpdater* BraveRendererUpdaterFactory::GetForProfile(
GetInstance()->GetServiceForBrowserContext(profile, true));
}

KeyedService* BraveRendererUpdaterFactory::BuildServiceInstanceFor(
std::unique_ptr<KeyedService>
BraveRendererUpdaterFactory::BuildServiceInstanceForBrowserContext(
content::BrowserContext* context) const {
auto* brave_wallet_service =
brave_wallet::BraveWalletServiceFactory::GetServiceForContext(context);

auto* keyring_service =
brave_wallet_service ? brave_wallet_service->keyring_service() : 0;
return new BraveRendererUpdater(static_cast<Profile*>(context),
keyring_service,
g_browser_process->local_state());
return std::make_unique<BraveRendererUpdater>(
static_cast<Profile*>(context), keyring_service,
g_browser_process->local_state());
}

bool BraveRendererUpdaterFactory::ServiceIsCreatedWithBrowserContext() const {
return true;
}

content::BrowserContext* BraveRendererUpdaterFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context);
}
13 changes: 6 additions & 7 deletions browser/profiles/brave_renderer_updater_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
#ifndef BRAVE_BROWSER_PROFILES_BRAVE_RENDERER_UPDATER_FACTORY_H_
#define BRAVE_BROWSER_PROFILES_BRAVE_RENDERER_UPDATER_FACTORY_H_

#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include <memory>

#include "base/no_destructor.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"

class Profile;
class BraveRendererUpdater;
Expand All @@ -18,7 +21,7 @@ class NoDestructor;

// Singleton that creates/deletes BraveRendererUpdater as new Profiles are
// created/shutdown.
class BraveRendererUpdaterFactory : public BrowserContextKeyedServiceFactory {
class BraveRendererUpdaterFactory : public ProfileKeyedServiceFactory {
public:
// Returns an instance of the BraveRendererUpdaterFactory singleton.
static BraveRendererUpdaterFactory* GetInstance();
Expand All @@ -31,17 +34,13 @@ class BraveRendererUpdaterFactory : public BrowserContextKeyedServiceFactory {
delete;

protected:
// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
std::unique_ptr<KeyedService> BuildServiceInstanceForBrowserContext(
content::BrowserContext* profile) const override;
bool ServiceIsCreatedWithBrowserContext() const override;

private:
friend base::NoDestructor<BraveRendererUpdaterFactory>;

content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;

BraveRendererUpdaterFactory();
~BraveRendererUpdaterFactory() override;
};
Expand Down

0 comments on commit 233cae0

Please sign in to comment.