Merge pull request #8455 from brave/remove_profile_wallet_service

This commit is contained in:
Jocelyn Liu
2021-04-06 22:15:38 -07:00
committed by GitHub
10 changed files with 23 additions and 28 deletions
+4 -7
View File
@@ -252,14 +252,12 @@ void BindCosmeticFiltersResources(
void MaybeBindBraveWalletProvider(
content::RenderFrameHost* const frame_host,
mojo::PendingReceiver<brave_wallet::mojom::BraveWalletProvider> receiver) {
auto* profile =
Profile::FromBrowserContext(frame_host->GetBrowserContext());
if (!brave_wallet::IsAllowedForProfile(profile))
auto* context = frame_host->GetBrowserContext();
if (!brave_wallet::IsAllowedForContext(context))
return;
BraveWalletService* service =
BraveWalletServiceFactory::GetInstance()->GetForProfile(
Profile::FromBrowserContext(profile));
BraveWalletServiceFactory::GetInstance()->GetForContext(context);
mojo::MakeSelfOwnedReceiver(
std::make_unique<brave_wallet::BraveWalletProviderImpl>(
@@ -608,8 +606,7 @@ bool BraveContentBrowserClient::HandleURLOverrideRewrite(
#if BUILDFLAG(BRAVE_WALLET_ENABLED) && BUILDFLAG(ENABLE_EXTENSIONS)
// If the Crypto Wallets extension is loaded, then it replaces the WebUI
Profile* profile = Profile::FromBrowserContext(browser_context);
auto* service = BraveWalletServiceFactory::GetForProfile(profile);
auto* service = BraveWalletServiceFactory::GetForContext(browser_context);
if (service->IsCryptoWalletsReady() &&
url->SchemeIs(content::kChromeUIScheme) &&
url->host() == ethereum_remote_client_host) {
@@ -4,12 +4,12 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "brave/browser/brave_wallet/brave_wallet_context_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/browser_context.h"
namespace brave_wallet {
bool IsAllowedForProfile(Profile* profile) {
if (profile && profile->IsTor())
bool IsAllowedForContext(content::BrowserContext* context) {
if (context && context->IsTor())
return false;
return true;
@@ -6,11 +6,13 @@
#ifndef BRAVE_BROWSER_BRAVE_WALLET_BRAVE_WALLET_CONTEXT_UTILS_H_
#define BRAVE_BROWSER_BRAVE_WALLET_BRAVE_WALLET_CONTEXT_UTILS_H_
class Profile;
namespace content {
class BrowserContext;
}
namespace brave_wallet {
bool IsAllowedForProfile(Profile* profile);
bool IsAllowedForContext(content::BrowserContext* context);
} // namespace brave_wallet
@@ -10,7 +10,6 @@
#include "brave/browser/brave_wallet/brave_wallet_delegate_impl.h"
#include "brave/components/brave_wallet/browser/brave_wallet_service.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "extensions/buildflags/buildflags.h"
@@ -27,9 +26,10 @@ BraveWalletServiceFactory* BraveWalletServiceFactory::GetInstance() {
}
// static
BraveWalletService* BraveWalletServiceFactory::GetForProfile(Profile* profile) {
BraveWalletService* BraveWalletServiceFactory::GetForContext(
content::BrowserContext* context) {
return static_cast<BraveWalletService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
GetInstance()->GetServiceForBrowserContext(context, true));
}
BraveWalletServiceFactory::BraveWalletServiceFactory()
@@ -47,7 +47,7 @@ BraveWalletServiceFactory::~BraveWalletServiceFactory() {}
KeyedService* BraveWalletServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new BraveWalletService(Profile::FromBrowserContext(context),
return new BraveWalletService(context,
std::make_unique<BraveWalletDelegateImpl>());
}
@@ -10,11 +10,10 @@
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class BraveWalletService;
class Profile;
class BraveWalletServiceFactory : public BrowserContextKeyedServiceFactory {
public:
static BraveWalletService* GetForProfile(Profile* profile);
static BraveWalletService* GetForContext(content::BrowserContext* context);
static BraveWalletServiceFactory* GetInstance();
private:
@@ -135,8 +135,8 @@ class EthJsonRpcBrowserTest : public InProcessBrowserTest {
BraveWalletService* GetBraveWalletService() {
BraveWalletService* service =
BraveWalletServiceFactory::GetInstance()->GetForProfile(
Profile::FromBrowserContext(browser()->profile()));
BraveWalletServiceFactory::GetInstance()->GetForContext(
browser()->profile());
EXPECT_TRUE(service);
return service;
}
+2 -3
View File
@@ -34,8 +34,7 @@ namespace {
BraveWalletService* GetBraveWalletService(
content::BrowserContext* context) {
return BraveWalletServiceFactory::GetInstance()
->GetForProfile(Profile::FromBrowserContext(context));
return BraveWalletServiceFactory::GetInstance()->GetForContext(context);
}
base::Value MakeSelectValue(const base::string16& name,
@@ -135,7 +134,7 @@ void BraveWalletLoadUIFunction::OnLoaded() {
ExtensionFunction::ResponseAction
BraveWalletShouldPromptForSetupFunction::Run() {
Profile* profile = Profile::FromBrowserContext(browser_context());
auto* service = BraveWalletServiceFactory::GetForProfile(profile);
auto* service = GetBraveWalletService(browser_context());
bool should_prompt = !service->IsCryptoWalletsSetup() &&
!profile->GetPrefs()->GetBoolean(kOptedIntoCryptoWallets);
return RespondNow(OneArgument(base::Value(should_prompt)));
@@ -16,7 +16,6 @@
#include "brave/components/brave_wallet/browser/pref_names.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/grit/chromium_strings.h"
#include "components/infobars/core/infobar.h"
@@ -98,8 +97,7 @@ bool CryptoWalletsInfoBarDelegate::Accept() {
InfoBarService::WebContentsFromInfoBar(infobar());
if (web_contents) {
auto* browser_context = web_contents->GetBrowserContext();
Profile* profile = Profile::FromBrowserContext(browser_context);
auto* service = BraveWalletServiceFactory::GetForProfile(profile);
auto* service = BraveWalletServiceFactory::GetForContext(browser_context);
service->MaybeLoadCryptoWalletsExtension(
base::BindOnce(&CryptoWalletsInfoBarDelegate::OnCryptoWalletsLoaded,
base::Unretained(this), web_contents));
+1 -1
View File
@@ -116,7 +116,7 @@ void BraveProfileManager::DoFinalInitForServices(Profile* profile,
brave_ads::AdsServiceFactory::GetForProfile(profile);
brave_rewards::RewardsServiceFactory::GetForProfile(profile);
#if BUILDFLAG(BRAVE_WALLET_ENABLED)
BraveWalletServiceFactory::GetForProfile(profile);
BraveWalletServiceFactory::GetForContext(profile);
#endif
#if BUILDFLAG(IPFS_ENABLED)
ipfs::IpfsServiceFactory::GetForContext(profile);
+1 -1
View File
@@ -91,7 +91,7 @@ void BraveRendererUpdater::UpdateRenderer(
bool use_brave_web3_provider = (static_cast<BraveWalletWeb3ProviderTypes>(
brave_wallet_web3_provider_.GetValue()) ==
BraveWalletWeb3ProviderTypes::BRAVE_WALLET) &&
brave_wallet::IsAllowedForProfile(profile_);
brave_wallet::IsAllowedForContext(profile_);
(*renderer_configuration)
->SetConfiguration(