| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "ash/mus/window_manager_application.h" | 5 #include "ash/mus/window_manager_application.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/mojo_interface_factory.h" | 9 #include "ash/mojo_interface_factory.h" |
| 10 #include "ash/mus/network_connect_delegate_mus.h" | 10 #include "ash/mus/network_connect_delegate_mus.h" |
| 11 #include "ash/mus/window_manager.h" | 11 #include "ash/mus/window_manager.h" |
| 12 #include "ash/public/cpp/config.h" | 12 #include "ash/public/cpp/config.h" |
| 13 #include "ash/shell_delegate.h" | |
| 14 #include "ash/system/power/power_status.h" | 13 #include "ash/system/power/power_status.h" |
| 15 #include "base/bind.h" | 14 #include "base/bind.h" |
| 16 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 17 #include "base/threading/sequenced_worker_pool.h" | 16 #include "base/threading/sequenced_worker_pool.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "chromeos/audio/cras_audio_handler.h" | 18 #include "chromeos/audio/cras_audio_handler.h" |
| 20 #include "chromeos/dbus/dbus_thread_manager.h" | 19 #include "chromeos/dbus/dbus_thread_manager.h" |
| 21 #include "chromeos/network/network_connect.h" | 20 #include "chromeos/network/network_connect.h" |
| 22 #include "chromeos/network/network_handler.h" | 21 #include "chromeos/network/network_handler.h" |
| 23 #include "chromeos/system/fake_statistics_provider.h" | 22 #include "chromeos/system/fake_statistics_provider.h" |
| 24 #include "device/bluetooth/bluetooth_adapter_factory.h" | 23 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 25 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 24 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 26 #include "services/service_manager/public/cpp/connector.h" | 25 #include "services/service_manager/public/cpp/connector.h" |
| 27 #include "services/service_manager/public/cpp/service_context.h" | 26 #include "services/service_manager/public/cpp/service_context.h" |
| 28 #include "services/tracing/public/cpp/provider.h" | 27 #include "services/tracing/public/cpp/provider.h" |
| 29 #include "services/ui/common/accelerator_util.h" | 28 #include "services/ui/common/accelerator_util.h" |
| 30 #include "ui/aura/env.h" | 29 #include "ui/aura/env.h" |
| 31 #include "ui/aura/mus/window_tree_client.h" | 30 #include "ui/aura/mus/window_tree_client.h" |
| 32 #include "ui/events/event.h" | 31 #include "ui/events/event.h" |
| 33 #include "ui/message_center/message_center.h" | 32 #include "ui/message_center/message_center.h" |
| 34 #include "ui/views/mus/aura_init.h" | 33 #include "ui/views/mus/aura_init.h" |
| 35 | 34 |
| 36 namespace ash { | 35 namespace ash { |
| 37 namespace mus { | 36 namespace mus { |
| 38 | 37 |
| 39 WindowManagerApplication::WindowManagerApplication( | 38 WindowManagerApplication::WindowManagerApplication() {} |
| 40 bool show_primary_host_on_connect, | |
| 41 Config ash_config, | |
| 42 std::unique_ptr<ash::ShellDelegate> shell_delegate) | |
| 43 : show_primary_host_on_connect_(show_primary_host_on_connect), | |
| 44 shell_delegate_(std::move(shell_delegate)), | |
| 45 ash_config_(ash_config) {} | |
| 46 | 39 |
| 47 WindowManagerApplication::~WindowManagerApplication() { | 40 WindowManagerApplication::~WindowManagerApplication() { |
| 48 // Destroy the WindowManager while still valid. This way we ensure | 41 // Destroy the WindowManager while still valid. This way we ensure |
| 49 // OnWillDestroyRootWindowController() is called (if it hasn't been already). | 42 // OnWillDestroyRootWindowController() is called (if it hasn't been already). |
| 50 window_manager_.reset(); | 43 window_manager_.reset(); |
| 51 | 44 |
| 52 if (blocking_pool_) { | 45 if (blocking_pool_) { |
| 53 // Like BrowserThreadImpl, the goal is to make it impossible for ash to | 46 // Like BrowserThreadImpl, the goal is to make it impossible for ash to |
| 54 // 'infinite loop' during shutdown, but to reasonably expect that all | 47 // 'infinite loop' during shutdown, but to reasonably expect that all |
| 55 // BLOCKING_SHUTDOWN tasks queued during shutdown get run. There's nothing | 48 // BLOCKING_SHUTDOWN tasks queued during shutdown get run. There's nothing |
| 56 // particularly scientific about the number chosen. | 49 // particularly scientific about the number chosen. |
| 57 const int kMaxNewShutdownBlockingTasks = 1000; | 50 const int kMaxNewShutdownBlockingTasks = 1000; |
| 58 blocking_pool_->Shutdown(kMaxNewShutdownBlockingTasks); | 51 blocking_pool_->Shutdown(kMaxNewShutdownBlockingTasks); |
| 59 } | 52 } |
| 60 | 53 |
| 61 statistics_provider_.reset(); | 54 statistics_provider_.reset(); |
| 62 ShutdownComponents(); | 55 ShutdownComponents(); |
| 63 } | 56 } |
| 64 | 57 |
| 65 service_manager::Connector* WindowManagerApplication::GetConnector() { | |
| 66 return context() ? context()->connector() : nullptr; | |
| 67 } | |
| 68 | |
| 69 void WindowManagerApplication::InitWindowManager( | 58 void WindowManagerApplication::InitWindowManager( |
| 70 std::unique_ptr<aura::WindowTreeClient> window_tree_client, | 59 std::unique_ptr<aura::WindowTreeClient> window_tree_client, |
| 71 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, | 60 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, |
| 72 bool init_network_handler) { | 61 bool init_network_handler) { |
| 73 // Tests may have already set the WindowTreeClient. | 62 // Tests may have already set the WindowTreeClient. |
| 74 if (!aura::Env::GetInstance()->HasWindowTreeClient()) | 63 if (!aura::Env::GetInstance()->HasWindowTreeClient()) |
| 75 aura::Env::GetInstance()->SetWindowTreeClient(window_tree_client.get()); | 64 aura::Env::GetInstance()->SetWindowTreeClient(window_tree_client.get()); |
| 76 InitializeComponents(init_network_handler); | 65 InitializeComponents(init_network_handler); |
| 77 | 66 |
| 78 // TODO(jamescook): Refactor StatisticsProvider so we can get just the data | 67 // TODO(jamescook): Refactor StatisticsProvider so we can get just the data |
| 79 // we need in ash. Right now StatisticsProviderImpl launches the crossystem | 68 // we need in ash. Right now StatisticsProviderImpl launches the crossystem |
| 80 // binary to get system data, which we don't want to do twice on startup. | 69 // binary to get system data, which we don't want to do twice on startup. |
| 81 statistics_provider_.reset( | 70 statistics_provider_.reset( |
| 82 new chromeos::system::ScopedFakeStatisticsProvider()); | 71 new chromeos::system::ScopedFakeStatisticsProvider()); |
| 83 statistics_provider_->SetMachineStatistic("initial_locale", "en-US"); | 72 statistics_provider_->SetMachineStatistic("initial_locale", "en-US"); |
| 84 statistics_provider_->SetMachineStatistic("keyboard_layout", ""); | 73 statistics_provider_->SetMachineStatistic("keyboard_layout", ""); |
| 85 | 74 |
| 86 window_manager_->Init(std::move(window_tree_client), blocking_pool, | 75 window_manager_->Init(std::move(window_tree_client), blocking_pool); |
| 87 std::move(shell_delegate_)); | |
| 88 } | 76 } |
| 89 | 77 |
| 90 void WindowManagerApplication::InitializeComponents(bool init_network_handler) { | 78 void WindowManagerApplication::InitializeComponents(bool init_network_handler) { |
| 91 message_center::MessageCenter::Initialize(); | 79 message_center::MessageCenter::Initialize(); |
| 92 | 80 |
| 93 // Must occur after mojo::ApplicationRunner has initialized AtExitManager, but | 81 // Must occur after mojo::ApplicationRunner has initialized AtExitManager, but |
| 94 // before WindowManager::Init(). | 82 // before WindowManager::Init(). |
| 95 chromeos::DBusThreadManager::Initialize( | 83 chromeos::DBusThreadManager::Initialize( |
| 96 chromeos::DBusThreadManager::PROCESS_ASH); | 84 chromeos::DBusThreadManager::PROCESS_ASH); |
| 97 | 85 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 122 } | 110 } |
| 123 | 111 |
| 124 void WindowManagerApplication::OnStart() { | 112 void WindowManagerApplication::OnStart() { |
| 125 mojo_interface_factory::RegisterInterfaces( | 113 mojo_interface_factory::RegisterInterfaces( |
| 126 ®istry_, base::ThreadTaskRunnerHandle::Get()); | 114 ®istry_, base::ThreadTaskRunnerHandle::Get()); |
| 127 | 115 |
| 128 aura_init_ = base::MakeUnique<views::AuraInit>( | 116 aura_init_ = base::MakeUnique<views::AuraInit>( |
| 129 context()->connector(), context()->identity(), "ash_mus_resources.pak", | 117 context()->connector(), context()->identity(), "ash_mus_resources.pak", |
| 130 "ash_mus_resources_200.pak", nullptr, | 118 "ash_mus_resources_200.pak", nullptr, |
| 131 views::AuraInit::Mode::AURA_MUS_WINDOW_MANAGER); | 119 views::AuraInit::Mode::AURA_MUS_WINDOW_MANAGER); |
| 132 window_manager_ = base::MakeUnique<WindowManager>( | 120 window_manager_ = |
| 133 context()->connector(), ash_config_, show_primary_host_on_connect_); | 121 base::MakeUnique<WindowManager>(context()->connector(), Config::MASH); |
| 134 | 122 |
| 135 tracing_.Initialize(context()->connector(), context()->identity().name()); | 123 tracing_.Initialize(context()->connector(), context()->identity().name()); |
| 136 | 124 |
| 137 std::unique_ptr<aura::WindowTreeClient> window_tree_client = | 125 std::unique_ptr<aura::WindowTreeClient> window_tree_client = |
| 138 base::MakeUnique<aura::WindowTreeClient>( | 126 base::MakeUnique<aura::WindowTreeClient>( |
| 139 context()->connector(), window_manager_.get(), window_manager_.get()); | 127 context()->connector(), window_manager_.get(), window_manager_.get()); |
| 140 const bool automatically_create_display_roots = | 128 window_tree_client->ConnectAsWindowManager(); |
| 141 window_manager_->config() == Config::MASH; | |
| 142 window_tree_client->ConnectAsWindowManager( | |
| 143 automatically_create_display_roots); | |
| 144 | 129 |
| 145 const size_t kMaxNumberThreads = 3u; // Matches that of content. | 130 const size_t kMaxNumberThreads = 3u; // Matches that of content. |
| 146 const char kThreadNamePrefix[] = "MashBlocking"; | 131 const char kThreadNamePrefix[] = "MashBlocking"; |
| 147 blocking_pool_ = new base::SequencedWorkerPool( | 132 blocking_pool_ = new base::SequencedWorkerPool( |
| 148 kMaxNumberThreads, kThreadNamePrefix, base::TaskPriority::USER_VISIBLE); | 133 kMaxNumberThreads, kThreadNamePrefix, base::TaskPriority::USER_VISIBLE); |
| 149 const bool init_network_handler = true; | 134 const bool init_network_handler = true; |
| 150 InitWindowManager(std::move(window_tree_client), blocking_pool_, | 135 InitWindowManager(std::move(window_tree_client), blocking_pool_, |
| 151 init_network_handler); | 136 init_network_handler); |
| 152 } | 137 } |
| 153 | 138 |
| 154 void WindowManagerApplication::OnBindInterface( | 139 void WindowManagerApplication::OnBindInterface( |
| 155 const service_manager::ServiceInfo& source_info, | 140 const service_manager::ServiceInfo& source_info, |
| 156 const std::string& interface_name, | 141 const std::string& interface_name, |
| 157 mojo::ScopedMessagePipeHandle interface_pipe) { | 142 mojo::ScopedMessagePipeHandle interface_pipe) { |
| 158 registry_.BindInterface(source_info.identity, interface_name, | 143 registry_.BindInterface(source_info.identity, interface_name, |
| 159 std::move(interface_pipe)); | 144 std::move(interface_pipe)); |
| 160 } | 145 } |
| 161 | 146 |
| 162 } // namespace mus | 147 } // namespace mus |
| 163 } // namespace ash | 148 } // namespace ash |
| OLD | NEW |