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 string16 QueryDevicePath(const string16& mount_point) { | |
26 string16 device = mount_point; | |
27 if (EndsWith(mount_point, L"\\", false)) | |
28 device = mount_point.substr(0, device.length() - 1); | |
29 string16 device_path; | |
30 if (!QueryDosDevice(device.c_str(), WriteInto(&device_path, kMaxPathBufLen), | |
31 kMaxPathBufLen)) | |
32 return string16(); | |
33 return device_path; | |
34 } | |
35 | |
25 bool IsRemovable(const string16& mount_point) { | 36 bool IsRemovable(const string16& mount_point) { |
vandebo (ex-Chrome)
2013/03/06 00:38:26
Instead of splitting this into two functions that
Greg Billock
2013/03/06 01:40:03
I like that plan.
| |
26 if (GetDriveType(mount_point.c_str()) != DRIVE_REMOVABLE) | 37 if (GetDriveType(mount_point.c_str()) != DRIVE_REMOVABLE) |
27 return false; | 38 return false; |
28 | 39 |
29 // We don't consider floppy disks as removable, so check for that. | 40 // We don't consider floppy disks as removable, so check for that. |
30 string16 device = mount_point; | 41 string16 device_path = QueryDevicePath(mount_point); |
31 if (EndsWith(mount_point, L"\\", false)) | |
32 device = mount_point.substr(0, device.length() - 1); | |
33 string16 device_path; | |
34 if (!QueryDosDevice(device.c_str(), WriteInto(&device_path, kMaxPathBufLen), | |
35 kMaxPathBufLen)) | |
36 return true; | |
37 return device_path.find(L"Floppy") == string16::npos; | 42 return device_path.find(L"Floppy") == string16::npos; |
38 } | 43 } |
39 | 44 |
45 bool IsFloppyDrive(const string16& mount_point) { | |
46 string16 device_path = QueryDevicePath(mount_point); | |
47 return device_path.find(L"Floppy") != string16::npos; | |
48 } | |
49 | |
40 // Returns 0 if the devicetype is not volume. | 50 // Returns 0 if the devicetype is not volume. |
41 uint32 GetVolumeBitMaskFromBroadcastHeader(LPARAM data) { | 51 uint32 GetVolumeBitMaskFromBroadcastHeader(LPARAM data) { |
42 DEV_BROADCAST_VOLUME* dev_broadcast_volume = | 52 DEV_BROADCAST_VOLUME* dev_broadcast_volume = |
43 reinterpret_cast<DEV_BROADCAST_VOLUME*>(data); | 53 reinterpret_cast<DEV_BROADCAST_VOLUME*>(data); |
44 if (dev_broadcast_volume->dbcv_devicetype == DBT_DEVTYP_VOLUME) | 54 if (dev_broadcast_volume->dbcv_devicetype == DBT_DEVTYP_VOLUME) |
45 return dev_broadcast_volume->dbcv_unitmask; | 55 return dev_broadcast_volume->dbcv_unitmask; |
46 return 0; | 56 return 0; |
47 } | 57 } |
48 | 58 |
49 // Returns true if |data| represents a logical volume structure. | 59 // Returns true if |data| represents a logical volume structure. |
(...skipping 30 matching lines...) Expand all Loading... | |
80 kMaxPathBufLen)) { | 90 kMaxPathBufLen)) { |
81 return false; | 91 return false; |
82 } | 92 } |
83 | 93 |
84 if (removable) | 94 if (removable) |
85 *removable = IsRemovable(mount_point); | 95 *removable = IsRemovable(mount_point); |
86 | 96 |
87 if (device_location) | 97 if (device_location) |
88 *device_location = mount_point; | 98 *device_location = mount_point; |
89 | 99 |
100 // If we're adding a floppy drive, return without querying any more | |
101 // drive metadata -- it will cause the floppy drive to seek. | |
102 if (IsFloppyDrive(device_path)) | |
103 return true; | |
104 | |
90 if (volume_size) | 105 if (volume_size) |
91 *volume_size = GetVolumeSize(mount_point); | 106 *volume_size = GetVolumeSize(mount_point); |
92 | 107 |
93 if (unique_id) { | 108 if (unique_id) { |
94 string16 guid; | 109 string16 guid; |
95 if (!GetVolumeNameForVolumeMountPoint(mount_point.c_str(), | 110 if (!GetVolumeNameForVolumeMountPoint(mount_point.c_str(), |
96 WriteInto(&guid, kMaxPathBufLen), | 111 WriteInto(&guid, kMaxPathBufLen), |
97 kMaxPathBufLen)) { | 112 kMaxPathBufLen)) { |
98 return false; | 113 return false; |
99 } | 114 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 kMaxPathBufLen); | 148 kMaxPathBufLen); |
134 if (find_handle == INVALID_HANDLE_VALUE) | 149 if (find_handle == INVALID_HANDLE_VALUE) |
135 return result; | 150 return result; |
136 | 151 |
137 while (true) { | 152 while (true) { |
138 string16 volume_path; | 153 string16 volume_path; |
139 DWORD return_count; | 154 DWORD return_count; |
140 if (GetVolumePathNamesForVolumeName(volume_name.c_str(), | 155 if (GetVolumePathNamesForVolumeName(volume_name.c_str(), |
141 WriteInto(&volume_path, kMaxPathBufLen), | 156 WriteInto(&volume_path, kMaxPathBufLen), |
142 kMaxPathBufLen, &return_count)) { | 157 kMaxPathBufLen, &return_count)) { |
143 if (IsRemovable(volume_path)) | 158 if (IsRemovable(volume_path)) |
vandebo (ex-Chrome)
2013/03/06 00:38:26
This call site still wants the old notion of remov
Greg Billock
2013/03/06 01:40:03
Yes. I think we can accommodate that.
| |
144 result.push_back(base::FilePath(volume_path)); | 159 result.push_back(base::FilePath(volume_path)); |
145 } else { | 160 } else { |
146 DPLOG(ERROR); | 161 DPLOG(ERROR); |
147 } | 162 } |
148 if (!FindNextVolume(find_handle, WriteInto(&volume_name, kMaxPathBufLen), | 163 if (!FindNextVolume(find_handle, WriteInto(&volume_name, kMaxPathBufLen), |
149 kMaxPathBufLen)) { | 164 kMaxPathBufLen)) { |
150 if (GetLastError() != ERROR_NO_MORE_FILES) | 165 if (GetLastError() != ERROR_NO_MORE_FILES) |
151 DPLOG(ERROR); | 166 DPLOG(ERROR); |
152 break; | 167 break; |
153 } | 168 } |
(...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. | 404 // If the device isn't type removable (like a CD), it won't be there. |
390 if (device_info == device_metadata_.end()) | 405 if (device_info == device_metadata_.end()) |
391 return; | 406 return; |
392 | 407 |
393 if (notifications_) | 408 if (notifications_) |
394 notifications_->ProcessDetach(device_info->second.device_id); | 409 notifications_->ProcessDetach(device_info->second.device_id); |
395 device_metadata_.erase(device_info); | 410 device_metadata_.erase(device_info); |
396 } | 411 } |
397 | 412 |
398 } // namespace chrome | 413 } // namespace chrome |
OLD | NEW |