| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <memory> | 5 #include <memory> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "mash/public/interfaces/launchable.mojom.h" | 10 #include "mash/public/interfaces/launchable.mojom.h" |
| 11 #include "mojo/public/cpp/bindings/binding_set.h" | 11 #include "mojo/public/cpp/bindings/binding_set.h" |
| 12 #include "services/service_manager/public/c/main.h" | 12 #include "services/service_manager/public/c/main.h" |
| 13 #include "services/service_manager/public/cpp/binder_registry.h" |
| 13 #include "services/service_manager/public/cpp/connection.h" | 14 #include "services/service_manager/public/cpp/connection.h" |
| 14 #include "services/service_manager/public/cpp/connector.h" | 15 #include "services/service_manager/public/cpp/connector.h" |
| 15 #include "services/service_manager/public/cpp/interface_factory.h" | 16 #include "services/service_manager/public/cpp/interface_factory.h" |
| 16 #include "services/service_manager/public/cpp/interface_registry.h" | 17 #include "services/service_manager/public/cpp/interface_registry.h" |
| 17 #include "services/service_manager/public/cpp/service.h" | 18 #include "services/service_manager/public/cpp/service.h" |
| 18 #include "services/service_manager/public/cpp/service_context.h" | 19 #include "services/service_manager/public/cpp/service_context.h" |
| 19 #include "services/service_manager/public/cpp/service_runner.h" | 20 #include "services/service_manager/public/cpp/service_runner.h" |
| 20 #include "services/tracing/public/cpp/provider.h" | 21 #include "services/tracing/public/cpp/provider.h" |
| 21 #include "ui/views/examples/example_base.h" | 22 #include "ui/views/examples/example_base.h" |
| 22 #include "ui/views/examples/examples_window.h" | 23 #include "ui/views/examples/examples_window.h" |
| 23 #include "ui/views/mus/aura_init.h" | 24 #include "ui/views/mus/aura_init.h" |
| 24 | 25 |
| 25 class ViewsExamples | 26 class ViewsExamples |
| 26 : public service_manager::Service, | 27 : public service_manager::Service, |
| 27 public mash::mojom::Launchable, | 28 public mash::mojom::Launchable, |
| 28 public service_manager::InterfaceFactory<mash::mojom::Launchable> { | 29 public service_manager::InterfaceFactory<mash::mojom::Launchable> { |
| 29 public: | 30 public: |
| 30 ViewsExamples() {} | 31 ViewsExamples() { |
| 32 registry_.AddInterface<mash::mojom::Launchable>(this); |
| 33 } |
| 31 ~ViewsExamples() override {} | 34 ~ViewsExamples() override {} |
| 32 | 35 |
| 33 private: | 36 private: |
| 34 // service_manager::Service: | 37 // service_manager::Service: |
| 35 void OnStart() override { | 38 void OnStart() override { |
| 36 tracing_.Initialize(context()->connector(), context()->identity().name()); | 39 tracing_.Initialize(context()->connector(), context()->identity().name()); |
| 37 aura_init_ = base::MakeUnique<views::AuraInit>( | 40 aura_init_ = base::MakeUnique<views::AuraInit>( |
| 38 context()->connector(), context()->identity(), | 41 context()->connector(), context()->identity(), |
| 39 "views_mus_resources.pak", std::string(), nullptr, | 42 "views_mus_resources.pak", std::string(), nullptr, |
| 40 views::AuraInit::Mode::AURA_MUS); | 43 views::AuraInit::Mode::AURA_MUS); |
| 41 } | 44 } |
| 42 bool OnConnect(const service_manager::ServiceInfo& remote_info, | 45 void OnBindInterface(const service_manager::ServiceInfo& source_info, |
| 43 service_manager::InterfaceRegistry* registry) override { | 46 const std::string& interface_name, |
| 44 registry->AddInterface<mash::mojom::Launchable>(this); | 47 mojo::ScopedMessagePipeHandle interface_pipe) override { |
| 45 return true; | 48 registry_.BindInterface(source_info.identity, interface_name, |
| 49 std::move(interface_pipe)); |
| 46 } | 50 } |
| 47 | 51 |
| 48 // mash::mojom::Launchable: | 52 // mash::mojom::Launchable: |
| 49 void Launch(uint32_t what, mash::mojom::LaunchMode how) override { | 53 void Launch(uint32_t what, mash::mojom::LaunchMode how) override { |
| 50 views::examples::ShowExamplesWindow(views::examples::QUIT_ON_CLOSE); | 54 views::examples::ShowExamplesWindow(views::examples::QUIT_ON_CLOSE); |
| 51 } | 55 } |
| 52 | 56 |
| 53 // service_manager::InterfaceFactory<mash::mojom::Launchable>: | 57 // service_manager::InterfaceFactory<mash::mojom::Launchable>: |
| 54 void Create(const service_manager::Identity& remote_identity, | 58 void Create(const service_manager::Identity& remote_identity, |
| 55 mash::mojom::LaunchableRequest request) override { | 59 mash::mojom::LaunchableRequest request) override { |
| 56 bindings_.AddBinding(this, std::move(request)); | 60 bindings_.AddBinding(this, std::move(request)); |
| 57 } | 61 } |
| 58 | 62 |
| 59 mojo::BindingSet<mash::mojom::Launchable> bindings_; | 63 mojo::BindingSet<mash::mojom::Launchable> bindings_; |
| 60 | 64 |
| 65 service_manager::BinderRegistry registry_; |
| 66 |
| 61 tracing::Provider tracing_; | 67 tracing::Provider tracing_; |
| 62 std::unique_ptr<views::AuraInit> aura_init_; | 68 std::unique_ptr<views::AuraInit> aura_init_; |
| 63 | 69 |
| 64 DISALLOW_COPY_AND_ASSIGN(ViewsExamples); | 70 DISALLOW_COPY_AND_ASSIGN(ViewsExamples); |
| 65 }; | 71 }; |
| 66 | 72 |
| 67 MojoResult ServiceMain(MojoHandle service_request_handle) { | 73 MojoResult ServiceMain(MojoHandle service_request_handle) { |
| 68 return service_manager::ServiceRunner(new ViewsExamples) | 74 return service_manager::ServiceRunner(new ViewsExamples) |
| 69 .Run(service_request_handle); | 75 .Run(service_request_handle); |
| 70 } | 76 } |
| OLD | NEW |