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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chromeos/extensions/file_browser_event_router.h" 5 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 base::Bind(&DirectoryExistsOnBlockingPool, 225 base::Bind(&DirectoryExistsOnBlockingPool,
226 directory_path, 226 directory_path,
227 success_callback, 227 success_callback,
228 failure_callback)); 228 failure_callback));
229 }; 229 };
230 230
231 } // namespace 231 } // namespace
232 232
233 FileBrowserEventRouter::FileBrowserEventRouter( 233 FileBrowserEventRouter::FileBrowserEventRouter(
234 Profile* profile) 234 Profile* profile)
235 : weak_factory_(this), 235 : notifications_(new FileBrowserNotifications(profile)),
236 notifications_(new FileBrowserNotifications(profile)),
237 pref_change_registrar_(new PrefChangeRegistrar), 236 pref_change_registrar_(new PrefChangeRegistrar),
238 profile_(profile), 237 profile_(profile),
239 num_remote_update_requests_(0), 238 num_remote_update_requests_(0),
240 shift_pressed_(false) { 239 shift_pressed_(false),
240 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
242 242
243 // Bind a weak reference back to |this| to avoid memory errors in case we
244 // shut down while a callback is in flight.
245 file_watcher_callback_ = 243 file_watcher_callback_ =
246 base::Bind(&RelayFileWatcherCallbackToUIThread, 244 base::Bind(&RelayFileWatcherCallbackToUIThread,
247 base::Bind(&FileBrowserEventRouter::HandleFileWatchNotification, 245 base::Bind(&FileBrowserEventRouter::HandleFileWatchNotification,
248 weak_factory_.GetWeakPtr())); 246 weak_factory_.GetWeakPtr()));
249 247
250 // Listen for the Shift modifier's state changes. 248 // Listen for the Shift modifier's state changes.
251 chromeos::SystemKeyEventListener* key_event_listener = 249 chromeos::SystemKeyEventListener* key_event_listener =
252 chromeos::SystemKeyEventListener::GetInstance(); 250 chromeos::SystemKeyEventListener::GetInstance();
253 if (key_event_listener) 251 if (key_event_listener)
254 key_event_listener->AddModifiersObserver(this); 252 key_event_listener->AddModifiersObserver(this);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 chromeos::ConnectivityStateHelper::Get()-> 315 chromeos::ConnectivityStateHelper::Get()->
318 AddNetworkManagerObserver(this); 316 AddNetworkManagerObserver(this);
319 } 317 }
320 suspend_state_delegate_.reset(new SuspendStateDelegateImpl()); 318 suspend_state_delegate_.reset(new SuspendStateDelegateImpl());
321 319
322 pref_change_registrar_->Init(profile_->GetPrefs()); 320 pref_change_registrar_->Init(profile_->GetPrefs());
323 321
324 pref_change_registrar_->Add( 322 pref_change_registrar_->Add(
325 prefs::kExternalStorageDisabled, 323 prefs::kExternalStorageDisabled,
326 base::Bind(&FileBrowserEventRouter::OnExternalStorageDisabledChanged, 324 base::Bind(&FileBrowserEventRouter::OnExternalStorageDisabledChanged,
327 base::Unretained(this))); 325 weak_factory_.GetWeakPtr()));
328 326
329 base::Closure callback = 327 base::Closure callback =
330 base::Bind(&FileBrowserEventRouter::OnFileBrowserPrefsChanged, 328 base::Bind(&FileBrowserEventRouter::OnFileBrowserPrefsChanged,
331 base::Unretained(this)); 329 weak_factory_.GetWeakPtr());
332 pref_change_registrar_->Add(prefs::kDisableDriveOverCellular, callback); 330 pref_change_registrar_->Add(prefs::kDisableDriveOverCellular, callback);
333 pref_change_registrar_->Add(prefs::kDisableDriveHostedFiles, callback); 331 pref_change_registrar_->Add(prefs::kDisableDriveHostedFiles, callback);
334 pref_change_registrar_->Add(prefs::kDisableDrive, callback); 332 pref_change_registrar_->Add(prefs::kDisableDrive, callback);
335 pref_change_registrar_->Add(prefs::kUse24HourClock, callback); 333 pref_change_registrar_->Add(prefs::kUse24HourClock, callback);
336 } 334 }
337 335
338 // File watch setup routines. 336 // File watch setup routines.
339 bool FileBrowserEventRouter::AddFileWatch( 337 bool FileBrowserEventRouter::AddFileWatch(
340 const base::FilePath& local_path, 338 const base::FilePath& local_path,
341 const base::FilePath& virtual_path, 339 const base::FilePath& virtual_path,
342 const std::string& extension_id) { 340 const std::string& extension_id) {
343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
344 342
345 base::AutoLock lock(lock_); 343 base::AutoLock lock(lock_);
346 base::FilePath watch_path = local_path; 344 base::FilePath watch_path = local_path;
347 bool is_remote_watch = false; 345 bool is_remote_watch = false;
348 // Tweak watch path for remote sources - we need to drop leading /special 346 // Tweak watch path for remote sources - we need to drop leading /special
349 // directory from there in order to be able to pair these events with 347 // directory from there in order to be able to pair these events with
350 // their change notifications. 348 // their change notifications.
351 if (drive::util::GetSpecialRemoteRootPath().IsParent(watch_path)) { 349 if (drive::util::GetSpecialRemoteRootPath().IsParent(watch_path)) {
352 watch_path = drive::util::ExtractDrivePath(watch_path); 350 watch_path = drive::util::ExtractDrivePath(watch_path);
353 is_remote_watch = true; 351 is_remote_watch = true;
354 BrowserThread::PostTask( 352 BrowserThread::PostTask(
355 BrowserThread::UI, FROM_HERE, 353 BrowserThread::UI, FROM_HERE,
356 base::Bind(&FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread, 354 base::Bind(&FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread,
357 this, true)); 355 weak_factory_.GetWeakPtr(), true));
satorux1 2013/04/08 06:34:36 Hmm, this is also broken, as weak_factory_.GetWea
358 } 356 }
359 357
360 WatcherMap::iterator iter = file_watchers_.find(watch_path); 358 WatcherMap::iterator iter = file_watchers_.find(watch_path);
361 if (iter == file_watchers_.end()) { 359 if (iter == file_watchers_.end()) {
362 scoped_ptr<FileWatcherExtensions> 360 scoped_ptr<FileWatcherExtensions>
363 watch(new FileWatcherExtensions(virtual_path, 361 watch(new FileWatcherExtensions(virtual_path,
364 extension_id, 362 extension_id,
365 is_remote_watch)); 363 is_remote_watch));
366 364
367 if (watch->Watch(watch_path, file_watcher_callback_)) 365 if (watch->Watch(watch_path, file_watcher_callback_))
(...skipping 14 matching lines...) Expand all
382 base::AutoLock lock(lock_); 380 base::AutoLock lock(lock_);
383 base::FilePath watch_path = local_path; 381 base::FilePath watch_path = local_path;
384 // Tweak watch path for remote sources - we need to drop leading /special 382 // Tweak watch path for remote sources - we need to drop leading /special
385 // directory from there in order to be able to pair these events with 383 // directory from there in order to be able to pair these events with
386 // their change notifications. 384 // their change notifications.
387 if (drive::util::GetSpecialRemoteRootPath().IsParent(watch_path)) { 385 if (drive::util::GetSpecialRemoteRootPath().IsParent(watch_path)) {
388 watch_path = drive::util::ExtractDrivePath(watch_path); 386 watch_path = drive::util::ExtractDrivePath(watch_path);
389 BrowserThread::PostTask( 387 BrowserThread::PostTask(
390 BrowserThread::UI, FROM_HERE, 388 BrowserThread::UI, FROM_HERE,
391 base::Bind(&FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread, 389 base::Bind(&FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread,
392 this, false)); 390 weak_factory_.GetWeakPtr(), false));
393 } 391 }
394 WatcherMap::iterator iter = file_watchers_.find(watch_path); 392 WatcherMap::iterator iter = file_watchers_.find(watch_path);
395 if (iter == file_watchers_.end()) 393 if (iter == file_watchers_.end())
396 return; 394 return;
397 // Remove the renderer process for this watch. 395 // Remove the renderer process for this watch.
398 iter->second->RemoveExtension(extension_id); 396 iter->second->RemoveExtension(extension_id);
399 if (iter->second->GetRefCount() == 0) { 397 if (iter->second->GetRefCount() == 0) {
400 delete iter->second; 398 delete iter->second;
401 file_watchers_.erase(iter); 399 file_watchers_.erase(iter);
402 } 400 }
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 } 969 }
972 970
973 bool FileBrowserEventRouter::FileWatcherExtensions::Watch( 971 bool FileBrowserEventRouter::FileWatcherExtensions::Watch(
974 const base::FilePath& path, 972 const base::FilePath& path,
975 const base::FilePathWatcher::Callback& callback) { 973 const base::FilePathWatcher::Callback& callback) {
976 if (is_remote_file_system_) 974 if (is_remote_file_system_)
977 return true; 975 return true;
978 976
979 return file_watcher_->Watch(path, false, callback); 977 return file_watcher_->Watch(path, false, callback);
980 } 978 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698