OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #ifndef UI_BASE_X_SELECTION_OWNER_H_ | 5 #ifndef UI_BASE_X_SELECTION_OWNER_H_ |
6 #define UI_BASE_X_SELECTION_OWNER_H_ | 6 #define UI_BASE_X_SELECTION_OWNER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 bool CanDispatchPropertyEvent(const XEvent& event); | 58 bool CanDispatchPropertyEvent(const XEvent& event); |
59 | 59 |
60 void OnPropertyEvent(const XEvent& event); | 60 void OnPropertyEvent(const XEvent& event); |
61 | 61 |
62 private: | 62 private: |
63 // Holds state related to an incremental data transfer. | 63 // Holds state related to an incremental data transfer. |
64 struct IncrementalTransfer { | 64 struct IncrementalTransfer { |
65 IncrementalTransfer(XID window, | 65 IncrementalTransfer(XID window, |
66 XAtom target, | 66 XAtom target, |
67 XAtom property, | 67 XAtom property, |
68 std::unique_ptr<XScopedEventSelector> event_selector, | |
68 const scoped_refptr<base::RefCountedMemory>& data, | 69 const scoped_refptr<base::RefCountedMemory>& data, |
69 int offset, | 70 int offset, |
70 base::TimeTicks timeout); | 71 base::TimeTicks timeout); |
71 IncrementalTransfer(const IncrementalTransfer& other); | |
72 ~IncrementalTransfer(); | 72 ~IncrementalTransfer(); |
73 | 73 |
74 // Parameters from the XSelectionRequest. The data is transferred over | 74 // Parameters from the XSelectionRequest. The data is transferred over |
75 // |property| on |window|. | 75 // |property| on |window|. |
76 XID window; | 76 XID window; |
77 XAtom target; | 77 XAtom target; |
78 XAtom property; | 78 XAtom property; |
79 | 79 |
80 // Selects events on |window|. | |
81 std::unique_ptr<XScopedEventSelector> event_selector; | |
82 | |
80 // The data to be transferred. | 83 // The data to be transferred. |
81 scoped_refptr<base::RefCountedMemory> data; | 84 scoped_refptr<base::RefCountedMemory> data; |
82 | 85 |
83 // The offset from the beginning of |data| of the first byte to be | 86 // The offset from the beginning of |data| of the first byte to be |
84 // transferred in the next chunk. | 87 // transferred in the next chunk. |
85 size_t offset; | 88 size_t offset; |
86 | 89 |
87 // Time when the transfer should be aborted because the selection requestor | 90 // Time when the transfer should be aborted because the selection requestor |
88 // is taking too long to notify us that we can send the next chunk. | 91 // is taking too long to notify us that we can send the next chunk. |
89 base::TimeTicks timeout; | 92 base::TimeTicks timeout; |
93 | |
94 DISALLOW_COPY_AND_ASSIGN(IncrementalTransfer); | |
90 }; | 95 }; |
91 | 96 |
97 typedef typename std::vector<std::unique_ptr<IncrementalTransfer>>::iterator | |
dcheng
2017/02/17 07:42:13
Nit: prefer using A = B; rather than typename B A;
pkotwicz
2017/02/17 19:19:07
Done.
| |
98 IncrementalTransferIt; | |
99 | |
92 // Attempts to convert the selection to |target|. If the conversion is | 100 // Attempts to convert the selection to |target|. If the conversion is |
93 // successful, true is returned and the result is stored in the |property| | 101 // successful, true is returned and the result is stored in the |property| |
94 // of |requestor|. | 102 // of |requestor|. |
95 bool ProcessTarget(XAtom target, XID requestor, XAtom property); | 103 bool ProcessTarget(XAtom target, XID requestor, XAtom property); |
96 | 104 |
97 // Sends the next chunk of data for given the incremental data transfer. | 105 // Sends the next chunk of data for given the incremental data transfer. |
98 void ProcessIncrementalTransfer(IncrementalTransfer* transfer); | 106 void ProcessIncrementalTransfer(IncrementalTransfer* transfer); |
99 | 107 |
100 // Aborts any incremental data transfers which have timed out. | 108 // Aborts any incremental data transfers which have timed out. |
101 void AbortStaleIncrementalTransfers(); | 109 void AbortStaleIncrementalTransfers(); |
102 | 110 |
103 // Called when the transfer at |it| has completed to do cleanup. | 111 // Called when the transfer at |it| has completed to do cleanup. |
104 void CompleteIncrementalTransfer( | 112 void CompleteIncrementalTransfer(IncrementalTransferIt it); |
105 std::vector<IncrementalTransfer>::iterator it); | |
106 | 113 |
107 // Returns the incremental data transfer, if any, which was waiting for | 114 // Returns the incremental data transfer, if any, which was waiting for |
108 // |event|. | 115 // |event|. |
109 std::vector<IncrementalTransfer>::iterator FindIncrementalTransferForEvent( | 116 IncrementalTransferIt FindIncrementalTransferForEvent(const XEvent& event); |
110 const XEvent& event); | |
111 | 117 |
112 // Our X11 state. | 118 // Our X11 state. |
113 XDisplay* x_display_; | 119 XDisplay* x_display_; |
114 XID x_window_; | 120 XID x_window_; |
115 | 121 |
116 // Events selected on the requesting window. | |
117 std::unique_ptr<XScopedEventSelector> requestor_events_; | |
118 | |
119 // The X11 selection that this instance communicates on. | 122 // The X11 selection that this instance communicates on. |
120 XAtom selection_name_; | 123 XAtom selection_name_; |
121 | 124 |
122 // The time that this instance took ownership of its selection. | 125 // The time that this instance took ownership of its selection. |
123 Time acquired_selection_timestamp_; | 126 Time acquired_selection_timestamp_; |
124 | 127 |
125 // The maximum size of data we can put in XChangeProperty(). | 128 // The maximum size of data we can put in XChangeProperty(). |
126 size_t max_request_size_; | 129 size_t max_request_size_; |
127 | 130 |
128 // The data we are currently serving. | 131 // The data we are currently serving. |
129 SelectionFormatMap format_map_; | 132 SelectionFormatMap format_map_; |
130 | 133 |
131 std::vector<IncrementalTransfer> incremental_transfers_; | 134 std::vector<std::unique_ptr<IncrementalTransfer>> incremental_transfers_; |
dcheng
2017/02/17 07:42:13
Another possibility (to make the typename shorter)
pkotwicz
2017/02/17 19:19:07
I'd rather not implement a custom move assignment
dcheng
2017/02/17 19:21:16
That's what = default is for though =)
Incrementa
| |
132 | 135 |
133 // Used to abort stale incremental data transfers. | 136 // Used to abort stale incremental data transfers. |
134 base::RepeatingTimer incremental_transfer_abort_timer_; | 137 base::RepeatingTimer incremental_transfer_abort_timer_; |
135 | 138 |
136 X11AtomCache atom_cache_; | 139 X11AtomCache atom_cache_; |
137 | 140 |
138 DISALLOW_COPY_AND_ASSIGN(SelectionOwner); | 141 DISALLOW_COPY_AND_ASSIGN(SelectionOwner); |
139 }; | 142 }; |
140 | 143 |
141 } // namespace ui | 144 } // namespace ui |
142 | 145 |
143 #endif // UI_BASE_X_SELECTION_OWNER_H_ | 146 #endif // UI_BASE_X_SELECTION_OWNER_H_ |
OLD | NEW |