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

Unified Diff: chrome/browser/chromeos/extensions/file_browser_event_router.cc

Issue 13474015: drive: Fix lifetime model of FileBrowserEventRouter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 7 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/chromeos/extensions/file_browser_event_router.cc
diff --git a/chrome/browser/chromeos/extensions/file_browser_event_router.cc b/chrome/browser/chromeos/extensions/file_browser_event_router.cc
index 40b4cf76e1f816676aeec19160a1c293f1283425..836a916adcf9f1242cb32e3923985e80fb7aa518 100644
--- a/chrome/browser/chromeos/extensions/file_browser_event_router.cc
+++ b/chrome/browser/chromeos/extensions/file_browser_event_router.cc
@@ -232,16 +232,14 @@ void DirectoryExistsOnUIThread(const base::FilePath& directory_path,
FileBrowserEventRouter::FileBrowserEventRouter(
Profile* profile)
- : weak_factory_(this),
- notifications_(new FileBrowserNotifications(profile)),
+ : notifications_(new FileBrowserNotifications(profile)),
pref_change_registrar_(new PrefChangeRegistrar),
profile_(profile),
num_remote_update_requests_(0),
- shift_pressed_(false) {
+ shift_pressed_(false),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- // Bind a weak reference back to |this| to avoid memory errors in case we
- // shut down while a callback is in flight.
file_watcher_callback_ =
base::Bind(&RelayFileWatcherCallbackToUIThread,
base::Bind(&FileBrowserEventRouter::HandleFileWatchNotification,
@@ -324,11 +322,11 @@ void FileBrowserEventRouter::ObserveFileSystemEvents() {
pref_change_registrar_->Add(
prefs::kExternalStorageDisabled,
base::Bind(&FileBrowserEventRouter::OnExternalStorageDisabledChanged,
- base::Unretained(this)));
+ weak_factory_.GetWeakPtr()));
base::Closure callback =
base::Bind(&FileBrowserEventRouter::OnFileBrowserPrefsChanged,
- base::Unretained(this));
+ weak_factory_.GetWeakPtr());
pref_change_registrar_->Add(prefs::kDisableDriveOverCellular, callback);
pref_change_registrar_->Add(prefs::kDisableDriveHostedFiles, callback);
pref_change_registrar_->Add(prefs::kDisableDrive, callback);
@@ -354,7 +352,7 @@ bool FileBrowserEventRouter::AddFileWatch(
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread,
- this, true));
+ weak_factory_.GetWeakPtr(), true));
satorux1 2013/04/08 06:34:36 Hmm, this is also broken, as weak_factory_.GetWea
}
WatcherMap::iterator iter = file_watchers_.find(watch_path);
@@ -389,7 +387,7 @@ void FileBrowserEventRouter::RemoveFileWatch(
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread,
- this, false));
+ weak_factory_.GetWeakPtr(), false));
}
WatcherMap::iterator iter = file_watchers_.find(watch_path);
if (iter == file_watchers_.end())

Powered by Google App Engine
This is Rietveld 408576698