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

Side by Side Diff: ash/drag_drop/drag_drop_controller.cc

Issue 1640503002: ash: Do not use MessageLoopForUI when not needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/drag_drop/drag_drop_controller.h" 5 #include "ash/drag_drop/drag_drop_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/drag_drop/drag_drop_tracker.h" 9 #include "ash/drag_drop/drag_drop_tracker.h"
10 #include "ash/drag_drop/drag_image_view.h" 10 #include "ash/drag_drop/drag_image_view.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/thread_task_runner_handle.h"
16 #include "ui/aura/client/capture_client.h" 17 #include "ui/aura/client/capture_client.h"
17 #include "ui/aura/env.h" 18 #include "ui/aura/env.h"
18 #include "ui/aura/window.h" 19 #include "ui/aura/window.h"
19 #include "ui/aura/window_delegate.h" 20 #include "ui/aura/window_delegate.h"
20 #include "ui/aura/window_event_dispatcher.h" 21 #include "ui/aura/window_event_dispatcher.h"
21 #include "ui/base/dragdrop/drag_drop_types.h" 22 #include "ui/base/dragdrop/drag_drop_types.h"
22 #include "ui/base/dragdrop/os_exchange_data.h" 23 #include "ui/base/dragdrop/os_exchange_data.h"
23 #include "ui/base/hit_test.h" 24 #include "ui/base/hit_test.h"
24 #include "ui/events/event.h" 25 #include "ui/events/event.h"
25 #include "ui/events/event_utils.h" 26 #include "ui/events/event_utils.h"
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 216
216 drag_window_ = NULL; 217 drag_window_ = NULL;
217 218
218 // Ends cancel animation if it's in progress. 219 // Ends cancel animation if it's in progress.
219 if (cancel_animation_) 220 if (cancel_animation_)
220 cancel_animation_->End(); 221 cancel_animation_->End();
221 222
222 if (should_block_during_drag_drop_) { 223 if (should_block_during_drag_drop_) {
223 base::RunLoop run_loop; 224 base::RunLoop run_loop;
224 quit_closure_ = run_loop.QuitClosure(); 225 quit_closure_ = run_loop.QuitClosure();
225 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); 226 base::MessageLoop* loop = base::MessageLoop::current();
226 base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop); 227 base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop);
227 run_loop.Run(); 228 run_loop.Run();
228 } 229 }
229 230
230 if (drag_operation_ == 0) { 231 if (drag_operation_ == 0) {
231 UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Cancel", source, 232 UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Cancel", source,
232 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT); 233 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT);
233 } else { 234 } else {
234 UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Drop", source, 235 UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Drop", source,
235 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT); 236 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT);
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 // By the time we finish animation, another drag/drop session may have 495 // By the time we finish animation, another drag/drop session may have
495 // started. We do not want to destroy the drag image in that case. 496 // started. We do not want to destroy the drag image in that case.
496 if (!IsDragDropInProgress()) 497 if (!IsDragDropInProgress())
497 drag_image_.reset(); 498 drag_image_.reset();
498 if (pending_long_tap_) { 499 if (pending_long_tap_) {
499 // If not in a nested message loop, we can forward the long tap right now. 500 // If not in a nested message loop, we can forward the long tap right now.
500 if (!should_block_during_drag_drop_) { 501 if (!should_block_during_drag_drop_) {
501 ForwardPendingLongTap(); 502 ForwardPendingLongTap();
502 } else { 503 } else {
503 // See comment about this in OnGestureEvent(). 504 // See comment about this in OnGestureEvent().
504 base::MessageLoopForUI::current()->PostTask( 505 base::ThreadTaskRunnerHandle::Get()->PostTask(
505 FROM_HERE, 506 FROM_HERE, base::Bind(&DragDropController::ForwardPendingLongTap,
506 base::Bind(&DragDropController::ForwardPendingLongTap, 507 weak_factory_.GetWeakPtr()));
507 weak_factory_.GetWeakPtr()));
508 } 508 }
509 } 509 }
510 } 510 }
511 511
512 void DragDropController::DoDragCancel(int drag_cancel_animation_duration_ms) { 512 void DragDropController::DoDragCancel(int drag_cancel_animation_duration_ms) {
513 ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer); 513 ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer);
514 514
515 // |drag_window_| can be NULL if we have just started the drag and have not 515 // |drag_window_| can be NULL if we have just started the drag and have not
516 // received any DragUpdates, or, if the |drag_window_| gets destroyed during 516 // received any DragUpdates, or, if the |drag_window_| gets destroyed during
517 // a drag/drop. 517 // a drag/drop.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 if (drag_window_) 564 if (drag_window_)
565 drag_window_->RemoveObserver(this); 565 drag_window_->RemoveObserver(this);
566 drag_window_ = NULL; 566 drag_window_ = NULL;
567 drag_data_ = NULL; 567 drag_data_ = NULL;
568 // Cleanup can be called again while deleting DragDropTracker, so delete 568 // Cleanup can be called again while deleting DragDropTracker, so delete
569 // the pointer with a local variable to avoid double free. 569 // the pointer with a local variable to avoid double free.
570 scoped_ptr<ash::DragDropTracker> holder = std::move(drag_drop_tracker_); 570 scoped_ptr<ash::DragDropTracker> holder = std::move(drag_drop_tracker_);
571 } 571 }
572 572
573 } // namespace ash 573 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698