Kris Giesing | 2ccd493 | 2015-11-20 10:07:46 -0800 | [diff] [blame] | 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 "base/macros.h" |
| 6 | #include "base/threading/sequenced_worker_pool.h" |
| 7 | #include "mojo/application/application_runner_chromium.h" |
| 8 | #include "mojo/public/c/system/main.h" |
| 9 | #include "mojo/public/cpp/application/application_connection.h" |
| 10 | #include "mojo/public/cpp/application/application_delegate.h" |
| 11 | #include "mojo/public/cpp/application/application_impl.h" |
| 12 | #include "mojo/public/cpp/application/connect.h" |
James Robinson | 854bd70 | 2016-02-01 11:27:53 -0800 | [diff] [blame] | 13 | #include "mojo/services/native_viewport/interfaces/native_viewport_event_dispatcher.mojom.h" |
Kris Giesing | 2ccd493 | 2015-11-20 10:07:46 -0800 | [diff] [blame] | 14 | #include "services/keyboard/linux/keyboard_service_impl.h" |
| 15 | |
| 16 | namespace keyboard { |
| 17 | |
| 18 | class KeyboardServiceFactoryImpl : public keyboard::KeyboardServiceFactory { |
| 19 | public: |
| 20 | explicit KeyboardServiceFactoryImpl( |
| 21 | mojo::InterfaceRequest<KeyboardServiceFactory> request) |
| 22 | : binding_(this, request.Pass()) {} |
| 23 | |
Viet-Trung Luu | 688f68e | 2016-05-13 14:12:04 -0700 | [diff] [blame^] | 24 | // |keyboard::KeyboardServiceFactory| implementation: |
Kris Giesing | 2ccd493 | 2015-11-20 10:07:46 -0800 | [diff] [blame] | 25 | void CreateKeyboardService( |
| 26 | mojo::InterfaceRequest<mojo::NativeViewportEventDispatcher> dispatcher, |
| 27 | mojo::InterfaceRequest<KeyboardService> request) override { |
| 28 | new LinuxKeyboardServiceImpl(request.Pass(), dispatcher.Pass()); |
| 29 | } |
| 30 | |
| 31 | private: |
| 32 | mojo::StrongBinding<keyboard::KeyboardServiceFactory> binding_; |
| 33 | |
| 34 | DISALLOW_COPY_AND_ASSIGN(KeyboardServiceFactoryImpl); |
| 35 | }; |
| 36 | |
Viet-Trung Luu | 688f68e | 2016-05-13 14:12:04 -0700 | [diff] [blame^] | 37 | class KeyboardServiceApp : public mojo::ApplicationDelegate { |
Kris Giesing | 2ccd493 | 2015-11-20 10:07:46 -0800 | [diff] [blame] | 38 | public: |
| 39 | KeyboardServiceApp() {} |
| 40 | ~KeyboardServiceApp() override {} |
| 41 | |
| 42 | private: |
| 43 | |
| 44 | // |ApplicationDelegate| override: |
| 45 | bool ConfigureIncomingConnection( |
| 46 | mojo::ApplicationConnection* connection) override { |
Viet-Trung Luu | 688f68e | 2016-05-13 14:12:04 -0700 | [diff] [blame^] | 47 | connection->GetServiceProviderImpl().AddService<KeyboardServiceFactory>([]( |
| 48 | const mojo::ConnectionContext& connection_context, |
| 49 | mojo::InterfaceRequest<KeyboardServiceFactory> |
| 50 | keyboard_service_factory_request) { |
| 51 | new KeyboardServiceFactoryImpl(keyboard_service_factory_request.Pass()); |
| 52 | }); |
Kris Giesing | 2ccd493 | 2015-11-20 10:07:46 -0800 | [diff] [blame] | 53 | return true; |
| 54 | } |
| 55 | |
Kris Giesing | 2ccd493 | 2015-11-20 10:07:46 -0800 | [diff] [blame] | 56 | private: |
Kris Giesing | 2ccd493 | 2015-11-20 10:07:46 -0800 | [diff] [blame] | 57 | DISALLOW_COPY_AND_ASSIGN(KeyboardServiceApp); |
| 58 | }; |
| 59 | |
| 60 | } // namespace keyboard |
| 61 | |
| 62 | MojoResult MojoMain(MojoHandle application_request) { |
| 63 | mojo::ApplicationRunnerChromium runner( |
| 64 | new keyboard::KeyboardServiceApp()); |
| 65 | return runner.Run(application_request); |
| 66 | } |