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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/event_router.cc

Issue 23477070: Move OnFileSystemMounted/BeingUnmounted to VolumeManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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_manager/event_router.h" 5 #include "chrome/browser/chromeos/extensions/file_manager/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/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_change_registrar.h" 10 #include "base/prefs/pref_change_registrar.h"
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 318
319 DLOG_IF(WARNING, !file_watchers_.empty()) 319 DLOG_IF(WARNING, !file_watchers_.empty())
320 << "Not all file watchers are " 320 << "Not all file watchers are "
321 << "removed. This can happen when Files.app is open during shutdown."; 321 << "removed. This can happen when Files.app is open during shutdown.";
322 STLDeleteValues(&file_watchers_); 322 STLDeleteValues(&file_watchers_);
323 if (!profile_) { 323 if (!profile_) {
324 NOTREACHED(); 324 NOTREACHED();
325 return; 325 return;
326 } 326 }
327 327
328 pref_change_registrar_->RemoveAll();
329
330 if (NetworkHandler::IsInitialized()) {
331 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this,
332 FROM_HERE);
333 }
334
335 DriveIntegrationService* integration_service =
336 DriveIntegrationServiceFactory::FindForProfileRegardlessOfStates(
337 profile_);
338 if (integration_service) {
339 integration_service->file_system()->RemoveObserver(this);
340 integration_service->drive_service()->RemoveObserver(this);
341 integration_service->job_list()->RemoveObserver(this);
342 }
343
328 VolumeManager* volume_manager = VolumeManager::Get(profile_); 344 VolumeManager* volume_manager = VolumeManager::Get(profile_);
329 if (volume_manager) 345 if (volume_manager)
330 volume_manager->RemoveObserver(this); 346 volume_manager->RemoveObserver(this);
331 347
332 DriveIntegrationService* integration_service =
333 DriveIntegrationServiceFactory::FindForProfileRegardlessOfStates(
334 profile_);
335 if (integration_service) {
336 integration_service->RemoveObserver(this);
337 integration_service->file_system()->RemoveObserver(this);
338 integration_service->drive_service()->RemoveObserver(this);
339 integration_service->job_list()->RemoveObserver(this);
340 }
341
342 if (NetworkHandler::IsInitialized()) {
343 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this,
344 FROM_HERE);
345 }
346 profile_ = NULL; 348 profile_ = NULL;
347 } 349 }
348 350
349 void EventRouter::ObserveFileSystemEvents() { 351 void EventRouter::ObserveFileSystemEvents() {
350 if (!profile_) { 352 if (!profile_) {
351 NOTREACHED(); 353 NOTREACHED();
352 return; 354 return;
353 } 355 }
354 if (!chromeos::LoginState::IsInitialized() || 356 if (!chromeos::LoginState::IsInitialized() ||
355 !chromeos::LoginState::Get()->IsUserLoggedIn()) { 357 !chromeos::LoginState::Get()->IsUserLoggedIn()) {
356 return; 358 return;
357 } 359 }
358 360
361 // VolumeManager's construction triggers DriveIntegrationService's
362 // construction, so it is necessary to call VolumeManager's Get before
363 // accessing DriveIntegrationService.
364 VolumeManager* volume_manager = VolumeManager::Get(profile_);
365 if (volume_manager)
366 volume_manager->AddObserver(this);
367
359 DriveIntegrationService* integration_service = 368 DriveIntegrationService* integration_service =
360 DriveIntegrationServiceFactory::GetForProfileRegardlessOfStates( 369 DriveIntegrationServiceFactory::FindForProfileRegardlessOfStates(
361 profile_); 370 profile_);
362 if (integration_service) { 371 if (integration_service) {
363 integration_service->AddObserver(this);
364 integration_service->drive_service()->AddObserver(this); 372 integration_service->drive_service()->AddObserver(this);
365 integration_service->file_system()->AddObserver(this); 373 integration_service->file_system()->AddObserver(this);
366 integration_service->job_list()->AddObserver(this); 374 integration_service->job_list()->AddObserver(this);
367 } 375 }
368 376
369 if (NetworkHandler::IsInitialized()) { 377 if (NetworkHandler::IsInitialized()) {
370 NetworkHandler::Get()->network_state_handler()->AddObserver(this, 378 NetworkHandler::Get()->network_state_handler()->AddObserver(this,
371 FROM_HERE); 379 FROM_HERE);
372 } 380 }
373 381
374 pref_change_registrar_->Init(profile_->GetPrefs()); 382 pref_change_registrar_->Init(profile_->GetPrefs());
375 base::Closure callback = 383 base::Closure callback =
376 base::Bind(&EventRouter::OnFileManagerPrefsChanged, 384 base::Bind(&EventRouter::OnFileManagerPrefsChanged,
377 weak_factory_.GetWeakPtr()); 385 weak_factory_.GetWeakPtr());
378 pref_change_registrar_->Add(prefs::kDisableDriveOverCellular, callback); 386 pref_change_registrar_->Add(prefs::kDisableDriveOverCellular, callback);
379 pref_change_registrar_->Add(prefs::kDisableDriveHostedFiles, callback); 387 pref_change_registrar_->Add(prefs::kDisableDriveHostedFiles, callback);
380 pref_change_registrar_->Add(prefs::kDisableDrive, callback); 388 pref_change_registrar_->Add(prefs::kDisableDrive, callback);
381 pref_change_registrar_->Add(prefs::kUse24HourClock, callback); 389 pref_change_registrar_->Add(prefs::kUse24HourClock, callback);
382
383 VolumeManager* volume_manager = VolumeManager::Get(profile_);
384 if (volume_manager)
385 volume_manager->AddObserver(this);
386 } 390 }
387 391
388 // File watch setup routines. 392 // File watch setup routines.
389 void EventRouter::AddFileWatch(const base::FilePath& local_path, 393 void EventRouter::AddFileWatch(const base::FilePath& local_path,
390 const base::FilePath& virtual_path, 394 const base::FilePath& virtual_path,
391 const std::string& extension_id, 395 const std::string& extension_id,
392 const BoolCallback& callback) { 396 const BoolCallback& callback) {
393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
394 DCHECK(!callback.is_null()); 398 DCHECK(!callback.is_null());
395 399
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 extensions::ExtensionSystem::Get(profile_)->event_router()-> 586 extensions::ExtensionSystem::Get(profile_)->event_router()->
583 DispatchEventToExtension(kFileManagerAppId, event.Pass()); 587 DispatchEventToExtension(kFileManagerAppId, event.Pass());
584 588
585 last_file_transfer_event_ = now; 589 last_file_transfer_event_ = now;
586 } 590 }
587 591
588 void EventRouter::OnDirectoryChanged(const base::FilePath& directory_path) { 592 void EventRouter::OnDirectoryChanged(const base::FilePath& directory_path) {
589 HandleFileWatchNotification(directory_path, false); 593 HandleFileWatchNotification(directory_path, false);
590 } 594 }
591 595
592 void EventRouter::OnFileSystemMounted() {
593 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
594
595 // Raise mount event.
596 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed
597 // or network is unreachable. These two errors will be handled later.
598 OnVolumeMounted(chromeos::MOUNT_ERROR_NONE,
599 CreateDriveVolumeInfo(),
600 false); // Not remounting.
601 }
602
603 void EventRouter::OnFileSystemBeingUnmounted() {
604 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
605 OnVolumeUnmounted(chromeos::MOUNT_ERROR_NONE, CreateDriveVolumeInfo());
606 }
607
608 void EventRouter::OnRefreshTokenInvalid() { 596 void EventRouter::OnRefreshTokenInvalid() {
609 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
610 598
611 // Raise a DriveConnectionStatusChanged event to notify the status offline. 599 // Raise a DriveConnectionStatusChanged event to notify the status offline.
612 BroadcastEvent( 600 BroadcastEvent(
613 profile_, 601 profile_,
614 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged, 602 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged,
615 make_scoped_ptr(new ListValue)); 603 make_scoped_ptr(new ListValue));
616 } 604 }
617 605
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 base::TimeDelta::FromSeconds(4)); 785 base::TimeDelta::FromSeconds(4));
798 } else { 786 } else {
799 notifications_->HideNotification(DesktopNotifications::FORMAT_START, 787 notifications_->HideNotification(DesktopNotifications::FORMAT_START,
800 device_path); 788 device_path);
801 notifications_->ShowNotification(DesktopNotifications::FORMAT_FAIL, 789 notifications_->ShowNotification(DesktopNotifications::FORMAT_FAIL,
802 device_path); 790 device_path);
803 } 791 }
804 } 792 }
805 793
806 } // namespace file_manager 794 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698