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

Side by Side Diff: services/ui/public/cpp/window_tree_client.cc

Issue 2259823003: Re-write many calls to WrapUnique() with MakeUnique() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "services/ui/public/cpp/window_tree_client.h" 5 #include "services/ui/public/cpp/window_tree_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 167
168 void WindowTreeClient::WaitForEmbed() { 168 void WindowTreeClient::WaitForEmbed() {
169 DCHECK(roots_.empty()); 169 DCHECK(roots_.empty());
170 // OnEmbed() is the first function called. 170 // OnEmbed() is the first function called.
171 binding_.WaitForIncomingMethodCall(); 171 binding_.WaitForIncomingMethodCall();
172 // TODO(sky): deal with pipe being closed before we get OnEmbed(). 172 // TODO(sky): deal with pipe being closed before we get OnEmbed().
173 } 173 }
174 174
175 void WindowTreeClient::DestroyWindow(Window* window) { 175 void WindowTreeClient::DestroyWindow(Window* window) {
176 DCHECK(tree_); 176 DCHECK(tree_);
177 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( 177 const uint32_t change_id = ScheduleInFlightChange(
178 new CrashInFlightChange(window, ChangeType::DELETE_WINDOW))); 178 base::MakeUnique<CrashInFlightChange>(window, ChangeType::DELETE_WINDOW));
179 tree_->DeleteWindow(change_id, server_id(window)); 179 tree_->DeleteWindow(change_id, server_id(window));
180 } 180 }
181 181
182 void WindowTreeClient::AddChild(Window* parent, Id child_id) { 182 void WindowTreeClient::AddChild(Window* parent, Id child_id) {
183 DCHECK(tree_); 183 DCHECK(tree_);
184 const uint32_t change_id = ScheduleInFlightChange( 184 const uint32_t change_id = ScheduleInFlightChange(
185 base::WrapUnique(new CrashInFlightChange(parent, ChangeType::ADD_CHILD))); 185 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::ADD_CHILD));
186 tree_->AddWindow(change_id, parent->server_id(), child_id); 186 tree_->AddWindow(change_id, parent->server_id(), child_id);
187 } 187 }
188 188
189 void WindowTreeClient::RemoveChild(Window* parent, Id child_id) { 189 void WindowTreeClient::RemoveChild(Window* parent, Id child_id) {
190 DCHECK(tree_); 190 DCHECK(tree_);
191 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( 191 const uint32_t change_id = ScheduleInFlightChange(
192 new CrashInFlightChange(parent, ChangeType::REMOVE_CHILD))); 192 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::REMOVE_CHILD));
193 tree_->RemoveWindowFromParent(change_id, child_id); 193 tree_->RemoveWindowFromParent(change_id, child_id);
194 } 194 }
195 195
196 void WindowTreeClient::AddTransientWindow(Window* window, 196 void WindowTreeClient::AddTransientWindow(Window* window,
197 Id transient_window_id) { 197 Id transient_window_id) {
198 DCHECK(tree_); 198 DCHECK(tree_);
199 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( 199 const uint32_t change_id =
200 new CrashInFlightChange(window, ChangeType::ADD_TRANSIENT_WINDOW))); 200 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>(
201 window, ChangeType::ADD_TRANSIENT_WINDOW));
201 tree_->AddTransientWindow(change_id, server_id(window), transient_window_id); 202 tree_->AddTransientWindow(change_id, server_id(window), transient_window_id);
202 } 203 }
203 204
204 void WindowTreeClient::RemoveTransientWindowFromParent(Window* window) { 205 void WindowTreeClient::RemoveTransientWindowFromParent(Window* window) {
205 DCHECK(tree_); 206 DCHECK(tree_);
206 const uint32_t change_id = 207 const uint32_t change_id =
207 ScheduleInFlightChange(base::WrapUnique(new CrashInFlightChange( 208 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>(
208 window, ChangeType::REMOVE_TRANSIENT_WINDOW_FROM_PARENT))); 209 window, ChangeType::REMOVE_TRANSIENT_WINDOW_FROM_PARENT));
209 tree_->RemoveTransientWindowFromParent(change_id, server_id(window)); 210 tree_->RemoveTransientWindowFromParent(change_id, server_id(window));
210 } 211 }
211 212
212 void WindowTreeClient::SetModal(Window* window) { 213 void WindowTreeClient::SetModal(Window* window) {
213 DCHECK(tree_); 214 DCHECK(tree_);
214 const uint32_t change_id = ScheduleInFlightChange( 215 const uint32_t change_id =
215 base::WrapUnique(new InFlightSetModalChange(window))); 216 ScheduleInFlightChange(base::MakeUnique<InFlightSetModalChange>(window));
216 tree_->SetModal(change_id, server_id(window)); 217 tree_->SetModal(change_id, server_id(window));
217 } 218 }
218 219
219 void WindowTreeClient::Reorder(Window* window, 220 void WindowTreeClient::Reorder(Window* window,
220 Id relative_window_id, 221 Id relative_window_id,
221 mojom::OrderDirection direction) { 222 mojom::OrderDirection direction) {
222 DCHECK(tree_); 223 DCHECK(tree_);
223 const uint32_t change_id = ScheduleInFlightChange( 224 const uint32_t change_id = ScheduleInFlightChange(
224 base::WrapUnique(new CrashInFlightChange(window, ChangeType::REORDER))); 225 base::MakeUnique<CrashInFlightChange>(window, ChangeType::REORDER));
225 tree_->ReorderWindow(change_id, server_id(window), relative_window_id, 226 tree_->ReorderWindow(change_id, server_id(window), relative_window_id,
226 direction); 227 direction);
227 } 228 }
228 229
229 bool WindowTreeClient::OwnsWindow(Window* window) const { 230 bool WindowTreeClient::OwnsWindow(Window* window) const {
230 // Windows created via CreateTopLevelWindow() are not owned by us, but have 231 // Windows created via CreateTopLevelWindow() are not owned by us, but have
231 // our client id. 232 // our client id.
232 return HiWord(server_id(window)) == client_id_ && 233 return HiWord(server_id(window)) == client_id_ &&
233 roots_.count(window) == 0; 234 roots_.count(window) == 0;
234 } 235 }
235 236
236 void WindowTreeClient::SetBounds(Window* window, 237 void WindowTreeClient::SetBounds(Window* window,
237 const gfx::Rect& old_bounds, 238 const gfx::Rect& old_bounds,
238 const gfx::Rect& bounds) { 239 const gfx::Rect& bounds) {
239 DCHECK(tree_); 240 DCHECK(tree_);
240 const uint32_t change_id = ScheduleInFlightChange( 241 const uint32_t change_id = ScheduleInFlightChange(
241 base::WrapUnique(new InFlightBoundsChange(window, old_bounds))); 242 base::MakeUnique<InFlightBoundsChange>(window, old_bounds));
242 tree_->SetWindowBounds(change_id, server_id(window), bounds); 243 tree_->SetWindowBounds(change_id, server_id(window), bounds);
243 } 244 }
244 245
245 void WindowTreeClient::SetCapture(Window* window) { 246 void WindowTreeClient::SetCapture(Window* window) {
246 // In order for us to get here we had to have exposed a window, which implies 247 // In order for us to get here we had to have exposed a window, which implies
247 // we got a client. 248 // we got a client.
248 DCHECK(tree_); 249 DCHECK(tree_);
249 if (capture_window_ == window) 250 if (capture_window_ == window)
250 return; 251 return;
251 const uint32_t change_id = ScheduleInFlightChange( 252 const uint32_t change_id = ScheduleInFlightChange(
252 base::WrapUnique(new InFlightCaptureChange(this, capture_window_))); 253 base::MakeUnique<InFlightCaptureChange>(this, capture_window_));
253 tree_->SetCapture(change_id, server_id(window)); 254 tree_->SetCapture(change_id, server_id(window));
254 LocalSetCapture(window); 255 LocalSetCapture(window);
255 } 256 }
256 257
257 void WindowTreeClient::ReleaseCapture(Window* window) { 258 void WindowTreeClient::ReleaseCapture(Window* window) {
258 // In order for us to get here we had to have exposed a window, which implies 259 // In order for us to get here we had to have exposed a window, which implies
259 // we got a client. 260 // we got a client.
260 DCHECK(tree_); 261 DCHECK(tree_);
261 if (capture_window_ != window) 262 if (capture_window_ != window)
262 return; 263 return;
263 const uint32_t change_id = ScheduleInFlightChange( 264 const uint32_t change_id = ScheduleInFlightChange(
264 base::WrapUnique(new InFlightCaptureChange(this, window))); 265 base::MakeUnique<InFlightCaptureChange>(this, window));
265 tree_->ReleaseCapture(change_id, server_id(window)); 266 tree_->ReleaseCapture(change_id, server_id(window));
266 LocalSetCapture(nullptr); 267 LocalSetCapture(nullptr);
267 } 268 }
268 269
269 void WindowTreeClient::SetClientArea( 270 void WindowTreeClient::SetClientArea(
270 Id window_id, 271 Id window_id,
271 const gfx::Insets& client_area, 272 const gfx::Insets& client_area,
272 const std::vector<gfx::Rect>& additional_client_areas) { 273 const std::vector<gfx::Rect>& additional_client_areas) {
273 DCHECK(tree_); 274 DCHECK(tree_);
274 tree_->SetClientArea(window_id, client_area, additional_client_areas); 275 tree_->SetClientArea(window_id, client_area, additional_client_areas);
275 } 276 }
276 277
277 void WindowTreeClient::SetHitTestMask(Id window_id, const gfx::Rect& mask) { 278 void WindowTreeClient::SetHitTestMask(Id window_id, const gfx::Rect& mask) {
278 DCHECK(tree_); 279 DCHECK(tree_);
279 tree_->SetHitTestMask(window_id, mask); 280 tree_->SetHitTestMask(window_id, mask);
280 } 281 }
281 282
282 void WindowTreeClient::ClearHitTestMask(Id window_id) { 283 void WindowTreeClient::ClearHitTestMask(Id window_id) {
283 DCHECK(tree_); 284 DCHECK(tree_);
284 tree_->SetHitTestMask(window_id, base::nullopt); 285 tree_->SetHitTestMask(window_id, base::nullopt);
285 } 286 }
286 287
287 void WindowTreeClient::SetFocus(Window* window) { 288 void WindowTreeClient::SetFocus(Window* window) {
288 // In order for us to get here we had to have exposed a window, which implies 289 // In order for us to get here we had to have exposed a window, which implies
289 // we got a client. 290 // we got a client.
290 DCHECK(tree_); 291 DCHECK(tree_);
291 const uint32_t change_id = ScheduleInFlightChange( 292 const uint32_t change_id = ScheduleInFlightChange(
292 base::WrapUnique(new InFlightFocusChange(this, focused_window_))); 293 base::MakeUnique<InFlightFocusChange>(this, focused_window_));
293 tree_->SetFocus(change_id, window ? server_id(window) : 0); 294 tree_->SetFocus(change_id, window ? server_id(window) : 0);
294 LocalSetFocus(window); 295 LocalSetFocus(window);
295 } 296 }
296 297
297 void WindowTreeClient::SetCanFocus(Id window_id, bool can_focus) { 298 void WindowTreeClient::SetCanFocus(Id window_id, bool can_focus) {
298 DCHECK(tree_); 299 DCHECK(tree_);
299 tree_->SetCanFocus(window_id, can_focus); 300 tree_->SetCanFocus(window_id, can_focus);
300 } 301 }
301 302
302 void WindowTreeClient::SetPredefinedCursor(Id window_id, 303 void WindowTreeClient::SetPredefinedCursor(Id window_id,
303 ui::mojom::Cursor cursor_id) { 304 ui::mojom::Cursor cursor_id) {
304 DCHECK(tree_); 305 DCHECK(tree_);
305 306
306 Window* window = GetWindowByServerId(window_id); 307 Window* window = GetWindowByServerId(window_id);
307 if (!window) 308 if (!window)
308 return; 309 return;
309 310
310 // We make an inflight change thing here. 311 // We make an inflight change thing here.
311 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( 312 const uint32_t change_id =
312 new InFlightPredefinedCursorChange(window, window->predefined_cursor()))); 313 ScheduleInFlightChange(base::MakeUnique<InFlightPredefinedCursorChange>(
314 window, window->predefined_cursor()));
313 tree_->SetPredefinedCursor(change_id, window_id, cursor_id); 315 tree_->SetPredefinedCursor(change_id, window_id, cursor_id);
314 } 316 }
315 317
316 void WindowTreeClient::SetVisible(Window* window, bool visible) { 318 void WindowTreeClient::SetVisible(Window* window, bool visible) {
317 DCHECK(tree_); 319 DCHECK(tree_);
318 const uint32_t change_id = ScheduleInFlightChange( 320 const uint32_t change_id = ScheduleInFlightChange(
319 base::WrapUnique(new InFlightVisibleChange(window, !visible))); 321 base::MakeUnique<InFlightVisibleChange>(window, !visible));
320 tree_->SetWindowVisibility(change_id, server_id(window), visible); 322 tree_->SetWindowVisibility(change_id, server_id(window), visible);
321 } 323 }
322 324
323 void WindowTreeClient::SetOpacity(Window* window, float opacity) { 325 void WindowTreeClient::SetOpacity(Window* window, float opacity) {
324 DCHECK(tree_); 326 DCHECK(tree_);
325 const uint32_t change_id = ScheduleInFlightChange( 327 const uint32_t change_id = ScheduleInFlightChange(
326 base::WrapUnique(new InFlightOpacityChange(window, window->opacity()))); 328 base::MakeUnique<InFlightOpacityChange>(window, window->opacity()));
327 tree_->SetWindowOpacity(change_id, server_id(window), opacity); 329 tree_->SetWindowOpacity(change_id, server_id(window), opacity);
328 } 330 }
329 331
330 void WindowTreeClient::SetProperty(Window* window, 332 void WindowTreeClient::SetProperty(Window* window,
331 const std::string& name, 333 const std::string& name,
332 mojo::Array<uint8_t> data) { 334 mojo::Array<uint8_t> data) {
333 DCHECK(tree_); 335 DCHECK(tree_);
334 336
335 mojo::Array<uint8_t> old_value(nullptr); 337 mojo::Array<uint8_t> old_value(nullptr);
336 if (window->HasSharedProperty(name)) 338 if (window->HasSharedProperty(name))
337 old_value = mojo::Array<uint8_t>::From(window->properties_[name]); 339 old_value = mojo::Array<uint8_t>::From(window->properties_[name]);
338 340
339 const uint32_t change_id = ScheduleInFlightChange( 341 const uint32_t change_id = ScheduleInFlightChange(
340 base::WrapUnique(new InFlightPropertyChange(window, name, old_value))); 342 base::MakeUnique<InFlightPropertyChange>(window, name, old_value));
341 tree_->SetWindowProperty(change_id, server_id(window), mojo::String(name), 343 tree_->SetWindowProperty(change_id, server_id(window), mojo::String(name),
342 std::move(data)); 344 std::move(data));
343 } 345 }
344 346
345 void WindowTreeClient::SetWindowTextInputState( 347 void WindowTreeClient::SetWindowTextInputState(
346 Id window_id, 348 Id window_id,
347 mojo::TextInputStatePtr state) { 349 mojo::TextInputStatePtr state) {
348 DCHECK(tree_); 350 DCHECK(tree_);
349 tree_->SetWindowTextInputState(window_id, std::move(state)); 351 tree_->SetWindowTextInputState(window_id, std::move(state));
350 } 352 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 Window* WindowTreeClient::NewWindowImpl( 491 Window* WindowTreeClient::NewWindowImpl(
490 NewWindowType type, 492 NewWindowType type,
491 const Window::SharedProperties* properties) { 493 const Window::SharedProperties* properties) {
492 DCHECK(tree_); 494 DCHECK(tree_);
493 Window* window = 495 Window* window =
494 new Window(this, MakeTransportId(client_id_, next_window_id_++)); 496 new Window(this, MakeTransportId(client_id_, next_window_id_++));
495 if (properties) 497 if (properties)
496 window->properties_ = *properties; 498 window->properties_ = *properties;
497 AddWindow(window); 499 AddWindow(window);
498 500
499 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( 501 const uint32_t change_id =
500 new CrashInFlightChange(window, type == NewWindowType::CHILD 502 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>(
501 ? ChangeType::NEW_WINDOW 503 window, type == NewWindowType::CHILD
502 : ChangeType::NEW_TOP_LEVEL_WINDOW))); 504 ? ChangeType::NEW_WINDOW
505 : ChangeType::NEW_TOP_LEVEL_WINDOW));
503 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties; 506 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties;
504 if (properties) { 507 if (properties) {
505 transport_properties = 508 transport_properties =
506 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(*properties); 509 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(*properties);
507 } 510 }
508 if (type == NewWindowType::CHILD) { 511 if (type == NewWindowType::CHILD) {
509 tree_->NewWindow(change_id, server_id(window), 512 tree_->NewWindow(change_id, server_id(window),
510 std::move(transport_properties)); 513 std::move(transport_properties));
511 } else { 514 } else {
512 roots_.insert(window); 515 roots_.insert(window);
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 Window* window, 1268 Window* window,
1266 const gfx::Vector2d& offset, 1269 const gfx::Vector2d& offset,
1267 const gfx::Insets& hit_area) { 1270 const gfx::Insets& hit_area) {
1268 if (window_manager_internal_client_) { 1271 if (window_manager_internal_client_) {
1269 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1272 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1270 server_id(window), offset.x(), offset.y(), hit_area); 1273 server_id(window), offset.x(), offset.y(), hit_area);
1271 } 1274 }
1272 } 1275 }
1273 1276
1274 } // namespace ui 1277 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/public/cpp/tests/window_server_shelltest_base.cc ('k') | services/ui/surfaces/display_compositor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698