diff options
Diffstat (limited to 'chromium/ui/base/x/selection_requestor.cc')
-rw-r--r-- | chromium/ui/base/x/selection_requestor.cc | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/chromium/ui/base/x/selection_requestor.cc b/chromium/ui/base/x/selection_requestor.cc index 7a83c814a75..6e01199f153 100644 --- a/chromium/ui/base/x/selection_requestor.cc +++ b/chromium/ui/base/x/selection_requestor.cc @@ -7,14 +7,12 @@ #include <algorithm> #include "base/memory/ref_counted_memory.h" -#include "base/run_loop.h" #include "ui/base/x/selection_owner.h" #include "ui/base/x/selection_utils.h" #include "ui/base/x/x11_util.h" #include "ui/events/platform/platform_event_source.h" #include "ui/events/platform/x11/x11_event_source.h" #include "ui/gfx/x/x11_atom_cache.h" -#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/xproto.h" namespace ui { @@ -28,7 +26,7 @@ const char kChromeSelection[] = "CHROME_SELECTION"; const int KSelectionRequestorTimerPeriodMs = 100; // The amount of time to wait for a request to complete before aborting it. -const int kRequestTimeoutMs = 10000; +const int kRequestTimeoutMs = 1000; static_assert(KSelectionRequestorTimerPeriodMs <= kRequestTimeoutMs, "timer period must be <= request timeout"); @@ -235,37 +233,30 @@ void SelectionRequestor::ConvertSelectionForCurrentRequest() { } void SelectionRequestor::BlockTillSelectionNotifyForRequest(Request* request) { - if (X11EventSource::HasInstance()) { - if (!abort_timer_.IsRunning()) { - abort_timer_.Start( - FROM_HERE, - base::TimeDelta::FromMilliseconds(KSelectionRequestorTimerPeriodMs), - this, &SelectionRequestor::AbortStaleRequests); - } - - base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed); - request->quit_closure = run_loop.QuitClosure(); - run_loop.Run(); - - // We cannot put logic to process the next request here because the RunLoop - // might be nested. For instance, request 'B' may start a RunLoop while the - // RunLoop for request 'A' is running. It is not possible to end the RunLoop - // for request 'A' without first ending the RunLoop for request 'B'. - } else { - // This occurs if PerformBlockingConvertSelection() is called during - // shutdown and the X11EventSource has already been destroyed. - auto* conn = x11::Connection::Get(); - auto& events = conn->events(); - while (!request->completed && request->timeout > base::TimeTicks::Now()) { - conn->Flush(); - conn->ReadResponses(); - if (!conn->events().empty()) { - x11::Event event = std::move(events.front()); - events.pop_front(); - dispatcher_->DispatchXEvent(&event); + auto* connection = x11::Connection::Get(); + auto& events = connection->events(); + size_t i = 0; + while (!request->completed && request->timeout > base::TimeTicks::Now()) { + connection->Flush(); + connection->ReadResponses(); + size_t events_size = events.size(); + for (; i < events_size; ++i) { + auto& event = events[i]; + if (auto* notify = event.As<x11::SelectionNotifyEvent>()) { + if (notify->requestor == x_window_) { + OnSelectionNotify(*notify); + event = x11::Event(); + } + } else if (auto* prop = event.As<x11::PropertyNotifyEvent>()) { + if (CanDispatchPropertyEvent(event)) { + OnPropertyEvent(event); + event = x11::Event(); + } } } + DCHECK_EQ(events_size, events.size()); } + AbortStaleRequests(); } SelectionRequestor::Request* SelectionRequestor::GetCurrentRequest() { |