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

Unified Diff: chrome/browser/ui/webui/settings/profile_info_handler.cc

Issue 1942323002: Fix a used-after-free caused by an unremoved Observer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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: chrome/browser/ui/webui/settings/profile_info_handler.cc
diff --git a/chrome/browser/ui/webui/settings/profile_info_handler.cc b/chrome/browser/ui/webui/settings/profile_info_handler.cc
index 6116ba9b8aedec4a31da8dd053f9bbe8523dda62..d852a1b930cf6d8b3c8fb5961c1de9e9868d0a4c 100644
--- a/chrome/browser/ui/webui/settings/profile_info_handler.cc
+++ b/chrome/browser/ui/webui/settings/profile_info_handler.cc
@@ -31,7 +31,11 @@ namespace settings {
const char ProfileInfoHandler::kProfileInfoChangedEventName[] =
"profile-info-changed";
-ProfileInfoHandler::ProfileInfoHandler(Profile* profile) : profile_(profile) {}
+ProfileInfoHandler::ProfileInfoHandler(Profile* profile)
+ : profile_(profile),
+ scoped_observer_(this) {}
+
+ProfileInfoHandler::~ProfileInfoHandler() {}
void ProfileInfoHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
@@ -40,9 +44,8 @@ void ProfileInfoHandler::RegisterMessages() {
}
void ProfileInfoHandler::OnJavascriptAllowed() {
- g_browser_process->profile_manager()
- ->GetProfileAttributesStorage()
- .AddObserver(this);
+ scoped_observer_.Add(
+ &g_browser_process->profile_manager()->GetProfileAttributesStorage());
#if defined(OS_CHROMEOS)
registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
@@ -51,9 +54,8 @@ void ProfileInfoHandler::OnJavascriptAllowed() {
}
void ProfileInfoHandler::OnJavascriptDisallowed() {
- g_browser_process->profile_manager()
- ->GetProfileAttributesStorage()
- .RemoveObserver(this);
+ scoped_observer_.Remove(
+ &g_browser_process->profile_manager()->GetProfileAttributesStorage());
#if defined(OS_CHROMEOS)
registrar_.RemoveAll();

Powered by Google App Engine
This is Rietveld 408576698