-
Notifications
You must be signed in to change notification settings - Fork 887
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves brave/brave-browser#19283
- Loading branch information
Showing
59 changed files
with
4,541 additions
and
62 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
88 changes: 88 additions & 0 deletions
88
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,88 @@ | ||
/* Copyright (c) 2022 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/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" | ||
|
||
#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>(); | ||
} | ||
|
||
return GetServiceForContext(context)->MakeRemote(); | ||
} | ||
|
||
// static | ||
BraveWalletAutoPinService* | ||
BraveWalletAutoPinServiceFactory::GetServiceForContext( | ||
content::BrowserContext* context) { | ||
if (!IsAllowedForContext(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) 2022 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_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,81 @@ | ||
/* Copyright (c) 2022 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/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" | ||
#include "brave/browser/ipfs/ipfs_local_pin_service_factory.h" | ||
#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>(); | ||
} | ||
|
||
return GetServiceForContext(context)->MakeRemote(); | ||
} | ||
|
||
// static | ||
BraveWalletPinService* BraveWalletPinServiceFactory::GetServiceForContext( | ||
content::BrowserContext* context) { | ||
if (!IsAllowedForContext(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()); | ||
} | ||
|
||
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)); | ||
} | ||
|
||
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,51 @@ | ||
/* Copyright (c) 2022 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_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/browser/ipfs/ipfs_service_factory.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* Copyright (c) 2022 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/ipfs/ipfs_local_pin_service_factory.h" | ||
|
||
#include <memory> | ||
#include <utility> | ||
|
||
#include "brave/browser/ipfs/ipfs_service_factory.h" | ||
#include "brave/components/ipfs/pin/ipfs_local_pin_service.h" | ||
#include "chrome/browser/profiles/incognito_helpers.h" | ||
#include "components/keyed_service/content/browser_context_dependency_manager.h" | ||
#include "components/prefs/pref_service.h" | ||
#include "components/user_prefs/user_prefs.h" | ||
|
||
namespace ipfs { | ||
|
||
// static | ||
IpfsLocalPinServiceFactory* IpfsLocalPinServiceFactory::GetInstance() { | ||
return base::Singleton<IpfsLocalPinServiceFactory>::get(); | ||
} | ||
|
||
// static | ||
IpfsLocalPinService* IpfsLocalPinServiceFactory::GetServiceForContext( | ||
content::BrowserContext* context) { | ||
return static_cast<IpfsLocalPinService*>( | ||
GetInstance()->GetServiceForBrowserContext(context, true)); | ||
} | ||
|
||
IpfsLocalPinServiceFactory::IpfsLocalPinServiceFactory() | ||
: BrowserContextKeyedServiceFactory( | ||
"IpfsLocalPinService", | ||
BrowserContextDependencyManager::GetInstance()) { | ||
DependsOn(ipfs::IpfsServiceFactory::GetInstance()); | ||
} | ||
|
||
IpfsLocalPinServiceFactory::~IpfsLocalPinServiceFactory() = default; | ||
|
||
KeyedService* IpfsLocalPinServiceFactory::BuildServiceInstanceFor( | ||
content::BrowserContext* context) const { | ||
return new IpfsLocalPinService(user_prefs::UserPrefs::Get(context), | ||
IpfsServiceFactory::GetForContext(context)); | ||
} | ||
|
||
content::BrowserContext* IpfsLocalPinServiceFactory::GetBrowserContextToUse( | ||
content::BrowserContext* context) const { | ||
return chrome::GetBrowserContextRedirectedInIncognito(context); | ||
} | ||
|
||
} // namespace ipfs |
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,42 @@ | ||
/* Copyright (c) 2022 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_IPFS_IPFS_LOCAL_PIN_SERVICE_FACTORY_H_ | ||
#define BRAVE_BROWSER_IPFS_IPFS_LOCAL_PIN_SERVICE_FACTORY_H_ | ||
|
||
#include "base/memory/singleton.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" | ||
|
||
namespace ipfs { | ||
|
||
class IpfsLocalPinService; | ||
|
||
class IpfsLocalPinServiceFactory : public BrowserContextKeyedServiceFactory { | ||
public: | ||
static IpfsLocalPinService* GetServiceForContext( | ||
content::BrowserContext* context); | ||
static IpfsLocalPinServiceFactory* GetInstance(); | ||
|
||
private: | ||
friend struct base::DefaultSingletonTraits<IpfsLocalPinServiceFactory>; | ||
|
||
IpfsLocalPinServiceFactory(); | ||
~IpfsLocalPinServiceFactory() override; | ||
|
||
IpfsLocalPinServiceFactory(const IpfsLocalPinServiceFactory&) = delete; | ||
IpfsLocalPinServiceFactory& operator=(const IpfsLocalPinServiceFactory&) = | ||
delete; | ||
|
||
KeyedService* BuildServiceInstanceFor( | ||
content::BrowserContext* context) const override; | ||
content::BrowserContext* GetBrowserContextToUse( | ||
content::BrowserContext* context) const override; | ||
}; | ||
|
||
} // namespace ipfs | ||
|
||
#endif // BRAVE_BROWSER_IPFS_IPFS_LOCAL_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.