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

Side by Side Diff: chrome/browser/ui/webui/settings/profile_info_handler.cc

Issue 2629083002: MD Settings: fix crash from strongly bound handler that goes away (Closed)
Patch Set: Created 3 years, 11 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 26 matching lines...) Expand all
37 ProfileInfoHandler::kProfileManagesSupervisedUsersChangedEventName[] = 37 ProfileInfoHandler::kProfileManagesSupervisedUsersChangedEventName[] =
38 "profile-manages-supervised-users-changed"; 38 "profile-manages-supervised-users-changed";
39 const char ProfileInfoHandler::kProfileStatsCountReadyEventName[] = 39 const char ProfileInfoHandler::kProfileStatsCountReadyEventName[] =
40 "profile-stats-count-ready"; 40 "profile-stats-count-ready";
41 41
42 ProfileInfoHandler::ProfileInfoHandler(Profile* profile) 42 ProfileInfoHandler::ProfileInfoHandler(Profile* profile)
43 : profile_(profile), 43 : profile_(profile),
44 #if defined(OS_CHROMEOS) 44 #if defined(OS_CHROMEOS)
45 user_manager_observer_(this), 45 user_manager_observer_(this),
46 #endif 46 #endif
47 profile_observer_(this) { 47 profile_observer_(this),
48 weak_ptr_factory_(this) {
48 #if defined(OS_CHROMEOS) 49 #if defined(OS_CHROMEOS)
49 // Set up the chrome://userimage/ source. 50 // Set up the chrome://userimage/ source.
50 content::URLDataSource::Add(profile, 51 content::URLDataSource::Add(profile,
51 new chromeos::options::UserImageSource()); 52 new chromeos::options::UserImageSource());
52 #endif 53 #endif
53 } 54 }
54 55
55 ProfileInfoHandler::~ProfileInfoHandler() {} 56 ProfileInfoHandler::~ProfileInfoHandler() {}
56 57
57 void ProfileInfoHandler::RegisterMessages() { 58 void ProfileInfoHandler::RegisterMessages() {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 void ProfileInfoHandler::HandleGetProfileInfo(const base::ListValue* args) { 118 void ProfileInfoHandler::HandleGetProfileInfo(const base::ListValue* args) {
118 AllowJavascript(); 119 AllowJavascript();
119 120
120 CHECK_EQ(1U, args->GetSize()); 121 CHECK_EQ(1U, args->GetSize());
121 const base::Value* callback_id; 122 const base::Value* callback_id;
122 CHECK(args->Get(0, &callback_id)); 123 CHECK(args->Get(0, &callback_id));
123 124
124 ResolveJavascriptCallback(*callback_id, *GetAccountNameAndIcon()); 125 ResolveJavascriptCallback(*callback_id, *GetAccountNameAndIcon());
125 } 126 }
126 127
127 #if !defined(OS_CHROMEOS) 128 #if !defined(OS_CHROMEOS)
Dan Beam 2017/01/12 03:02:53 yeah yeah yeah, so |weak_ptr_factory_| isn't #if'd
128 void ProfileInfoHandler::HandleGetProfileStats(const base::ListValue* args) { 129 void ProfileInfoHandler::HandleGetProfileStats(const base::ListValue* args) {
129 AllowJavascript(); 130 AllowJavascript();
130 131
131 // Because there is open browser window for the current profile, statistics 132 // Because there is open browser window for the current profile, statistics
132 // from the ProfileAttributesStorage may not be up-to-date or may be missing 133 // from the ProfileAttributesStorage may not be up-to-date or may be missing
133 // (e.g., |item.success| is false). Therefore, query the actual statistics. 134 // (e.g., |item.success| is false). Therefore, query the actual statistics.
134 ProfileStatisticsFactory::GetForProfile(profile_)->GatherStatistics( 135 ProfileStatisticsFactory::GetForProfile(profile_)->GatherStatistics(
135 base::Bind(&ProfileInfoHandler::PushProfileStatsCount, 136 base::Bind(&ProfileInfoHandler::PushProfileStatsCount,
136 base::Unretained(this))); 137 weak_ptr_factory_.GetWeakPtr()));
137 } 138 }
138 139
139 void ProfileInfoHandler::PushProfileStatsCount( 140 void ProfileInfoHandler::PushProfileStatsCount(
140 profiles::ProfileCategoryStats stats) { 141 profiles::ProfileCategoryStats stats) {
141 int count = 0; 142 int count = 0;
142 for (const auto& item : stats) { 143 for (const auto& item : stats) {
143 std::unique_ptr<base::DictionaryValue> stat(new base::DictionaryValue); 144 std::unique_ptr<base::DictionaryValue> stat(new base::DictionaryValue);
144 if (!item.success) { 145 if (!item.success) {
145 count = 0; 146 count = 0;
146 break; 147 break;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 response->SetString("name", name); 225 response->SetString("name", name);
225 response->SetString("iconUrl", icon_url); 226 response->SetString("iconUrl", icon_url);
226 return base::WrapUnique(response); 227 return base::WrapUnique(response);
227 } 228 }
228 229
229 bool ProfileInfoHandler::IsProfileManagingSupervisedUsers() const { 230 bool ProfileInfoHandler::IsProfileManagingSupervisedUsers() const {
230 return !profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUsers)->empty(); 231 return !profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUsers)->empty();
231 } 232 }
232 233
233 } // namespace settings 234 } // 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