[Clipboard] Update ReadImage in clipboard as async
This CL update ReadImage in clipboard to be asynchronous for all
platform.
This CL also implement getImage from android clipboard.
Bug:1055924
Change-Id: Id969665aa612138ae96f9e7445cddc011ccc40f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2071287
Reviewed-by: Daniel Cheng <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Reviewed-by: Darwin Huang <[email protected]>
Reviewed-by: Ted Choc <[email protected]>
Commit-Queue: Gang Wu <[email protected]>
Cr-Commit-Position: refs/heads/master@{#754926}
diff --git a/components/omnibox/browser/clipboard_provider.cc b/components/omnibox/browser/clipboard_provider.cc
index 8cab614..754e773 100644
--- a/components/omnibox/browser/clipboard_provider.cc
+++ b/components/omnibox/browser/clipboard_provider.cc
@@ -335,10 +335,9 @@
return false;
}
- base::Optional<gfx::Image> optional_image =
- clipboard_content_->GetRecentImageFromClipboard();
- if (!optional_image)
+ if (!clipboard_content_->HasRecentImageFromClipboard()) {
return false;
+ }
// Make sure current provider supports image search
TemplateURLService* url_service = client_->GetTemplateURLService();
@@ -355,6 +354,20 @@
// when the match is created).
base::TimeDelta clipboard_contents_age =
clipboard_content_->GetClipboardContentAge();
+ clipboard_content_->GetRecentImageFromClipboard(
+ base::BindOnce(&ClipboardProvider::OnReceiveImage,
+ callback_weak_ptr_factory_.GetWeakPtr(), input,
+ url_service, clipboard_contents_age));
+ return true;
+}
+
+void ClipboardProvider::OnReceiveImage(
+ const AutocompleteInput& input,
+ TemplateURLService* url_service,
+ base::TimeDelta clipboard_contents_age,
+ base::Optional<gfx::Image> optional_image) {
+ if (!optional_image)
+ return;
done_ = false;
PostTaskAndReplyWithResult(
FROM_HERE,
@@ -363,7 +376,6 @@
base::BindOnce(&ClipboardProvider::ConstructImageMatchCallback,
callback_weak_ptr_factory_.GetWeakPtr(), input,
url_service, clipboard_contents_age));
- return true;
}
scoped_refptr<base::RefCountedMemory> ClipboardProvider::EncodeClipboardImage(