Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Unified Diff: components/autofill/content/renderer/autofill_agent.cc

Issue 1960023002: Destroy (Password)AutofillAgent safely (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « components/autofill/content/renderer/autofill_agent.h ('k') | components/autofill/content/renderer/form_autofill_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698