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

Side by Side Diff: ui/views/mus/screen_mus.cc

Issue 1797153002: Reinstate wait-for-Initialize when Chrome is run in Mash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shell-client
Patch Set: fix views_mus_unittests too Created 4 years, 9 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 unified diff | Download patch
« no previous file with comments | « ui/views/mus/screen_mus.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/views/mus/screen_mus.h" 5 #include "ui/views/mus/screen_mus.h"
6 6
7 #include "mojo/converters/geometry/geometry_type_converters.h" 7 #include "mojo/converters/geometry/geometry_type_converters.h"
8 #include "mojo/shell/public/cpp/connection.h" 8 #include "mojo/shell/public/cpp/connection.h"
9 #include "mojo/shell/public/cpp/connector.h" 9 #include "mojo/shell/public/cpp/connector.h"
10 #include "ui/gfx/display_finder.h" 10 #include "ui/gfx/display_finder.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 void ScreenMus::Init(mojo::Connector* connector) { 77 void ScreenMus::Init(mojo::Connector* connector) {
78 gfx::Screen::SetScreenInstance(this); 78 gfx::Screen::SetScreenInstance(this);
79 79
80 connector->ConnectToInterface("mojo:mus", &display_manager_); 80 connector->ConnectToInterface("mojo:mus", &display_manager_);
81 81
82 display_manager_->AddObserver( 82 display_manager_->AddObserver(
83 display_manager_observer_binding_.CreateInterfacePtrAndBind()); 83 display_manager_observer_binding_.CreateInterfacePtrAndBind());
84 84
85 // We need the set of displays before we can continue. Wait for it. 85 // We need the set of displays before we can continue. Wait for it.
86 wait_for_displays_loop_.reset(new base::RunLoop); 86 //
87 wait_for_displays_loop_->Run(); 87 // TODO(rockot): Do something better here. This should not have to block tasks
88 // from running on the calling thread. http://crbug.com/594852.
89 display_manager_observer_binding_.WaitForIncomingMethodCall();
88 90
89 // The WaitForIncomingMethodCall() should have supplied the set of Displays. 91 // The WaitForIncomingMethodCall() should have supplied the set of Displays.
90 DCHECK(displays_.size()); 92 DCHECK(displays_.size());
91 } 93 }
92 94
93 int ScreenMus::FindDisplayIndexById(int64_t id) const { 95 int ScreenMus::FindDisplayIndexById(int64_t id) const {
94 for (size_t i = 0; i < displays_.size(); ++i) { 96 for (size_t i = 0; i < displays_.size(); ++i) {
95 if (displays_[i].id() == id) 97 if (displays_[i].id() == id)
96 return static_cast<int>(i); 98 return static_cast<int>(i);
97 } 99 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 displays_ = displays.To<std::vector<gfx::Display>>(); 199 displays_ = displays.To<std::vector<gfx::Display>>();
198 for (size_t i = 0; i < displays.size(); ++i) { 200 for (size_t i = 0; i < displays.size(); ++i) {
199 if (displays[i]->is_primary) { 201 if (displays[i]->is_primary) {
200 primary_display_index_ = static_cast<int>(i); 202 primary_display_index_ = static_cast<int>(i);
201 // TODO(sky): Make WindowManagerFrameValues per display. 203 // TODO(sky): Make WindowManagerFrameValues per display.
202 WindowManagerFrameValues frame_values = 204 WindowManagerFrameValues frame_values =
203 displays[i]->frame_decoration_values.To<WindowManagerFrameValues>(); 205 displays[i]->frame_decoration_values.To<WindowManagerFrameValues>();
204 WindowManagerFrameValues::SetInstance(frame_values); 206 WindowManagerFrameValues::SetInstance(frame_values);
205 } 207 }
206 } 208 }
207
208 DCHECK(wait_for_displays_loop_);
209 wait_for_displays_loop_->Quit();
210 } 209 }
211 210
212 void ScreenMus::OnDisplaysChanged( 211 void ScreenMus::OnDisplaysChanged(
213 mojo::Array<mus::mojom::DisplayPtr> transport_displays) { 212 mojo::Array<mus::mojom::DisplayPtr> transport_displays) {
214 for (size_t i = 0; i < transport_displays.size(); ++i) { 213 for (size_t i = 0; i < transport_displays.size(); ++i) {
215 const bool is_primary = transport_displays[i]->is_primary; 214 const bool is_primary = transport_displays[i]->is_primary;
216 ProcessDisplayChanged(transport_displays[i].To<gfx::Display>(), is_primary); 215 ProcessDisplayChanged(transport_displays[i].To<gfx::Display>(), is_primary);
217 if (is_primary) { 216 if (is_primary) {
218 WindowManagerFrameValues frame_values = 217 WindowManagerFrameValues frame_values =
219 transport_displays[i] 218 transport_displays[i]
220 ->frame_decoration_values.To<WindowManagerFrameValues>(); 219 ->frame_decoration_values.To<WindowManagerFrameValues>();
221 WindowManagerFrameValues::SetInstance(frame_values); 220 WindowManagerFrameValues::SetInstance(frame_values);
222 delegate_->OnWindowManagerFrameValuesChanged(); 221 delegate_->OnWindowManagerFrameValuesChanged();
223 } 222 }
224 } 223 }
225 } 224 }
226 225
227 void ScreenMus::OnDisplayRemoved(int64_t id) { 226 void ScreenMus::OnDisplayRemoved(int64_t id) {
228 const int index = FindDisplayIndexById(id); 227 const int index = FindDisplayIndexById(id);
229 DCHECK_NE(-1, index); 228 DCHECK_NE(-1, index);
230 // Another display must become primary before the existing primary is 229 // Another display must become primary before the existing primary is
231 // removed. 230 // removed.
232 DCHECK_NE(index, primary_display_index_); 231 DCHECK_NE(index, primary_display_index_);
233 const gfx::Display display = displays_[index]; 232 const gfx::Display display = displays_[index];
234 FOR_EACH_OBSERVER(gfx::DisplayObserver, observers_, 233 FOR_EACH_OBSERVER(gfx::DisplayObserver, observers_,
235 OnDisplayRemoved(display)); 234 OnDisplayRemoved(display));
236 } 235 }
237 236
238 } // namespace views 237 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/screen_mus.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698