Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_DEVICE_EVENT_ROUTER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_DEVICE_EVENT_ROUTER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/observer_list.h" | |
| 12 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" | |
| 13 #include "chrome/common/extensions/api/file_browser_private.h" | |
| 14 #include "chromeos/dbus/power_manager_client.h" | |
| 15 #include "chromeos/disks/disk_mount_manager.h" | |
| 16 | |
| 17 namespace file_manager { | |
| 18 | |
| 19 enum DeviceState { | |
| 20 // Device is not being scanned and is not hard unplugged. | |
| 21 DEVICE_STATE_USUAL, | |
| 22 DEVICE_SCANNED, | |
| 23 DEVICE_SCANNED_AND_REPORTED, | |
| 24 DEVICE_HARD_UNPLUGGED, | |
| 25 DEVICE_HARD_UNPLUGGED_AND_REPORTED | |
| 26 }; | |
| 27 | |
| 28 // Event router for device events. | |
| 29 class DeviceEventRouter : public VolumeManagerObserver, | |
| 30 public chromeos::PowerManagerClient::Observer { | |
| 31 public: | |
| 32 // If |zero_time_delta| is true, it overrides time delta of delayed tasks with | |
| 33 // zero for testing so that the tasks are executed by RunLoop::RunUntilIdle. | |
| 34 explicit DeviceEventRouter(bool zero_time_delta = false); | |
|
mtomasz
2014/08/21 08:32:47
Default argument values are not allowed by our sty
hirono
2014/08/21 08:48:32
Done.
| |
| 35 virtual ~DeviceEventRouter(); | |
| 36 | |
| 37 // Turns the startup flag on, and then turns it off after few seconds. | |
| 38 void Startup(); | |
| 39 | |
| 40 // VolumeManagerObserver overrides. | |
| 41 virtual void OnDiskAdded(const chromeos::disks::DiskMountManager::Disk& disk, | |
| 42 bool mounting) OVERRIDE; | |
| 43 virtual void OnDiskRemoved( | |
| 44 const chromeos::disks::DiskMountManager::Disk& disk) OVERRIDE; | |
| 45 virtual void OnDeviceAdded(const std::string& device_path) OVERRIDE; | |
| 46 virtual void OnDeviceRemoved(const std::string& device_path) OVERRIDE; | |
| 47 virtual void OnVolumeMounted(chromeos::MountError error_code, | |
| 48 const VolumeInfo& volume_info, | |
| 49 bool is_remounting) OVERRIDE; | |
| 50 virtual void OnVolumeUnmounted(chromeos::MountError error_code, | |
| 51 const VolumeInfo& volume_info) OVERRIDE; | |
| 52 virtual void OnFormatStarted(const std::string& device_path, | |
| 53 bool success) OVERRIDE; | |
| 54 virtual void OnFormatCompleted(const std::string& device_path, | |
| 55 bool success) OVERRIDE; | |
| 56 | |
| 57 // TODO(hirono): Remove the method from VolumeManagerObserver. | |
| 58 virtual void OnHardUnplugged(const std::string& device_path) OVERRIDE; | |
| 59 | |
| 60 // PowerManagerClient::Observer overrides. | |
| 61 virtual void SuspendImminent() OVERRIDE; | |
| 62 virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE; | |
| 63 | |
| 64 protected: | |
| 65 // Handles a device event containing |type| and |device_path|. | |
| 66 virtual void OnDeviceEvent( | |
| 67 extensions::api::file_browser_private::DeviceEventType type, | |
| 68 const std::string& device_path) = 0; | |
| 69 // Returns external storage is disabled or not. | |
| 70 virtual bool IsExternalStorageDisabled() = 0; | |
| 71 | |
| 72 private: | |
| 73 // Post a delayed task by referring |zero_time_delta_|. | |
| 74 void PostDelayedTask(const base::Closure& closure, base::TimeDelta time); | |
|
mtomasz
2014/08/21 08:32:47
Is this still used?
hirono
2014/08/21 08:48:32
This is a helper method to call MessageLoop::PostD
| |
| 75 | |
| 76 void StartupDelayed(); | |
| 77 void OnDeviceAddedDelayed(const std::string& device_path); | |
| 78 void SuspendDoneDelayed(); | |
| 79 | |
| 80 // Obtains device state of the device having |device_path|. | |
| 81 DeviceState GetDeviceState(const std::string& device_path); | |
|
mtomasz
2014/08/21 08:32:47
Can this method be const?
hirono
2014/08/21 08:48:32
Done.
| |
| 82 | |
| 83 // Sets device state to the device having |device_path|. | |
| 84 void SetDeviceState(const std::string& device_path, DeviceState state); | |
| 85 | |
| 86 // Whther to use zero time delta for testing or not. | |
| 87 const bool zero_time_delta_; | |
| 88 | |
| 89 // Whether the profile is starting up or not. | |
| 90 bool is_starting_up_; | |
| 91 | |
| 92 // Whether the system is resuming or not. | |
| 93 bool is_resuming_; | |
| 94 | |
| 95 // Map of device path and device state. | |
| 96 std::map<std::string, DeviceState> device_states_; | |
| 97 | |
| 98 // Note: This should remain the last member so it'll be destroyed and | |
| 99 // invalidate the weak pointers before any other members are destroyed. | |
| 100 base::WeakPtrFactory<DeviceEventRouter> weak_factory_; | |
| 101 DISALLOW_COPY_AND_ASSIGN(DeviceEventRouter); | |
| 102 }; | |
| 103 } // namespace file_manager | |
| 104 | |
| 105 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_DEVICE_EVENT_ROUTER_H _ | |
| OLD | NEW |