зеркало из https://github.com/electron/electron.git
More migration of ServiceContext to ServiceBinding
https://chromium-review.googlesource.com/c/chromium/src/+/1357534
This commit is contained in:
Родитель
606c84b302
Коммит
0e39ec688a
|
@ -7,12 +7,14 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "base/command_line.h"
|
#include "base/command_line.h"
|
||||||
|
#include "base/threading/sequenced_task_runner_handle.h"
|
||||||
#include "content/public/child/child_thread.h"
|
#include "content/public/child/child_thread.h"
|
||||||
#include "content/public/common/service_manager_connection.h"
|
#include "content/public/common/service_manager_connection.h"
|
||||||
#include "content/public/common/simple_connection_filter.h"
|
#include "content/public/common/simple_connection_filter.h"
|
||||||
#include "content/public/utility/utility_thread.h"
|
#include "content/public/utility/utility_thread.h"
|
||||||
#include "services/proxy_resolver/proxy_resolver_service.h"
|
#include "services/proxy_resolver/proxy_resolver_service.h"
|
||||||
#include "services/proxy_resolver/public/mojom/proxy_resolver.mojom.h"
|
#include "services/proxy_resolver/public/mojom/proxy_resolver.mojom.h"
|
||||||
|
#include "services/service_manager/public/cpp/service.h"
|
||||||
#include "services/service_manager/sandbox/switches.h"
|
#include "services/service_manager/sandbox/switches.h"
|
||||||
|
|
||||||
#if BUILDFLAG(ENABLE_PRINTING)
|
#if BUILDFLAG(ENABLE_PRINTING)
|
||||||
|
@ -30,6 +32,40 @@
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
void RunServiceAsyncThenTerminateProcess(
|
||||||
|
std::unique_ptr<service_manager::Service> service) {
|
||||||
|
service_manager::Service::RunAsyncUntilTermination(
|
||||||
|
std::move(service),
|
||||||
|
base::BindOnce([] { content::UtilityThread::Get()->ReleaseProcess(); }));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<service_manager::Service> CreateProxyResolverService(
|
||||||
|
service_manager::mojom::ServiceRequest request) {
|
||||||
|
return std::make_unique<proxy_resolver::ProxyResolverService>(
|
||||||
|
std::move(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
using ServiceFactory =
|
||||||
|
base::OnceCallback<std::unique_ptr<service_manager::Service>()>;
|
||||||
|
void RunServiceOnIOThread(ServiceFactory factory) {
|
||||||
|
base::OnceClosure terminate_process = base::BindOnce(
|
||||||
|
base::IgnoreResult(&base::SequencedTaskRunner::PostTask),
|
||||||
|
base::SequencedTaskRunnerHandle::Get(), FROM_HERE,
|
||||||
|
base::BindOnce([] { content::UtilityThread::Get()->ReleaseProcess(); }));
|
||||||
|
content::ChildThread::Get()->GetIOTaskRunner()->PostTask(
|
||||||
|
FROM_HERE,
|
||||||
|
base::BindOnce(
|
||||||
|
[](ServiceFactory factory, base::OnceClosure terminate_process) {
|
||||||
|
service_manager::Service::RunAsyncUntilTermination(
|
||||||
|
std::move(factory).Run(), std::move(terminate_process));
|
||||||
|
},
|
||||||
|
std::move(factory), std::move(terminate_process)));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
AtomContentUtilityClient::AtomContentUtilityClient() : elevated_(false) {
|
AtomContentUtilityClient::AtomContentUtilityClient() : elevated_(false) {
|
||||||
#if BUILDFLAG(ENABLE_PRINTING) && defined(OS_WIN)
|
#if BUILDFLAG(ENABLE_PRINTING) && defined(OS_WIN)
|
||||||
printing_handler_ = std::make_unique<printing::PrintingHandler>();
|
printing_handler_ = std::make_unique<printing::PrintingHandler>();
|
||||||
|
@ -85,31 +121,35 @@ bool AtomContentUtilityClient::OnMessageReceived(const IPC::Message& message) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomContentUtilityClient::RegisterServices(StaticServiceMap* services) {
|
bool AtomContentUtilityClient::HandleServiceRequest(
|
||||||
service_manager::EmbeddedServiceInfo proxy_resolver_info;
|
const std::string& service_name,
|
||||||
proxy_resolver_info.task_runner =
|
service_manager::mojom::ServiceRequest request) {
|
||||||
content::ChildThread::Get()->GetIOTaskRunner();
|
if (service_name == proxy_resolver::mojom::kProxyResolverServiceName) {
|
||||||
proxy_resolver_info.factory =
|
RunServiceOnIOThread(
|
||||||
base::BindRepeating(&proxy_resolver::ProxyResolverService::CreateService);
|
base::BindOnce(&CreateProxyResolverService, std::move(request)));
|
||||||
services->emplace(proxy_resolver::mojom::kProxyResolverServiceName,
|
return true;
|
||||||
proxy_resolver_info);
|
}
|
||||||
|
|
||||||
#if BUILDFLAG(ENABLE_PRINTING)
|
auto service = MaybeCreateMainThreadService(service_name, std::move(request));
|
||||||
service_manager::EmbeddedServiceInfo printing_info;
|
if (service) {
|
||||||
printing_info.factory =
|
RunServiceAsyncThenTerminateProcess(std::move(service));
|
||||||
base::BindRepeating(&printing::PrintingService::CreateService);
|
return true;
|
||||||
services->emplace(printing::mojom::kChromePrintingServiceName, printing_info);
|
}
|
||||||
#endif
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<service_manager::Service>
|
std::unique_ptr<service_manager::Service>
|
||||||
AtomContentUtilityClient::HandleServiceRequest(
|
AtomContentUtilityClient::MaybeCreateMainThreadService(
|
||||||
const std::string& service_name,
|
const std::string& service_name,
|
||||||
service_manager::mojom::ServiceRequest request) {
|
service_manager::mojom::ServiceRequest request) {
|
||||||
#if BUILDFLAG(ENABLE_PRINTING)
|
#if BUILDFLAG(ENABLE_PRINTING)
|
||||||
if (service_name == printing::mojom::kServiceName) {
|
if (service_name == printing::mojom::kServiceName) {
|
||||||
return printing::CreatePdfCompositorService(std::string(),
|
return printing::CreatePdfCompositorService(std::move(request));
|
||||||
std::move(request));
|
}
|
||||||
|
|
||||||
|
if (service_name == printing::mojom::kChromePrintingServiceName) {
|
||||||
|
return std::make_unique<printing::PrintingService>(std::move(request));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -26,13 +26,14 @@ class AtomContentUtilityClient : public content::ContentUtilityClient {
|
||||||
|
|
||||||
void UtilityThreadStarted() override;
|
void UtilityThreadStarted() override;
|
||||||
bool OnMessageReceived(const IPC::Message& message) override;
|
bool OnMessageReceived(const IPC::Message& message) override;
|
||||||
void RegisterServices(StaticServiceMap* services) override;
|
bool HandleServiceRequest(
|
||||||
|
|
||||||
std::unique_ptr<service_manager::Service> HandleServiceRequest(
|
|
||||||
const std::string& service_name,
|
const std::string& service_name,
|
||||||
service_manager::mojom::ServiceRequest request) override;
|
service_manager::mojom::ServiceRequest request) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::unique_ptr<service_manager::Service> MaybeCreateMainThreadService(
|
||||||
|
const std::string& service_name,
|
||||||
|
service_manager::mojom::ServiceRequest request);
|
||||||
#if BUILDFLAG(ENABLE_PRINTING) && defined(OS_WIN)
|
#if BUILDFLAG(ENABLE_PRINTING) && defined(OS_WIN)
|
||||||
std::unique_ptr<printing::PrintingHandler> printing_handler_;
|
std::unique_ptr<printing::PrintingHandler> printing_handler_;
|
||||||
#endif
|
#endif
|
||||||
|
|
Загрузка…
Ссылка в новой задаче