OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <windows.h> |
| 6 |
| 7 #include "base/at_exit.h" |
| 8 #include "base/command_line.h" |
| 9 #include "base/debug/stack_trace.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/process/launch.h" |
| 13 #include "base/threading/thread.h" |
| 14 #include "build/build_config.h" |
| 15 #include "mojo/application/public/cpp/application_connection.h" |
| 16 #include "mojo/application/public/cpp/application_delegate.h" |
| 17 #include "mojo/application/public/cpp/application_impl.h" |
| 18 #include "mojo/application/public/cpp/interface_factory.h" |
| 19 #include "mojo/application/public/interfaces/application.mojom.h" |
| 20 #include "mojo/common/weak_binding_set.h" |
| 21 #include "mojo/message_pump/message_pump_mojo.h" |
| 22 #include "mojo/runner/child/runner_connection.h" |
| 23 #include "mojo/runner/child/test_native_service.mojom.h" |
| 24 #include "mojo/runner/init.h" |
| 25 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" |
| 26 #include "third_party/mojo/src/mojo/edk/embedder/process_delegate.h" |
| 27 |
| 28 namespace { |
| 29 |
| 30 class EDKState : public mojo::embedder::ProcessDelegate { |
| 31 public: |
| 32 EDKState() : io_thread_("io_thread") { |
| 33 mojo::embedder::Init(); |
| 34 |
| 35 // Create and start our I/O thread. |
| 36 base::Thread::Options io_thread_options(base::MessageLoop::TYPE_IO, 0); |
| 37 CHECK(io_thread_.StartWithOptions(io_thread_options)); |
| 38 io_runner_ = io_thread_.task_runner().get(); |
| 39 CHECK(io_runner_.get()); |
| 40 |
| 41 // TODO(vtl): This should be SLAVE, not NONE. |
| 42 mojo::embedder::InitIPCSupport(mojo::embedder::ProcessType::NONE, |
| 43 io_runner_, this, io_runner_, |
| 44 mojo::embedder::ScopedPlatformHandle()); |
| 45 } |
| 46 ~EDKState() override { mojo::embedder::ShutdownIPCSupport(); } |
| 47 |
| 48 private: |
| 49 // mojo::embedder::ProcessDelegate: |
| 50 void OnShutdownComplete() override {} |
| 51 |
| 52 base::Thread io_thread_; |
| 53 scoped_refptr<base::SingleThreadTaskRunner> io_runner_; |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(EDKState); |
| 56 }; |
| 57 |
| 58 class TargetApplicationDelegate |
| 59 : public mojo::ApplicationDelegate, |
| 60 public mojo::runner::test::TestNativeService, |
| 61 public mojo::InterfaceFactory<mojo::runner::test::TestNativeService> { |
| 62 public: |
| 63 TargetApplicationDelegate() {} |
| 64 ~TargetApplicationDelegate() override {} |
| 65 |
| 66 private: |
| 67 // mojo::ApplicationDelegate: |
| 68 void Initialize(mojo::ApplicationImpl* app) override {} |
| 69 bool ConfigureIncomingConnection( |
| 70 mojo::ApplicationConnection* connection) override { |
| 71 connection->AddService<mojo::runner::test::TestNativeService>(this); |
| 72 return true; |
| 73 } |
| 74 |
| 75 // mojo::runner::test::TestNativeService: |
| 76 void Invert(bool from_driver, const InvertCallback& callback) override { |
| 77 callback.Run(!from_driver); |
| 78 } |
| 79 |
| 80 // mojo::InterfaceFactory<mojo::runner::test::TestNativeService>: |
| 81 void Create(mojo::ApplicationConnection* connection, |
| 82 mojo::InterfaceRequest<mojo::runner::test::TestNativeService> |
| 83 request) override { |
| 84 bindings_.AddBinding(this, request.Pass()); |
| 85 } |
| 86 |
| 87 mojo::WeakBindingSet<mojo::runner::test::TestNativeService> bindings_; |
| 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(TargetApplicationDelegate); |
| 90 }; |
| 91 |
| 92 } // namespace |
| 93 |
| 94 int main(int argc, char** argv) { |
| 95 base::AtExitManager at_exit; |
| 96 base::CommandLine::Init(argc, argv); |
| 97 |
| 98 mojo::runner::InitializeLogging(); |
| 99 mojo::runner::WaitForDebuggerIfNecessary(); |
| 100 |
| 101 #if !defined(OFFICIAL_BUILD) |
| 102 base::debug::EnableInProcessStackDumping(); |
| 103 #if defined(OS_WIN) |
| 104 base::RouteStdioToConsole(false); |
| 105 #endif |
| 106 #endif |
| 107 |
| 108 { |
| 109 EDKState edk; |
| 110 |
| 111 mojo::InterfaceRequest<mojo::Application> application_request; |
| 112 scoped_ptr<mojo::runner::RunnerConnection> connection( |
| 113 mojo::runner::RunnerConnection::ConnectToRunner(&application_request)); |
| 114 |
| 115 TargetApplicationDelegate delegate; |
| 116 { |
| 117 base::MessageLoop loop(mojo::common::MessagePumpMojo::Create()); |
| 118 mojo::ApplicationImpl impl(&delegate, application_request.Pass()); |
| 119 loop.Run(); |
| 120 } |
| 121 |
| 122 connection.reset(); |
| 123 } |
| 124 |
| 125 return 0; |
| 126 } |
OLD | NEW |