#include "components/custom_handlers/simple_protocol_handler_registry_factory.h"
#include <memory>
#include "base/no_destructor.h"
#include "build/build_config.h"
#include "components/custom_handlers/protocol_handler_registry.h"
#include "components/custom_handlers/test_protocol_handler_registry_delegate.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
namespace custom_handlers {
SimpleProtocolHandlerRegistryFactory*
SimpleProtocolHandlerRegistryFactory::GetInstance() {
static base::NoDestructor<SimpleProtocolHandlerRegistryFactory> factory;
return factory.get();
}
std::unique_ptr<KeyedService> BuildProtocolHandlerRegistryService(
content::BrowserContext* context) {
return custom_handlers::ProtocolHandlerRegistry::Create(
nullptr, std::make_unique<TestProtocolHandlerRegistryDelegate>());
}
BrowserContextKeyedServiceFactory::TestingFactory
SimpleProtocolHandlerRegistryFactory::GetDefaultFactory() {
return base::BindRepeating(&BuildProtocolHandlerRegistryService);
}
ProtocolHandlerRegistry*
SimpleProtocolHandlerRegistryFactory::GetForBrowserContext(
content::BrowserContext* context,
bool create) {
return static_cast<ProtocolHandlerRegistry*>(
GetInstance()->GetServiceForBrowserContext(context, create));
}
SimpleProtocolHandlerRegistryFactory::SimpleProtocolHandlerRegistryFactory()
: BrowserContextKeyedServiceFactory(
"ProtocolHandlerRegistry",
BrowserContextDependencyManager::GetInstance()) {}
bool SimpleProtocolHandlerRegistryFactory::ServiceIsCreatedWithBrowserContext()
const {
return true;
}
bool SimpleProtocolHandlerRegistryFactory::ServiceIsNULLWhileTesting() const {
return true;
}
std::unique_ptr<KeyedService>
SimpleProtocolHandlerRegistryFactory::BuildServiceInstanceForBrowserContext(
content::BrowserContext* context) const {
return BuildProtocolHandlerRegistryService(context);
}
}