Skip to content

Commit

Permalink
MD Settings: fix crash from strongly bound handler that goes away
Browse files Browse the repository at this point in the history
R=mahmadi@chromium.org
BUG=679993

Review-Url: https://codereview.chromium.org/2629083002
Cr-Commit-Position: refs/heads/master@{#443312}
  • Loading branch information
danbeam authored and Commit bot committed Jan 12, 2017
1 parent bc2f42e commit c013415
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions chrome/browser/ui/webui/settings/profile_info_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ ProfileInfoHandler::ProfileInfoHandler(Profile* profile)
#if defined(OS_CHROMEOS)
user_manager_observer_(this),
#endif
profile_observer_(this) {
profile_observer_(this),
weak_ptr_factory_(this) {
#if defined(OS_CHROMEOS)
// Set up the chrome://userimage/ source.
content::URLDataSource::Add(profile,
Expand Down Expand Up @@ -133,7 +134,7 @@ void ProfileInfoHandler::HandleGetProfileStats(const base::ListValue* args) {
// (e.g., |item.success| is false). Therefore, query the actual statistics.
ProfileStatisticsFactory::GetForProfile(profile_)->GatherStatistics(
base::Bind(&ProfileInfoHandler::PushProfileStatsCount,
base::Unretained(this)));
weak_ptr_factory_.GetWeakPtr()));
}

void ProfileInfoHandler::PushProfileStatsCount(
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/ui/webui/settings/profile_info_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <memory>

#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
Expand Down Expand Up @@ -95,6 +96,8 @@ class ProfileInfoHandler : public SettingsPageUIHandler,
// Used to listen for changes in the list of managed supervised users.
PrefChangeRegistrar profile_pref_registrar_;

base::WeakPtrFactory<ProfileInfoHandler> weak_ptr_factory_;

DISALLOW_COPY_AND_ASSIGN(ProfileInfoHandler);
};

Expand Down

0 comments on commit c013415

Please sign in to comment.