Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 "ash/mus/window_manager_application.h" | |
| 6 #include "ash/shell.h" | |
| 7 #include "ash/shell/example_app_list_presenter.h" | |
| 8 #include "ash/shell/example_session_controller_client.h" | |
| 9 #include "ash/shell/shell_delegate_impl.h" | |
| 10 #include "ash/shell/window_type_launcher.h" | |
| 11 #include "ash/shell/window_watcher.h" | |
| 12 #include "ash/shell_observer.h" | |
| 13 #include "base/bind.h" | |
| 14 #include "base/bind_helpers.h" | |
| 15 #include "base/memory/ptr_util.h" | |
| 16 #include "services/service_manager/public/c/main.h" | |
| 17 #include "services/service_manager/public/cpp/connector.h" | |
| 18 #include "services/service_manager/public/cpp/service_runner.h" | |
| 19 #include "services/ui/public/cpp/input_devices/input_device_client.h" | |
| 20 #include "services/ui/public/interfaces/constants.mojom.h" | |
| 21 #include "ui/app_list/presenter/app_list.h" | |
| 22 #include "ui/aura/window.h" | |
| 23 #include "ui/aura/window_tree_host.h" | |
| 24 #include "ui/display/screen.h" | |
| 25 #include "ui/views/examples/examples_window.h" | |
| 26 | |
| 27 namespace { | |
| 28 | |
| 29 void ShowViewsExamples() { | |
| 30 views::examples::ShowExamplesWindow(views::examples::DO_NOTHING_ON_CLOSE); | |
| 31 } | |
| 32 | |
| 33 class ShellInit : public ash::shell::ShellDelegateImpl, | |
| 34 public ash::ShellObserver { | |
| 35 public: | |
| 36 ShellInit() { | |
| 37 input_device_client_ = base::MakeUnique<ui::InputDeviceClient>(); | |
|
kylechar
2017/04/26 16:41:44
nit: move to initializer list.
sky
2017/04/26 19:36:41
Moved to separate cl.
| |
| 38 } | |
| 39 ~ShellInit() override = default; | |
| 40 | |
| 41 void set_window_manager_app(ash::mus::WindowManagerApplication* app) { | |
| 42 window_manager_app_ = app; | |
| 43 } | |
| 44 | |
| 45 // ash::shell::ShellDelegateImpl: | |
| 46 void PreInit() override { | |
| 47 DCHECK(window_manager_app_->GetConnector()); | |
| 48 ui::mojom::InputDeviceServerPtr server; | |
| 49 window_manager_app_->GetConnector()->BindInterface(ui::mojom::kServiceName, | |
| 50 &server); | |
| 51 input_device_client_->Connect(std::move(server)); | |
| 52 | |
| 53 ash::shell::ShellDelegateImpl::PreInit(); | |
| 54 ash::Shell::Get()->AddShellObserver(this); | |
| 55 } | |
| 56 | |
| 57 // ash::ShellObserver: | |
| 58 void OnShellInitialized() override { | |
| 59 ash::Shell::Get()->RemoveShellObserver(this); | |
| 60 | |
| 61 // Initialize session controller client and create fake user sessions. The | |
| 62 // fake user sessions makes ash into the logged in state. | |
| 63 example_session_controller_client_ = | |
| 64 base::MakeUnique<ash::shell::ExampleSessionControllerClient>( | |
| 65 ash::Shell::Get()->session_controller()); | |
| 66 example_session_controller_client_->Initialize(); | |
| 67 | |
| 68 window_watcher_ = base::MakeUnique<ash::shell::WindowWatcher>(); | |
| 69 display::Screen::GetScreen()->AddObserver(window_watcher_.get()); | |
| 70 ash::shell::InitWindowTypeLauncher(base::Bind(&ShowViewsExamples)); | |
| 71 | |
| 72 // Initialize the example app list presenter. | |
| 73 example_app_list_presenter_ = | |
| 74 base::MakeUnique<ash::shell::ExampleAppListPresenter>(); | |
| 75 ash::Shell::Get()->app_list()->SetAppListPresenter( | |
| 76 example_app_list_presenter_->CreateInterfacePtrAndBind()); | |
| 77 | |
| 78 ash::Shell::GetPrimaryRootWindow()->GetHost()->Show(); | |
| 79 } | |
| 80 | |
| 81 private: | |
| 82 std::unique_ptr<ash::shell::ExampleAppListPresenter> | |
| 83 example_app_list_presenter_; | |
| 84 std::unique_ptr<ash::shell::WindowWatcher> window_watcher_; | |
| 85 std::unique_ptr<ash::shell::ExampleSessionControllerClient> | |
| 86 example_session_controller_client_; | |
| 87 std::unique_ptr<ui::InputDeviceClient> input_device_client_; | |
| 88 ash::mus::WindowManagerApplication* window_manager_app_ = nullptr; | |
| 89 | |
| 90 DISALLOW_COPY_AND_ASSIGN(ShellInit); | |
| 91 }; | |
| 92 | |
| 93 } // namespace | |
| 94 | |
| 95 MojoResult ServiceMain(MojoHandle service_request_handle) { | |
| 96 const bool show_primary_host_on_connect = false; | |
| 97 std::unique_ptr<ShellInit> shell_init_ptr = base::MakeUnique<ShellInit>(); | |
| 98 ShellInit* shell_init = shell_init_ptr.get(); | |
| 99 ash::mus::WindowManagerApplication* window_manager_app = | |
| 100 new ash::mus::WindowManagerApplication(show_primary_host_on_connect, | |
| 101 ash::Config::MUS, | |
| 102 std::move(shell_init_ptr)); | |
| 103 shell_init->set_window_manager_app(window_manager_app); | |
| 104 service_manager::ServiceRunner runner(window_manager_app); | |
| 105 return runner.Run(service_request_handle); | |
| 106 } | |
| OLD | NEW |