Commit 0539784b authored by Gang Wu's avatar Gang Wu Committed by Commit Bot

Using gfx::ImageSkia instead of gfx::Image when cross threads

gfx::Image is not ThreadSafe, so use gfx::ImageSkia instead when we
need to pass image between threads.

Bug:1100967

Change-Id: I7511f9b83e2a3e384c37fdb6b308bb00ab353948
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2299460Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Gang Wu <gangwu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789523}
parent 5f685c86
......@@ -40,7 +40,6 @@ import org.chromium.base.test.params.ParameterSet;
import org.chromium.base.test.params.ParameterizedRunner;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.FlakyTest;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeTabbedActivity;
......@@ -553,7 +552,6 @@ public class SearchActivityTest {
@Test
@SmallTest
@DisabledTest(message = "Flaky - https://crbug.com/1100967")
@Features.
EnableFeatures({ChromeFeatureList.OMNIBOX_ENABLE_CLIPBOARD_PROVIDER_IMAGE_SUGGESTIONS})
public void testImageSearch() throws InterruptedException, Exception {
......@@ -634,7 +632,6 @@ public class SearchActivityTest {
@Test
@SmallTest
@DisabledTest(message = "Flaky - https://crbug.com/1100967")
@Features.
EnableFeatures({ChromeFeatureList.OMNIBOX_ENABLE_CLIPBOARD_PROVIDER_IMAGE_SUGGESTIONS})
public void testImageSearch_OnlyTrustedIntentCanPost() throws InterruptedException, Exception {
......
......@@ -33,6 +33,7 @@
#include "components/strings/grit/components_strings.h"
#include "components/url_formatter/url_formatter.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_util.h"
namespace {
......@@ -376,18 +377,20 @@ void ClipboardProvider::OnReceiveImage(
if (!optional_image)
return;
done_ = false;
gfx::ImageSkia image_skia = *optional_image.value().ToImageSkia();
image_skia.MakeThreadSafe();
base::ThreadPool::PostTaskAndReplyWithResult(
FROM_HERE,
base::BindOnce(&ClipboardProvider::EncodeClipboardImage,
optional_image.value()),
base::BindOnce(&ClipboardProvider::EncodeClipboardImage, image_skia),
base::BindOnce(&ClipboardProvider::ConstructImageMatchCallback,
callback_weak_ptr_factory_.GetWeakPtr(), input,
url_service, clipboard_contents_age));
}
scoped_refptr<base::RefCountedMemory> ClipboardProvider::EncodeClipboardImage(
gfx::Image image) {
gfx::Image resized_image = gfx::ResizedImageForSearchByImage(image);
gfx::ImageSkia image_skia) {
gfx::Image resized_image =
gfx::ResizedImageForSearchByImage(gfx::Image(image_skia));
return resized_image.As1xPNGBytes();
}
......
......@@ -63,7 +63,7 @@ class ClipboardProvider : public AutocompleteProvider {
// Resize and encode the image data into bytes. This can take some time if the
// image is large, so this should happen on a background thread.
static scoped_refptr<base::RefCountedMemory> EncodeClipboardImage(
gfx::Image image);
gfx::ImageSkia image);
// Construct the actual image match once the image has been encoded into
// bytes. This should be called back on the main thread.
void ConstructImageMatchCallback(
......
......@@ -25,6 +25,7 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_unittest_util.h"
#include "url/gurl.h"
......@@ -156,7 +157,7 @@ TEST_F(ClipboardProviderTest, MatchesImage) {
gfx::Image test_image = gfx::test::CreateImage(/*height=*/10, /*width=*/10);
scoped_refptr<base::RefCountedMemory> image_bytes =
provider_->EncodeClipboardImage(test_image);
provider_->EncodeClipboardImage(*test_image.ToImageSkia());
ASSERT_TRUE(image_bytes);
provider_->ConstructImageMatchCallback(CreateAutocompleteInput(true),
&template_url_service, clipboard_age,
......
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