Commit 59171772 authored by Dominic Mazzoni's avatar Dominic Mazzoni Committed by Commit Bot

Accessible image descriptions: fix bug in language computation.

In http://crrev.com/c/2148248 we added support for computing the
preferred language for a request, which isn't necessarily the same
as the user's primary language or the primary language of the web page
being visited.

However, the request key we were expecting to get from the server was
being generated based on the original language tag - while the request
key computed from the server response was based on the computed language.

As a result, if the computed language differed from the page language they
didn't match and getting results would fail.

The fix is just to compute the preferred language before we generate the
request key.

Bug: 1090234, 1070505
AX-Relnotes: N/A
Change-Id: Ia2b4038d9e634c6908478333aae6c00781fba49e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2226300
Auto-Submit: Dominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarAndrew Moylan <amoylan@chromium.org>
Commit-Queue: Andrew Moylan <amoylan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774084}
parent 059ea0c9
...@@ -418,10 +418,17 @@ void Annotator::BindReceiver(mojo::PendingReceiver<mojom::Annotator> receiver) { ...@@ -418,10 +418,17 @@ void Annotator::BindReceiver(mojo::PendingReceiver<mojom::Annotator> receiver) {
void Annotator::AnnotateImage( void Annotator::AnnotateImage(
const std::string& source_id, const std::string& source_id,
const std::string& description_language_tag, const std::string& page_language,
mojo::PendingRemote<mojom::ImageProcessor> image_processor, mojo::PendingRemote<mojom::ImageProcessor> image_processor,
AnnotateImageCallback callback) { AnnotateImageCallback callback) {
const RequestKey request_key(source_id, description_language_tag); // Compute the desired language for the description result, based on the
// page language, the accept languages, the top languages, and the
// server languages.
const std::string preferred_language =
ComputePreferredLanguage(page_language);
client_->RecordLanguageMetrics(page_language, preferred_language);
const RequestKey request_key(source_id, preferred_language);
// Return cached results if they exist. // Return cached results if they exist.
const auto cache_lookup = cached_results_.find(request_key); const auto cache_lookup = cached_results_.find(request_key);
...@@ -602,7 +609,7 @@ void Annotator::OnJpgImageDataReceived( ...@@ -602,7 +609,7 @@ void Annotator::OnJpgImageDataReceived(
const int32_t width, const int32_t width,
const int32_t height) { const int32_t height) {
const std::string& source_id = request_key.first; const std::string& source_id = request_key.first;
const std::string& page_language = request_key.second; const std::string& request_language = request_key.second;
ReportPixelFetchSuccess(!image_bytes.empty()); ReportPixelFetchSuccess(!image_bytes.empty());
...@@ -616,17 +623,10 @@ void Annotator::OnJpgImageDataReceived( ...@@ -616,17 +623,10 @@ void Annotator::OnJpgImageDataReceived(
// Local processing is no longer ongoing. // Local processing is no longer ongoing.
local_processors_.erase(request_key); local_processors_.erase(request_key);
// Compute the desired language for the description result, based on the
// page language, the accept languages, the top languages, and the
// server languages.
const std::string preferred_language =
ComputePreferredLanguage(page_language);
client_->RecordLanguageMetrics(page_language, preferred_language);
// Schedule a server request for this image. // Schedule a server request for this image.
server_request_queue_.emplace_front(source_id, server_request_queue_.emplace_front(source_id,
IsWithinDescPolicy(width, height), IsWithinDescPolicy(width, height),
preferred_language, image_bytes); request_language, image_bytes);
pending_requests_.insert(request_key); pending_requests_.insert(request_key);
// Start sending batches to the server. // Start sending batches to the server.
......
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