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