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

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

Issue 23890002: Extract OnDiskEvent and OnFormatEvent logic part from EventRouter to VolumeManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 // Remove the watcher if |watch_path| is no longer watched by any extensions. 383 // Remove the watcher if |watch_path| is no longer watched by any extensions.
384 iter->second->RemoveExtension(extension_id); 384 iter->second->RemoveExtension(extension_id);
385 if (iter->second->GetExtensionIds().empty()) { 385 if (iter->second->GetExtensionIds().empty()) {
386 delete iter->second; 386 delete iter->second;
387 file_watchers_.erase(iter); 387 file_watchers_.erase(iter);
388 } 388 }
389 } 389 }
390 390
391 void EventRouter::OnDiskEvent(DiskMountManager::DiskEvent event, 391 void EventRouter::OnDiskEvent(DiskMountManager::DiskEvent event,
392 const DiskMountManager::Disk* disk) { 392 const DiskMountManager::Disk* disk) {
393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 393 // Disk event is dispatched by VolumeManager now. Do nothing.
394
395 // Disregard hidden devices.
396 if (disk->is_hidden())
397 return;
398 if (event == DiskMountManager::DISK_ADDED) {
399 OnDiskAdded(disk);
400 } else if (event == DiskMountManager::DISK_REMOVED) {
401 OnDiskRemoved(disk);
402 }
403 } 394 }
404 395
405 void EventRouter::OnDeviceEvent(DiskMountManager::DeviceEvent event, 396 void EventRouter::OnDeviceEvent(DiskMountManager::DeviceEvent event,
406 const std::string& device_path) { 397 const std::string& device_path) {
407 // Device event is dispatched by VolumeManager now. Do nothing. 398 // Device event is dispatched by VolumeManager now. Do nothing.
408 } 399 }
409 400
410 void EventRouter::OnMountEvent( 401 void EventRouter::OnMountEvent(
411 DiskMountManager::MountEvent event, 402 DiskMountManager::MountEvent event,
412 chromeos::MountError error_code, 403 chromeos::MountError error_code,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 base::FilePath(mount_info.source_path), 445 base::FilePath(mount_info.source_path),
455 base::Bind(&OnMarkAsUnmounted)); 446 base::Bind(&OnMarkAsUnmounted));
456 } 447 }
457 } 448 }
458 } 449 }
459 } 450 }
460 451
461 void EventRouter::OnFormatEvent(DiskMountManager::FormatEvent event, 452 void EventRouter::OnFormatEvent(DiskMountManager::FormatEvent event,
462 chromeos::FormatError error_code, 453 chromeos::FormatError error_code,
463 const std::string& device_path) { 454 const std::string& device_path) {
464 if (event == DiskMountManager::FORMAT_STARTED) { 455 // Format event is dispatched by VolumeManager now. Do nothing.
465 OnFormatStarted(device_path, error_code == chromeos::FORMAT_ERROR_NONE);
466 } else if (event == DiskMountManager::FORMAT_COMPLETED) {
467 OnFormatCompleted(device_path, error_code == chromeos::FORMAT_ERROR_NONE);
468 }
469 } 456 }
470 457
471 void EventRouter::NetworkManagerChanged() { 458 void EventRouter::NetworkManagerChanged() {
472 if (!profile_ || 459 if (!profile_ ||
473 !extensions::ExtensionSystem::Get(profile_)->event_router()) { 460 !extensions::ExtensionSystem::Get(profile_)->event_router()) {
474 NOTREACHED(); 461 NOTREACHED();
475 return; 462 return;
476 } 463 }
477 scoped_ptr<extensions::Event> event(new extensions::Event( 464 scoped_ptr<extensions::Event> event(new extensions::Event(
478 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged, 465 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged,
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 // If there is no DCIM folder or an external photo importer is not available, 742 // If there is no DCIM folder or an external photo importer is not available,
756 // then launch Files.app. 743 // then launch Files.app.
757 DirectoryExistsOnUIThread( 744 DirectoryExistsOnUIThread(
758 dcim_path, 745 dcim_path,
759 IsGooglePhotosInstalled(profile_) ? 746 IsGooglePhotosInstalled(profile_) ?
760 base::Bind(&base::DoNothing) : 747 base::Bind(&base::DoNothing) :
761 base::Bind(&util::OpenRemovableDrive, mount_path), 748 base::Bind(&util::OpenRemovableDrive, mount_path),
762 base::Bind(&util::OpenRemovableDrive, mount_path)); 749 base::Bind(&util::OpenRemovableDrive, mount_path));
763 } 750 }
764 751
765 void EventRouter::OnDiskAdded(const DiskMountManager::Disk* disk) { 752 void EventRouter::OnDiskAdded(
753 const DiskMountManager::Disk& disk, bool mounting) {
766 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 754 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
767 755
768 VLOG(1) << "Disk added: " << disk->device_path(); 756 if (!mounting) {
769 if (disk->device_path().empty()) { 757 // If the disk is not being mounted, we don't want the Scanning
770 VLOG(1) << "Empty system path for " << disk->device_path(); 758 // notification to persist.
771 return;
772 }
773
774 // If disk is not mounted yet and it has media and there is no policy
775 // forbidding external storage, give it a try.
776 if (disk->mount_path().empty() && disk->has_media() &&
777 !profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) {
778 // Initiate disk mount operation. MountPath auto-detects the filesystem
779 // format if the second argument is empty. The third argument (mount label)
780 // is not used in a disk mount operation.
781 DiskMountManager::GetInstance()->MountPath(
782 disk->device_path(), std::string(), std::string(),
783 chromeos::MOUNT_TYPE_DEVICE);
784 } else {
785 // Either the disk was mounted or it has no media. In both cases we don't
786 // want the Scanning notification to persist.
787 notifications_->HideNotification(DesktopNotifications::DEVICE, 759 notifications_->HideNotification(DesktopNotifications::DEVICE,
788 disk->system_path_prefix()); 760 disk.system_path_prefix());
789 } 761 }
790 } 762 }
791 763
792 void EventRouter::OnDiskRemoved(const DiskMountManager::Disk* disk) { 764 void EventRouter::OnDiskRemoved(const DiskMountManager::Disk& disk) {
793 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 765 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
794 766 // Do nothing.
795 VLOG(1) << "Disk removed: " << disk->device_path();
796
797 if (!disk->mount_path().empty()) {
798 DiskMountManager::GetInstance()->UnmountPath(
799 disk->mount_path(),
800 chromeos::UNMOUNT_OPTIONS_LAZY,
801 DiskMountManager::UnmountPathCallback());
802 }
803 } 767 }
804 768
805 void EventRouter::OnDeviceAdded(const std::string& device_path) { 769 void EventRouter::OnDeviceAdded(const std::string& device_path) {
806 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 770 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
807 771
808 // If the policy is set instead of showing the new device notification, 772 // If the policy is set instead of showing the new device notification,
809 // we show a notification that the operation is not permitted. 773 // we show a notification that the operation is not permitted.
810 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { 774 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) {
811 notifications_->ShowNotification( 775 notifications_->ShowNotification(
812 DesktopNotifications::DEVICE_EXTERNAL_STORAGE_DISABLED, 776 DesktopNotifications::DEVICE_EXTERNAL_STORAGE_DISABLED,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 if (success) { 814 if (success) {
851 notifications_->HideNotification(DesktopNotifications::FORMAT_START, 815 notifications_->HideNotification(DesktopNotifications::FORMAT_START,
852 device_path); 816 device_path);
853 notifications_->ShowNotification(DesktopNotifications::FORMAT_SUCCESS, 817 notifications_->ShowNotification(DesktopNotifications::FORMAT_SUCCESS,
854 device_path); 818 device_path);
855 // Hide it after a couple of seconds. 819 // Hide it after a couple of seconds.
856 notifications_->HideNotificationDelayed( 820 notifications_->HideNotificationDelayed(
857 DesktopNotifications::FORMAT_SUCCESS, 821 DesktopNotifications::FORMAT_SUCCESS,
858 device_path, 822 device_path,
859 base::TimeDelta::FromSeconds(4)); 823 base::TimeDelta::FromSeconds(4));
860 // MountPath auto-detects filesystem format if second argument is empty.
861 // The third argument (mount label) is not used in a disk mount operation.
862 DiskMountManager::GetInstance()->MountPath(device_path, std::string(),
863 std::string(),
864 chromeos::MOUNT_TYPE_DEVICE);
865 } else { 824 } else {
866 notifications_->HideNotification(DesktopNotifications::FORMAT_START, 825 notifications_->HideNotification(DesktopNotifications::FORMAT_START,
867 device_path); 826 device_path);
868 notifications_->ShowNotification(DesktopNotifications::FORMAT_FAIL, 827 notifications_->ShowNotification(DesktopNotifications::FORMAT_FAIL,
869 device_path); 828 device_path);
870 } 829 }
871 } 830 }
872 831
873 } // namespace file_manager 832 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698