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

Side by Side 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: Address feedback 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/webui/settings/profile_info_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/settings/profile_info_handler.h" 5 #include "chrome/browser/ui/webui/settings/profile_info_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 24 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
25 #include "third_party/skia/include/core/SkBitmap.h" 25 #include "third_party/skia/include/core/SkBitmap.h"
26 #endif 26 #endif
27 27
28 namespace settings { 28 namespace settings {
29 29
30 // static 30 // static
31 const char ProfileInfoHandler::kProfileInfoChangedEventName[] = 31 const char ProfileInfoHandler::kProfileInfoChangedEventName[] =
32 "profile-info-changed"; 32 "profile-info-changed";
33 33
34 ProfileInfoHandler::ProfileInfoHandler(Profile* profile) : profile_(profile) {} 34 ProfileInfoHandler::ProfileInfoHandler(Profile* profile)
35 : profile_(profile),
36 profile_observer_(this) {}
37
38 ProfileInfoHandler::~ProfileInfoHandler() {}
35 39
36 void ProfileInfoHandler::RegisterMessages() { 40 void ProfileInfoHandler::RegisterMessages() {
37 web_ui()->RegisterMessageCallback( 41 web_ui()->RegisterMessageCallback(
38 "getProfileInfo", base::Bind(&ProfileInfoHandler::HandleGetProfileInfo, 42 "getProfileInfo", base::Bind(&ProfileInfoHandler::HandleGetProfileInfo,
39 base::Unretained(this))); 43 base::Unretained(this)));
40 } 44 }
41 45
42 void ProfileInfoHandler::OnJavascriptAllowed() { 46 void ProfileInfoHandler::OnJavascriptAllowed() {
43 g_browser_process->profile_manager() 47 profile_observer_.Add(
44 ->GetProfileAttributesStorage() 48 &g_browser_process->profile_manager()->GetProfileAttributesStorage());
45 .AddObserver(this);
46 49
47 #if defined(OS_CHROMEOS) 50 #if defined(OS_CHROMEOS)
48 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, 51 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
49 content::NotificationService::AllSources()); 52 content::NotificationService::AllSources());
50 #endif 53 #endif
51 } 54 }
52 55
53 void ProfileInfoHandler::OnJavascriptDisallowed() { 56 void ProfileInfoHandler::OnJavascriptDisallowed() {
54 g_browser_process->profile_manager() 57 profile_observer_.Remove(
55 ->GetProfileAttributesStorage() 58 &g_browser_process->profile_manager()->GetProfileAttributesStorage());
56 .RemoveObserver(this);
57 59
58 #if defined(OS_CHROMEOS) 60 #if defined(OS_CHROMEOS)
59 registrar_.RemoveAll(); 61 registrar_.RemoveAll();
60 #endif 62 #endif
61 } 63 }
62 64
63 #if defined(OS_CHROMEOS) 65 #if defined(OS_CHROMEOS)
64 void ProfileInfoHandler::Observe(int type, 66 void ProfileInfoHandler::Observe(int type,
65 const content::NotificationSource& source, 67 const content::NotificationSource& source,
66 const content::NotificationDetails& details) { 68 const content::NotificationDetails& details) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 143 }
142 #endif // defined(OS_CHROMEOS) 144 #endif // defined(OS_CHROMEOS)
143 145
144 base::DictionaryValue* response = new base::DictionaryValue(); 146 base::DictionaryValue* response = new base::DictionaryValue();
145 response->SetString("name", name); 147 response->SetString("name", name);
146 response->SetString("iconUrl", icon_url); 148 response->SetString("iconUrl", icon_url);
147 return base::WrapUnique(response); 149 return base::WrapUnique(response);
148 } 150 }
149 151
150 } // namespace settings 152 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/profile_info_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698