Send "PDF Searchify started" message only once to the browser process.
PdfSearchify feature promo is triggered every time PDF Searchify starts, but it is shown only once. To reduce the unnecessary trips through different layers, send the message to the browser process only once. Bug: 360803943 Change-Id: Ic34a9b01c85cbb802092a78d06f1aa5099230da0 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6261061 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Mike West <mkwst@chromium.org> Auto-Submit: Ramin Halavati <rhalavati@chromium.org> Reviewed-by: Mike West <mkwst@chromium.org> Cr-Commit-Position: refs/heads/main@{#1421248}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
a0bb6987d3
commit
bf5ea84be4
@ -154,7 +154,10 @@ void PDFDocumentHelper::SetPluginCanSave(bool can_save) {
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
void PDFDocumentHelper::OnSearchifyStarted() {
|
||||
client_->OnSearchifyStarted(&GetWebContents());
|
||||
if (!searchify_started_) {
|
||||
searchify_started_ = true;
|
||||
client_->OnSearchifyStarted(&GetWebContents());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -150,6 +150,9 @@ class PDFDocumentHelper
|
||||
|
||||
bool is_document_load_complete_ = false;
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
bool searchify_started_ = false;
|
||||
#endif
|
||||
mojo::Remote<mojom::PdfListener> remote_pdf_client_;
|
||||
|
||||
base::ObserverList<Observer> observers_;
|
||||
|
@ -68,7 +68,8 @@ interface PdfHost {
|
||||
// Notifies the embedder know the plugin can handle save commands internally.
|
||||
SetPluginCanSave(bool can_save);
|
||||
|
||||
// Notifies that PDF searchifier has started processing pages.
|
||||
// Notifies that PDF searchifier has started processing pages. This should be
|
||||
// called at most once.
|
||||
[EnableIf=enable_screen_ai_service]
|
||||
OnSearchifyStarted();
|
||||
};
|
||||
|
@ -1459,7 +1459,10 @@ void PdfViewWebPlugin::OnSearchifyStateChange(bool busy) {
|
||||
return;
|
||||
}
|
||||
|
||||
pdf_host_->OnSearchifyStarted();
|
||||
if (!searchify_started_) {
|
||||
searchify_started_ = true;
|
||||
pdf_host_->OnSearchifyStarted();
|
||||
}
|
||||
|
||||
if (!show_searchify_in_progress_) {
|
||||
// The UI is asked to show the progress indicator with 1s delay, so that if
|
||||
|
@ -935,6 +935,9 @@ class PdfViewWebPlugin final : public PDFiumEngineClient,
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
bool show_searchify_in_progress_ = false;
|
||||
|
||||
// Tells if searchify ever started.
|
||||
bool searchify_started_ = false;
|
||||
#endif
|
||||
|
||||
base::WeakPtrFactory<PdfViewWebPlugin> weak_factory_{this};
|
||||
|
@ -1805,6 +1805,8 @@ TEST_F(PdfViewWebPluginTest, OnSearchifyStarted) {
|
||||
|
||||
plugin_->OnSearchifyStateChange(true);
|
||||
|
||||
EXPECT_CALL(pdf_host_, OnSearchifyStarted);
|
||||
|
||||
// Wait for the state to be propagated.
|
||||
base::RunLoop run_loop;
|
||||
base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask(
|
||||
@ -1856,6 +1858,16 @@ TEST_F(PdfViewWebPluginTest, OnSearchifyStartedAndStoppedWithDelay) {
|
||||
plugin_->OnSearchifyStateChange(false);
|
||||
}
|
||||
|
||||
TEST_F(PdfViewWebPluginTest, OnSearchifyStartedMoreThanOnce) {
|
||||
plugin_->OnSearchifyStateChange(true);
|
||||
plugin_->OnSearchifyStateChange(false);
|
||||
plugin_->OnSearchifyStateChange(true);
|
||||
|
||||
EXPECT_CALL(pdf_host_, OnSearchifyStarted);
|
||||
|
||||
pdf_receiver_.FlushForTesting();
|
||||
}
|
||||
|
||||
TEST_F(PdfViewWebPluginTest, OnHasSearchifyText) {
|
||||
base::Value::Dict message;
|
||||
message.Set("type", "setHasSearchifyText");
|
||||
|
Reference in New Issue
Block a user