OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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_USB_MOUNT_OBSERVER_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_USB_MOUNT_OBSERVER_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 #include <map> | |
11 #include <vector> | |
12 | |
13 #include "chrome/browser/chromeos/cros/mount_library.h" | |
14 #include "content/common/notification_observer.h" | |
15 #include "content/common/notification_registrar.h" | |
16 #include "content/common/notification_source.h" | |
17 #include "content/common/notification_type.h" | |
18 | |
19 class Browser; | |
20 template <typename T> struct DefaultSingletonTraits; | |
21 class Profile; | |
22 | |
23 namespace chromeos { // NOLINT | |
24 | |
25 // Used to monitor mount changes and popup a new window when | |
26 // a new mounted usb device is found. | |
27 class USBMountObserver : public MountLibrary::Observer, | |
28 public NotificationObserver { | |
29 public: | |
30 struct BrowserWithPath { | |
31 Browser* browser; | |
32 std::string device_path; | |
33 std::string mount_path; | |
34 }; | |
35 | |
36 static USBMountObserver* GetInstance(); | |
37 | |
38 // NotificationObserver overrides. | |
39 virtual void Observe(NotificationType type, | |
40 const NotificationSource& source, | |
41 const NotificationDetails& details); | |
42 | |
43 // MountLibrary::Observer overrides. | |
44 virtual void DiskChanged(MountLibraryEventType event, | |
45 const MountLibrary::Disk* disk); | |
46 virtual void DeviceChanged(MountLibraryEventType event, | |
47 const std::string& device_path); | |
48 | |
49 private: | |
50 friend struct DefaultSingletonTraits<USBMountObserver>; | |
51 typedef std::vector<BrowserWithPath>::iterator BrowserIterator; | |
52 typedef std::map<std::string, std::string> MountPointMap; | |
53 | |
54 USBMountObserver() {} | |
55 virtual ~USBMountObserver() {} | |
56 | |
57 // USB mount event handlers. | |
58 void OnDiskAdded(const MountLibrary::Disk* disk); | |
59 void OnDiskRemoved(const MountLibrary::Disk* disk); | |
60 void OnDiskChanged(const MountLibrary::Disk* disk); | |
61 void OnDeviceAdded(const std::string& device_path); | |
62 void OnDeviceRemoved(const std::string& device_path); | |
63 void OnDeviceScanned(const std::string& device_path); | |
64 | |
65 BrowserIterator FindBrowserForPath(const std::string& path); | |
66 | |
67 // Sends filesystem changed extension message to all renderers. | |
68 void FireFileSystemChanged(const std::string& web_path); | |
69 | |
70 void RemoveBrowserFromVector(const std::string& path); | |
71 | |
72 // Used to create a window of a standard size, and add it to a list | |
73 // of tracked browser windows in case that device goes away. | |
74 void OpenFileBrowse(const std::string& url, | |
75 const std::string& device_path, | |
76 bool small); | |
77 | |
78 std::vector<BrowserWithPath> browsers_; | |
79 NotificationRegistrar registrar_; | |
80 MountPointMap mounted_devices_; | |
81 | |
82 DISALLOW_COPY_AND_ASSIGN(USBMountObserver); | |
83 }; | |
84 | |
85 } // namespace chromeos | |
86 #endif // CHROME_BROWSER_CHROMEOS_USB_MOUNT_OBSERVER_H_ | |
OLD | NEW |