Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/storage_monitor/volume_mount_watcher_win.h" | 5 #include "chrome/browser/storage_monitor/volume_mount_watcher_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <dbt.h> | 8 #include <dbt.h> |
| 9 #include <fileapi.h> | 9 #include <fileapi.h> |
| 10 | 10 |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" | 15 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" |
| 16 #include "chrome/browser/storage_monitor/media_storage_util.h" | 16 #include "chrome/browser/storage_monitor/media_storage_util.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 | 18 |
| 19 using content::BrowserThread; | 19 using content::BrowserThread; |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const DWORD kMaxPathBufLen = MAX_PATH + 1; | 23 const DWORD kMaxPathBufLen = MAX_PATH + 1; |
| 24 | 24 |
| 25 bool IsRemovable(const string16& mount_point) { | 25 enum DeviceType { |
| 26 FLOPPY, | |
| 27 REMOVABLE, | |
| 28 FIXED | |
|
vandebo (ex-Chrome)
2013/03/06 01:49:08
nit: add , at end so that future additions don't h
Greg Billock
2013/03/06 18:33:24
Done.
| |
| 29 }; | |
| 30 | |
| 31 DeviceType GetDeviceType(const string16& mount_point) { | |
| 26 if (GetDriveType(mount_point.c_str()) != DRIVE_REMOVABLE) | 32 if (GetDriveType(mount_point.c_str()) != DRIVE_REMOVABLE) |
| 27 return false; | 33 return FIXED; |
| 28 | 34 |
| 29 // We don't consider floppy disks as removable, so check for that. | 35 // We don't consider floppy disks as removable, so check for that. |
| 30 string16 device = mount_point; | 36 string16 device = mount_point; |
| 31 if (EndsWith(mount_point, L"\\", false)) | 37 if (EndsWith(mount_point, L"\\", false)) |
| 32 device = mount_point.substr(0, device.length() - 1); | 38 device = mount_point.substr(0, device.length() - 1); |
| 33 string16 device_path; | 39 string16 device_path; |
| 34 if (!QueryDosDevice(device.c_str(), WriteInto(&device_path, kMaxPathBufLen), | 40 if (!QueryDosDevice(device.c_str(), WriteInto(&device_path, kMaxPathBufLen), |
| 35 kMaxPathBufLen)) | 41 kMaxPathBufLen)) |
| 36 return true; | 42 return REMOVABLE; |
| 37 return device_path.find(L"Floppy") == string16::npos; | 43 return device_path.find(L"Floppy") == string16::npos ? REMOVABLE : FLOPPY; |
| 38 } | 44 } |
| 39 | 45 |
| 40 // Returns 0 if the devicetype is not volume. | 46 // Returns 0 if the devicetype is not volume. |
| 41 uint32 GetVolumeBitMaskFromBroadcastHeader(LPARAM data) { | 47 uint32 GetVolumeBitMaskFromBroadcastHeader(LPARAM data) { |
| 42 DEV_BROADCAST_VOLUME* dev_broadcast_volume = | 48 DEV_BROADCAST_VOLUME* dev_broadcast_volume = |
| 43 reinterpret_cast<DEV_BROADCAST_VOLUME*>(data); | 49 reinterpret_cast<DEV_BROADCAST_VOLUME*>(data); |
| 44 if (dev_broadcast_volume->dbcv_devicetype == DBT_DEVTYP_VOLUME) | 50 if (dev_broadcast_volume->dbcv_devicetype == DBT_DEVTYP_VOLUME) |
| 45 return dev_broadcast_volume->dbcv_unitmask; | 51 return dev_broadcast_volume->dbcv_unitmask; |
| 46 return 0; | 52 return 0; |
| 47 } | 53 } |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 74 string16* name, | 80 string16* name, |
| 75 bool* removable, | 81 bool* removable, |
| 76 uint64* volume_size) { | 82 uint64* volume_size) { |
| 77 string16 mount_point; | 83 string16 mount_point; |
| 78 if (!GetVolumePathName(device_path.value().c_str(), | 84 if (!GetVolumePathName(device_path.value().c_str(), |
| 79 WriteInto(&mount_point, kMaxPathBufLen), | 85 WriteInto(&mount_point, kMaxPathBufLen), |
| 80 kMaxPathBufLen)) { | 86 kMaxPathBufLen)) { |
| 81 return false; | 87 return false; |
| 82 } | 88 } |
| 83 | 89 |
| 90 DeviceType device_type = GetDeviceType(mount_point); | |
| 84 if (removable) | 91 if (removable) |
| 85 *removable = IsRemovable(mount_point); | 92 *removable = (device_type == REMOVABLE); |
| 86 | 93 |
| 87 if (device_location) | 94 if (device_location) |
| 88 *device_location = mount_point; | 95 *device_location = mount_point; |
| 89 | 96 |
| 97 // If we're adding a floppy drive, return without querying any more | |
| 98 // drive metadata -- it will cause the floppy drive to seek. | |
| 99 if (device_type == FLOPPY) | |
| 100 return true; | |
| 101 | |
| 90 if (volume_size) | 102 if (volume_size) |
| 91 *volume_size = GetVolumeSize(mount_point); | 103 *volume_size = GetVolumeSize(mount_point); |
| 92 | 104 |
| 93 if (unique_id) { | 105 if (unique_id) { |
| 94 string16 guid; | 106 string16 guid; |
| 95 if (!GetVolumeNameForVolumeMountPoint(mount_point.c_str(), | 107 if (!GetVolumeNameForVolumeMountPoint(mount_point.c_str(), |
| 96 WriteInto(&guid, kMaxPathBufLen), | 108 WriteInto(&guid, kMaxPathBufLen), |
| 97 kMaxPathBufLen)) { | 109 kMaxPathBufLen)) { |
| 98 return false; | 110 return false; |
| 99 } | 111 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 kMaxPathBufLen); | 145 kMaxPathBufLen); |
| 134 if (find_handle == INVALID_HANDLE_VALUE) | 146 if (find_handle == INVALID_HANDLE_VALUE) |
| 135 return result; | 147 return result; |
| 136 | 148 |
| 137 while (true) { | 149 while (true) { |
| 138 string16 volume_path; | 150 string16 volume_path; |
| 139 DWORD return_count; | 151 DWORD return_count; |
| 140 if (GetVolumePathNamesForVolumeName(volume_name.c_str(), | 152 if (GetVolumePathNamesForVolumeName(volume_name.c_str(), |
| 141 WriteInto(&volume_path, kMaxPathBufLen), | 153 WriteInto(&volume_path, kMaxPathBufLen), |
| 142 kMaxPathBufLen, &return_count)) { | 154 kMaxPathBufLen, &return_count)) { |
| 143 if (IsRemovable(volume_path)) | 155 if (GetDeviceType(volume_path) == REMOVABLE) |
|
vandebo (ex-Chrome)
2013/03/06 01:49:08
Actually I'm not sure we want this at all. If we
Greg Billock
2013/03/06 18:33:24
That makes sense. Let's get rid of it. Although wi
| |
| 144 result.push_back(base::FilePath(volume_path)); | 156 result.push_back(base::FilePath(volume_path)); |
| 145 } else { | 157 } else { |
| 146 DPLOG(ERROR); | 158 DPLOG(ERROR); |
| 147 } | 159 } |
| 148 if (!FindNextVolume(find_handle, WriteInto(&volume_name, kMaxPathBufLen), | 160 if (!FindNextVolume(find_handle, WriteInto(&volume_name, kMaxPathBufLen), |
| 149 kMaxPathBufLen)) { | 161 kMaxPathBufLen)) { |
| 150 if (GetLastError() != ERROR_NO_MORE_FILES) | 162 if (GetLastError() != ERROR_NO_MORE_FILES) |
| 151 DPLOG(ERROR); | 163 DPLOG(ERROR); |
| 152 break; | 164 break; |
| 153 } | 165 } |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 // If the device isn't type removable (like a CD), it won't be there. | 401 // If the device isn't type removable (like a CD), it won't be there. |
| 390 if (device_info == device_metadata_.end()) | 402 if (device_info == device_metadata_.end()) |
| 391 return; | 403 return; |
| 392 | 404 |
| 393 if (notifications_) | 405 if (notifications_) |
| 394 notifications_->ProcessDetach(device_info->second.device_id); | 406 notifications_->ProcessDetach(device_info->second.device_id); |
| 395 device_metadata_.erase(device_info); | 407 device_metadata_.erase(device_info); |
| 396 } | 408 } |
| 397 | 409 |
| 398 } // namespace chrome | 410 } // namespace chrome |
| OLD | NEW |