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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/device_event_router.h

Issue 472603004: Add DeviceEventRouter class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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
(Empty)
1 // 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.
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 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.
19 // Device is not being scanned and is not hard unplugged.
20 DEVICE_STATE_USUAL,
21 DEVICE_SCANNED,
22 DEVICE_SCANNED_AND_REPORTED,
23 DEVICE_HARD_UNPLUGGED,
24 DEVICE_HARD_UNPLUGGED_AND_REPORTED
25 };
26
27 // Event router for device events.
28 class DeviceEventRouter : public VolumeManagerObserver,
29 public chromeos::PowerManagerClient::Observer {
30 public:
31 DeviceEventRouter();
32 virtual ~DeviceEventRouter();
33
34 // Turns the startup flag on, and then turns it off after few seconds.
35 void Startup();
36
37 // VolumeManagerObserver overrides.
38 virtual void OnDiskAdded(const chromeos::disks::DiskMountManager::Disk& disk,
39 bool mounting) OVERRIDE;
40 virtual void OnDiskRemoved(
41 const chromeos::disks::DiskMountManager::Disk& disk) OVERRIDE;
42 virtual void OnDeviceAdded(const std::string& device_path) OVERRIDE;
43 virtual void OnDeviceRemoved(const std::string& device_path) OVERRIDE;
44 virtual void OnVolumeMounted(chromeos::MountError error_code,
45 const VolumeInfo& volume_info,
46 bool is_remounting) OVERRIDE;
47 virtual void OnVolumeUnmounted(chromeos::MountError error_code,
48 const VolumeInfo& volume_info) OVERRIDE;
49 virtual void OnFormatStarted(const std::string& device_path,
50 bool success) OVERRIDE;
51 virtual void OnFormatCompleted(const std::string& device_path,
52 bool success) OVERRIDE;
53
54 // TODO(hirono): Remove the method from VolumeManagerObserver.
55 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.
56
57 // PowerManagerClient::Observer overrides.
58 virtual void SuspendImminent() OVERRIDE;
59 virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE;
60
61 protected:
62 // Handles a device event containing |type| and |device_path|.
63 virtual void OnDeviceEvent(
64 extensions::api::file_browser_private::DeviceEventType type,
65 const std::string& device_path) = 0;
66 // 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.
67 virtual bool IsExternalStorageDisabled() = 0;
68 // Sends |callback| to run after |time| passed.
69 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
70 const base::TimeDelta time) = 0;
71
72 private:
73 void StartupDelayed();
74 void OnDeviceAddedDelayed(const std::string& device_path);
75 void SuspendDoneDelayed();
76
77 // Obtains device state of the device having |device_path|.
78 DeviceState GetDeviceState(const std::string& device_path);
79 // Sets device state to the device having |device_path|.
80 void SetDeviceState(const std::string& device_path, DeviceState state);
81
82 // 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.
83 bool is_startup_;
84 // Whether the system was just suspended or not.
85 bool is_suspended_;
86 // Map of device path and device state.
87 std::map<std::string, DeviceState> device_states_;
88
89 // Note: This should remain the last member so it'll be destroyed and
90 // invalidate the weak pointers before any other members are destroyed.
91 base::WeakPtrFactory<DeviceEventRouter> weak_factory_;
92 DISALLOW_COPY_AND_ASSIGN(DeviceEventRouter);
93 };
94 } // namespace file_manager
95
96 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_DEVICE_EVENT_ROUTER_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698