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