Commit 51ad7cb7 authored by Alex Newcomer's avatar Alex Newcomer Committed by Chromium LUCI CQ

Multipaste: add a delay to post task

The debouncing we have in place is not slow enough for
the web async clipboard api. Pasting from the google searchbox
results in multiple clipboard reads, and debouncing requires more of a
delay than provided by PostTask. Add a 100ms delay instead.

Bug: 1167403
Change-Id: Id24b6a7d21b7dd6e471a8f79635fc25cdae194f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2636886
Commit-Queue: Alex Newcomer <newcomer@chromium.org>
Reviewed-by: default avatarAndrew Xu <andrewxu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845279}
parent aba9ad90
......@@ -88,12 +88,16 @@ void ClipboardHistory::OnClipboardDataChanged() {
// Debounce calls to `OnClipboardOperation()`. Certain surfaces
// (Omnibox) may Read/Write to the clipboard multiple times in one user
// initiated operation.
// initiated operation. Add a delay because PostTask is too fast to debounce
// multiple operations through the async web clipboard API. See
// https://crbug.com/1167403.
clipboard_histogram_weak_factory_.InvalidateWeakPtrs();
base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(&ClipboardHistory::OnClipboardOperation,
clipboard_histogram_weak_factory_.GetWeakPtr(),
/*copy=*/true));
base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&ClipboardHistory::OnClipboardOperation,
clipboard_histogram_weak_factory_.GetWeakPtr(),
/*copy=*/true),
base::TimeDelta::FromMilliseconds(100));
// We post commit |clipboard_data| at the end of the current task sequence to
// debounce the case where multiple copies are programmatically performed.
......@@ -116,12 +120,16 @@ void ClipboardHistory::OnClipboardDataRead() {
// Debounce calls to `OnClipboardOperation()`. Certain surfaces
// (Omnibox) may Read/Write to the clipboard multiple times in one user
// initiated operation.
// initiated operation. Add a delay because PostTask is too fast to debounce
// multiple operations through the async web clipboard API. See
// https://crbug.com/1167403.
clipboard_histogram_weak_factory_.InvalidateWeakPtrs();
base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(&ClipboardHistory::OnClipboardOperation,
clipboard_histogram_weak_factory_.GetWeakPtr(),
/*copy=*/false));
base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&ClipboardHistory::OnClipboardOperation,
clipboard_histogram_weak_factory_.GetWeakPtr(),
/*copy=*/false),
base::TimeDelta::FromMilliseconds(100));
}
void ClipboardHistory::OnClipboardOperation(bool copy) {
......
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