Chromium Code Reviews| Index: chrome/browser/chromeos/extensions/file_manager/device_event_router.h |
| diff --git a/chrome/browser/chromeos/extensions/file_manager/device_event_router.h b/chrome/browser/chromeos/extensions/file_manager/device_event_router.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d7631278ccc796e5f662cbac6ea7680c70a08338 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/extensions/file_manager/device_event_router.h |
| @@ -0,0 +1,96 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
|
mtomasz
2014/08/20 06:31:01
nit: no (c).
hirono
2014/08/20 08:07:17
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_DEVICE_EVENT_ROUTER_H_ |
| +#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_DEVICE_EVENT_ROUTER_H_ |
| + |
| +#include <map> |
| +#include <string> |
| + |
| +#include "base/observer_list.h" |
| +#include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" |
| +#include "chrome/common/extensions/api/file_browser_private.h" |
| +#include "chromeos/dbus/power_manager_client.h" |
| +#include "chromeos/disks/disk_mount_manager.h" |
| + |
| +namespace file_manager { |
| +enum DeviceState { |
|
mtomasz
2014/08/20 06:31:01
nit:
AFAIK we usually put extra \n after opening a
hirono
2014/08/20 08:07:16
Done.
|
| + // Device is not being scanned and is not hard unplugged. |
| + DEVICE_STATE_USUAL, |
| + DEVICE_SCANNED, |
| + DEVICE_SCANNED_AND_REPORTED, |
| + DEVICE_HARD_UNPLUGGED, |
| + DEVICE_HARD_UNPLUGGED_AND_REPORTED |
| +}; |
| + |
| +// Event router for device events. |
| +class DeviceEventRouter : public VolumeManagerObserver, |
| + public chromeos::PowerManagerClient::Observer { |
| + public: |
| + DeviceEventRouter(); |
| + virtual ~DeviceEventRouter(); |
| + |
| + // Turns the startup flag on, and then turns it off after few seconds. |
| + void Startup(); |
| + |
| + // VolumeManagerObserver overrides. |
| + virtual void OnDiskAdded(const chromeos::disks::DiskMountManager::Disk& disk, |
| + bool mounting) OVERRIDE; |
| + virtual void OnDiskRemoved( |
| + const chromeos::disks::DiskMountManager::Disk& disk) OVERRIDE; |
| + virtual void OnDeviceAdded(const std::string& device_path) OVERRIDE; |
| + virtual void OnDeviceRemoved(const std::string& device_path) OVERRIDE; |
| + virtual void OnVolumeMounted(chromeos::MountError error_code, |
| + const VolumeInfo& volume_info, |
| + bool is_remounting) OVERRIDE; |
| + virtual void OnVolumeUnmounted(chromeos::MountError error_code, |
| + const VolumeInfo& volume_info) OVERRIDE; |
| + virtual void OnFormatStarted(const std::string& device_path, |
| + bool success) OVERRIDE; |
| + virtual void OnFormatCompleted(const std::string& device_path, |
| + bool success) OVERRIDE; |
| + |
| + // TODO(hirono): Remove the method from VolumeManagerObserver. |
| + virtual void OnHardUnplugged(const std::string& device_path) OVERRIDE {} |
|
mtomasz
2014/08/20 06:31:01
nit: Shall implementation be in the .cc file?
hirono
2014/08/20 08:07:17
Done.
|
| + |
| + // PowerManagerClient::Observer overrides. |
| + virtual void SuspendImminent() OVERRIDE; |
| + virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE; |
| + |
| + protected: |
| + // Handles a device event containing |type| and |device_path|. |
| + virtual void OnDeviceEvent( |
| + extensions::api::file_browser_private::DeviceEventType type, |
| + const std::string& device_path) = 0; |
| + // Returns external storage is disabled or not. |
|
mtomasz
2014/08/20 06:31:01
nit: We usually put \n between methods if there is
hirono
2014/08/20 08:07:17
Done.
|
| + virtual bool IsExternalStorageDisabled() = 0; |
| + // Sends |callback| to run after |time| passed. |
| + virtual void PostDelayedTask(const base::Closure& callback, |
|
mtomasz
2014/08/20 06:31:01
Do we need it? We could just normally post a task
hirono
2014/08/20 08:07:16
I checked, but the method looks deprecated.
https:
mtomasz
2014/08/20 08:20:17
Indeed it is deprecated, base::RunLoop should be u
|
| + const base::TimeDelta time) = 0; |
| + |
| + private: |
| + void StartupDelayed(); |
| + void OnDeviceAddedDelayed(const std::string& device_path); |
| + void SuspendDoneDelayed(); |
| + |
| + // Obtains device state of the device having |device_path|. |
| + DeviceState GetDeviceState(const std::string& device_path); |
| + // Sets device state to the device having |device_path|. |
| + void SetDeviceState(const std::string& device_path, DeviceState state); |
| + |
| + // Whether the profile was just startupped or not. |
|
mtomasz
2014/08/20 06:31:02
nit: startupped -> starting up
nit: is_startup_ ->
hirono
2014/08/20 08:07:17
Done.
|
| + bool is_startup_; |
| + // Whether the system was just suspended or not. |
| + bool is_suspended_; |
| + // Map of device path and device state. |
| + std::map<std::string, DeviceState> device_states_; |
| + |
| + // Note: This should remain the last member so it'll be destroyed and |
| + // invalidate the weak pointers before any other members are destroyed. |
| + base::WeakPtrFactory<DeviceEventRouter> weak_factory_; |
| + DISALLOW_COPY_AND_ASSIGN(DeviceEventRouter); |
| +}; |
| +} // namespace file_manager |
| + |
| +#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_DEVICE_EVENT_ROUTER_H_ |