Commit ccedfa2a authored by Maria Kazinova's avatar Maria Kazinova Committed by Commit Bot

[IOS] Stop propagating autofill suggestions that are not longer relevant

to AutofillAgent.

This fixes a bug when no longer required suggestions are returned
asynchronously and are propagated to AutofillAgent latest instead of
actually requested suggestions.

Bug: 1097015
Change-Id: I263bcf619b1a4898a68837890abe3e5a7a483f8d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2421460Reviewed-by: default avatarJohn Wu <jzw@chromium.org>
Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarVadym Doroshenko  <dvadym@chromium.org>
Commit-Queue: Maria Kazinova <kazinova@google.com>
Cr-Commit-Position: refs/heads/master@{#810811}
parent 9c3f4e0c
......@@ -500,6 +500,11 @@ class AutofillClient : public RiskDataLoader {
// Returns a LogManager instance. May be null for platforms that don't support
// this.
virtual LogManager* GetLogManager() const;
#if defined(OS_IOS)
// Checks whether the qurrent query is the most recent one.
virtual bool IsQueryIDRelevant(int query_id) = 0;
#endif
};
} // namespace autofill
......
......@@ -87,6 +87,10 @@ void AutofillExternalDelegate::OnSuggestionsReturned(
bool is_all_server_suggestions) {
if (query_id != query_id_)
return;
#if defined(OS_IOS)
if (!manager_->client()->IsQueryIDRelevant(query_id))
return;
#endif
std::vector<Suggestion> suggestions(input_suggestions);
......
......@@ -263,6 +263,12 @@ void TestAutofillClient::LoadRiskData(
std::move(callback).Run("some risk data");
}
#if defined(OS_IOS)
bool TestAutofillClient::IsQueryIDRelevant(int query_id) {
return true;
}
#endif
void TestAutofillClient::InitializeUKMSources() {
test_ukm_recorder_.UpdateSourceURL(source_id_, form_origin_);
}
......
......@@ -148,6 +148,10 @@ class TestAutofillClient : public AutofillClient {
void LoadRiskData(
base::OnceCallback<void(const std::string&)> callback) override;
#if defined(OS_IOS)
bool IsQueryIDRelevant(int query_id) override;
#endif
// Initializes UKM source from form_origin_. This needs to be called
// in unittests after calling Purge for ukm recorder to re-initialize
// sources.
......
......@@ -195,6 +195,9 @@ void UpdateFieldManagerForClearedIDs(
_last_submitted_autofill_driver;
scoped_refptr<FieldDataManager> _fieldDataManager;
// ID of the last Autofill query made. Used to discard outdated suggestions.
int _lastQueryID;
}
@end
......@@ -226,6 +229,7 @@ void UpdateFieldManagerForClearedIDs(
UniqueIDDataTabHelper* uniqueIDDataTabHelper =
UniqueIDDataTabHelper::FromWebState(_webState);
_fieldDataManager = uniqueIDDataTabHelper->GetFieldDataManager();
_lastQueryID = 0;
}
return self;
}
......@@ -336,9 +340,6 @@ autofillManagerFromWebState:(web::WebState*)webState
if (!autofillManager)
return;
// Passed to delegates; we don't use it so it's set to zero.
int queryId = 0;
// Find the right field.
autofill::FormFieldData field;
GetFormField(&field, form, SysNSStringToUTF16(fieldIdentifier));
......@@ -350,7 +351,7 @@ autofillManagerFromWebState:(web::WebState*)webState
// Query the AutofillManager for suggestions. Results will arrive in
// -showAutofillPopup:popupDelegate:.
autofillManager->OnQueryFormFieldAutofill(
queryId, form, field, gfx::RectF(),
++_lastQueryID, form, field, gfx::RectF(),
/*autoselect_first_suggestion=*/false);
}
......@@ -610,6 +611,10 @@ autofillManagerFromWebState:(web::WebState*)webState
popupDelegate:base::WeakPtr<autofill::AutofillPopupDelegate>()];
}
- (bool)isQueryIDRelevant:(int)queryID {
return queryID == _lastQueryID;
}
#pragma mark - CRWWebStateObserver
- (void)webStateWasShown:(web::WebState*)webState {
......
......@@ -23,6 +23,9 @@ struct Suggestion;
- (void)hideAutofillPopup;
// Checks whether the qurrent query is the most recent one.
- (bool)isQueryIDRelevant:(int)queryID;
@end
#endif // COMPONENTS_AUTOFILL_IOS_BROWSER_AUTOFILL_CLIENT_IOS_BRIDGE_H_
......@@ -121,6 +121,8 @@ class ChromeAutofillClientIOS : public AutofillClient {
LogManager* GetLogManager() const override;
bool IsQueryIDRelevant(int query_id) override;
private:
PrefService* pref_service_;
syncer::SyncService* sync_service_;
......
......@@ -396,4 +396,8 @@ LogManager* ChromeAutofillClientIOS::GetLogManager() const {
return log_manager_.get();
}
bool ChromeAutofillClientIOS::IsQueryIDRelevant(int query_id) {
return [bridge_ isQueryIDRelevant:query_id];
}
} // namespace autofill
......@@ -339,6 +339,10 @@ using autofill::FieldRendererId;
[_autofillAgent hideAutofillPopup];
}
- (bool)isQueryIDRelevant:(int)queryID {
return [_autofillAgent isQueryIDRelevant:queryID];
}
- (void)
confirmCreditCardAccountName:(const base::string16&)name
callback:
......
......@@ -116,6 +116,8 @@ class WebViewAutofillClientIOS : public AutofillClient {
void set_bridge(id<CWVAutofillClientIOSBridge> bridge) { bridge_ = bridge; }
bool IsQueryIDRelevant(int query_id) override;
private:
PrefService* pref_service_;
PersonalDataManager* personal_data_manager_;
......
......@@ -304,4 +304,8 @@ LogManager* WebViewAutofillClientIOS::GetLogManager() const {
return log_manager_.get();
}
bool WebViewAutofillClientIOS::IsQueryIDRelevant(int query_id) {
return [bridge_ isQueryIDRelevant:query_id];
}
} // namespace autofill
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