| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/files/file_path_watcher.h" | 13 #include "base/files/file_path_watcher.h" |
| 14 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/string16.h" | 16 #include "base/string16.h" |
| 17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 18 #include "chrome/browser/chromeos/disks/disk_mount_manager.h" | 18 #include "chrome/browser/chromeos/disks/disk_mount_manager.h" |
| 19 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" | |
| 20 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" | |
| 21 #include "chrome/browser/profiles/profile_keyed_service.h" | |
| 22 #include "chrome/browser/profiles/profile_keyed_service_factory.h" | |
| 23 | 19 |
| 24 class FileBrowserNotifications; | 20 class FileBrowserNotifications; |
| 25 class Profile; | 21 class Profile; |
| 26 | 22 |
| 27 // Used to monitor disk mount changes and signal when new mounted usb device is | 23 // Used to monitor disk mount changes and signal when new mounted usb device is |
| 28 // found. | 24 // found. |
| 29 class FileBrowserEventRouter | 25 class ExtensionFileBrowserEventRouter |
| 30 : public ProfileKeyedService, | 26 : public chromeos::disks::DiskMountManager::Observer { |
| 31 public chromeos::disks::DiskMountManager::Observer, | |
| 32 public gdata::GDataOperationRegistry::Observer { | |
| 33 public: | 27 public: |
| 34 // ProfileKeyedService overrides. | 28 explicit ExtensionFileBrowserEventRouter(Profile* profile); |
| 35 virtual void Shutdown() OVERRIDE; | 29 virtual ~ExtensionFileBrowserEventRouter(); |
| 36 | |
| 37 // Starts observing file system change events. Currently only | 30 // Starts observing file system change events. Currently only |
| 38 // CrosDisksClient events are being observed. | 31 // CrosDisksClient events are being observed. |
| 39 void ObserveFileSystemEvents(); | 32 void ObserveFileSystemEvents(); |
| 40 | 33 |
| 41 // File watch setup routines. | 34 // File watch setup routines. |
| 42 bool AddFileWatch(const FilePath& file_path, | 35 bool AddFileWatch(const FilePath& file_path, |
| 43 const FilePath& virtual_path, | 36 const FilePath& virtual_path, |
| 44 const std::string& extension_id); | 37 const std::string& extension_id); |
| 45 void RemoveFileWatch(const FilePath& file_path, | 38 void RemoveFileWatch(const FilePath& file_path, |
| 46 const std::string& extension_id); | 39 const std::string& extension_id); |
| 47 | 40 |
| 48 // CrosDisksClient::Observer overrides. | 41 // CrosDisksClient::Observer overrides. |
| 49 virtual void DiskChanged(chromeos::disks::DiskMountManagerEventType event, | 42 virtual void DiskChanged(chromeos::disks::DiskMountManagerEventType event, |
| 50 const chromeos::disks::DiskMountManager::Disk* disk) | 43 const chromeos::disks::DiskMountManager::Disk* disk) |
| 51 OVERRIDE; | 44 OVERRIDE; |
| 52 virtual void DeviceChanged(chromeos::disks::DiskMountManagerEventType event, | 45 virtual void DeviceChanged(chromeos::disks::DiskMountManagerEventType event, |
| 53 const std::string& device_path) OVERRIDE; | 46 const std::string& device_path) OVERRIDE; |
| 54 virtual void MountCompleted( | 47 virtual void MountCompleted( |
| 55 chromeos::disks::DiskMountManager::MountEvent event_type, | 48 chromeos::disks::DiskMountManager::MountEvent event_type, |
| 56 chromeos::MountError error_code, | 49 chromeos::MountError error_code, |
| 57 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) | 50 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) |
| 58 OVERRIDE; | 51 OVERRIDE; |
| 59 | 52 |
| 60 // GDataOperationRegistry::Observer overrides. | |
| 61 virtual void OnProgressUpdate( | |
| 62 const std::vector<gdata::GDataOperationRegistry::ProgressStatus>& list) | |
| 63 OVERRIDE; | |
| 64 | |
| 65 private: | 53 private: |
| 66 friend class FileBrowserEventRouterFactory; | |
| 67 | |
| 68 // Helper class for passing through file watch notification events. | 54 // Helper class for passing through file watch notification events. |
| 69 class FileWatcherDelegate : public base::files::FilePathWatcher::Delegate { | 55 class FileWatcherDelegate : public base::files::FilePathWatcher::Delegate { |
| 70 public: | 56 public: |
| 71 explicit FileWatcherDelegate(FileBrowserEventRouter* router); | 57 explicit FileWatcherDelegate(ExtensionFileBrowserEventRouter* router); |
| 72 | 58 |
| 73 private: | 59 private: |
| 74 // base::files::FilePathWatcher::Delegate overrides. | 60 // base::files::FilePathWatcher::Delegate overrides. |
| 75 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE; | 61 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE; |
| 76 virtual void OnFilePathError(const FilePath& path) OVERRIDE; | 62 virtual void OnFilePathError(const FilePath& path) OVERRIDE; |
| 77 | 63 |
| 78 void HandleFileWatchOnUIThread(const FilePath& local_path, bool got_error); | 64 void HandleFileWatchOnUIThread(const FilePath& local_path, bool got_error); |
| 79 | 65 |
| 80 FileBrowserEventRouter* router_; | 66 ExtensionFileBrowserEventRouter* router_; |
| 81 }; | 67 }; |
| 82 | 68 |
| 83 typedef std::map<std::string, int> ExtensionUsageRegistry; | 69 typedef std::map<std::string, int> ExtensionUsageRegistry; |
| 84 | 70 |
| 85 class FileWatcherExtensions { | 71 class FileWatcherExtensions { |
| 86 public: | 72 public: |
| 87 FileWatcherExtensions(const FilePath& path, | 73 FileWatcherExtensions(const FilePath& path, |
| 88 const std::string& extension_id); | 74 const std::string& extension_id); |
| 89 | 75 |
| 90 ~FileWatcherExtensions() {} | 76 ~FileWatcherExtensions() {} |
| (...skipping 13 matching lines...) Expand all Loading... |
| 104 private: | 90 private: |
| 105 linked_ptr<base::files::FilePathWatcher> file_watcher; | 91 linked_ptr<base::files::FilePathWatcher> file_watcher; |
| 106 FilePath local_path; | 92 FilePath local_path; |
| 107 FilePath virtual_path; | 93 FilePath virtual_path; |
| 108 ExtensionUsageRegistry extensions; | 94 ExtensionUsageRegistry extensions; |
| 109 unsigned int ref_count; | 95 unsigned int ref_count; |
| 110 }; | 96 }; |
| 111 | 97 |
| 112 typedef std::map<FilePath, FileWatcherExtensions*> WatcherMap; | 98 typedef std::map<FilePath, FileWatcherExtensions*> WatcherMap; |
| 113 | 99 |
| 114 explicit FileBrowserEventRouter(Profile* profile); | |
| 115 virtual ~FileBrowserEventRouter(); | |
| 116 | |
| 117 // USB mount event handlers. | 100 // USB mount event handlers. |
| 118 void OnDiskAdded(const chromeos::disks::DiskMountManager::Disk* disk); | 101 void OnDiskAdded(const chromeos::disks::DiskMountManager::Disk* disk); |
| 119 void OnDiskRemoved(const chromeos::disks::DiskMountManager::Disk* disk); | 102 void OnDiskRemoved(const chromeos::disks::DiskMountManager::Disk* disk); |
| 120 void OnDiskMounted(const chromeos::disks::DiskMountManager::Disk* disk); | 103 void OnDiskMounted(const chromeos::disks::DiskMountManager::Disk* disk); |
| 121 void OnDiskUnmounted(const chromeos::disks::DiskMountManager::Disk* disk); | 104 void OnDiskUnmounted(const chromeos::disks::DiskMountManager::Disk* disk); |
| 122 void OnDeviceAdded(const std::string& device_path); | 105 void OnDeviceAdded(const std::string& device_path); |
| 123 void OnDeviceRemoved(const std::string& device_path); | 106 void OnDeviceRemoved(const std::string& device_path); |
| 124 void OnDeviceScanned(const std::string& device_path); | 107 void OnDeviceScanned(const std::string& device_path); |
| 125 void OnFormattingStarted(const std::string& device_path, bool success); | 108 void OnFormattingStarted(const std::string& device_path, bool success); |
| 126 void OnFormattingFinished(const std::string& device_path, bool success); | 109 void OnFormattingFinished(const std::string& device_path, bool success); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 149 void OpenFileBrowse(const std::string& url, | 132 void OpenFileBrowse(const std::string& url, |
| 150 const std::string& device_path, | 133 const std::string& device_path, |
| 151 bool small); | 134 bool small); |
| 152 | 135 |
| 153 scoped_refptr<FileWatcherDelegate> delegate_; | 136 scoped_refptr<FileWatcherDelegate> delegate_; |
| 154 WatcherMap file_watchers_; | 137 WatcherMap file_watchers_; |
| 155 scoped_ptr<FileBrowserNotifications> notifications_; | 138 scoped_ptr<FileBrowserNotifications> notifications_; |
| 156 Profile* profile_; | 139 Profile* profile_; |
| 157 base::Lock lock_; | 140 base::Lock lock_; |
| 158 | 141 |
| 159 DISALLOW_COPY_AND_ASSIGN(FileBrowserEventRouter); | 142 DISALLOW_COPY_AND_ASSIGN(ExtensionFileBrowserEventRouter); |
| 160 }; | |
| 161 | |
| 162 // Singleton that owns all FileBrowserEventRouter and associates | |
| 163 // them with Profiles. | |
| 164 class FileBrowserEventRouterFactory | |
| 165 : public ProfileKeyedServiceFactory { | |
| 166 public: | |
| 167 // Returns the FileBrowserEventRouter for |profile|, creating it if | |
| 168 // it is not yet created. | |
| 169 static FileBrowserEventRouter* GetForProfile(Profile* profile); | |
| 170 | |
| 171 // Returns the FileBrowserEventRouterFactory instance. | |
| 172 static FileBrowserEventRouterFactory* GetInstance(); | |
| 173 | |
| 174 private: | |
| 175 friend struct DefaultSingletonTraits<FileBrowserEventRouterFactory>; | |
| 176 | |
| 177 FileBrowserEventRouterFactory(); | |
| 178 virtual ~FileBrowserEventRouterFactory(); | |
| 179 | |
| 180 // ProfileKeyedServiceFactory: | |
| 181 virtual ProfileKeyedService* BuildServiceInstanceFor( | |
| 182 Profile* profile) const OVERRIDE; | |
| 183 }; | 143 }; |
| 184 | 144 |
| 185 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ | 145 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ |
| OLD | NEW |