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/+/2622285
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Nick Yamane <nickdiego@igalia.com>
Cr-Commit-Position: refs/heads/master@{#842395}
diff --git a/ui/base/clipboard/clipboard_ozone.cc b/ui/base/clipboard/clipboard_ozone.cc
index 1140e65..4975a153 100644
--- a/ui/base/clipboard/clipboard_ozone.cc
+++ b/ui/base/clipboard/clipboard_ozone.cc
@@ -201,7 +201,6 @@
   void PerformRequestAndWaitForResult(ClipboardBuffer buffer,
                                       Request* request) {
     DCHECK(request);
-    DCHECK(!abort_timer_.IsRunning());
     DCHECK(!pending_request_);
 
     pending_request_ = request;
@@ -228,16 +227,12 @@
     request->finish_closure = run_loop.QuitClosure();
 
     // Set a timeout timer after which the request will be aborted.
-    abort_timer_.Start(FROM_HERE, kRequestTimeout, this,
-                       &AsyncClipboardOzone::AbortStalledRequest);
+    base::OneShotTimer abort_timer;
+    abort_timer.Start(FROM_HERE, kRequestTimeout, this,
+                      &AsyncClipboardOzone::CompleteRequest);
     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) {
     auto callback = base::BindOnce(&AsyncClipboardOzone::OnTextRead,
                                    weak_factory_.GetWeakPtr());
@@ -275,7 +270,7 @@
   void CompleteRequest() {
     if (!pending_request_)
       return;
-    abort_timer_.Stop();
+
     if (pending_request_->finish_closure)
       std::move(pending_request_->finish_closure).Run();
     pending_request_ = nullptr;
@@ -295,9 +290,6 @@
   // A current pending request being processed.
   Request* pending_request_ = nullptr;
 
-  // Aborts |pending_request| after Request::timeout.
-  base::RepeatingTimer abort_timer_;
-
   // Provides communication to a system clipboard under ozone level.
   PlatformClipboard* const platform_clipboard_ = nullptr;