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_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ 7 #pragma once 8 9 #include <string> 10 #include <map> 11 12 #include "base/memory/linked_ptr.h" 13 #include "base/string16.h" 14 #include "chrome/browser/chromeos/cros/mount_library.h" 15 16 class Profile; 17 18 namespace chromeos { 19 class SystemNotification; 20 } 21 22 // Used to monitor disk mount changes and signal when new mounted usb device is 23 // found. 24 class ExtensionFileBrowserEventRouter 25 : public chromeos::MountLibrary::Observer { 26 public: 27 static ExtensionFileBrowserEventRouter* GetInstance(); 28 29 // Starts/stops observing file system change events. Currently only 30 // MountLibrary events are being observed. 31 void ObserveFileSystemEvents(Profile* profile); 32 void StopObservingFileSystemEvents(); 33 34 // MountLibrary::Observer overrides. 35 virtual void DiskChanged(chromeos::MountLibraryEventType event, 36 const chromeos::MountLibrary::Disk* disk); 37 virtual void DeviceChanged(chromeos::MountLibraryEventType event, 38 const std::string& device_path); 39 40 private: 41 friend struct DefaultSingletonTraits<ExtensionFileBrowserEventRouter>; 42 typedef std::map<std::string, linked_ptr<chromeos::SystemNotification> > 43 NotificationMap; 44 typedef std::map<std::string, std::string> MountPointMap; 45 46 ExtensionFileBrowserEventRouter(); 47 virtual ~ExtensionFileBrowserEventRouter(); 48 49 // USB mount event handlers. 50 void OnDiskAdded(const chromeos::MountLibrary::Disk* disk); 51 void OnDiskRemoved(const chromeos::MountLibrary::Disk* disk); 52 void OnDiskChanged(const chromeos::MountLibrary::Disk* disk); 53 void OnDeviceAdded(const std::string& device_path); 54 void OnDeviceRemoved(const std::string& device_path); 55 void OnDeviceScanned(const std::string& device_path); 56 57 // Finds first notifications corresponding to the same device. Ensures that 58 // we don't pop up multiple notifications for the same device. 59 NotificationMap::iterator FindNotificationForPath(const std::string& path); 60 61 // Sends filesystem changed extension message to all renderers. 62 void DispatchEvent(const chromeos::MountLibrary::Disk* disk, bool added); 63 64 void RemoveBrowserFromVector(const std::string& path); 65 66 // Used to create a window of a standard size, and add it to a list 67 // of tracked browser windows in case that device goes away. 68 void OpenFileBrowse(const std::string& url, 69 const std::string& device_path, 70 bool small); 71 72 // Show/hide desktop notifications. 73 void ShowDeviceNotification(const std::string& system_path, 74 int icon_resource_id, 75 const string16& message); 76 void HideDeviceNotification(const std::string& system_path); 77 78 MountPointMap mounted_devices_; 79 NotificationMap notifications_; 80 Profile* profile_; 81 82 DISALLOW_COPY_AND_ASSIGN(ExtensionFileBrowserEventRouter); 83 }; 84 85 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ 86