Commit 8e3745ac authored by blundell's avatar blundell Committed by Commit bot

Enable connection to Mojo services from Blink

This CL enables connections to Mojo services from Blink; more specifically,
from //third_party/WebKit/Source/modules, where dependencies on Chromium
code are in general undesired (including on Mojo services' client
libraries). To enable connecting to services without using the
Service Manager's client library, this CL does the following:

(1) Adds a method to Platform that exposes the connection to the
ServiceManager as a service_manager::mojom::blink::ConnectorPtr.
(2) Builds a bare-bones ServiceConnector around this ConnectorPtr that
supports connecting to Mojo services by name from Blink.
(3) Ports TimeZoneMonitor to be hosted in the Device Service as an example
of connecting to an interface that is hosted in a service other than
//content/browser from Blink.

ServiceConnector being "bare-bones" includes the facts that:
- Unlike blink::InterfaceProvider, blink::ServiceConnector is currently
thread-hostile. This should be easy to relax using similar mechanisms as
InterfaceProviderImpl.
- There is currently no API for obtaining an InterfaceProvider for a given
service (or a thread-safe wrapper, per the above comment). Again, this should
be easy to add.

This CL also moves the definition of the device service name to mojom instead
of C++ in order to facilitate using this constant from Blink.

BUG=612341
TEST=http://crbug.com/288697#c12: load the page, change the system time zone,
     and then click "recheck" to ensure that the renderer picks up the new
     time zone. Don't reload the page, which is likely to give you a new
     renderer process, use the "recheck" link on the page.

