-
Notifications
You must be signed in to change notification settings - Fork 873
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16073 from brave/brave_19283_2
Core part for local nft pinning
- Loading branch information
Showing
71 changed files
with
4,943 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
browser/brave_wallet/brave_wallet_auto_pin_service_factory.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright (c) 2023 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/brave_wallet/brave_wallet_auto_pin_service_factory.h" | ||
|
||
#include <memory> | ||
#include <utility> | ||
|
||
#include "brave/browser/brave_wallet/brave_wallet_context_utils.h" | ||
#include "brave/browser/brave_wallet/brave_wallet_pin_service_factory.h" | ||
#include "brave/browser/brave_wallet/brave_wallet_service_factory.h" | ||
// TODO(cypt4) : Refactor brave/browser/ipfs into separate component (#27486) | ||
#include "brave/browser/ipfs/ipfs_service_factory.h" // nogncheck | ||
|
||
#include "brave/components/brave_wallet/browser/brave_wallet_pin_service.h" | ||
#include "brave/components/brave_wallet/browser/brave_wallet_service.h" | ||
|
||
#include "chrome/browser/profiles/incognito_helpers.h" | ||
#include "components/keyed_service/content/browser_context_dependency_manager.h" | ||
#include "components/user_prefs/user_prefs.h" | ||
|
||
namespace brave_wallet { | ||
|
||
// static | ||
BraveWalletAutoPinServiceFactory* | ||
BraveWalletAutoPinServiceFactory::GetInstance() { | ||
return base::Singleton<BraveWalletAutoPinServiceFactory>::get(); | ||
} | ||
|
||
// static | ||
mojo::PendingRemote<mojom::WalletAutoPinService> | ||
BraveWalletAutoPinServiceFactory::GetForContext( | ||
content::BrowserContext* context) { | ||
if (!IsAllowedForContext(context)) { | ||
return mojo::PendingRemote<mojom::WalletAutoPinService>(); | ||
} | ||
|
||
auto* service = GetServiceForContext(context); | ||
|
||
if (!service) { | ||
return mojo::PendingRemote<mojom::WalletAutoPinService>(); | ||
} | ||
|
||
return service->MakeRemote(); | ||
} | ||
|
||
// static | ||
BraveWalletAutoPinService* | ||
BraveWalletAutoPinServiceFactory::GetServiceForContext( | ||
content::BrowserContext* context) { | ||
if (!IsAllowedForContext(context)) { | ||
return nullptr; | ||
} | ||
if (!ipfs::IpfsServiceFactory::IsIpfsEnabled(context)) { | ||
return nullptr; | ||
} | ||
return static_cast<BraveWalletAutoPinService*>( | ||
GetInstance()->GetServiceForBrowserContext(context, true)); | ||
} | ||
|
||
// static | ||
void BraveWalletAutoPinServiceFactory::BindForContext( | ||
content::BrowserContext* context, | ||
mojo::PendingReceiver<mojom::WalletAutoPinService> receiver) { | ||
auto* service = | ||
BraveWalletAutoPinServiceFactory::GetServiceForContext(context); | ||
if (service) { | ||
service->Bind(std::move(receiver)); | ||
} | ||
} | ||
|
||
BraveWalletAutoPinServiceFactory::BraveWalletAutoPinServiceFactory() | ||
: BrowserContextKeyedServiceFactory( | ||
"BraveWalletAutoPinService", | ||
BrowserContextDependencyManager::GetInstance()) { | ||
DependsOn(BraveWalletServiceFactory::GetInstance()); | ||
DependsOn(BraveWalletPinServiceFactory::GetInstance()); | ||
} | ||
|
||
BraveWalletAutoPinServiceFactory::~BraveWalletAutoPinServiceFactory() = default; | ||
|
||
KeyedService* BraveWalletAutoPinServiceFactory::BuildServiceInstanceFor( | ||
content::BrowserContext* context) const { | ||
return new BraveWalletAutoPinService( | ||
user_prefs::UserPrefs::Get(context), | ||
BraveWalletServiceFactory::GetServiceForContext(context), | ||
BraveWalletPinServiceFactory::GetServiceForContext(context)); | ||
} | ||
|
||
content::BrowserContext* | ||
BraveWalletAutoPinServiceFactory::GetBrowserContextToUse( | ||
content::BrowserContext* context) const { | ||
return chrome::GetBrowserContextRedirectedInIncognito(context); | ||
} | ||
|
||
} // namespace brave_wallet |
54 changes: 54 additions & 0 deletions
54
browser/brave_wallet/brave_wallet_auto_pin_service_factory.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) 2023 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/. | ||
|
||
#ifndef BRAVE_BROWSER_BRAVE_WALLET_BRAVE_WALLET_AUTO_PIN_SERVICE_FACTORY_H_ | ||
#define BRAVE_BROWSER_BRAVE_WALLET_BRAVE_WALLET_AUTO_PIN_SERVICE_FACTORY_H_ | ||
|
||
#include "base/memory/singleton.h" | ||
|
||
#include "brave/components/brave_wallet/browser/brave_wallet_auto_pin_service.h" | ||
#include "brave/components/brave_wallet/common/brave_wallet.mojom.h" | ||
#include "components/keyed_service/content/browser_context_keyed_service_factory.h" | ||
#include "components/keyed_service/core/keyed_service.h" | ||
#include "content/public/browser/browser_context.h" | ||
#include "mojo/public/cpp/bindings/pending_receiver.h" | ||
#include "mojo/public/cpp/bindings/pending_remote.h" | ||
|
||
namespace brave_wallet { | ||
|
||
class BraveWalletAutoPinService; | ||
|
||
class BraveWalletAutoPinServiceFactory | ||
: public BrowserContextKeyedServiceFactory { | ||
public: | ||
static mojo::PendingRemote<mojom::WalletAutoPinService> GetForContext( | ||
content::BrowserContext* context); | ||
static BraveWalletAutoPinService* GetServiceForContext( | ||
content::BrowserContext* context); | ||
static BraveWalletAutoPinServiceFactory* GetInstance(); | ||
static void BindForContext( | ||
content::BrowserContext* context, | ||
mojo::PendingReceiver<mojom::WalletAutoPinService> receiver); | ||
|
||
private: | ||
friend struct base::DefaultSingletonTraits<BraveWalletAutoPinServiceFactory>; | ||
|
||
BraveWalletAutoPinServiceFactory(); | ||
~BraveWalletAutoPinServiceFactory() override; | ||
|
||
BraveWalletAutoPinServiceFactory(const BraveWalletAutoPinServiceFactory&) = | ||
delete; | ||
BraveWalletAutoPinServiceFactory& operator=( | ||
const BraveWalletAutoPinServiceFactory&) = delete; | ||
|
||
KeyedService* BuildServiceInstanceFor( | ||
content::BrowserContext* context) const override; | ||
content::BrowserContext* GetBrowserContextToUse( | ||
content::BrowserContext* context) const override; | ||
}; | ||
|
||
} // namespace brave_wallet | ||
|
||
#endif // BRAVE_BROWSER_BRAVE_WALLET_BRAVE_WALLET_AUTO_PIN_SERVICE_FACTORY_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (c) 2023 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/brave_wallet/brave_wallet_pin_service_factory.h" | ||
|
||
#include <memory> | ||
#include <utility> | ||
|
||
#include "brave/browser/brave_wallet/brave_wallet_context_utils.h" | ||
#include "brave/browser/brave_wallet/json_rpc_service_factory.h" | ||
// TODO(cypt4) : Refactor brave/browser into separate component (#27486) | ||
#include "brave/browser/ipfs/ipfs_local_pin_service_factory.h" // nogncheck | ||
#include "brave/browser/ipfs/ipfs_service_factory.h" // nogncheck | ||
#include "brave/components/brave_wallet/browser/brave_wallet_pin_service.h" | ||
#include "brave/components/brave_wallet/browser/brave_wallet_service.h" | ||
#include "brave/components/brave_wallet/browser/brave_wallet_service_delegate.h" | ||
#include "chrome/browser/profiles/incognito_helpers.h" | ||
#include "components/keyed_service/content/browser_context_dependency_manager.h" | ||
#include "components/user_prefs/user_prefs.h" | ||
|
||
namespace brave_wallet { | ||
|
||
// static | ||
BraveWalletPinServiceFactory* BraveWalletPinServiceFactory::GetInstance() { | ||
return base::Singleton<BraveWalletPinServiceFactory>::get(); | ||
} | ||
|
||
// static | ||
mojo::PendingRemote<mojom::WalletPinService> | ||
BraveWalletPinServiceFactory::GetForContext(content::BrowserContext* context) { | ||
if (!IsAllowedForContext(context)) { | ||
return mojo::PendingRemote<mojom::WalletPinService>(); | ||
} | ||
|
||
auto* service = GetServiceForContext(context); | ||
if (!service) { | ||
return mojo::PendingRemote<mojom::WalletPinService>(); | ||
} | ||
|
||
return service->MakeRemote(); | ||
} | ||
|
||
// static | ||
BraveWalletPinService* BraveWalletPinServiceFactory::GetServiceForContext( | ||
content::BrowserContext* context) { | ||
if (!IsAllowedForContext(context)) { | ||
return nullptr; | ||
} | ||
if (!ipfs::IpfsServiceFactory::IsIpfsEnabled(context)) { | ||
return nullptr; | ||
} | ||
return static_cast<BraveWalletPinService*>( | ||
GetInstance()->GetServiceForBrowserContext(context, true)); | ||
} | ||
|
||
// static | ||
void BraveWalletPinServiceFactory::BindForContext( | ||
content::BrowserContext* context, | ||
mojo::PendingReceiver<mojom::WalletPinService> receiver) { | ||
auto* service = BraveWalletPinServiceFactory::GetServiceForContext(context); | ||
if (service) { | ||
service->Bind(std::move(receiver)); | ||
} | ||
} | ||
|
||
BraveWalletPinServiceFactory::BraveWalletPinServiceFactory() | ||
: BrowserContextKeyedServiceFactory( | ||
"BraveWalletPinService", | ||
BrowserContextDependencyManager::GetInstance()) { | ||
DependsOn(brave_wallet::JsonRpcServiceFactory::GetInstance()); | ||
DependsOn(ipfs::IpfsLocalPinServiceFactory::GetInstance()); | ||
DependsOn(ipfs::IpfsServiceFactory::GetInstance()); | ||
} | ||
|
||
BraveWalletPinServiceFactory::~BraveWalletPinServiceFactory() = default; | ||
|
||
KeyedService* BraveWalletPinServiceFactory::BuildServiceInstanceFor( | ||
content::BrowserContext* context) const { | ||
return new BraveWalletPinService( | ||
user_prefs::UserPrefs::Get(context), | ||
JsonRpcServiceFactory::GetServiceForContext(context), | ||
ipfs::IpfsLocalPinServiceFactory::GetServiceForContext(context), | ||
ipfs::IpfsServiceFactory::GetForContext(context)); | ||
} | ||
|
||
content::BrowserContext* BraveWalletPinServiceFactory::GetBrowserContextToUse( | ||
content::BrowserContext* context) const { | ||
return chrome::GetBrowserContextRedirectedInIncognito(context); | ||
} | ||
|
||
} // namespace brave_wallet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) 2023 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/. | ||
|
||
#ifndef BRAVE_BROWSER_BRAVE_WALLET_BRAVE_WALLET_PIN_SERVICE_FACTORY_H_ | ||
#define BRAVE_BROWSER_BRAVE_WALLET_BRAVE_WALLET_PIN_SERVICE_FACTORY_H_ | ||
|
||
#include "base/memory/singleton.h" | ||
#include "brave/components/brave_wallet/common/brave_wallet.mojom.h" | ||
#include "components/keyed_service/content/browser_context_keyed_service_factory.h" | ||
#include "components/keyed_service/core/keyed_service.h" | ||
#include "content/public/browser/browser_context.h" | ||
#include "mojo/public/cpp/bindings/pending_receiver.h" | ||
#include "mojo/public/cpp/bindings/pending_remote.h" | ||
|
||
namespace brave_wallet { | ||
|
||
class BraveWalletPinService; | ||
|
||
class BraveWalletPinServiceFactory : public BrowserContextKeyedServiceFactory { | ||
public: | ||
static mojo::PendingRemote<mojom::WalletPinService> GetForContext( | ||
content::BrowserContext* context); | ||
static BraveWalletPinService* GetServiceForContext( | ||
content::BrowserContext* context); | ||
static BraveWalletPinServiceFactory* GetInstance(); | ||
static void BindForContext( | ||
content::BrowserContext* context, | ||
mojo::PendingReceiver<mojom::WalletPinService> receiver); | ||
|
||
private: | ||
friend struct base::DefaultSingletonTraits<BraveWalletPinServiceFactory>; | ||
|
||
BraveWalletPinServiceFactory(); | ||
~BraveWalletPinServiceFactory() override; | ||
|
||
BraveWalletPinServiceFactory(const BraveWalletPinServiceFactory&) = delete; | ||
BraveWalletPinServiceFactory& operator=(const BraveWalletPinServiceFactory&) = | ||
delete; | ||
|
||
KeyedService* BuildServiceInstanceFor( | ||
content::BrowserContext* context) const override; | ||
content::BrowserContext* GetBrowserContextToUse( | ||
content::BrowserContext* context) const override; | ||
}; | ||
|
||
} // namespace brave_wallet | ||
|
||
#endif // BRAVE_BROWSER_BRAVE_WALLET_BRAVE_WALLET_PIN_SERVICE_FACTORY_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.