| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_STORAGE_MONITOR_VOLUME_MOUNT_WATCHER_WIN_H_ | 5 #ifndef COMPONENTS_STORAGE_MONITOR_VOLUME_MOUNT_WATCHER_WIN_H_ |
| 6 #define COMPONENTS_STORAGE_MONITOR_VOLUME_MOUNT_WATCHER_WIN_H_ | 6 #define COMPONENTS_STORAGE_MONITOR_VOLUME_MOUNT_WATCHER_WIN_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/sequenced_task_runner.h" | 17 #include "base/sequenced_task_runner.h" |
| 18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 19 #include "base/threading/sequenced_worker_pool.h" | |
| 20 #include "components/storage_monitor/storage_info.h" | 19 #include "components/storage_monitor/storage_info.h" |
| 21 #include "components/storage_monitor/storage_monitor.h" | 20 #include "components/storage_monitor/storage_monitor.h" |
| 22 | 21 |
| 23 namespace storage_monitor { | 22 namespace storage_monitor { |
| 24 | 23 |
| 25 class TestVolumeMountWatcherWin; | 24 class TestVolumeMountWatcherWin; |
| 26 | 25 |
| 27 // This class watches the volume mount points and sends notifications to | 26 // This class watches the volume mount points and sends notifications to |
| 28 // StorageMonitor about the device attach/detach events. | 27 // StorageMonitor about the device attach/detach events. |
| 29 // This is a singleton class instantiated by StorageMonitorWin. | 28 // This is a singleton class instantiated by StorageMonitorWin. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 const base::FilePath& device_path, | 82 const base::FilePath& device_path, |
| 84 const GetDeviceDetailsCallbackType& get_device_details_callback, | 83 const GetDeviceDetailsCallbackType& get_device_details_callback, |
| 85 base::WeakPtr<VolumeMountWatcherWin> volume_watcher); | 84 base::WeakPtr<VolumeMountWatcherWin> volume_watcher); |
| 86 | 85 |
| 87 // Mark that a device we started a metadata check for has completed. | 86 // Mark that a device we started a metadata check for has completed. |
| 88 virtual void DeviceCheckComplete(const base::FilePath& device_path); | 87 virtual void DeviceCheckComplete(const base::FilePath& device_path); |
| 89 | 88 |
| 90 virtual GetAttachedDevicesCallbackType GetAttachedDevicesCallback() const; | 89 virtual GetAttachedDevicesCallbackType GetAttachedDevicesCallback() const; |
| 91 virtual GetDeviceDetailsCallbackType GetDeviceDetailsCallback() const; | 90 virtual GetDeviceDetailsCallbackType GetDeviceDetailsCallback() const; |
| 92 | 91 |
| 93 // Worker pool used to collect device information. Used because some | 92 // Used for device info calls that may take a long time. |
| 94 // devices freeze workers trying to get device info, resulting in | 93 scoped_refptr<base::SequencedTaskRunner> device_info_task_runner_; |
| 95 // shutdown hangs. | |
| 96 scoped_refptr<base::SequencedWorkerPool> device_info_worker_pool_; | |
| 97 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
| 98 | 94 |
| 99 private: | 95 private: |
| 100 friend class TestVolumeMountWatcherWin; | 96 friend class TestVolumeMountWatcherWin; |
| 101 | 97 |
| 102 // Key: Mass storage device mount point. | 98 // Key: Mass storage device mount point. |
| 103 // Value: Mass storage device metadata. | 99 // Value: Mass storage device metadata. |
| 104 typedef std::map<base::FilePath, StorageInfo> MountPointDeviceMetadataMap; | 100 typedef std::map<base::FilePath, StorageInfo> MountPointDeviceMetadataMap; |
| 105 | 101 |
| 106 // Maintain a set of device attribute check calls in-flight. Only accessed | 102 // Maintain a set of device attribute check calls in-flight. Only accessed |
| 107 // on the UI thread. This is to try and prevent the same device from | 103 // on the UI thread. This is to try and prevent the same device from |
| 108 // occupying our worker pool in case of windows API call hangs. | 104 // occupying our worker pool in case of windows API call hangs. |
| 109 std::set<base::FilePath> pending_device_checks_; | 105 std::set<base::FilePath> pending_device_checks_; |
| 110 | 106 |
| 111 // A map from device mount point to device metadata. Only accessed on the UI | 107 // A map from device mount point to device metadata. Only accessed on the UI |
| 112 // thread. | 108 // thread. |
| 113 MountPointDeviceMetadataMap device_metadata_; | 109 MountPointDeviceMetadataMap device_metadata_; |
| 114 | 110 |
| 115 // The notifications object to use to signal newly attached volumes. Only | 111 // The notifications object to use to signal newly attached volumes. Only |
| 116 // removable devices will be notified. | 112 // removable devices will be notified. |
| 117 StorageMonitor::Receiver* notifications_; | 113 StorageMonitor::Receiver* notifications_; |
| 118 | 114 |
| 119 base::WeakPtrFactory<VolumeMountWatcherWin> weak_factory_; | 115 base::WeakPtrFactory<VolumeMountWatcherWin> weak_factory_; |
| 120 | 116 |
| 121 DISALLOW_COPY_AND_ASSIGN(VolumeMountWatcherWin); | 117 DISALLOW_COPY_AND_ASSIGN(VolumeMountWatcherWin); |
| 122 }; | 118 }; |
| 123 | 119 |
| 124 } // namespace storage_monitor | 120 } // namespace storage_monitor |
| 125 | 121 |
| 126 #endif // COMPONENTS_STORAGE_MONITOR_VOLUME_MOUNT_WATCHER_WIN_H_ | 122 #endif // COMPONENTS_STORAGE_MONITOR_VOLUME_MOUNT_WATCHER_WIN_H_ |
| OLD | NEW |