Review-Url: https://codereview.chromium.org/2460723003
Cr-Commit-Position: refs/heads/master@{#439498}
parent 6a575333
...@@ -77,8 +77,6 @@ source_set("browser") { ...@@ -77,8 +77,6 @@ source_set("browser") {
"//device/power_save_blocker", "//device/power_save_blocker",
"//device/screen_orientation/public/interfaces", "//device/screen_orientation/public/interfaces",
"//device/sensors/public/cpp", "//device/sensors/public/cpp",
"//device/time_zone_monitor",
"//device/time_zone_monitor/public/interfaces",
"//device/vibration", "//device/vibration",
"//device/wake_lock", "//device/wake_lock",
"//gin", "//gin",
...@@ -107,7 +105,7 @@ source_set("browser") { ...@@ -107,7 +105,7 @@ source_set("browser") {
"//printing/features", "//printing/features",
"//services/catalog/public/interfaces:constants", "//services/catalog/public/interfaces:constants",
"//services/device:lib", "//services/device:lib",
"//services/device/public/cpp", "//services/device/public/interfaces",
"//services/file:lib", "//services/file:lib",
"//services/file/public/interfaces", "//services/file/public/interfaces",
"//services/service_manager", "//services/service_manager",
......
...@@ -25,7 +25,6 @@ include_rules = [ ...@@ -25,7 +25,6 @@ include_rules = [
"+device/power_save_blocker", "+device/power_save_blocker",
"+device/screen_orientation/public/interfaces", "+device/screen_orientation/public/interfaces",
"+device/sensors/public", "+device/sensors/public",
"+device/time_zone_monitor", # For TimeZoneMonitor creation.
"+device/vibration", # For Vibration API "+device/vibration", # For Vibration API
"+device/vr", # For WebVR API "+device/vr", # For WebVR API
"+device/wake_lock", "+device/wake_lock",
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
#include "services/device/device_service.h" #include "services/device/device_service.h"
#include "services/device/public/cpp/constants.h" #include "services/device/public/interfaces/constants.mojom.h"
#include "services/file/file_service.h" #include "services/file/file_service.h"
#include "services/file/public/interfaces/constants.mojom.h" #include "services/file/public/interfaces/constants.mojom.h"
#include "services/file/user_id_map.h" #include "services/file/user_id_map.h"
...@@ -465,7 +465,7 @@ void BrowserContext::Initialize( ...@@ -465,7 +465,7 @@ void BrowserContext::Initialize(
info.factory = info.factory =
base::Bind(&device::CreateDeviceService, base::Bind(&device::CreateDeviceService,
BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE)); BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE));
connection->AddEmbeddedService(device::kDeviceServiceName, info); connection->AddEmbeddedService(device::mojom::kServiceName, info);
if (base::CommandLine::ForCurrentProcess()->HasSwitch( if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kMojoLocalStorage)) { switches::kMojoLocalStorage)) {
......
...@@ -92,7 +92,6 @@ ...@@ -92,7 +92,6 @@
#include "content/public/common/result_codes.h" #include "content/public/common/result_codes.h"
#include "device/battery/battery_status_service.h" #include "device/battery/battery_status_service.h"
#include "device/gamepad/gamepad_service.h" #include "device/gamepad/gamepad_service.h"
#include "device/time_zone_monitor/time_zone_monitor.h"
#include "media/base/media.h" #include "media/base/media.h"
#include "media/base/user_input_monitor.h" #include "media/base/user_input_monitor.h"
#include "media/midi/midi_service.h" #include "media/midi/midi_service.h"
...@@ -1543,13 +1542,6 @@ int BrowserMainLoop::BrowserThreadsStarted() { ...@@ -1543,13 +1542,6 @@ int BrowserMainLoop::BrowserThreadsStarted() {
io_thread_->task_runner(), main_thread_->task_runner()); io_thread_->task_runner(), main_thread_->task_runner());
} }
{
TRACE_EVENT0("startup",
"BrowserMainLoop::BrowserThreadsStarted::TimeZoneMonitor");
time_zone_monitor_ =
device::TimeZoneMonitor::Create(file_thread_->task_runner());
}
{ {
TRACE_EVENT0("startup", TRACE_EVENT0("startup",
"BrowserMainLoop::BrowserThreadsStarted::SaveFileManager"); "BrowserMainLoop::BrowserThreadsStarted::SaveFileManager");
......
...@@ -35,10 +35,6 @@ class TraceEventSystemStatsMonitor; ...@@ -35,10 +35,6 @@ class TraceEventSystemStatsMonitor;
} // namespace trace_event } // namespace trace_event
} // namespace base } // namespace base
namespace device {
class TimeZoneMonitor;
}
namespace media { namespace media {
#if defined(OS_WIN) #if defined(OS_WIN)
class SystemMessageWindowWin; class SystemMessageWindowWin;
...@@ -142,9 +138,6 @@ class CONTENT_EXPORT BrowserMainLoop { ...@@ -142,9 +138,6 @@ class CONTENT_EXPORT BrowserMainLoop {
media::UserInputMonitor* user_input_monitor() const { media::UserInputMonitor* user_input_monitor() const {
return user_input_monitor_.get(); return user_input_monitor_.get();
} }
device::TimeZoneMonitor* time_zone_monitor() const {
return time_zone_monitor_.get();
}
midi::MidiService* midi_service() const { return midi_service_.get(); } midi::MidiService* midi_service() const { return midi_service_.get(); }
base::Thread* indexed_db_thread() const { return indexed_db_thread_.get(); } base::Thread* indexed_db_thread() const { return indexed_db_thread_.get(); }
...@@ -311,7 +304,6 @@ class CONTENT_EXPORT BrowserMainLoop { ...@@ -311,7 +304,6 @@ class CONTENT_EXPORT BrowserMainLoop {
std::unique_ptr<ResourceDispatcherHostImpl> resource_dispatcher_host_; std::unique_ptr<ResourceDispatcherHostImpl> resource_dispatcher_host_;
std::unique_ptr<MediaStreamManager> media_stream_manager_; std::unique_ptr<MediaStreamManager> media_stream_manager_;
std::unique_ptr<SpeechRecognitionManagerImpl> speech_recognition_manager_; std::unique_ptr<SpeechRecognitionManagerImpl> speech_recognition_manager_;
std::unique_ptr<device::TimeZoneMonitor> time_zone_monitor_;
scoped_refptr<SaveFileManager> save_file_manager_; scoped_refptr<SaveFileManager> save_file_manager_;
// DO NOT add members here. Add them to the right categories above. // DO NOT add members here. Add them to the right categories above.
......
...@@ -166,7 +166,6 @@ ...@@ -166,7 +166,6 @@
#include "device/battery/battery_monitor_impl.h" #include "device/battery/battery_monitor_impl.h"
#include "device/gamepad/gamepad_monitor.h" #include "device/gamepad/gamepad_monitor.h"
#include "device/power_monitor/power_monitor_message_broadcaster.h" #include "device/power_monitor/power_monitor_message_broadcaster.h"
#include "device/time_zone_monitor/time_zone_monitor.h"
#include "gpu/GLES2/gl2extchromium.h" #include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/client/gpu_switches.h" #include "gpu/command_buffer/client/gpu_switches.h"
#include "gpu/command_buffer/common/gles2_cmd_utils.h" #include "gpu/command_buffer/common/gles2_cmd_utils.h"
...@@ -1245,16 +1244,6 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() { ...@@ -1245,16 +1244,6 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() {
registry.get(), base::Bind(&CreateMemoryCoordinatorHandle, GetID())); registry.get(), base::Bind(&CreateMemoryCoordinatorHandle, GetID()));
} }
// BrowserMainLoop, which owns TimeZoneMonitor, is alive for the lifetime of
// Mojo communication (see BrowserMainLoop::ShutdownThreadsAndCleanUp(),
// which shuts down Mojo). Hence, passing that TimeZoneMonitor instance as
// a raw pointer here is safe.
AddUIThreadInterface(
registry.get(),
base::Bind(&device::TimeZoneMonitor::Bind,
base::Unretained(
BrowserMainLoop::GetInstance()->time_zone_monitor())));
AddUIThreadInterface( AddUIThreadInterface(
registry.get(), registry.get(),
base::Bind(&device::PowerMonitorMessageBroadcaster::Create)); base::Bind(&device::PowerMonitorMessageBroadcaster::Create));
......
...@@ -212,6 +212,7 @@ target(link_target_type, "child") { ...@@ -212,6 +212,7 @@ target(link_target_type, "child") {
public_deps = [ public_deps = [
"//gpu/ipc/client:client", "//gpu/ipc/client:client",
"//services/service_manager/public/interfaces:interfaces_blink",
] ]
deps = [ deps = [
......
...@@ -48,7 +48,10 @@ ...@@ -48,7 +48,10 @@
#include "content/child/web_url_request_util.h" #include "content/child/web_url_request_util.h"
#include "content/child/worker_thread_registry.h" #include "content/child/worker_thread_registry.h"
#include "content/public/common/content_client.h" #include "content/public/common/content_client.h"
#include "content/public/common/service_manager_connection.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/interfaces/connector.mojom.h"
#include "third_party/WebKit/public/platform/WebData.h" #include "third_party/WebKit/public/platform/WebData.h"
#include "third_party/WebKit/public/platform/WebFloatPoint.h" #include "third_party/WebKit/public/platform/WebFloatPoint.h"
#include "third_party/WebKit/public/platform/WebSecurityOrigin.h" #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
...@@ -71,11 +74,6 @@ using blink::scheduler::WebThreadImplForWorkerScheduler; ...@@ -71,11 +74,6 @@ using blink::scheduler::WebThreadImplForWorkerScheduler;
namespace content { namespace content {
namespace {
} // namespace
static int ToMessageID(WebLocalizedString::Name name) { static int ToMessageID(WebLocalizedString::Name name) {
switch (name) { switch (name) {
case WebLocalizedString::AXAMPMFieldText: case WebLocalizedString::AXAMPMFieldText:
...@@ -790,6 +788,19 @@ bool BlinkPlatformImpl::databaseSetFileSize( ...@@ -790,6 +788,19 @@ bool BlinkPlatformImpl::databaseSetFileSize(
return false; return false;
} }
void BlinkPlatformImpl::bindServiceConnector(
service_manager::mojom::blink::ConnectorRequest request) {
if (!ChildThreadImpl::current())
return;
service_manager::mojom::ConnectorRequest chromium_request;
chromium_request.Bind(request.PassMessagePipe());
ChildThreadImpl::current()
->GetServiceManagerConnection()
->GetConnector()
->BindRequest(std::move(chromium_request));
}
blink::WebString BlinkPlatformImpl::signedPublicKeyAndChallengeString( blink::WebString BlinkPlatformImpl::signedPublicKeyAndChallengeString(
unsigned key_size_index, unsigned key_size_index,
const blink::WebString& challenge, const blink::WebString& challenge,
......
...@@ -81,6 +81,9 @@ class CONTENT_EXPORT BlinkPlatformImpl ...@@ -81,6 +81,9 @@ class CONTENT_EXPORT BlinkPlatformImpl
size_t actualMemoryUsageMB() override; size_t actualMemoryUsageMB() override;
size_t numberOfProcessors() override; size_t numberOfProcessors() override;
void bindServiceConnector(
service_manager::mojom::blink::ConnectorRequest request) override;
size_t maxDecodedImageBytes() override; size_t maxDecodedImageBytes() override;
uint32_t getUniqueIdForProcess() override; uint32_t getUniqueIdForProcess() override;
blink::WebString userAgent() override; blink::WebString userAgent() override;
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
}, },
"requires": { "requires": {
"content_browser": [ "renderer" ], "content_browser": [ "renderer" ],
"device": [ "device:time_zone_monitor" ],
"ui": [ "ui": [
"discardable_memory", "discardable_memory",
"gpu_client" "gpu_client"
......
...@@ -13,9 +13,17 @@ source_set("lib") { ...@@ -13,9 +13,17 @@ source_set("lib") {
deps = [ deps = [
"//base", "//base",
"//device/time_zone_monitor",
"//services/service_manager/public/cpp", "//services/service_manager/public/cpp",
] ]
public_deps = [
# TODO(blundell): This dep shouldn't be necessary at all,
# but content_shell fails to link in the component build if
# this isn't here as a public_dep.
"//device/time_zone_monitor/public/interfaces",
]
data_deps = [ data_deps = [
":manifest", ":manifest",
] ]
......
include_rules = [
"+device",
]
...@@ -7,7 +7,10 @@ ...@@ -7,7 +7,10 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/threading/thread_task_runner_handle.h"
#include "device/time_zone_monitor/time_zone_monitor.h"
#include "services/service_manager/public/cpp/connection.h" #include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/interface_registry.h"
namespace device { namespace device {
...@@ -26,7 +29,15 @@ void DeviceService::OnStart() {} ...@@ -26,7 +29,15 @@ void DeviceService::OnStart() {}
bool DeviceService::OnConnect(const service_manager::ServiceInfo& remote_info, bool DeviceService::OnConnect(const service_manager::ServiceInfo& remote_info,
service_manager::InterfaceRegistry* registry) { service_manager::InterfaceRegistry* registry) {
registry->AddInterface<mojom::TimeZoneMonitor>(this);
return true; return true;
} }
void DeviceService::Create(const service_manager::Identity& remote_identity,
mojom::TimeZoneMonitorRequest request) {
if (!time_zone_monitor_)
time_zone_monitor_ = device::TimeZoneMonitor::Create(file_task_runner_);
time_zone_monitor_->Bind(std::move(request));
}
} // namespace device } // namespace device
...@@ -5,21 +5,24 @@ ...@@ -5,21 +5,24 @@
#ifndef SERVICES_DEVICE_DEVICE_SERVICE_H_ #ifndef SERVICES_DEVICE_DEVICE_SERVICE_H_
#define SERVICES_DEVICE_DEVICE_SERVICE_H_ #define SERVICES_DEVICE_DEVICE_SERVICE_H_
#include "base/callback_forward.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "device/time_zone_monitor/public/interfaces/time_zone_monitor.mojom.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "services/service_manager/public/cpp/interface_factory.h" #include "services/service_manager/public/cpp/interface_factory.h"
#include "services/service_manager/public/cpp/service.h" #include "services/service_manager/public/cpp/service.h"
namespace device { namespace device {
class TimeZoneMonitor;
std::unique_ptr<service_manager::Service> CreateDeviceService( std::unique_ptr<service_manager::Service> CreateDeviceService(
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); scoped_refptr<base::SingleThreadTaskRunner> file_task_runner);
class DeviceService : public service_manager::Service { class DeviceService
: public service_manager::Service,
public service_manager::InterfaceFactory<mojom::TimeZoneMonitor> {
public: public:
explicit DeviceService( DeviceService(scoped_refptr<base::SingleThreadTaskRunner> file_task_runner);
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner);
~DeviceService() override; ~DeviceService() override;
private: private:
...@@ -28,6 +31,11 @@ class DeviceService : public service_manager::Service { ...@@ -28,6 +31,11 @@ class DeviceService : public service_manager::Service {
bool OnConnect(const service_manager::ServiceInfo& remote_info, bool OnConnect(const service_manager::ServiceInfo& remote_info,
service_manager::InterfaceRegistry* registry) override; service_manager::InterfaceRegistry* registry) override;
// InterfaceFactory<mojom::TimeZoneMonitor>:
void Create(const service_manager::Identity& remote_identity,
mojom::TimeZoneMonitorRequest request) override;
std::unique_ptr<device::TimeZoneMonitor> time_zone_monitor_;
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
DISALLOW_COPY_AND_ASSIGN(DeviceService); DISALLOW_COPY_AND_ASSIGN(DeviceService);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
"interface_provider_specs": { "interface_provider_specs": {
"service_manager:connector": { "service_manager:connector": {
"provides": { "provides": {
"device:time_zone_monitor": [ "device::mojom::TimeZoneMonitor" ]
}, },
"requires": { "requires": {
} }
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_DEVICE_PUBLIC_CPP_CONSTANTS_H_
#define SERVICES_DEVICE_PUBLIC_CPP_CONSTANTS_H_
namespace device {
extern const char kDeviceServiceName[];
} // namespace device
#endif // SERVICES_DEVICE_PUBLIC_CPP_CONSTANTS_H_
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
source_set("cpp") { import("//mojo/public/tools/bindings/mojom.gni")
mojom("interfaces") {
sources = [ sources = [
"constants.cc", "constants.mojom",
"constants.h",
] ]
} }
per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS
...@@ -2,10 +2,6 @@ ...@@ -2,10 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "services/device/public/cpp/constants.h" module device.mojom;
namespace device { const string kServiceName = "device";
const char kDeviceServiceName[] = "device";
} // namespace device
...@@ -13,6 +13,9 @@ blink_modules_sources("time_zone_monitor") { ...@@ -13,6 +13,9 @@ blink_modules_sources("time_zone_monitor") {
deps = [ deps = [
"//device/time_zone_monitor/public/interfaces:interfaces_blink", "//device/time_zone_monitor/public/interfaces:interfaces_blink",
"//mojo/public/cpp/bindings", "//mojo/public/cpp/bindings",
"//services/device/public/interfaces:interfaces_blink",
"//services/service_manager/public/interfaces:interfaces_blink",
"//third_party/WebKit/Source/platform",
"//third_party/icu:icui18n", "//third_party/icu:icui18n",
] ]
} }
include_rules = [ include_rules = [
"+device/time_zone_monitor/public/interfaces/time_zone_monitor.mojom-blink.h", "+device/time_zone_monitor/public/interfaces/time_zone_monitor.mojom-blink.h",
"+mojo/public/cpp/bindings/binding.h", "+mojo/public/cpp/bindings/binding.h",
"+services/device/public/interfaces/constants.mojom-blink.h",
"+third_party/icu/source/i18n/unicode/timezone.h", "+third_party/icu/source/i18n/unicode/timezone.h",
] ]
...@@ -10,8 +10,9 @@ ...@@ -10,8 +10,9 @@
#include "core/dom/ExecutionContextTask.h" #include "core/dom/ExecutionContextTask.h"
#include "core/workers/WorkerBackingThread.h" #include "core/workers/WorkerBackingThread.h"
#include "core/workers/WorkerThread.h" #include "core/workers/WorkerThread.h"
#include "public/platform/InterfaceProvider.h" #include "platform/ServiceConnector.h"
#include "public/platform/Platform.h" #include "public/platform/Platform.h"
#include "services/device/public/interfaces/constants.mojom-blink.h"
#include "third_party/icu/source/i18n/unicode/timezone.h" #include "third_party/icu/source/i18n/unicode/timezone.h"
#include <v8.h> #include <v8.h>
...@@ -36,8 +37,8 @@ void TimeZoneMonitorClient::Init() { ...@@ -36,8 +37,8 @@ void TimeZoneMonitorClient::Init() {
DEFINE_STATIC_LOCAL(TimeZoneMonitorClient, instance, ()); DEFINE_STATIC_LOCAL(TimeZoneMonitorClient, instance, ());
device::mojom::blink::TimeZoneMonitorPtr monitor; device::mojom::blink::TimeZoneMonitorPtr monitor;
Platform::current()->interfaceProvider()->getInterface( ServiceConnector::instance().connectToInterface(
mojo::GetProxy(&monitor)); device::mojom::blink::kServiceName, mojo::GetProxy(&monitor));
monitor->AddClient(instance.m_binding.CreateInterfacePtrAndBind()); monitor->AddClient(instance.m_binding.CreateInterfacePtrAndBind());
} }
......
...@@ -333,6 +333,7 @@ component("platform") { ...@@ -333,6 +333,7 @@ component("platform") {
"SecureTextInput.cpp", "SecureTextInput.cpp",
"SecureTextInput.h", "SecureTextInput.h",
"SerializedResource.h", "SerializedResource.h",
"ServiceConnector.h",
"SharedBuffer.cpp", "SharedBuffer.cpp",
"SharedBuffer.h", "SharedBuffer.h",
"SharedBufferChunkReader.cpp", "SharedBufferChunkReader.cpp",
...@@ -1443,6 +1444,7 @@ component("platform") { ...@@ -1443,6 +1444,7 @@ component("platform") {
"//gpu/command_buffer/common:common", "//gpu/command_buffer/common:common",
"//media", "//media",
"//net", "//net",
"//services/service_manager/public/interfaces:interfaces_blink",
"//skia", "//skia",
"//third_party:jpeg", "//third_party:jpeg",
"//third_party/WebKit/Source/wtf", "//third_party/WebKit/Source/wtf",
......
...@@ -33,6 +33,7 @@ include_rules = [ ...@@ -33,6 +33,7 @@ include_rules = [
"+mozilla", "+mozilla",
"+platform", "+platform",
"+public/platform", "+public/platform",
"+services/service_manager/public/interfaces",
"+skia/ext", "+skia/ext",
"+third_party/ced/src/compact_enc_det/compact_enc_det.h", "+third_party/ced/src/compact_enc_det/compact_enc_det.h",
"+third_party/khronos", "+third_party/khronos",
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ServiceConnector_h
#define ServiceConnector_h
#include "mojo/public/cpp/bindings/binding.h"
#include "public/platform/Platform.h"
#include "services/service_manager/public/interfaces/connector.mojom-blink.h"
#include "wtf/StdLibExtras.h"
namespace blink {
// ServiceConnector supports connecting to Mojo services by name.
class ServiceConnector {
public:
static ServiceConnector& instance() {
DEFINE_STATIC_LOCAL(ServiceConnector, instance, ());
return instance;
}
template <typename Interface>
void connectToInterface(const char* serviceName,
mojo::InterfaceRequest<Interface> request) {
if (!m_connector.is_bound())
Platform::current()->bindServiceConnector(mojo::GetProxy(&m_connector));
if (m_connector.encountered_error())
return;
service_manager::mojom::blink::IdentityPtr remoteIdentity(
service_manager::mojom::blink::Identity::New());
remoteIdentity->name = serviceName;
remoteIdentity->user_id = service_manager::mojom::blink::kInheritUserID;
remoteIdentity->instance = "";
service_manager::mojom::blink::InterfaceProviderPtr remoteInterfaces;
m_connector->Connect(std::move(remoteIdentity), GetProxy(&remoteInterfaces),
nullptr,
base::Bind(&ServiceConnector::onConnectionCompleted));
remoteInterfaces->GetInterface(Interface::Name_, request.PassMessagePipe());
}
private:
ServiceConnector() {}
static void onConnectionCompleted(
service_manager::mojom::ConnectResult result,
const WTF::String& targetUserID) {}
service_manager::mojom::blink::ConnectorPtr m_connector;
};
} // namespace blink
#endif // ServiceConnector_h
...@@ -151,4 +151,7 @@ InterfaceProvider* Platform::interfaceProvider() { ...@@ -151,4 +151,7 @@ InterfaceProvider* Platform::interfaceProvider() {
return InterfaceProvider::getEmptyInterfaceProvider(); return InterfaceProvider::getEmptyInterfaceProvider();
} }
void Platform::bindServiceConnector(
service_manager::mojom::blink::ConnectorRequest request) {}
} // namespace blink } // namespace blink
...@@ -591,6 +591,10 @@ source_set("blink_headers") { ...@@ -591,6 +591,10 @@ source_set("blink_headers") {
"//third_party/icu:icu_config", "//third_party/icu:icu_config",
] ]
public_deps = [
"//services/service_manager/public/interfaces:interfaces_blink",
]
deps = [ deps = [
":generate_mojo_bindings", ":generate_mojo_bindings",
] ]
......
...@@ -19,6 +19,7 @@ include_rules = [ ...@@ -19,6 +19,7 @@ include_rules = [
"+platform/weborigin", "+platform/weborigin",
"+public/platform", "+public/platform",
"-public/web", "-public/web",
"+services/service_manager/public/interfaces",
"+third_party/skia", "+third_party/skia",
"+url", "+url",
"-web", "-web",
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "base/metrics/user_metrics_action.h" #include "base/metrics/user_metrics_action.h"
#include "cc/resources/shared_bitmap.h" #include "cc/resources/shared_bitmap.h"
#include "cc/surfaces/frame_sink_id.h" #include "cc/surfaces/frame_sink_id.h"
#include "services/service_manager/public/interfaces/connector.mojom-blink.h"
namespace gpu { namespace gpu {
class GpuMemoryBufferManager; class GpuMemoryBufferManager;
...@@ -604,6 +605,9 @@ class BLINK_PLATFORM_EXPORT Platform { ...@@ -604,6 +605,9 @@ class BLINK_PLATFORM_EXPORT Platform {
virtual InterfaceProvider* interfaceProvider(); virtual InterfaceProvider* interfaceProvider();
virtual void bindServiceConnector(
service_manager::mojom::blink::ConnectorRequest);
// Platform events ----------------------------------------------------- // Platform events -----------------------------------------------------
// Device Orientation, Device Motion, Device Light, Battery, Gamepad. // Device Orientation, Device Motion, Device Light, Battery, Gamepad.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment