Commit 5ca86f30 authored by Nick Diego Yamane's avatar Nick Diego Yamane Committed by Chromium LUCI CQ

ozone/linux: clipboard: Use one-shot timer for abortion

So far, a RepeatingTimer is used to abort the ClipboardOzone's requests
and it's not being properly stopped when it's triggered (timeout). This
switches to a OneShotTimer as well as resets pending_request_ after the
internal run loop quits, so covering both the successful and abortion
cases.

R=dcheng@chromium.org

Bug: 1165466
Change-Id: I5e7108b93999aa4632a2834b1667cf75aa7d1cb9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2622285Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Nick Yamane <nickdiego@igalia.com>
Cr-Commit-Position: refs/heads/master@{#842395}
parent 908f7394
...@@ -201,7 +201,6 @@ class ClipboardOzone::AsyncClipboardOzone { ...@@ -201,7 +201,6 @@ class ClipboardOzone::AsyncClipboardOzone {
void PerformRequestAndWaitForResult(ClipboardBuffer buffer, void PerformRequestAndWaitForResult(ClipboardBuffer buffer,
Request* request) { Request* request) {
DCHECK(request); DCHECK(request);
DCHECK(!abort_timer_.IsRunning());
DCHECK(!pending_request_); DCHECK(!pending_request_);
pending_request_ = request; pending_request_ = request;
...@@ -228,16 +227,12 @@ class ClipboardOzone::AsyncClipboardOzone { ...@@ -228,16 +227,12 @@ class ClipboardOzone::AsyncClipboardOzone {
request->finish_closure = run_loop.QuitClosure(); request->finish_closure = run_loop.QuitClosure();
// Set a timeout timer after which the request will be aborted. // Set a timeout timer after which the request will be aborted.
abort_timer_.Start(FROM_HERE, kRequestTimeout, this, base::OneShotTimer abort_timer;
&AsyncClipboardOzone::AbortStalledRequest); abort_timer.Start(FROM_HERE, kRequestTimeout, this,
&AsyncClipboardOzone::CompleteRequest);
run_loop.Run(); run_loop.Run();
} }
void AbortStalledRequest() {
if (pending_request_ && pending_request_->finish_closure)
std::move(pending_request_->finish_closure).Run();
}
void DispatchReadRequest(ClipboardBuffer buffer, Request* request) { void DispatchReadRequest(ClipboardBuffer buffer, Request* request) {
auto callback = base::BindOnce(&AsyncClipboardOzone::OnTextRead, auto callback = base::BindOnce(&AsyncClipboardOzone::OnTextRead,
weak_factory_.GetWeakPtr()); weak_factory_.GetWeakPtr());
...@@ -275,7 +270,7 @@ class ClipboardOzone::AsyncClipboardOzone { ...@@ -275,7 +270,7 @@ class ClipboardOzone::AsyncClipboardOzone {
void CompleteRequest() { void CompleteRequest() {
if (!pending_request_) if (!pending_request_)
return; return;
abort_timer_.Stop();
if (pending_request_->finish_closure) if (pending_request_->finish_closure)
std::move(pending_request_->finish_closure).Run(); std::move(pending_request_->finish_closure).Run();
pending_request_ = nullptr; pending_request_ = nullptr;
...@@ -295,9 +290,6 @@ class ClipboardOzone::AsyncClipboardOzone { ...@@ -295,9 +290,6 @@ class ClipboardOzone::AsyncClipboardOzone {
// A current pending request being processed. // A current pending request being processed.
Request* pending_request_ = nullptr; Request* pending_request_ = nullptr;
// Aborts |pending_request| after Request::timeout.
base::RepeatingTimer abort_timer_;
// Provides communication to a system clipboard under ozone level. // Provides communication to a system clipboard under ozone level.
PlatformClipboard* const platform_clipboard_ = nullptr; PlatformClipboard* const platform_clipboard_ = nullptr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment