Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/app_mode/app_mode_utils.h" | 15 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 17 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
| 18 #include "chrome/browser/chromeos/drive/file_change.h" | 18 #include "chrome/browser/chromeos/drive/file_change.h" |
| 19 #include "chrome/browser/chromeos/drive/file_system_interface.h" | 19 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
| 20 #include "chrome/browser/chromeos/drive/file_system_util.h" | 20 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 21 #include "chrome/browser/chromeos/extensions/file_manager/device_event_router.h" | |
| 21 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" | 22 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" |
| 22 #include "chrome/browser/chromeos/file_manager/app_id.h" | 23 #include "chrome/browser/chromeos/file_manager/app_id.h" |
| 23 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" | 24 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
| 24 #include "chrome/browser/chromeos/file_manager/open_util.h" | 25 #include "chrome/browser/chromeos/file_manager/open_util.h" |
| 25 #include "chrome/browser/chromeos/file_manager/volume_manager.h" | 26 #include "chrome/browser/chromeos/file_manager/volume_manager.h" |
| 26 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | 27 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
| 27 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | 28 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
| 28 #include "chrome/browser/drive/drive_service_interface.h" | 29 #include "chrome/browser/drive/drive_service_interface.h" |
| 29 #include "chrome/browser/extensions/extension_service.h" | 30 #include "chrome/browser/extensions/extension_service.h" |
| 30 #include "chrome/browser/extensions/extension_util.h" | 31 #include "chrome/browser/extensions/extension_util.h" |
| 31 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
| 32 #include "chrome/browser/profiles/profile_manager.h" | 33 #include "chrome/browser/profiles/profile_manager.h" |
| 33 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
| 34 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 36 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 35 #include "chromeos/login/login_state.h" | 37 #include "chromeos/login/login_state.h" |
| 36 #include "chromeos/network/network_handler.h" | 38 #include "chromeos/network/network_handler.h" |
| 37 #include "chromeos/network/network_state_handler.h" | 39 #include "chromeos/network/network_state_handler.h" |
| 38 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
| 39 #include "content/public/browser/notification_source.h" | 41 #include "content/public/browser/notification_source.h" |
| 40 #include "content/public/browser/render_process_host.h" | 42 #include "content/public/browser/render_process_host.h" |
| 41 #include "content/public/browser/storage_partition.h" | 43 #include "content/public/browser/storage_partition.h" |
| 42 #include "extensions/browser/event_router.h" | 44 #include "extensions/browser/event_router.h" |
| 43 #include "extensions/browser/extension_host.h" | 45 #include "extensions/browser/extension_host.h" |
| 44 #include "extensions/browser/extension_prefs.h" | 46 #include "extensions/browser/extension_prefs.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 return false; | 280 return false; |
| 279 } else { | 281 } else { |
| 280 *last_time = now; | 282 *last_time = now; |
| 281 return true; | 283 return true; |
| 282 } | 284 } |
| 283 } | 285 } |
| 284 | 286 |
| 285 // Obtains whether the Files.app should handle the volume or not. | 287 // Obtains whether the Files.app should handle the volume or not. |
| 286 bool ShouldShowNotificationForVolume( | 288 bool ShouldShowNotificationForVolume( |
| 287 Profile* profile, | 289 Profile* profile, |
| 288 file_browser_private::MountCompletedEventType event_type, | 290 const DeviceEventRouter& device_event_router, |
| 289 chromeos::MountError error, | 291 const VolumeInfo& volume_info) { |
| 290 const VolumeInfo& volume_info, | |
| 291 bool is_remounting) { | |
| 292 if (event_type != file_browser_private::MOUNT_COMPLETED_EVENT_TYPE_MOUNT) | |
| 293 return false; | |
| 294 | |
| 295 if (volume_info.type != VOLUME_TYPE_MTP && | 292 if (volume_info.type != VOLUME_TYPE_MTP && |
| 296 volume_info.type != VOLUME_TYPE_REMOVABLE_DISK_PARTITION) { | 293 volume_info.type != VOLUME_TYPE_REMOVABLE_DISK_PARTITION) { |
| 297 return false; | 294 return false; |
| 298 } | 295 } |
| 299 | 296 |
| 300 if (error != chromeos::MOUNT_ERROR_NONE) | 297 if (device_event_router.is_resuming() || device_event_router.is_starting_up()) |
| 301 return false; | |
| 302 | |
| 303 if (is_remounting) | |
| 304 return false; | 298 return false; |
| 305 | 299 |
| 306 // Do not attempt to open File Manager while the login is in progress or | 300 // Do not attempt to open File Manager while the login is in progress or |
| 307 // the screen is locked or running in kiosk app mode and make sure the file | 301 // the screen is locked or running in kiosk app mode and make sure the file |
| 308 // manager is opened only for the active user. | 302 // manager is opened only for the active user. |
| 309 if (chromeos::LoginDisplayHostImpl::default_host() || | 303 if (chromeos::LoginDisplayHostImpl::default_host() || |
| 310 chromeos::ScreenLocker::default_screen_locker() || | 304 chromeos::ScreenLocker::default_screen_locker() || |
| 311 chrome::IsRunningInForcedAppMode() || | 305 chrome::IsRunningInForcedAppMode() || |
| 312 profile != ProfileManager::GetActiveUserProfile()) { | 306 profile != ProfileManager::GetActiveUserProfile()) { |
| 313 return false; | 307 return false; |
| 314 } | 308 } |
| 315 | 309 |
| 316 // Do not pop-up the File Manager, if the recovery tool is running. | 310 // Do not pop-up the File Manager, if the recovery tool is running. |
| 317 if (IsRecoveryToolRunning(profile)) | 311 if (IsRecoveryToolRunning(profile)) |
| 318 return false; | 312 return false; |
| 319 | 313 |
| 320 // If the disable-default-apps flag is on, Files.app is not opened | 314 // If the disable-default-apps flag is on, Files.app is not opened |
| 321 // automatically on device mount not to obstruct the manual test. | 315 // automatically on device mount not to obstruct the manual test. |
| 322 if (CommandLine::ForCurrentProcess()->HasSwitch( | 316 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 323 switches::kDisableDefaultApps)) { | 317 switches::kDisableDefaultApps)) { |
| 324 return false; | 318 return false; |
| 325 } | 319 } |
| 326 | 320 |
| 327 return true; | 321 return true; |
| 328 } | 322 } |
| 329 | 323 |
| 324 // Sub-part of the event router for handling device events. | |
| 325 class DeviceEventRouterImpl : public DeviceEventRouter { | |
| 326 public: | |
| 327 explicit DeviceEventRouterImpl(Profile* profile) | |
| 328 : DeviceEventRouter(base::TimeDelta::FromSeconds(0)), profile_(profile) {} | |
|
mtomasz
2014/08/25 04:37:37
Shall 0 be passed here?
hirono
2014/08/25 06:40:57
No, it's a bug. Thank you for catching.
| |
| 329 | |
| 330 // Overrides | |
|
mtomasz
2014/08/25 04:37:37
nit: ... -> DeviceEventRouter overrides. for consi
hirono
2014/08/25 06:40:57
Done.
| |
| 331 virtual void OnDeviceEvent(file_browser_private::DeviceEventType type, | |
| 332 const std::string& device_path) OVERRIDE { | |
| 333 file_browser_private::DeviceEvent event; | |
| 334 event.type = type; | |
| 335 event.device_path = device_path; | |
| 336 | |
| 337 BroadcastEvent(profile_, | |
| 338 file_browser_private::OnDeviceChanged::kEventName, | |
| 339 file_browser_private::OnDeviceChanged::Create(event)); | |
| 340 } | |
| 341 | |
| 342 // Overrides | |
| 343 virtual bool IsExternalStorageDisabled() OVERRIDE { | |
| 344 return profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled); | |
| 345 } | |
| 346 | |
| 347 private: | |
| 348 Profile* const profile_; | |
|
mtomasz
2014/08/25 04:37:36
How about: DISALLOW_COPY_AND_ASSIGN?
hirono
2014/08/25 06:40:57
Done.
| |
| 349 }; | |
| 350 | |
| 330 } // namespace | 351 } // namespace |
| 331 | 352 |
| 332 // Pass dummy value to JobInfo's constructor for make it default constructible. | 353 // Pass dummy value to JobInfo's constructor for make it default constructible. |
| 333 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus() | 354 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus() |
| 334 : job_info(drive::TYPE_DOWNLOAD_FILE) { | 355 : job_info(drive::TYPE_DOWNLOAD_FILE) { |
| 335 } | 356 } |
| 336 | 357 |
| 337 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus( | 358 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus( |
| 338 const drive::JobInfo& info, const std::string& status) | 359 const drive::JobInfo& info, const std::string& status) |
| 339 : job_info(info), status(status) { | 360 : job_info(info), status(status) { |
| 340 } | 361 } |
| 341 | 362 |
| 342 EventRouter::EventRouter(Profile* profile) | 363 EventRouter::EventRouter(Profile* profile) |
| 343 : pref_change_registrar_(new PrefChangeRegistrar), | 364 : pref_change_registrar_(new PrefChangeRegistrar), |
| 344 profile_(profile), | 365 profile_(profile), |
| 345 multi_user_window_manager_observer_registered_(false), | 366 multi_user_window_manager_observer_registered_(false), |
| 367 device_event_router_(new DeviceEventRouterImpl(profile)), | |
| 346 weak_factory_(this) { | 368 weak_factory_(this) { |
| 347 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 348 } | 370 } |
| 349 | 371 |
| 350 EventRouter::~EventRouter() { | 372 EventRouter::~EventRouter() { |
| 351 } | 373 } |
| 352 | 374 |
| 353 void EventRouter::Shutdown() { | 375 void EventRouter::Shutdown() { |
| 354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 355 | 377 |
| 356 DLOG_IF(WARNING, !file_watchers_.empty()) | 378 DLOG_IF(WARNING, !file_watchers_.empty()) |
| 357 << "Not all file watchers are " | 379 << "Not all file watchers are " |
| 358 << "removed. This can happen when Files.app is open during shutdown."; | 380 << "removed. This can happen when Files.app is open during shutdown."; |
| 359 STLDeleteValues(&file_watchers_); | 381 STLDeleteValues(&file_watchers_); |
| 360 if (!profile_) { | 382 if (!profile_) { |
| 361 NOTREACHED(); | 383 NOTREACHED(); |
| 362 return; | 384 return; |
| 363 } | 385 } |
| 364 | 386 |
| 365 pref_change_registrar_->RemoveAll(); | 387 pref_change_registrar_->RemoveAll(); |
| 366 | 388 |
| 367 if (NetworkHandler::IsInitialized()) { | 389 if (NetworkHandler::IsInitialized()) { |
| 368 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, | 390 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, |
| 369 FROM_HERE); | 391 FROM_HERE); |
| 370 } | 392 } |
| 371 | 393 |
| 372 DriveIntegrationService* integration_service = | 394 DriveIntegrationService* const integration_service = |
| 373 DriveIntegrationServiceFactory::FindForProfile(profile_); | 395 DriveIntegrationServiceFactory::FindForProfile(profile_); |
| 374 if (integration_service) { | 396 if (integration_service) { |
| 375 integration_service->file_system()->RemoveObserver(this); | 397 integration_service->file_system()->RemoveObserver(this); |
| 376 integration_service->drive_service()->RemoveObserver(this); | 398 integration_service->drive_service()->RemoveObserver(this); |
| 377 integration_service->job_list()->RemoveObserver(this); | 399 integration_service->job_list()->RemoveObserver(this); |
| 378 } | 400 } |
| 379 | 401 |
| 380 VolumeManager* volume_manager = VolumeManager::Get(profile_); | 402 VolumeManager* const volume_manager = VolumeManager::Get(profile_); |
| 381 if (volume_manager) | 403 if (volume_manager) { |
| 382 volume_manager->RemoveObserver(this); | 404 volume_manager->RemoveObserver(this); |
| 405 volume_manager->RemoveObserver(device_event_router_.get()); | |
| 406 } | |
| 407 | |
| 408 chromeos::PowerManagerClient* const power_manager_client = | |
| 409 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); | |
| 410 power_manager_client->RemoveObserver(device_event_router_.get()); | |
| 383 | 411 |
| 384 chrome::MultiUserWindowManager* const multi_user_window_manager = | 412 chrome::MultiUserWindowManager* const multi_user_window_manager = |
| 385 chrome::MultiUserWindowManager::GetInstance(); | 413 chrome::MultiUserWindowManager::GetInstance(); |
| 386 if (multi_user_window_manager && | 414 if (multi_user_window_manager && |
| 387 multi_user_window_manager_observer_registered_) { | 415 multi_user_window_manager_observer_registered_) { |
| 388 multi_user_window_manager_observer_registered_ = false; | 416 multi_user_window_manager_observer_registered_ = false; |
| 389 multi_user_window_manager->RemoveObserver(this); | 417 multi_user_window_manager->RemoveObserver(this); |
| 390 } | 418 } |
| 391 | 419 |
| 392 profile_ = NULL; | 420 profile_ = NULL; |
| 393 } | 421 } |
| 394 | 422 |
| 395 void EventRouter::ObserveEvents() { | 423 void EventRouter::ObserveEvents() { |
| 396 if (!profile_) { | 424 if (!profile_) { |
| 397 NOTREACHED(); | 425 NOTREACHED(); |
| 398 return; | 426 return; |
| 399 } | 427 } |
| 400 if (!chromeos::LoginState::IsInitialized() || | 428 if (!chromeos::LoginState::IsInitialized() || |
| 401 !chromeos::LoginState::Get()->IsUserLoggedIn()) { | 429 !chromeos::LoginState::Get()->IsUserLoggedIn()) { |
| 402 return; | 430 return; |
| 403 } | 431 } |
| 404 | 432 |
| 433 // Ignore device events for the first few seconds. | |
| 434 device_event_router_->Startup(); | |
| 435 | |
| 405 // VolumeManager's construction triggers DriveIntegrationService's | 436 // VolumeManager's construction triggers DriveIntegrationService's |
| 406 // construction, so it is necessary to call VolumeManager's Get before | 437 // construction, so it is necessary to call VolumeManager's Get before |
| 407 // accessing DriveIntegrationService. | 438 // accessing DriveIntegrationService. |
| 408 VolumeManager* volume_manager = VolumeManager::Get(profile_); | 439 VolumeManager* const volume_manager = VolumeManager::Get(profile_); |
| 409 if (volume_manager) | 440 if (volume_manager) { |
| 410 volume_manager->AddObserver(this); | 441 volume_manager->AddObserver(this); |
|
mtomasz
2014/08/25 04:37:36
Does EventRouter need to observe VolumeManager? Mo
hirono
2014/08/25 06:40:57
EventRouter needs to observe VolumeManager to catc
mtomasz
2014/08/25 07:48:23
SGTM.
| |
| 442 volume_manager->AddObserver(device_event_router_.get()); | |
| 443 } | |
| 411 | 444 |
| 412 DriveIntegrationService* integration_service = | 445 chromeos::PowerManagerClient* const power_manager_client = |
| 446 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); | |
| 447 power_manager_client->AddObserver(device_event_router_.get()); | |
| 448 | |
| 449 DriveIntegrationService* const integration_service = | |
| 413 DriveIntegrationServiceFactory::FindForProfile(profile_); | 450 DriveIntegrationServiceFactory::FindForProfile(profile_); |
| 414 if (integration_service) { | 451 if (integration_service) { |
| 415 integration_service->drive_service()->AddObserver(this); | 452 integration_service->drive_service()->AddObserver(this); |
| 416 integration_service->file_system()->AddObserver(this); | 453 integration_service->file_system()->AddObserver(this); |
| 417 integration_service->job_list()->AddObserver(this); | 454 integration_service->job_list()->AddObserver(this); |
| 418 } | 455 } |
| 419 | 456 |
| 420 if (NetworkHandler::IsInitialized()) { | 457 if (NetworkHandler::IsInitialized()) { |
| 421 NetworkHandler::Get()->network_state_handler()->AddObserver(this, | 458 NetworkHandler::Get()->network_state_handler()->AddObserver(this, |
| 422 FROM_HERE); | 459 FROM_HERE); |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 817 event.entry.additional_properties.SetString( | 854 event.entry.additional_properties.SetString( |
| 818 "fileFullPath", "/" + entry_definition.full_path.value()); | 855 "fileFullPath", "/" + entry_definition.full_path.value()); |
| 819 event.entry.additional_properties.SetBoolean("fileIsDirectory", | 856 event.entry.additional_properties.SetBoolean("fileIsDirectory", |
| 820 entry_definition.is_directory); | 857 entry_definition.is_directory); |
| 821 | 858 |
| 822 BroadcastEvent(profile_, | 859 BroadcastEvent(profile_, |
| 823 file_browser_private::OnDirectoryChanged::kEventName, | 860 file_browser_private::OnDirectoryChanged::kEventName, |
| 824 file_browser_private::OnDirectoryChanged::Create(event)); | 861 file_browser_private::OnDirectoryChanged::Create(event)); |
| 825 } | 862 } |
| 826 | 863 |
| 827 void EventRouter::DispatchDeviceEvent( | |
| 828 file_browser_private::DeviceEventType type, | |
| 829 const std::string& device_path) { | |
| 830 file_browser_private::DeviceEvent event; | |
| 831 | |
| 832 event.type = type; | |
| 833 event.device_path = device_path; | |
| 834 BroadcastEvent(profile_, | |
| 835 file_browser_private::OnDeviceChanged::kEventName, | |
| 836 file_browser_private::OnDeviceChanged::Create(event)); | |
| 837 } | |
| 838 | |
| 839 void EventRouter::OnDiskAdded( | 864 void EventRouter::OnDiskAdded( |
| 840 const DiskMountManager::Disk& disk, bool mounting) { | 865 const DiskMountManager::Disk& disk, bool mounting) { |
| 841 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 866 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 842 | 867 // Do nothing. |
| 843 if (!mounting) { | |
| 844 // If the disk is not being mounted, we don't want the Scanning | |
| 845 // notification to persist. | |
| 846 DispatchDeviceEvent( | |
| 847 file_browser_private::DEVICE_EVENT_TYPE_SCAN_CANCELED, | |
| 848 disk.system_path_prefix()); | |
| 849 } | |
| 850 } | 868 } |
| 851 | 869 |
| 852 void EventRouter::OnDiskRemoved(const DiskMountManager::Disk& disk) { | 870 void EventRouter::OnDiskRemoved(const DiskMountManager::Disk& disk) { |
| 853 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 871 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 854 // Do nothing. | 872 // Do nothing. |
| 855 } | 873 } |
| 856 | 874 |
| 857 void EventRouter::OnDeviceAdded(const std::string& device_path) { | 875 void EventRouter::OnDeviceAdded(const std::string& device_path) { |
| 858 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 876 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 859 | 877 // Do nothing. |
| 860 // If the policy is set instead of showing the new device notification, | |
| 861 // we show a notification that the operation is not permitted. | |
| 862 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { | |
| 863 DispatchDeviceEvent( | |
| 864 file_browser_private::DEVICE_EVENT_TYPE_DISABLED, | |
| 865 device_path); | |
| 866 return; | |
| 867 } | |
| 868 | |
| 869 DispatchDeviceEvent( | |
| 870 file_browser_private::DEVICE_EVENT_TYPE_ADDED, | |
| 871 device_path); | |
| 872 } | 878 } |
| 873 | 879 |
| 874 void EventRouter::OnDeviceRemoved(const std::string& device_path) { | 880 void EventRouter::OnDeviceRemoved(const std::string& device_path) { |
| 875 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 881 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 876 DispatchDeviceEvent( | 882 // Do nothing. |
| 877 file_browser_private::DEVICE_EVENT_TYPE_REMOVED, | |
| 878 device_path); | |
| 879 } | 883 } |
| 880 | 884 |
| 881 void EventRouter::OnVolumeMounted(chromeos::MountError error_code, | 885 void EventRouter::OnVolumeMounted(chromeos::MountError error_code, |
| 882 const VolumeInfo& volume_info, | 886 const VolumeInfo& volume_info, |
| 883 bool is_remounting) { | 887 bool is_remounting) { |
| 884 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 888 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 885 // profile_ is NULL if ShutdownOnUIThread() is called earlier. This can | 889 // profile_ is NULL if ShutdownOnUIThread() is called earlier. This can |
| 886 // happen at shutdown. This should be removed after removing Drive mounting | 890 // happen at shutdown. This should be removed after removing Drive mounting |
| 887 // code in addMount. (addMount -> OnFileSystemMounted -> OnVolumeMounted is | 891 // code in addMount. (addMount -> OnFileSystemMounted -> OnVolumeMounted is |
| 888 // the only path to come here after Shutdown is called). | 892 // the only path to come here after Shutdown is called). |
| 889 if (!profile_) | 893 if (!profile_) |
| 890 return; | 894 return; |
| 895 | |
| 891 DispatchMountCompletedEvent( | 896 DispatchMountCompletedEvent( |
| 892 file_browser_private::MOUNT_COMPLETED_EVENT_TYPE_MOUNT, | 897 file_browser_private::MOUNT_COMPLETED_EVENT_TYPE_MOUNT, |
| 893 error_code, | 898 error_code, |
| 894 volume_info, | 899 volume_info); |
| 895 is_remounting); | |
| 896 } | 900 } |
| 897 | 901 |
| 898 void EventRouter::OnVolumeUnmounted(chromeos::MountError error_code, | 902 void EventRouter::OnVolumeUnmounted(chromeos::MountError error_code, |
| 899 const VolumeInfo& volume_info) { | 903 const VolumeInfo& volume_info) { |
| 900 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 904 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 901 DispatchMountCompletedEvent( | 905 DispatchMountCompletedEvent( |
| 902 file_browser_private::MOUNT_COMPLETED_EVENT_TYPE_UNMOUNT, | 906 file_browser_private::MOUNT_COMPLETED_EVENT_TYPE_UNMOUNT, |
| 903 error_code, | 907 error_code, |
| 904 volume_info, | 908 volume_info); |
| 905 false); | |
| 906 } | |
| 907 | |
| 908 void EventRouter::OnHardUnplugged(const std::string& device_path) { | |
| 909 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 910 DispatchDeviceEvent(file_browser_private::DEVICE_EVENT_TYPE_HARD_UNPLUGGED, | |
| 911 device_path); | |
| 912 } | 909 } |
| 913 | 910 |
| 914 void EventRouter::DispatchMountCompletedEvent( | 911 void EventRouter::DispatchMountCompletedEvent( |
| 915 file_browser_private::MountCompletedEventType event_type, | 912 file_browser_private::MountCompletedEventType event_type, |
| 916 chromeos::MountError error, | 913 chromeos::MountError error, |
| 917 const VolumeInfo& volume_info, | 914 const VolumeInfo& volume_info) { |
| 918 bool is_remounting) { | |
| 919 // Build an event object. | 915 // Build an event object. |
| 920 file_browser_private::MountCompletedEvent event; | 916 file_browser_private::MountCompletedEvent event; |
| 921 event.event_type = event_type; | 917 event.event_type = event_type; |
| 922 event.status = MountErrorToMountCompletedStatus(error); | 918 event.status = MountErrorToMountCompletedStatus(error); |
| 923 util::VolumeInfoToVolumeMetadata( | 919 util::VolumeInfoToVolumeMetadata( |
| 924 profile_, volume_info, &event.volume_metadata); | 920 profile_, volume_info, &event.volume_metadata); |
| 925 event.is_remounting = is_remounting; | |
| 926 event.should_notify = ShouldShowNotificationForVolume( | 921 event.should_notify = ShouldShowNotificationForVolume( |
| 927 profile_, event_type, error, volume_info, is_remounting); | 922 profile_, *device_event_router_, volume_info); |
| 928 BroadcastEvent(profile_, | 923 BroadcastEvent(profile_, |
| 929 file_browser_private::OnMountCompleted::kEventName, | 924 file_browser_private::OnMountCompleted::kEventName, |
| 930 file_browser_private::OnMountCompleted::Create(event)); | 925 file_browser_private::OnMountCompleted::Create(event)); |
| 931 } | 926 } |
| 932 | 927 |
| 933 void EventRouter::OnFormatStarted(const std::string& device_path, | 928 void EventRouter::OnFormatStarted(const std::string& device_path, |
| 934 bool success) { | 929 bool success) { |
| 935 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 930 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 936 | 931 // Do nothing. |
| 937 if (success) { | |
| 938 DispatchDeviceEvent(file_browser_private::DEVICE_EVENT_TYPE_FORMAT_START, | |
| 939 device_path); | |
| 940 } else { | |
| 941 DispatchDeviceEvent(file_browser_private::DEVICE_EVENT_TYPE_FORMAT_FAIL, | |
| 942 device_path); | |
| 943 } | |
| 944 } | 932 } |
| 945 | 933 |
| 946 void EventRouter::OnFormatCompleted(const std::string& device_path, | 934 void EventRouter::OnFormatCompleted(const std::string& device_path, |
| 947 bool success) { | 935 bool success) { |
| 948 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 936 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 949 DispatchDeviceEvent(success ? | 937 // Do nothing. |
| 950 file_browser_private::DEVICE_EVENT_TYPE_FORMAT_SUCCESS : | |
| 951 file_browser_private::DEVICE_EVENT_TYPE_FORMAT_FAIL, | |
| 952 device_path); | |
| 953 } | 938 } |
| 954 | 939 |
| 955 void EventRouter::Observe(int type, | 940 void EventRouter::Observe(int type, |
| 956 const content::NotificationSource& source, | 941 const content::NotificationSource& source, |
| 957 const content::NotificationDetails& details) { | 942 const content::NotificationDetails& details) { |
| 958 if (type == chrome::NOTIFICATION_PROFILE_ADDED) { | 943 if (type == chrome::NOTIFICATION_PROFILE_ADDED) { |
| 959 Profile* const added_profile = content::Source<Profile>(source).ptr(); | 944 Profile* const added_profile = content::Source<Profile>(source).ptr(); |
| 960 if (!added_profile->IsOffTheRecord()) | 945 if (!added_profile->IsOffTheRecord()) |
| 961 GrantAccessForAddedProfileToRunningInstance(added_profile, profile_); | 946 GrantAccessForAddedProfileToRunningInstance(added_profile, profile_); |
| 962 | 947 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 977 } | 962 } |
| 978 } | 963 } |
| 979 | 964 |
| 980 void EventRouter::OnOwnerEntryChanged(aura::Window* window) { | 965 void EventRouter::OnOwnerEntryChanged(aura::Window* window) { |
| 981 BroadcastEvent(profile_, | 966 BroadcastEvent(profile_, |
| 982 file_browser_private::OnDesktopChanged::kEventName, | 967 file_browser_private::OnDesktopChanged::kEventName, |
| 983 file_browser_private::OnDesktopChanged::Create()); | 968 file_browser_private::OnDesktopChanged::Create()); |
| 984 } | 969 } |
| 985 | 970 |
| 986 } // namespace file_manager | 971 } // namespace file_manager |
| OLD | NEW |