Android: Get rid of extra dup()s on launching child processes
[chromium-blink-merge.git] / ui / views / widget / desktop_aura / desktop_drag_drop_client_win.cc
blob25699e500dccb2fc9600753792c9369fba65f860
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
3 // found in the LICENSE file.
5 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h"
7 #include "base/metrics/histogram_macros.h"
8 #include "base/tracked_objects.h"
9 #include "ui/base/dragdrop/drag_drop_types.h"
10 #include "ui/base/dragdrop/drag_source_win.h"
11 #include "ui/base/dragdrop/drop_target_event.h"
12 #include "ui/base/dragdrop/os_exchange_data_provider_win.h"
13 #include "ui/views/widget/desktop_aura/desktop_drop_target_win.h"
14 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h"
16 namespace views {
18 DesktopDragDropClientWin::DesktopDragDropClientWin(
19 aura::Window* root_window,
20 HWND window)
21 : drag_drop_in_progress_(false),
22 drag_operation_(0),
23 weak_factory_(this) {
24 drop_target_ = new DesktopDropTargetWin(root_window, window);
27 DesktopDragDropClientWin::~DesktopDragDropClientWin() {
28 if (drag_drop_in_progress_)
29 DragCancel();
32 int DesktopDragDropClientWin::StartDragAndDrop(
33 const ui::OSExchangeData& data,
34 aura::Window* root_window,
35 aura::Window* source_window,
36 const gfx::Point& root_location,
37 int operation,
38 ui::DragDropTypes::DragEventSource source) {
39 drag_drop_in_progress_ = true;
40 drag_operation_ = operation;
42 base::WeakPtr<DesktopDragDropClientWin> alive(weak_factory_.GetWeakPtr());
44 drag_source_ = new ui::DragSourceWin;
45 scoped_refptr<ui::DragSourceWin> drag_source_copy = drag_source_;
47 DWORD effect;
49 UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Start", source,
50 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT);
52 // Use task stopwatch to exclude the drag-drop time current task, if any.
53 tracked_objects::TaskStopwatch stopwatch;
54 stopwatch.Start();
55 HRESULT result = DoDragDrop(
56 ui::OSExchangeDataProviderWin::GetIDataObject(data), drag_source_.get(),
57 ui::DragDropTypes::DragOperationToDropEffect(operation), &effect);
58 stopwatch.Stop();
60 if (alive)
61 drag_drop_in_progress_ = false;
63 if (result != DRAGDROP_S_DROP)
64 effect = DROPEFFECT_NONE;
66 int drag_operation = ui::DragDropTypes::DropEffectToDragOperation(effect);
68 if (drag_operation == ui::DragDropTypes::DRAG_NONE) {
69 UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Cancel", source,
70 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT);
71 } else {
72 UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Drop", source,
73 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT);
76 return drag_operation;
79 void DesktopDragDropClientWin::DragUpdate(aura::Window* target,
80 const ui::LocatedEvent& event) {
83 void DesktopDragDropClientWin::Drop(aura::Window* target,
84 const ui::LocatedEvent& event) {
87 void DesktopDragDropClientWin::DragCancel() {
88 drag_source_->CancelDrag();
89 drag_operation_ = 0;
92 bool DesktopDragDropClientWin::IsDragDropInProgress() {
93 return drag_drop_in_progress_;
96 void DesktopDragDropClientWin::OnNativeWidgetDestroying(HWND window) {
97 if (drop_target_.get()) {
98 RevokeDragDrop(window);
99 drop_target_ = NULL;
103 } // namespace views