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) : profile_(profile) {} | |
| 328 | |
| 329 // DeviceEventRouter overrides. | |
| 330 virtual void OnDeviceEvent(file_browser_private::DeviceEventType type, | |
| 331 const std::string& device_path) OVERRIDE { | |
| 332 file_browser_private::DeviceEvent event; | |
|
mtomasz
2014/08/25 07:48:23
nit: How about adding a DCHECK if we are on the UI
hirono
2014/08/26 01:06:45
Done.
| |
| 333 event.type = type; | |
| 334 event.device_path = device_path; | |
| 335 | |
| 336 BroadcastEvent(profile_, | |
| 337 file_browser_private::OnDeviceChanged::kEventName, | |
| 338 file_browser_private::OnDeviceChanged::Create(event)); | |
| 339 } | |
| 340 | |
| 341 // DeviceEventRouter overrides. | |
| 342 virtual bool IsExternalStorageDisabled() OVERRIDE { | |
| 343 return profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled); | |
|
mtomasz
2014/08/25 07:48:23
nit: ditto
hirono
2014/08/26 01:06:45
Done.
| |
| 344 } | |
| 345 | |
| 346 private: | |
| 347 Profile* const profile_; | |
| 348 | |
| 349 DISALLOW_COPY_AND_ASSIGN(DeviceEventRouterImpl); | |
| 350 }; | |
| 351 | |
| 330 } // namespace | 352 } // namespace |
| 331 | 353 |
| 332 // Pass dummy value to JobInfo's constructor for make it default constructible. | 354 // Pass dummy value to JobInfo's constructor for make it default constructible. |
| 333 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus() | 355 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus() |
| 334 : job_info(drive::TYPE_DOWNLOAD_FILE) { | 356 : job_info(drive::TYPE_DOWNLOAD_FILE) { |
| 335 } | 357 } |
| 336 | 358 |
| 337 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus( | 359 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus( |
| 338 const drive::JobInfo& info, const std::string& status) | 360 const drive::JobInfo& info, const std::string& status) |
| 339 : job_info(info), status(status) { | 361 : job_info(info), status(status) { |
| 340 } | 362 } |
| 341 | 363 |
| 342 EventRouter::EventRouter(Profile* profile) | 364 EventRouter::EventRouter(Profile* profile) |
| 343 : pref_change_registrar_(new PrefChangeRegistrar), | 365 : pref_change_registrar_(new PrefChangeRegistrar), |
| 344 profile_(profile), | 366 profile_(profile), |
| 345 multi_user_window_manager_observer_registered_(false), | 367 multi_user_window_manager_observer_registered_(false), |
| 368 device_event_router_(new DeviceEventRouterImpl(profile)), | |
| 346 weak_factory_(this) { | 369 weak_factory_(this) { |
| 347 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 370 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 348 } | 371 } |
| 349 | 372 |
| 350 EventRouter::~EventRouter() { | 373 EventRouter::~EventRouter() { |
| 351 } | 374 } |
| 352 | 375 |
| 353 void EventRouter::Shutdown() { | 376 void EventRouter::Shutdown() { |
| 354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 355 | 378 |
| 356 DLOG_IF(WARNING, !file_watchers_.empty()) | 379 DLOG_IF(WARNING, !file_watchers_.empty()) |
| 357 << "Not all file watchers are " | 380 << "Not all file watchers are " |
| 358 << "removed. This can happen when Files.app is open during shutdown."; | 381 << "removed. This can happen when Files.app is open during shutdown."; |
| 359 STLDeleteValues(&file_watchers_); | 382 STLDeleteValues(&file_watchers_); |
| 360 if (!profile_) { | 383 if (!profile_) { |
| 361 NOTREACHED(); | 384 NOTREACHED(); |
| 362 return; | 385 return; |
| 363 } | 386 } |
| 364 | 387 |
| 365 pref_change_registrar_->RemoveAll(); | 388 pref_change_registrar_->RemoveAll(); |
| 366 | 389 |
| 367 if (NetworkHandler::IsInitialized()) { | 390 if (NetworkHandler::IsInitialized()) { |
| 368 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, | 391 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, |
| 369 FROM_HERE); | 392 FROM_HERE); |
| 370 } | 393 } |
| 371 | 394 |
| 372 DriveIntegrationService* integration_service = | 395 DriveIntegrationService* const integration_service = |
| 373 DriveIntegrationServiceFactory::FindForProfile(profile_); | 396 DriveIntegrationServiceFactory::FindForProfile(profile_); |
| 374 if (integration_service) { | 397 if (integration_service) { |
| 375 integration_service->file_system()->RemoveObserver(this); | 398 integration_service->file_system()->RemoveObserver(this); |
| 376 integration_service->drive_service()->RemoveObserver(this); | 399 integration_service->drive_service()->RemoveObserver(this); |
| 377 integration_service->job_list()->RemoveObserver(this); | 400 integration_service->job_list()->RemoveObserver(this); |
| 378 } | 401 } |
| 379 | 402 |
| 380 VolumeManager* volume_manager = VolumeManager::Get(profile_); | 403 VolumeManager* const volume_manager = VolumeManager::Get(profile_); |
| 381 if (volume_manager) | 404 if (volume_manager) { |
| 382 volume_manager->RemoveObserver(this); | 405 volume_manager->RemoveObserver(this); |
| 406 volume_manager->RemoveObserver(device_event_router_.get()); | |
| 407 } | |
| 408 | |
| 409 chromeos::PowerManagerClient* const power_manager_client = | |
| 410 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); | |
| 411 power_manager_client->RemoveObserver(device_event_router_.get()); | |
| 383 | 412 |
| 384 chrome::MultiUserWindowManager* const multi_user_window_manager = | 413 chrome::MultiUserWindowManager* const multi_user_window_manager = |
| 385 chrome::MultiUserWindowManager::GetInstance(); | 414 chrome::MultiUserWindowManager::GetInstance(); |
| 386 if (multi_user_window_manager && | 415 if (multi_user_window_manager && |
| 387 multi_user_window_manager_observer_registered_) { | 416 multi_user_window_manager_observer_registered_) { |
| 388 multi_user_window_manager_observer_registered_ = false; | 417 multi_user_window_manager_observer_registered_ = false; |
| 389 multi_user_window_manager->RemoveObserver(this); | 418 multi_user_window_manager->RemoveObserver(this); |
| 390 } | 419 } |
| 391 | 420 |
| 392 profile_ = NULL; | 421 profile_ = NULL; |
| 393 } | 422 } |
| 394 | 423 |
| 395 void EventRouter::ObserveEvents() { | 424 void EventRouter::ObserveEvents() { |
| 396 if (!profile_) { | 425 if (!profile_) { |
| 397 NOTREACHED(); | 426 NOTREACHED(); |
| 398 return; | 427 return; |
| 399 } | 428 } |
| 400 if (!chromeos::LoginState::IsInitialized() || | 429 if (!chromeos::LoginState::IsInitialized() || |
| 401 !chromeos::LoginState::Get()->IsUserLoggedIn()) { | 430 !chromeos::LoginState::Get()->IsUserLoggedIn()) { |
| 402 return; | 431 return; |
| 403 } | 432 } |
| 404 | 433 |
| 434 // Ignore device events for the first few seconds. | |
| 435 device_event_router_->Startup(); | |
| 436 | |
| 405 // VolumeManager's construction triggers DriveIntegrationService's | 437 // VolumeManager's construction triggers DriveIntegrationService's |
| 406 // construction, so it is necessary to call VolumeManager's Get before | 438 // construction, so it is necessary to call VolumeManager's Get before |
| 407 // accessing DriveIntegrationService. | 439 // accessing DriveIntegrationService. |
| 408 VolumeManager* volume_manager = VolumeManager::Get(profile_); | 440 VolumeManager* const volume_manager = VolumeManager::Get(profile_); |
| 409 if (volume_manager) | 441 if (volume_manager) { |
| 410 volume_manager->AddObserver(this); | 442 volume_manager->AddObserver(this); |
| 443 volume_manager->AddObserver(device_event_router_.get()); | |
| 444 } | |
| 411 | 445 |
| 412 DriveIntegrationService* integration_service = | 446 chromeos::PowerManagerClient* const power_manager_client = |
| 447 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); | |
| 448 power_manager_client->AddObserver(device_event_router_.get()); | |
| 449 | |
| 450 DriveIntegrationService* const integration_service = | |
| 413 DriveIntegrationServiceFactory::FindForProfile(profile_); | 451 DriveIntegrationServiceFactory::FindForProfile(profile_); |
| 414 if (integration_service) { | 452 if (integration_service) { |
| 415 integration_service->drive_service()->AddObserver(this); | 453 integration_service->drive_service()->AddObserver(this); |
| 416 integration_service->file_system()->AddObserver(this); | 454 integration_service->file_system()->AddObserver(this); |
| 417 integration_service->job_list()->AddObserver(this); | 455 integration_service->job_list()->AddObserver(this); |
| 418 } | 456 } |
| 419 | 457 |
| 420 if (NetworkHandler::IsInitialized()) { | 458 if (NetworkHandler::IsInitialized()) { |
| 421 NetworkHandler::Get()->network_state_handler()->AddObserver(this, | 459 NetworkHandler::Get()->network_state_handler()->AddObserver(this, |
| 422 FROM_HERE); | 460 FROM_HERE); |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 817 event.entry.additional_properties.SetString( | 855 event.entry.additional_properties.SetString( |
| 818 "fileFullPath", "/" + entry_definition.full_path.value()); | 856 "fileFullPath", "/" + entry_definition.full_path.value()); |
| 819 event.entry.additional_properties.SetBoolean("fileIsDirectory", | 857 event.entry.additional_properties.SetBoolean("fileIsDirectory", |
| 820 entry_definition.is_directory); | 858 entry_definition.is_directory); |
| 821 | 859 |
| 822 BroadcastEvent(profile_, | 860 BroadcastEvent(profile_, |
| 823 file_browser_private::OnDirectoryChanged::kEventName, | 861 file_browser_private::OnDirectoryChanged::kEventName, |
| 824 file_browser_private::OnDirectoryChanged::Create(event)); | 862 file_browser_private::OnDirectoryChanged::Create(event)); |
| 825 } | 863 } |
| 826 | 864 |
| 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( | 865 void EventRouter::OnDiskAdded( |
| 840 const DiskMountManager::Disk& disk, bool mounting) { | 866 const DiskMountManager::Disk& disk, bool mounting) { |
| 841 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 867 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 842 | 868 // 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 } | 869 } |
| 851 | 870 |
| 852 void EventRouter::OnDiskRemoved(const DiskMountManager::Disk& disk) { | 871 void EventRouter::OnDiskRemoved(const DiskMountManager::Disk& disk) { |
| 853 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 872 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 854 // Do nothing. | 873 // Do nothing. |
| 855 } | 874 } |
| 856 | 875 |
| 857 void EventRouter::OnDeviceAdded(const std::string& device_path) { | 876 void EventRouter::OnDeviceAdded(const std::string& device_path) { |
| 858 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 877 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 859 | 878 // 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 } | 879 } |
| 873 | 880 |
| 874 void EventRouter::OnDeviceRemoved(const std::string& device_path) { | 881 void EventRouter::OnDeviceRemoved(const std::string& device_path) { |
| 875 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 882 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 876 DispatchDeviceEvent( | 883 // Do nothing. |
| 877 file_browser_private::DEVICE_EVENT_TYPE_REMOVED, | |
| 878 device_path); | |
| 879 } | 884 } |
| 880 | 885 |
| 881 void EventRouter::OnVolumeMounted(chromeos::MountError error_code, | 886 void EventRouter::OnVolumeMounted(chromeos::MountError error_code, |
| 882 const VolumeInfo& volume_info, | 887 const VolumeInfo& volume_info, |
| 883 bool is_remounting) { | 888 bool is_remounting) { |
| 884 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 889 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 885 // profile_ is NULL if ShutdownOnUIThread() is called earlier. This can | 890 // profile_ is NULL if ShutdownOnUIThread() is called earlier. This can |
| 886 // happen at shutdown. This should be removed after removing Drive mounting | 891 // happen at shutdown. This should be removed after removing Drive mounting |
| 887 // code in addMount. (addMount -> OnFileSystemMounted -> OnVolumeMounted is | 892 // code in addMount. (addMount -> OnFileSystemMounted -> OnVolumeMounted is |
| 888 // the only path to come here after Shutdown is called). | 893 // the only path to come here after Shutdown is called). |
| 889 if (!profile_) | 894 if (!profile_) |
| 890 return; | 895 return; |
| 896 | |
| 891 DispatchMountCompletedEvent( | 897 DispatchMountCompletedEvent( |
| 892 file_browser_private::MOUNT_COMPLETED_EVENT_TYPE_MOUNT, | 898 file_browser_private::MOUNT_COMPLETED_EVENT_TYPE_MOUNT, |
| 893 error_code, | 899 error_code, |
| 894 volume_info, | 900 volume_info); |
| 895 is_remounting); | |
| 896 } | 901 } |
| 897 | 902 |
| 898 void EventRouter::OnVolumeUnmounted(chromeos::MountError error_code, | 903 void EventRouter::OnVolumeUnmounted(chromeos::MountError error_code, |
| 899 const VolumeInfo& volume_info) { | 904 const VolumeInfo& volume_info) { |
| 900 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 905 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 901 DispatchMountCompletedEvent( | 906 DispatchMountCompletedEvent( |
| 902 file_browser_private::MOUNT_COMPLETED_EVENT_TYPE_UNMOUNT, | 907 file_browser_private::MOUNT_COMPLETED_EVENT_TYPE_UNMOUNT, |
| 903 error_code, | 908 error_code, |
| 904 volume_info, | 909 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 } | 910 } |
| 913 | 911 |
| 914 void EventRouter::DispatchMountCompletedEvent( | 912 void EventRouter::DispatchMountCompletedEvent( |
| 915 file_browser_private::MountCompletedEventType event_type, | 913 file_browser_private::MountCompletedEventType event_type, |
| 916 chromeos::MountError error, | 914 chromeos::MountError error, |
| 917 const VolumeInfo& volume_info, | 915 const VolumeInfo& volume_info) { |
| 918 bool is_remounting) { | |
| 919 // Build an event object. | 916 // Build an event object. |
| 920 file_browser_private::MountCompletedEvent event; | 917 file_browser_private::MountCompletedEvent event; |
| 921 event.event_type = event_type; | 918 event.event_type = event_type; |
| 922 event.status = MountErrorToMountCompletedStatus(error); | 919 event.status = MountErrorToMountCompletedStatus(error); |
| 923 util::VolumeInfoToVolumeMetadata( | 920 util::VolumeInfoToVolumeMetadata( |
| 924 profile_, volume_info, &event.volume_metadata); | 921 profile_, volume_info, &event.volume_metadata); |
| 925 event.is_remounting = is_remounting; | |
| 926 event.should_notify = ShouldShowNotificationForVolume( | 922 event.should_notify = ShouldShowNotificationForVolume( |
| 927 profile_, event_type, error, volume_info, is_remounting); | 923 profile_, *device_event_router_, volume_info); |
| 928 BroadcastEvent(profile_, | 924 BroadcastEvent(profile_, |
| 929 file_browser_private::OnMountCompleted::kEventName, | 925 file_browser_private::OnMountCompleted::kEventName, |
| 930 file_browser_private::OnMountCompleted::Create(event)); | 926 file_browser_private::OnMountCompleted::Create(event)); |
| 931 } | 927 } |
| 932 | 928 |
| 933 void EventRouter::OnFormatStarted(const std::string& device_path, | 929 void EventRouter::OnFormatStarted(const std::string& device_path, |
| 934 bool success) { | 930 bool success) { |
| 935 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 931 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 936 | 932 // 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 } | 933 } |
| 945 | 934 |
| 946 void EventRouter::OnFormatCompleted(const std::string& device_path, | 935 void EventRouter::OnFormatCompleted(const std::string& device_path, |
| 947 bool success) { | 936 bool success) { |
| 948 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 937 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 949 DispatchDeviceEvent(success ? | 938 // Do nothing. |
| 950 file_browser_private::DEVICE_EVENT_TYPE_FORMAT_SUCCESS : | |
| 951 file_browser_private::DEVICE_EVENT_TYPE_FORMAT_FAIL, | |
| 952 device_path); | |
| 953 } | 939 } |
| 954 | 940 |
| 955 void EventRouter::Observe(int type, | 941 void EventRouter::Observe(int type, |
| 956 const content::NotificationSource& source, | 942 const content::NotificationSource& source, |
| 957 const content::NotificationDetails& details) { | 943 const content::NotificationDetails& details) { |
| 958 if (type == chrome::NOTIFICATION_PROFILE_ADDED) { | 944 if (type == chrome::NOTIFICATION_PROFILE_ADDED) { |
| 959 Profile* const added_profile = content::Source<Profile>(source).ptr(); | 945 Profile* const added_profile = content::Source<Profile>(source).ptr(); |
| 960 if (!added_profile->IsOffTheRecord()) | 946 if (!added_profile->IsOffTheRecord()) |
| 961 GrantAccessForAddedProfileToRunningInstance(added_profile, profile_); | 947 GrantAccessForAddedProfileToRunningInstance(added_profile, profile_); |
| 962 | 948 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 977 } | 963 } |
| 978 } | 964 } |
| 979 | 965 |
| 980 void EventRouter::OnOwnerEntryChanged(aura::Window* window) { | 966 void EventRouter::OnOwnerEntryChanged(aura::Window* window) { |
| 981 BroadcastEvent(profile_, | 967 BroadcastEvent(profile_, |
| 982 file_browser_private::OnDesktopChanged::kEventName, | 968 file_browser_private::OnDesktopChanged::kEventName, |
| 983 file_browser_private::OnDesktopChanged::Create()); | 969 file_browser_private::OnDesktopChanged::Create()); |
| 984 } | 970 } |
| 985 | 971 |
| 986 } // namespace file_manager | 972 } // namespace file_manager |
| OLD | NEW |