-
Notifications
You must be signed in to change notification settings - Fork 845
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
159 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* 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_IOS_BROWSER_BRAVE_WALLET_ZCASH_WALLET_SERVICE_FACTORY_H_ | ||
#define BRAVE_IOS_BROWSER_BRAVE_WALLET_ZCASH_WALLET_SERVICE_FACTORY_H_ | ||
|
||
#include <memory> | ||
|
||
#include "brave/components/brave_wallet/common/brave_wallet.mojom.h" | ||
#include "components/keyed_service/ios/browser_state_keyed_service_factory.h" | ||
#include "mojo/public/cpp/bindings/pending_remote.h" | ||
|
||
class ChromeBrowserState; | ||
class KeyedService; | ||
|
||
namespace base { | ||
template <typename T> | ||
class NoDestructor; | ||
} // namespace base | ||
|
||
namespace web { | ||
class BrowserState; | ||
} // namespace web | ||
|
||
namespace brave_wallet { | ||
|
||
class ZCashWalletService; | ||
|
||
class ZCashWalletServiceFactory : public BrowserStateKeyedServiceFactory { | ||
public: | ||
// Creates the service if it doesn't exist already for |browser_state|. | ||
static mojo::PendingRemote<mojom::ZCashWalletService> GetForBrowserState( | ||
ChromeBrowserState* browser_state); | ||
|
||
static ZCashWalletService* GetServiceForState( | ||
ChromeBrowserState* browser_state); | ||
|
||
static ZCashWalletServiceFactory* GetInstance(); | ||
|
||
private: | ||
friend base::NoDestructor<ZCashWalletServiceFactory>; | ||
|
||
ZCashWalletServiceFactory(); | ||
~ZCashWalletServiceFactory() override; | ||
|
||
// BrowserContextKeyedServiceFactory: | ||
// BrowserStateKeyedServiceFactory implementation. | ||
std::unique_ptr<KeyedService> BuildServiceInstanceFor( | ||
web::BrowserState* context) const override; | ||
bool ServiceIsNULLWhileTesting() const override; | ||
web::BrowserState* GetBrowserStateToUse( | ||
web::BrowserState* context) const override; | ||
|
||
ZCashWalletServiceFactory(const ZCashWalletServiceFactory&) = delete; | ||
ZCashWalletServiceFactory& operator=(const ZCashWalletServiceFactory&) = | ||
delete; | ||
}; | ||
|
||
} // namespace brave_wallet | ||
|
||
#endif // BRAVE_IOS_BROWSER_BRAVE_WALLET_ZCASH_WALLET_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,74 @@ | ||
/* 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/ios/browser/brave_wallet/zcash_wallet_service_factory.h" | ||
|
||
#include "brave/components/brave_wallet/browser/pref_names.h" | ||
#include "brave/components/brave_wallet/browser/zcash/zcash_wallet_service.h" | ||
#include "brave/components/brave_wallet/common/common_utils.h" | ||
#include "brave/ios/browser/brave_wallet/keyring_service_factory.h" | ||
#include "components/keyed_service/core/keyed_service.h" | ||
#include "components/keyed_service/ios/browser_state_dependency_manager.h" | ||
#include "ios/chrome/browser/shared/model/application_context/application_context.h" | ||
#include "ios/chrome/browser/shared/model/browser_state/browser_state_otr_helper.h" | ||
#include "ios/chrome/browser/shared/model/browser_state/chrome_browser_state.h" | ||
#include "ios/web/public/browser_state.h" | ||
|
||
namespace brave_wallet { | ||
|
||
// static | ||
mojo::PendingRemote<mojom::ZCashWalletService> | ||
ZCashWalletServiceFactory::GetForBrowserState( | ||
ChromeBrowserState* browser_state) { | ||
return static_cast<ZCashWalletService*>( | ||
GetInstance()->GetServiceForBrowserState(browser_state, true)) | ||
->MakeRemote(); | ||
} | ||
|
||
// static | ||
ZCashWalletService* ZCashWalletServiceFactory::GetServiceForState( | ||
ChromeBrowserState* browser_state) { | ||
return static_cast<ZCashWalletService*>( | ||
GetInstance()->GetServiceForBrowserState(browser_state, true)); | ||
} | ||
|
||
// static | ||
ZCashWalletServiceFactory* ZCashWalletServiceFactory::GetInstance() { | ||
static base::NoDestructor<ZCashWalletServiceFactory> instance; | ||
return instance.get(); | ||
} | ||
|
||
ZCashWalletServiceFactory::ZCashWalletServiceFactory() | ||
: BrowserStateKeyedServiceFactory( | ||
"ZCashWalletService", | ||
BrowserStateDependencyManager::GetInstance()) { | ||
DependsOn(KeyringServiceFactory::GetInstance()); | ||
} | ||
|
||
ZCashWalletServiceFactory::~ZCashWalletServiceFactory() = default; | ||
|
||
std::unique_ptr<KeyedService> | ||
ZCashWalletServiceFactory::BuildServiceInstanceFor( | ||
web::BrowserState* context) const { | ||
auto* browser_state = ChromeBrowserState::FromBrowserState(context); | ||
if (!IsZCashEnabled()) { | ||
return nullptr; | ||
} | ||
std::unique_ptr<ZCashWalletService> zcash_service(new ZCashWalletService( | ||
KeyringServiceFactory::GetServiceForState(browser_state), | ||
browser_state->GetPrefs(), browser_state->GetSharedURLLoaderFactory())); | ||
return zcash_service; | ||
} | ||
|
||
bool ZCashWalletServiceFactory::ServiceIsNULLWhileTesting() const { | ||
return true; | ||
} | ||
|
||
web::BrowserState* ZCashWalletServiceFactory::GetBrowserStateToUse( | ||
web::BrowserState* context) const { | ||
return GetBrowserStateRedirectedInIncognito(context); | ||
} | ||
|
||
} // namespace brave_wallet |