Commit 5f4fc857 authored by Francois Doray's avatar Francois Doray Committed by Commit Bot

CHECK that clipboard is only use on whitelisted threads.

Previously, using the clipboard on a non-whitelisted thread triggered
a DumpWithoutCrashing + NOTREACHED. If a developer introduced code that
used the clipboard on an incorrect thread, they were not warned
immediately unless they had DCHECKs enabled. The issue could only be
noticed once an official version of Chrome started generating crash
reports via DumpWithoutCrashing (e.g. https://crbug.com/872737). This
CL replaces the DumpWithoutCrashing + NOTREACHED with a CHECK to
ensure that developers can't miss the issue.

Bug: 872737
Change-Id: I5de2c1498245604fc94ca29c35518cc0c9531b0f
Reviewed-on: https://chromium-review.googlesource.com/1170595Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582323}
parent 786483ca
......@@ -8,7 +8,6 @@
#include <limits>
#include <memory>
#include "base/debug/dump_without_crashing.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/stl_util.h"
......@@ -156,13 +155,12 @@ base::PlatformThreadId Clipboard::GetAndValidateThreadID() {
const base::PlatformThreadId id = base::PlatformThread::CurrentId();
// TODO(fdoray): Surround this block with #if DCHECK_IS_ON() and remove the
// DumpWithoutCrashing() call once https://crbug.com/662055 is resolved.
// A Clipboard instance must be allocated for every thread that uses the
// clipboard. To prevented unbounded memory use, CHECK that the current thread
// was whitelisted to use the clipboard. This is a CHECK rather than a DCHECK
// to catch incorrect usage in production (e.g. https://crbug.com/872737).
AllowedThreadsVector* allowed_threads = allowed_threads_.Pointer();
if (!allowed_threads->empty() && !base::ContainsValue(*allowed_threads, id)) {
NOTREACHED();
base::debug::DumpWithoutCrashing();
}
CHECK(allowed_threads->empty() || base::ContainsValue(*allowed_threads, id));
return id;
}
......
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