Commit 1ce8f12d authored by Alex Newcomer's avatar Alex Newcomer Committed by Commit Bot

cros: Wait before replacing top of clipboard

Problem Background:
Some applications take considerable time before finishing a paste.
Also, some applications read the clipboard multiple times per paste.
When the user selects an item from CBHistory that is not the first item,
we need to take the selected item and put it on the clipboard. Then we
create a synthetic paste event. With no delay, we were then replacing
the old top of the clipboard. Paste is async and can take some time.

This means that we may replace the top of the clipboard before the paste
is completed. To avoid this, add a 100ms wait before returning the
original item to the top of the clipboard.

Bug: 11055737
Change-Id: I2f229ebccc00b8241d22bd0341a8c67eeb0b57ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2303450Reviewed-by: default avatarAndrew Xu <andrewxu@chromium.org>
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Commit-Queue: Alex Newcomer <newcomer@chromium.org>
Auto-Submit: Alex Newcomer <newcomer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789165}
parent abae7fa2
......@@ -12,7 +12,9 @@
#include "ash/public/cpp/window_tree_host_lookup.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shell.h"
#include "base/location.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/clipboard/clipboard.h"
......@@ -235,9 +237,18 @@ void ClipboardHistoryController::MenuOptionSelected(int index) {
DCHECK(host);
host->DeliverEventToSink(&synthetic_key_event);
// Replace the original item back on top of the clipboard.
if (selected_item_not_on_top)
WriteClipboardDataToClipboard(*(clipboard_items_.begin()));
if (!selected_item_not_on_top)
return;
// Replace the original item back on top of the clipboard. Some apps take a
// long time to receive the paste event, also some apps will read from the
// clipboard multiple times per paste. Wait 100ms before replacing the item
// back onto the clipboard.
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&WriteClipboardDataToClipboard,
*(clipboard_items_.begin())),
base::TimeDelta::FromMilliseconds(100));
}
} // namespace ash
\ No newline at end of file
......@@ -8,6 +8,7 @@
#include <memory>
#include <vector>
#include "base/memory/weak_ptr.h"
#include "ui/base/models/simple_menu_model.h"
namespace ui {
......@@ -53,6 +54,8 @@ class ClipboardHistoryController {
std::unique_ptr<ui::SimpleMenuModel::Delegate> menu_delegate_;
// The items we show in the contextual menu. Saved so we can paste them later.
std::vector<ui::ClipboardData> clipboard_items_;
base::WeakPtrFactory<ClipboardHistoryController> weak_ptr_factory_{this};
};
} // namespace ash
......
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