Index: components/autofill/content/renderer/autofill_agent.cc |
diff --git a/components/autofill/content/renderer/autofill_agent.cc b/components/autofill/content/renderer/autofill_agent.cc |
index e233d106484d074fd3e691c6aa492bbbd637b3ca..61c665e9691de7b9a7e787ac57bad110f8b8eef9 100644 |
--- a/components/autofill/content/renderer/autofill_agent.cc |
+++ b/components/autofill/content/renderer/autofill_agent.cc |
@@ -312,6 +312,16 @@ void AutofillAgent::FocusedNodeChanged(const WebNode& node) { |
element_ = *element; |
} |
+void AutofillAgent::OnDestruct() { |
+ Shutdown(); |
+ base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
+} |
+ |
+void AutofillAgent::Shutdown() { |
+ legacy_.Shutdown(); |
+ weak_ptr_factory_.InvalidateWeakPtrs(); |
+} |
+ |
void AutofillAgent::FocusChangeComplete() { |
WebDocument doc = render_frame()->GetWebFrame()->document(); |
WebElement focused_element; |
@@ -844,12 +854,17 @@ AutofillAgent::LegacyAutofillAgent::LegacyAutofillAgent( |
AutofillAgent::LegacyAutofillAgent::~LegacyAutofillAgent() { |
} |
+void AutofillAgent::LegacyAutofillAgent::Shutdown() { |
+ agent_ = nullptr; |
+} |
+ |
void AutofillAgent::LegacyAutofillAgent::OnDestruct() { |
// No-op. Don't delete |this|. |
} |
void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { |
- agent_->FocusChangeComplete(); |
+ if (agent_) |
+ agent_->FocusChangeComplete(); |
} |
} // namespace autofill |