diff --git a/sky/services/engine/BUILD.gn b/sky/services/engine/BUILD.gn index e31d3fdf26a..80c4f5dadd9 100644 --- a/sky/services/engine/BUILD.gn +++ b/sky/services/engine/BUILD.gn @@ -11,6 +11,7 @@ mojom("interfaces") { ] deps = [ + "//mojo/public/interfaces/application", "//mojo/services/asset_bundle/interfaces", "//sky/services/pointer:interfaces", ] diff --git a/sky/services/engine/sky_engine.mojom b/sky/services/engine/sky_engine.mojom index 792054d788e..5ecb125cc8e 100644 --- a/sky/services/engine/sky_engine.mojom +++ b/sky/services/engine/sky_engine.mojom @@ -4,6 +4,8 @@ module sky; +import "mojo/public/interfaces/application/service_provider.mojom"; +import "mojo/public/interfaces/application/shell.mojom"; import "mojo/services/asset_bundle/interfaces/asset_bundle.mojom"; import "sky/services/engine/input_event.mojom"; import "sky/services/pointer/pointer.mojom"; @@ -18,7 +20,15 @@ struct ViewportMetrics { double padding_left; }; +struct ServicesData { + mojo.Shell? shell; + mojo.ServiceProvider? services_provided_by_embedder; + mojo.ServiceProvider&? services_provided_to_embedder; +}; + interface SkyEngine { + SetServices(ServicesData services); + OnActivityPaused(); OnActivityResumed(); diff --git a/sky/shell/BUILD.gn b/sky/shell/BUILD.gn index 60a8d62bcf6..fb97458ee5d 100644 --- a/sky/shell/BUILD.gn +++ b/sky/shell/BUILD.gn @@ -10,8 +10,6 @@ source_set("common") { "rasterizer.h", "platform_view.cc", "platform_view.h", - "service_provider.cc", - "service_provider.h", "shell.cc", "shell.h", "shell_view.cc", @@ -114,7 +112,6 @@ if (is_android) { generate_jni("jni_headers") { sources = [ - "platform/android/org/domokit/sky/shell/PlatformServiceProvider.java", "platform/android/org/domokit/sky/shell/PlatformViewAndroid.java", "platform/android/org/domokit/sky/shell/SkyMain.java", "platform/android/org/domokit/sky/shell/TracingController.java", @@ -126,8 +123,6 @@ if (is_android) { shared_library("sky_shell") { sources = [ "platform/android/library_loader.cc", - "platform/android/platform_service_provider_android.cc", - "platform/android/platform_service_provider_android.h", "platform/android/platform_view_android.cc", "platform/android/platform_view_android.h", "platform/android/sky_main.cc", @@ -239,7 +234,8 @@ if (is_android) { sources += [ "platform/mac/platform_mac.h", "platform/mac/platform_mac.mm", - "platform/mac/platform_service_provider_mac.cc", + "platform/mac/platform_service_provider.cc", + "platform/mac/platform_service_provider.h", "platform/mac/platform_view_mac.h", "platform/mac/platform_view_mac.mm", ] @@ -265,7 +261,6 @@ if (is_android) { sources = [ "platform/linux/main_linux.cc", - "platform/linux/platform_service_provider_linux.cc", "platform/linux/platform_view_linux.cc", ] @@ -285,7 +280,8 @@ if (is_android) { "platform/mac/main_mac.mm", "platform/mac/platform_mac.h", "platform/mac/platform_mac.mm", - "platform/mac/platform_service_provider_mac.cc", + "platform/mac/platform_service_provider.cc", + "platform/mac/platform_service_provider.h", "platform/mac/platform_view_mac.h", "platform/mac/platform_view_mac.mm", "platform/mac/sky_app_delegate.h", diff --git a/sky/shell/platform/android/library_loader.cc b/sky/shell/platform/android/library_loader.cc index 9063e083db1..90be9d3b919 100644 --- a/sky/shell/platform/android/library_loader.cc +++ b/sky/shell/platform/android/library_loader.cc @@ -11,7 +11,6 @@ #include "base/logging.h" #include "mojo/android/system/base_run_loop.h" #include "mojo/android/system/core_impl.h" -#include "sky/shell/platform/android/platform_service_provider_android.h" #include "sky/shell/platform/android/platform_view_android.h" #include "sky/shell/platform/android/sky_main.h" #include "sky/shell/platform/android/tracing_controller.h" @@ -22,7 +21,6 @@ namespace { base::android::RegistrationMethod kSkyRegisteredMethods[] = { {"CoreImpl", mojo::android::RegisterCoreImpl}, {"BaseRunLoop", mojo::android::RegisterBaseRunLoop}, - {"PlatformServiceProvider", sky::shell::RegisterPlatformServiceProvider}, {"PlatformViewAndroid", sky::shell::PlatformViewAndroid::Register}, {"SkyMain", sky::shell::RegisterSkyMain}, {"TracingController", sky::shell::RegisterTracingController}, diff --git a/sky/shell/platform/android/org/domokit/sky/shell/PlatformServiceProvider.java b/sky/shell/platform/android/org/domokit/sky/shell/PlatformServiceProvider.java index 70b88666551..9eb57ad491d 100644 --- a/sky/shell/platform/android/org/domokit/sky/shell/PlatformServiceProvider.java +++ b/sky/shell/platform/android/org/domokit/sky/shell/PlatformServiceProvider.java @@ -6,8 +6,6 @@ package org.domokit.sky.shell; import android.content.Context; -import org.chromium.base.CalledByNative; -import org.chromium.base.JNINamespace; import org.chromium.mojo.system.Core; import org.chromium.mojo.system.MessagePipeHandle; import org.chromium.mojo.system.MojoException; @@ -17,19 +15,10 @@ import org.chromium.mojom.mojo.ServiceProvider; /** * A collection of services implemented in Java. **/ -@JNINamespace("sky::shell") public class PlatformServiceProvider implements ServiceProvider { private Core mCore; private Context mContext; - @SuppressWarnings("unused") - @CalledByNative - public static void create(Context context, int nativeHandle) { - Core core = CoreImpl.getInstance(); - MessagePipeHandle pipe = core.acquireNativeHandle(nativeHandle).toMessagePipeHandle(); - ServiceProvider.MANAGER.bind(new PlatformServiceProvider(core, context), pipe); - } - public PlatformServiceProvider(Core core, Context context) { assert core != null; assert context != null; diff --git a/sky/shell/platform/android/org/domokit/sky/shell/PlatformViewAndroid.java b/sky/shell/platform/android/org/domokit/sky/shell/PlatformViewAndroid.java index 4737deb7a2a..043c83ef01f 100644 --- a/sky/shell/platform/android/org/domokit/sky/shell/PlatformViewAndroid.java +++ b/sky/shell/platform/android/org/domokit/sky/shell/PlatformViewAndroid.java @@ -28,6 +28,8 @@ import org.chromium.mojom.pointer.PointerPacket; import org.chromium.mojom.pointer.PointerType; import org.chromium.mojom.sky.SkyEngine; import org.chromium.mojom.sky.ViewportMetrics; +import org.chromium.mojom.sky.ServicesData; +import org.chromium.mojom.mojo.ServiceProvider; import java.util.ArrayList; import java.util.List; @@ -44,6 +46,7 @@ public class PlatformViewAndroid extends SurfaceView { private long mNativePlatformView; private SkyEngine.Proxy mSkyEngine; + private PlatformServiceProvider mServiceProvider; private final SurfaceHolder.Callback mSurfaceCallback; private final EdgeDims mPadding; private final KeyboardServiceState mKeyboardState; @@ -257,10 +260,19 @@ public class PlatformViewAndroid extends SurfaceView { private void attach() { Core core = CoreImpl.getInstance(); - Pair> result = + Pair> engine = SkyEngine.MANAGER.getInterfaceRequest(core); - mSkyEngine = result.first; - mNativePlatformView = nativeAttach(result.second.passHandle().releaseNativeHandle()); + mSkyEngine = engine.first; + mNativePlatformView = nativeAttach(engine.second.passHandle().releaseNativeHandle()); + + Pair> serviceProvider = + ServiceProvider.MANAGER.getInterfaceRequest(core); + mServiceProvider = new PlatformServiceProvider(core, getContext()); + ServiceProvider.MANAGER.bind(mServiceProvider, serviceProvider.second); + + ServicesData services = new ServicesData(); + services.servicesProvidedByEmbedder = serviceProvider.first; + mSkyEngine.setServices(services); } private static native long nativeAttach(int inputObserverHandle); diff --git a/sky/shell/platform/android/platform_service_provider_android.cc b/sky/shell/platform/android/platform_service_provider_android.cc deleted file mode 100644 index c71b6ea7719..00000000000 --- a/sky/shell/platform/android/platform_service_provider_android.cc +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2015 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. - -#include "sky/shell/platform/android/platform_service_provider_android.h" - -#include "base/android/jni_android.h" -#include "base/bind.h" -#include "base/trace_event/trace_event.h" -#include "jni/PlatformServiceProvider_jni.h" -#include "mojo/public/cpp/bindings/interface_request.h" -#include "sky/shell/service_provider.h" - -namespace sky { -namespace shell { -namespace { - -void CreatePlatformServiceProvider( - mojo::InterfaceRequest request) { - Java_PlatformServiceProvider_create( - base::android::AttachCurrentThread(), - base::android::GetApplicationContext(), - request.PassMessagePipe().release().value()); -} - -} // namespace - -bool RegisterPlatformServiceProvider(JNIEnv* env) { - return RegisterNativesImpl(env); -} - -mojo::ServiceProviderPtr CreateServiceProvider( - ServiceProviderContext* context) { - mojo::MessagePipe pipe; - context->platform_task_runner->PostTask( - FROM_HERE, - base::Bind(CreatePlatformServiceProvider, - base::Passed(mojo::MakeRequest( - pipe.handle1.Pass())))); - return mojo::MakeProxy( - mojo::InterfacePtrInfo(pipe.handle0.Pass(), 0u)); -} - -} // namespace shell -} // namespace sky diff --git a/sky/shell/platform/android/platform_service_provider_android.h b/sky/shell/platform/android/platform_service_provider_android.h deleted file mode 100644 index 682835646a1..00000000000 --- a/sky/shell/platform/android/platform_service_provider_android.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2015 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 SKY_SHELL_PLATFORM_SERVICE_PROVIDER_ANDROID_H_ -#define SKY_SHELL_PLATFORM_SERVICE_PROVIDER_ANDROID_H_ - -#include - -namespace sky { -namespace shell { - -bool RegisterPlatformServiceProvider(JNIEnv* env); - -} // namespace shell -} // namespace sky - -#endif // SKY_SHELL_PLATFORM_SERVICE_PROVIDER_ANDROID_H_ diff --git a/sky/shell/platform/android/sky_main.cc b/sky/shell/platform/android/sky_main.cc index e53dbb0e94a..c2cb38f95cd 100644 --- a/sky/shell/platform/android/sky_main.cc +++ b/sky/shell/platform/android/sky_main.cc @@ -21,7 +21,6 @@ #include "jni/SkyMain_jni.h" #include "mojo/edk/embedder/embedder.h" #include "mojo/edk/embedder/simple_platform_support.h" -#include "sky/shell/service_provider.h" #include "sky/shell/shell.h" using base::LazyInstance; @@ -78,8 +77,7 @@ static void Init(JNIEnv* env, mojo::embedder::Init(std::unique_ptr( new mojo::embedder::SimplePlatformSupport())); - Shell::InitStandalone(make_scoped_ptr(new ServiceProviderContext( - g_java_message_loop.Get()->task_runner()))); + Shell::InitStandalone(); InitializeTracing(); } diff --git a/sky/shell/platform/android/update_service_android.cc b/sky/shell/platform/android/update_service_android.cc index c87e080ff01..b74c85ec6a0 100644 --- a/sky/shell/platform/android/update_service_android.cc +++ b/sky/shell/platform/android/update_service_android.cc @@ -39,9 +39,7 @@ void UpdateTaskAndroid::Start() { } void UpdateTaskAndroid::DidCreateIsolate(Dart_Isolate isolate) { - Internals::Create(isolate, CreateServiceProvider( - Shell::Shared().service_provider_context()), - nullptr); + Internals::Create(isolate, nullptr, nullptr); } void UpdateTaskAndroid::RunDartOnUIThread() { diff --git a/sky/shell/platform/ios/sky_surface.mm b/sky/shell/platform/ios/sky_surface.mm index 654cb3353dd..49489886d97 100644 --- a/sky/shell/platform/ios/sky_surface.mm +++ b/sky/shell/platform/ios/sky_surface.mm @@ -12,9 +12,10 @@ #include "mojo/public/cpp/bindings/interface_request.h" #include "sky/services/engine/input_event.mojom.h" #include "sky/services/pointer/pointer.mojom.h" +#include "sky/shell/platform/mac/platform_service_provider.h" #include "sky/shell/platform/mac/platform_view_mac.h" -#include "sky/shell/shell_view.h" #include "sky/shell/shell.h" +#include "sky/shell/shell_view.h" #include "sky/shell/ui_delegate.h" #include @@ -184,8 +185,14 @@ static std::string SkPictureTracingPath() { } - (void)connectToEngineAndLoad { - auto interface_request = mojo::GetProxy(&_sky_engine); - self.platformView->ConnectToEngine(interface_request.Pass()); + self.platformView->ConnectToEngine(mojo::GetProxy(&_sky_engine)); + + mojo::ServiceProviderPtr service_provider; + new sky::shell::PlatformServiceProvider(mojo::GetProxy(&service_provider)); + sky::ServicesDataPtr services = sky::ServicesData::New(); + services->services_provided_by_embedder = service_provider.Pass(); + _sky_engine->SetServices(services.Pass()); + mojo::String bundle_path([self flxBundlePath]); _sky_engine->RunFromPrecompiledSnapshot(bundle_path); } diff --git a/sky/shell/platform/linux/main_linux.cc b/sky/shell/platform/linux/main_linux.cc index 53f42d48733..b25611efa00 100644 --- a/sky/shell/platform/linux/main_linux.cc +++ b/sky/shell/platform/linux/main_linux.cc @@ -10,7 +10,6 @@ #include "base/message_loop/message_loop.h" #include "mojo/edk/embedder/embedder.h" #include "mojo/edk/embedder/simple_platform_support.h" -#include "sky/shell/service_provider.h" #include "sky/shell/shell.h" #include "sky/shell/switches.h" #include "sky/shell/testing/testing.h" @@ -31,8 +30,7 @@ int main(int argc, const char* argv[]) { mojo::embedder::Init(std::unique_ptr( new mojo::embedder::SimplePlatformSupport())); - sky::shell::Shell::InitStandalone(make_scoped_ptr( - new sky::shell::ServiceProviderContext(message_loop.task_runner()))); + sky::shell::Shell::InitStandalone(); if (!sky::shell::InitForTesting()) { sky::shell::switches::PrintUsage("sky_shell"); diff --git a/sky/shell/platform/linux/platform_service_provider_linux.cc b/sky/shell/platform/linux/platform_service_provider_linux.cc deleted file mode 100644 index 5cef4003121..00000000000 --- a/sky/shell/platform/linux/platform_service_provider_linux.cc +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2015 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. - -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/lazy_instance.h" -#include "base/location.h" -#include "base/single_thread_task_runner.h" -#include "mojo/public/cpp/bindings/strong_binding.h" -#include "mojo/public/interfaces/application/service_provider.mojom.h" -#include "sky/shell/service_provider.h" -#include "sky/shell/testing/test_runner.h" - -namespace sky { -namespace shell { -namespace { - -class PlatformServiceProvider : public mojo::ServiceProvider { - public: - PlatformServiceProvider(mojo::InterfaceRequest request) - : binding_(this, request.Pass()) {} - - void ConnectToService(const mojo::String& service_name, - mojo::ScopedMessagePipeHandle client_handle) override { - } - - private: - mojo::StrongBinding binding_; -}; - -static void CreatePlatformServiceProvider( - mojo::InterfaceRequest request) { - new PlatformServiceProvider(request.Pass()); -} - -} // namespace - -mojo::ServiceProviderPtr CreateServiceProvider( - ServiceProviderContext* context) { - DCHECK(context); - mojo::MessagePipe pipe; - auto request = mojo::MakeRequest(pipe.handle1.Pass()); - context->platform_task_runner->PostTask( - FROM_HERE, base::Bind(CreatePlatformServiceProvider, base::Passed(&request))); - return mojo::MakeProxy( - mojo::InterfacePtrInfo(pipe.handle0.Pass(), 0u)); -} - -} // namespace shell -} // namespace sky diff --git a/sky/shell/platform/mac/platform_mac.mm b/sky/shell/platform/mac/platform_mac.mm index e0cad93cd72..745d2f15609 100644 --- a/sky/shell/platform/mac/platform_mac.mm +++ b/sky/shell/platform/mac/platform_mac.mm @@ -14,7 +14,6 @@ #include "base/message_loop/message_loop.h" #include "mojo/edk/embedder/embedder.h" #include "mojo/edk/embedder/simple_platform_support.h" -#include "sky/shell/service_provider.h" #include "sky/shell/shell.h" #include "sky/shell/ui_delegate.h" #include "ui/gl/gl_surface.h" @@ -65,8 +64,7 @@ int PlatformMacMain(int argc, mojo::embedder::Init(std::unique_ptr( new mojo::embedder::SimplePlatformSupport())); - sky::shell::Shell::InitStandalone(make_scoped_ptr( - new sky::shell::ServiceProviderContext(message_loop->task_runner()))); + sky::shell::Shell::InitStandalone(); result = callback(); diff --git a/sky/shell/platform/mac/platform_service_provider.cc b/sky/shell/platform/mac/platform_service_provider.cc new file mode 100644 index 00000000000..32bf23c54c3 --- /dev/null +++ b/sky/shell/platform/mac/platform_service_provider.cc @@ -0,0 +1,46 @@ +// Copyright 2015 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. + +#include "sky/shell/platform/mac/platform_service_provider.h" + +namespace sky { +namespace shell { + +PlatformServiceProvider::PlatformServiceProvider( + mojo::InterfaceRequest request) + : binding_(this, request.Pass()) { +} + +PlatformServiceProvider::~PlatformServiceProvider() { +} + +void PlatformServiceProvider::ConnectToService( + const mojo::String& service_name, + mojo::ScopedMessagePipeHandle client_handle) { + if (service_name == mojo::NetworkService::Name_) { + network_.Create(nullptr, mojo::MakeRequest( + client_handle.Pass())); + } +#if TARGET_OS_IPHONE + if (service_name == ::keyboard::KeyboardService::Name_) { + keyboard_.Create(nullptr, mojo::MakeRequest<::keyboard::KeyboardService>( + client_handle.Pass())); + } + if (service_name == ::media::MediaPlayer::Name_) { + media_player_.Create(nullptr, mojo::MakeRequest<::media::MediaPlayer>( + client_handle.Pass())); + } + if (service_name == ::media::MediaService::Name_) { + media_service_.Create(nullptr, mojo::MakeRequest<::media::MediaService>( + client_handle.Pass())); + } + if (service_name == ::vsync::VSyncProvider::Name_) { + vsync_.Create(nullptr, mojo::MakeRequest<::vsync::VSyncProvider>( + client_handle.Pass())); + } +#endif +} + +} // namespace shell +} // namespace sky diff --git a/sky/shell/platform/mac/platform_service_provider.h b/sky/shell/platform/mac/platform_service_provider.h new file mode 100644 index 00000000000..dcdbd27b613 --- /dev/null +++ b/sky/shell/platform/mac/platform_service_provider.h @@ -0,0 +1,50 @@ +// Copyright 2015 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 SKY_SHELL_PLATFORM_MAC_SERVICE_PROVIDER_H_ +#define SKY_SHELL_PLATFORM_MAC_SERVICE_PROVIDER_H_ + +#include "mojo/public/interfaces/application/service_provider.mojom.h" +#include "sky/engine/wtf/Assertions.h" +#include "sky/services/ns_net/network_service_impl.h" + +#if TARGET_OS_IPHONE +#include "sky/services/keyboard/ios/keyboard_service_impl.h" +#include "sky/services/media/ios/media_service_impl.h" +#include "sky/services/media/ios/media_player_impl.h" +#include "sky/services/vsync/ios/vsync_provider_impl.h" +#endif + +#if !TARGET_OS_IPHONE +#include "sky/shell/testing/test_runner.h" +#endif + +namespace sky { +namespace shell { + +class PlatformServiceProvider : public mojo::ServiceProvider { + public: + PlatformServiceProvider(mojo::InterfaceRequest request); + ~PlatformServiceProvider() override; + + void ConnectToService(const mojo::String& service_name, + mojo::ScopedMessagePipeHandle client_handle) override; + + private: + mojo::StrongBinding binding_; + mojo::NetworkServiceFactory network_; +#if TARGET_OS_IPHONE + sky::services::keyboard::KeyboardServiceFactory keyboard_; + sky::services::media::MediaPlayerFactory media_player_; + sky::services::media::MediaServiceFactory media_service_; + sky::services::vsync::VSyncProviderFactory vsync_; +#endif + + DISALLOW_COPY_AND_ASSIGN(PlatformServiceProvider); +}; + +} // namespace shell +} // namespace sky + +#endif // SKY_SHELL_PLATFORM_MAC_SERVICE_PROVIDER_H_ diff --git a/sky/shell/platform/mac/platform_service_provider_mac.cc b/sky/shell/platform/mac/platform_service_provider_mac.cc deleted file mode 100644 index 4a0b49f32b7..00000000000 --- a/sky/shell/platform/mac/platform_service_provider_mac.cc +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2015 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. - -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/lazy_instance.h" -#include "base/location.h" -#include "base/single_thread_task_runner.h" -#include "mojo/public/interfaces/application/service_provider.mojom.h" -#include "sky/engine/wtf/Assertions.h" -#include "sky/services/ns_net/network_service_impl.h" -#include "sky/shell/service_provider.h" - -#if TARGET_OS_IPHONE -#include "sky/services/keyboard/ios/keyboard_service_impl.h" -#include "sky/services/media/ios/media_service_impl.h" -#include "sky/services/media/ios/media_player_impl.h" -#include "sky/services/vsync/ios/vsync_provider_impl.h" -#endif - -#if !TARGET_OS_IPHONE -#include "sky/shell/testing/test_runner.h" -#endif - -namespace sky { -namespace shell { - -class PlatformServiceProvider : public mojo::ServiceProvider { - public: - PlatformServiceProvider(mojo::InterfaceRequest request) - : binding_(this, request.Pass()) {} - - void ConnectToService(const mojo::String& service_name, - mojo::ScopedMessagePipeHandle client_handle) override { - if (service_name == mojo::NetworkService::Name_) { - network_.Create(nullptr, mojo::MakeRequest( - client_handle.Pass())); - } -#if TARGET_OS_IPHONE - if (service_name == ::keyboard::KeyboardService::Name_) { - keyboard_.Create(nullptr, mojo::MakeRequest<::keyboard::KeyboardService>( - client_handle.Pass())); - } - if (service_name == ::media::MediaPlayer::Name_) { - media_player_.Create(nullptr, mojo::MakeRequest<::media::MediaPlayer>( - client_handle.Pass())); - } - if (service_name == ::media::MediaService::Name_) { - media_service_.Create(nullptr, mojo::MakeRequest<::media::MediaService>( - client_handle.Pass())); - } - if (service_name == ::vsync::VSyncProvider::Name_) { - vsync_.Create(nullptr, mojo::MakeRequest<::vsync::VSyncProvider>( - client_handle.Pass())); - } -#endif - } - - private: - mojo::StrongBinding binding_; - mojo::NetworkServiceFactory network_; -#if TARGET_OS_IPHONE - sky::services::keyboard::KeyboardServiceFactory keyboard_; - sky::services::media::MediaPlayerFactory media_player_; - sky::services::media::MediaServiceFactory media_service_; - sky::services::vsync::VSyncProviderFactory vsync_; -#endif -}; - -static void CreatePlatformServiceProvider( - mojo::InterfaceRequest request) { - new PlatformServiceProvider(request.Pass()); -} - -mojo::ServiceProviderPtr CreateServiceProvider( - ServiceProviderContext* context) { - DCHECK(context); - mojo::MessagePipe pipe; - auto request = mojo::MakeRequest(pipe.handle1.Pass()); - context->platform_task_runner->PostTask( - FROM_HERE, - base::Bind(CreatePlatformServiceProvider, base::Passed(request.Pass()))); - return mojo::MakeProxy( - mojo::InterfacePtrInfo(pipe.handle0.Pass(), 0u)); -} - -} // namespace shell -} // namespace sky diff --git a/sky/shell/platform/mac/sky_window.mm b/sky/shell/platform/mac/sky_window.mm index 6ec6f1b7158..23bf48b57b7 100644 --- a/sky/shell/platform/mac/sky_window.mm +++ b/sky/shell/platform/mac/sky_window.mm @@ -9,6 +9,7 @@ #include "sky/services/engine/input_event.mojom.h" #include "sky/services/pointer/pointer.mojom.h" #include "sky/shell/platform/mac/platform_view_mac.h" +#include "sky/shell/platform/mac/platform_service_provider.h" #include "sky/shell/shell_view.h" #include "sky/shell/shell.h" #include "sky/shell/switches.h" @@ -76,8 +77,13 @@ static inline pointer::PointerType EventTypeFromNSEventPhase(NSEventPhase phase) // We also want a separate setup for normal apps vs SkyShell // normal apps only use a flx vs. SkyShell which always pulls from network. - (void)setupAndLoadDart { - auto interface_request = mojo::GetProxy(&_sky_engine); - self.platformView->ConnectToEngine(interface_request.Pass()); + self.platformView->ConnectToEngine(mojo::GetProxy(&_sky_engine)); + + mojo::ServiceProviderPtr service_provider; + new sky::shell::PlatformServiceProvider(mojo::GetProxy(&service_provider)); + sky::ServicesDataPtr services = sky::ServicesData::New(); + services->services_provided_by_embedder = service_provider.Pass(); + _sky_engine->SetServices(services.Pass()); base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); diff --git a/sky/shell/platform/mojo/BUILD.gn b/sky/shell/platform/mojo/BUILD.gn index 6578e975274..fa189230042 100644 --- a/sky/shell/platform/mojo/BUILD.gn +++ b/sky/shell/platform/mojo/BUILD.gn @@ -12,7 +12,6 @@ mojo_native_application("mojo") { "content_handler_impl.cc", "content_handler_impl.h", "main_mojo.cc", - "platform_service_provider_mojo.cc", "platform_view_mojo.cc", "platform_view_mojo.h", "sky_application_impl.cc", diff --git a/sky/shell/platform/mojo/main_mojo.cc b/sky/shell/platform/mojo/main_mojo.cc index 1c04203afb8..e6bf7e0ad98 100644 --- a/sky/shell/platform/mojo/main_mojo.cc +++ b/sky/shell/platform/mojo/main_mojo.cc @@ -15,7 +15,6 @@ #include "mojo/public/cpp/application/interface_factory_impl.h" #include "mojo/services/content_handler/interfaces/content_handler.mojom.h" #include "sky/shell/shell.h" -#include "sky/shell/service_provider.h" #include "sky/shell/platform/mojo/content_handler_impl.h" namespace sky { @@ -32,9 +31,7 @@ class MojoApp : public mojo::ApplicationDelegate, void Initialize(mojo::ApplicationImpl* app) override { mojo::icu::Initialize(app); tracing_.Initialize(app); - - Shell::Init(make_scoped_ptr( - new ServiceProviderContext(base::MessageLoop::current()->task_runner()))); + Shell::Init(); } bool ConfigureIncomingConnection( diff --git a/sky/shell/platform/mojo/platform_service_provider_mojo.cc b/sky/shell/platform/mojo/platform_service_provider_mojo.cc deleted file mode 100644 index f562469576d..00000000000 --- a/sky/shell/platform/mojo/platform_service_provider_mojo.cc +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2015 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. - -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/lazy_instance.h" -#include "base/location.h" -#include "base/single_thread_task_runner.h" -#include "mojo/public/cpp/bindings/strong_binding.h" -#include "mojo/public/interfaces/application/service_provider.mojom.h" -#include "sky/shell/service_provider.h" - -namespace sky { -namespace shell { -namespace { - -class PlatformServiceProvider : public mojo::ServiceProvider { - public: - PlatformServiceProvider(mojo::InterfaceRequest request) - : binding_(this, request.Pass()) {} - - void ConnectToService(const mojo::String& service_name, - mojo::ScopedMessagePipeHandle client_handle) override { - } - - private: - mojo::StrongBinding binding_; -}; - -static void CreatePlatformServiceProvider( - mojo::InterfaceRequest request) { - new PlatformServiceProvider(request.Pass()); -} - -} // namespace - -mojo::ServiceProviderPtr CreateServiceProvider( - ServiceProviderContext* context) { - DCHECK(context); - mojo::MessagePipe pipe; - auto request = mojo::MakeRequest(pipe.handle1.Pass()); - context->platform_task_runner->PostTask( - FROM_HERE, base::Bind(CreatePlatformServiceProvider, base::Passed(&request))); - return mojo::MakeProxy( - mojo::InterfacePtrInfo(pipe.handle0.Pass(), 0u)); -} - -} // namespace shell -} // namespace sky diff --git a/sky/shell/service_provider.cc b/sky/shell/service_provider.cc deleted file mode 100644 index 3b2b9ad1870..00000000000 --- a/sky/shell/service_provider.cc +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2015 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. - -#include "sky/shell/service_provider.h" - -#include "base/single_thread_task_runner.h" - -namespace sky { -namespace shell { - -ServiceProviderContext::ServiceProviderContext( - scoped_refptr runner) - : platform_task_runner(runner.Pass()) {} - -ServiceProviderContext::~ServiceProviderContext() { -} - -} // namespace shell -} // namespace sky diff --git a/sky/shell/service_provider.h b/sky/shell/service_provider.h deleted file mode 100644 index cff6b6cb85b..00000000000 --- a/sky/shell/service_provider.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2015 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 SKY_SHELL_SERVICE_PROVIDER_H_ -#define SKY_SHELL_SERVICE_PROVIDER_H_ - -#include "base/memory/ref_counted.h" -#include "mojo/public/cpp/system/core.h" -#include "mojo/public/interfaces/application/service_provider.mojom.h" - -namespace base { -class SingleThreadTaskRunner; -} - -namespace sky { -namespace shell { - -class ServiceProviderContext { - public: - ServiceProviderContext(scoped_refptr runner); - ~ServiceProviderContext(); - - scoped_refptr platform_task_runner; -}; - -// Implemented in platform_service_provider.cc for each platform. -mojo::ServiceProviderPtr CreateServiceProvider(ServiceProviderContext* context); - -} // namespace shell -} // namespace sky - -#endif // SKY_SHELL_SERVICE_PROVIDER_H_ diff --git a/sky/shell/shell.cc b/sky/shell/shell.cc index 58f93c313eb..5ac513dcb6f 100644 --- a/sky/shell/shell.cc +++ b/sky/shell/shell.cc @@ -49,8 +49,7 @@ base::LazyInstance g_discardable; } // namespace -Shell::Shell(scoped_ptr service_provider_context) - : service_provider_context_(service_provider_context.Pass()) { +Shell::Shell() { DCHECK(!g_shell); base::Thread::Options options; @@ -74,19 +73,17 @@ Shell::Shell(scoped_ptr service_provider_context) Shell::~Shell() { } -void Shell::InitStandalone( - scoped_ptr service_provider_context) { +void Shell::InitStandalone() { CHECK(base::i18n::InitializeICU()); #if !defined(OS_LINUX) CHECK(gfx::GLSurface::InitializeOneOff()); #endif - Init(service_provider_context.Pass()); + Init(); } -void Shell::Init(scoped_ptr service_provider_context) { +void Shell::Init() { base::DiscardableMemoryAllocator::SetInstance(&g_discardable.Get()); - - g_shell = new Shell(service_provider_context.Pass()); + g_shell = new Shell(); } Shell& Shell::Shared() { diff --git a/sky/shell/shell.h b/sky/shell/shell.h index 8c4a9916584..23787007d76 100644 --- a/sky/shell/shell.h +++ b/sky/shell/shell.h @@ -10,23 +10,19 @@ #include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" #include "base/threading/thread.h" -#include "sky/shell/service_provider.h" #include "sky/shell/tracing_controller.h" namespace sky { namespace shell { -class ServiceProviderContext; class Shell { public: ~Shell(); // Init the shell to stand alone from MojoShell. - static void InitStandalone( - scoped_ptr service_provider_context); + static void InitStandalone(); // Init the shell to run inside MojoShell. - static void Init( - scoped_ptr service_provider_context); + static void Init(); static Shell& Shared(); @@ -42,14 +38,10 @@ class Shell { return io_task_runner_.get(); } - ServiceProviderContext* service_provider_context() const { - return service_provider_context_.get(); - } - TracingController& tracing_controller(); private: - explicit Shell(scoped_ptr service_provider_context); + explicit Shell(); void InitGPU(const base::Thread::Options& options); void InitUI(const base::Thread::Options& options); @@ -62,7 +54,6 @@ class Shell { scoped_refptr ui_task_runner_; scoped_refptr io_task_runner_; - scoped_ptr service_provider_context_; TracingController tracing_controller_; DISALLOW_COPY_AND_ASSIGN(Shell); diff --git a/sky/shell/shell_view.cc b/sky/shell/shell_view.cc index cdc5de297f4..a6860b8ad3a 100644 --- a/sky/shell/shell_view.cc +++ b/sky/shell/shell_view.cc @@ -39,7 +39,6 @@ ShellView::~ShellView() { void ShellView::CreateEngine() { Engine::Config config; - config.service_provider_context = shell_.service_provider_context(); config.gpu_task_runner = shell_.gpu_task_runner(); config.raster_callback = rasterizer_->GetRasterCallback(); engine_.reset(new Engine(config)); diff --git a/sky/shell/ui/engine.cc b/sky/shell/ui/engine.cc index 87ceb2f6510..5f6dbda1414 100644 --- a/sky/shell/ui/engine.cc +++ b/sky/shell/ui/engine.cc @@ -19,7 +19,6 @@ #include "sky/engine/public/web/WebRuntimeFeatures.h" #include "sky/shell/dart/dart_library_provider_files.h" #include "sky/shell/dart/dart_library_provider_network.h" -#include "sky/shell/service_provider.h" #include "sky/shell/switches.h" #include "sky/shell/switches.h" #include "sky/shell/ui/animator.h" @@ -64,15 +63,6 @@ Engine::Engine(const Config& config) activity_running_(false), have_surface_(false), weak_factory_(this) { - mojo::ServiceProviderPtr service_provider = - CreateServiceProvider(config.service_provider_context); - -#if defined(OS_ANDROID) || defined(OS_IOS) - // TODO(abarth): Implement VSyncProvider on other platforms. - vsync::VSyncProviderPtr vsync_provider; - mojo::ConnectToService(service_provider.get(), &vsync_provider); - animator_->set_vsync_provider(vsync_provider.Pass()); -#endif } Engine::~Engine() { @@ -130,6 +120,17 @@ void Engine::OnOutputSurfaceDestroyed(const base::Closure& gpu_continuation) { config_.gpu_task_runner->PostTask(FROM_HERE, gpu_continuation); } +void Engine::SetServices(ServicesDataPtr services) { + services_ = services.Pass(); + +#if defined(OS_ANDROID) || defined(OS_IOS) + // TODO(abarth): Implement VSyncProvider on other platforms. + vsync::VSyncProviderPtr vsync_provider; + mojo::ConnectToService(services_->services_provided_by_embedder.get(), &vsync_provider); + animator_->set_vsync_provider(vsync_provider.Pass()); +#endif +} + void Engine::OnViewportMetricsChanged(ViewportMetricsPtr metrics) { physical_size_.SetSize(metrics->physical_width, metrics->physical_height); @@ -242,9 +243,7 @@ void Engine::OnActivityResumed() { } void Engine::DidCreateIsolate(Dart_Isolate isolate) { - Internals::Create(isolate, - CreateServiceProvider(config_.service_provider_context), - root_bundle_.Pass()); + Internals::Create(isolate, services_.Pass(), root_bundle_.Pass()); } void Engine::StopAnimator() { diff --git a/sky/shell/ui/engine.h b/sky/shell/ui/engine.h index fb22c402326..f8cbc80467d 100644 --- a/sky/shell/ui/engine.h +++ b/sky/shell/ui/engine.h @@ -19,7 +19,6 @@ #include "sky/engine/public/sky/sky_view.h" #include "sky/engine/public/sky/sky_view_client.h" #include "sky/shell/rasterizer.h" -#include "sky/shell/service_provider.h" #include "sky/shell/ui_delegate.h" #include "third_party/skia/include/core/SkPicture.h" #include "ui/gfx/geometry/size.h" @@ -37,8 +36,6 @@ class Engine : public UIDelegate, Config(); ~Config(); - ServiceProviderContext* service_provider_context; - RasterCallback raster_callback; scoped_refptr gpu_task_runner; }; @@ -62,6 +59,7 @@ class Engine : public UIDelegate, void OnOutputSurfaceDestroyed(const base::Closure& gpu_continuation) override; // SkyEngine implementation: + void SetServices(ServicesDataPtr services) override; void OnViewportMetricsChanged(ViewportMetricsPtr metrics) override; void OnInputEvent(InputEventPtr event) override; void OnPointerPacket(pointer::PointerPacketPtr packet) override; @@ -92,6 +90,7 @@ class Engine : public UIDelegate, Config config_; scoped_ptr animator_; + ServicesDataPtr services_; mojo::asset_bundle::AssetBundlePtr root_bundle_; scoped_ptr dart_library_provider_; std::unique_ptr sky_view_; diff --git a/sky/shell/ui/internals.cc b/sky/shell/ui/internals.cc index 05adb76f624..24fe7f233a8 100644 --- a/sky/shell/ui/internals.cc +++ b/sky/shell/ui/internals.cc @@ -77,12 +77,12 @@ const uint8_t* GetSymbol(Dart_NativeFunction native_function) { } // namespace void Internals::Create(Dart_Isolate isolate, - mojo::ServiceProviderPtr service_provider, + ServicesDataPtr services, mojo::asset_bundle::AssetBundlePtr root_bundle) { EnsureNatives(); DartState* state = DartState::From(isolate); - state->SetUserData(&kInternalsKey, new Internals(service_provider.Pass(), + state->SetUserData(&kInternalsKey, new Internals(services.Pass(), root_bundle.Pass())); Dart_Handle library = Dart_LookupLibrary(ToDart("dart:ui_internals")); CHECK(!LogIfError(library)); @@ -90,14 +90,15 @@ void Internals::Create(Dart_Isolate isolate, library, GetNativeFunction, GetSymbol))); } -Internals::Internals(mojo::ServiceProviderPtr platform_service_provider, +Internals::Internals(ServicesDataPtr services, mojo::asset_bundle::AssetBundlePtr root_bundle) - : root_bundle_(root_bundle.Pass()), - service_provider_impl_(GetProxy(&service_provider_)), - - platform_service_provider_(platform_service_provider.Pass()) { - service_provider_impl_.set_fallback_service_provider( - platform_service_provider_.get()); + : services_(services.Pass()), + root_bundle_(root_bundle.Pass()), + service_provider_impl_(GetProxy(&service_provider_)) { + if (services_ && services_->services_provided_by_embedder) { + service_provider_impl_.set_fallback_service_provider( + services_->services_provided_by_embedder.get()); + } service_provider_impl_.AddService(this); // Currently we don't consume any services provided by the application. diff --git a/sky/shell/ui/internals.h b/sky/shell/ui/internals.h index 0d028cb06f6..db2e1c61167 100644 --- a/sky/shell/ui/internals.h +++ b/sky/shell/ui/internals.h @@ -11,6 +11,7 @@ #include "mojo/public/cpp/application/service_provider_impl.h" #include "mojo/public/interfaces/application/service_provider.mojom.h" #include "mojo/services/asset_bundle/interfaces/asset_bundle.mojom.h" +#include "sky/services/engine/sky_engine.mojom.h" namespace mojo { class ApplicationConnection; @@ -26,7 +27,7 @@ class Internals ~Internals() override; static void Create(Dart_Isolate isolate, - mojo::ServiceProviderPtr platform_service_provider, + ServicesDataPtr services, mojo::asset_bundle::AssetBundlePtr root_bundle); mojo::Handle TakeServicesProvidedByEmbedder(); @@ -34,7 +35,7 @@ class Internals mojo::Handle TakeServicesProvidedToEmbedder(); private: - explicit Internals(mojo::ServiceProviderPtr platform_service_provider, + explicit Internals(ServicesDataPtr services, mojo::asset_bundle::AssetBundlePtr root_bundle); // |mojo::InterfaceFactory| implementation: @@ -42,10 +43,11 @@ class Internals mojo::ApplicationConnection* connection, mojo::InterfaceRequest) override; + ServicesDataPtr services_; mojo::asset_bundle::AssetBundlePtr root_bundle_; + mojo::ServiceProviderPtr service_provider_; mojo::ServiceProviderImpl service_provider_impl_; - mojo::ServiceProviderPtr platform_service_provider_; // A ServiceProvider supplied by the application that exposes services to // the embedder.