Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1683)

Unified Diff: ash/mus/window_manager.cc

Issue 2302673002: mash: Avoid shelf crashes on display removal. (Closed)
Patch Set: minor cleanup. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/mus/window_manager.cc
diff --git a/ash/mus/window_manager.cc b/ash/mus/window_manager.cc
index 964a1dfeaa85851962ed4bc7231afc88b55bc18e..f85bcf7edbc0a544e1c4d363296f347558f8a75c 100644
--- a/ash/mus/window_manager.cc
+++ b/ash/mus/window_manager.cc
@@ -22,6 +22,7 @@
#include "ash/mus/shell_delegate_mus.h"
#include "ash/mus/window_manager_observer.h"
#include "ash/public/interfaces/container.mojom.h"
+#include "services/shell/public/cpp/connector.h"
#include "services/ui/common/event_matcher_util.h"
#include "services/ui/common/types.h"
#include "services/ui/public/cpp/property_type_converters.h"
@@ -32,16 +33,29 @@
#include "services/ui/public/interfaces/window_manager.mojom.h"
#include "ui/app_list/presenter/app_list_presenter.h"
#include "ui/base/hit_test.h"
+#include "ui/display/screen_base.h"
#include "ui/events/mojo/event.mojom.h"
#include "ui/views/mus/pointer_watcher_event_router.h"
-#include "ui/views/mus/screen_mus.h"
+#include "ui/views/mus/window_manager_frame_values.h"
+
+namespace mojo {
+
+template <>
+struct TypeConverter<views::WindowManagerFrameValues,
+ ui::mojom::FrameDecorationValuesPtr> {
+ static views::WindowManagerFrameValues Convert(
+ const ui::mojom::FrameDecorationValuesPtr& input) {
+ views::WindowManagerFrameValues result;
+ result.normal_insets = input->normal_client_area_insets;
+ result.maximized_insets = input->maximized_client_area_insets;
+ result.max_title_bar_button_width = input->max_title_bar_button_width;
+ return result;
+ }
+};
-namespace ash {
-namespace mus {
+} // namespace mojo
-void AssertTrue(bool success) {
- DCHECK(success);
-}
+namespace {
// TODO(jamescook): Port ash::sysui::AppListPresenterMus and eliminate this.
class AppListPresenterStub : public app_list::AppListPresenter {
@@ -66,8 +80,13 @@ class AppListPresenterStub : public app_list::AppListPresenter {
DISALLOW_COPY_AND_ASSIGN(AppListPresenterStub);
};
+} // namespace
+
+namespace ash {
+namespace mus {
+
WindowManager::WindowManager(shell::Connector* connector)
- : connector_(connector) {}
+ : connector_(connector), display_manager_observer_binding_(this) {}
WindowManager::~WindowManager() {
// NOTE: |window_tree_client_| may already be null.
@@ -161,11 +180,33 @@ void WindowManager::RemoveObserver(WindowManagerObserver* observer) {
RootWindowController* WindowManager::CreateRootWindowController(
ui::Window* window,
const display::Display& display) {
- // TODO(sky): there is timing issues with using ScreenMus.
+ // TODO(sky): There are timing issues with using ScreenBase.
if (!screen_) {
- std::unique_ptr<views::ScreenMus> screen(new views::ScreenMus(nullptr));
- screen->Init(connector_);
- screen_ = std::move(screen);
+ screen_.reset(new display::ScreenBase());
+
+ ui::mojom::DisplayManagerPtr display_manager;
+ connector_->ConnectToInterface("mojo:ui", &display_manager);
sky 2016/09/01 23:51:17 The windowmanager shouldn't need to connect to dis
+ display_manager->AddObserver(
+ display_manager_observer_binding_.CreateInterfacePtrAndBind());
+
+ // We need the set of displays before we can continue. Wait for it.
+ //
+ // TODO(rockot): Do something better here. This should not have to block
+ // tasks from running on the calling thread. http://crbug.com/594852.
+ bool success =
+ display_manager_observer_binding_.WaitForIncomingMethodCall();
+
+ // The WaitForIncomingMethodCall() should have supplied the set of Displays,
+ // unless mus is going down, in which case encountered_error() is true, or
+ // the call to WaitForIncomingMethodCall() failed.
+ if (screen_->display_list()->displays().empty()) {
+ DCHECK(display_manager.encountered_error() || !success);
+ // In this case we install a default display and assume the process is
+ // going to exit shortly so that the real value doesn't matter.
+ screen_->display_list()->AddDisplay(
+ display::Display(0xFFFFFFFF, gfx::Rect(0, 0, 801, 802)),
+ display::DisplayList::Type::PRIMARY);
+ }
}
std::unique_ptr<RootWindowController> root_window_controller_ptr(
@@ -251,8 +292,7 @@ bool WindowManager::OnWmSetProperty(
ui::Window* window,
const std::string& name,
std::unique_ptr<std::vector<uint8_t>>* new_data) {
- // TODO(sky): constrain this to set of keys we know about, and allowed
- // values.
+ // TODO(sky): constrain this to set of keys we know about, and allowed values.
return name == ui::mojom::WindowManager::kShowState_Property ||
name == ui::mojom::WindowManager::kPreferredSize_Property ||
name == ui::mojom::WindowManager::kResizeBehavior_Property ||
@@ -313,5 +353,52 @@ ui::mojom::EventResult WindowManager::OnAccelerator(uint32_t id,
return iter->second->OnAccelerator(id, event);
}
+void WindowManager::OnDisplays(
+ mojo::Array<ui::mojom::WsDisplayPtr> ws_displays) {
+ // This should only be called once from Init() before any observers have been
+ // added.
+ DCHECK(screen_->display_list()->displays().empty());
+ for (size_t i = 0; i < ws_displays.size(); ++i) {
+ const bool is_primary = ws_displays[i]->is_primary;
+ screen_->display_list()->AddDisplay(
+ ws_displays[i]->display, is_primary
+ ? display::DisplayList::Type::PRIMARY
+ : display::DisplayList::Type::NOT_PRIMARY);
+ if (is_primary) {
+ // TODO(sky): Make views::WindowManagerFrameValues per display.
+ views::WindowManagerFrameValues frame_values =
+ ws_displays[i]
+ ->frame_decoration_values.To<views::WindowManagerFrameValues>();
+ views::WindowManagerFrameValues::SetInstance(frame_values);
+ }
+ }
+ DCHECK(!screen_->display_list()->displays().empty());
+}
+
+void WindowManager::OnDisplaysChanged(
+ mojo::Array<ui::mojom::WsDisplayPtr> ws_displays) {
+ for (size_t i = 0; i < ws_displays.size(); ++i) {
+ const bool is_primary = ws_displays[i]->is_primary;
+ screen_->ProcessDisplayChanged(ws_displays[i]->display, is_primary);
+ if (is_primary) {
+ views::WindowManagerFrameValues frame_values =
+ ws_displays[i]
+ ->frame_decoration_values.To<views::WindowManagerFrameValues>();
+ views::WindowManagerFrameValues::SetInstance(frame_values);
+ }
+ }
+}
+
+void WindowManager::OnDisplayRemoved(int64_t id) {
+ // Shutdown the root window controller before removing the display.
+ for (auto& root_window_controller : root_window_controllers_) {
+ if (root_window_controller->display().id() == id) {
+ root_window_controller->Shutdown();
+ break;
+ }
+ }
+ screen_->display_list()->RemoveDisplay(id);
+}
+
} // namespace mus
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698