| 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 | 8 |
| 9 #include <dbt.h> | 9 #include <dbt.h> |
| 10 #include <fileapi.h> | 10 #include <fileapi.h> |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 WriteInto(&guid, kMaxPathBufLen), | 141 WriteInto(&guid, kMaxPathBufLen), |
| 142 kMaxPathBufLen)) { | 142 kMaxPathBufLen)) { |
| 143 return false; | 143 return false; |
| 144 } | 144 } |
| 145 | 145 |
| 146 // If we're adding a floppy drive, return without querying any more | 146 // If we're adding a floppy drive, return without querying any more |
| 147 // drive metadata -- it will cause the floppy drive to seek. | 147 // drive metadata -- it will cause the floppy drive to seek. |
| 148 // Note: treats FLOPPY as FIXED_MASS_STORAGE. This is intentional. | 148 // Note: treats FLOPPY as FIXED_MASS_STORAGE. This is intentional. |
| 149 DeviceType device_type = GetDeviceType(mount_point); | 149 DeviceType device_type = GetDeviceType(mount_point); |
| 150 if (device_type == FLOPPY) { | 150 if (device_type == FLOPPY) { |
| 151 info->device_id = chrome::StorageInfo::MakeDeviceId( | 151 info->set_device_id(chrome::StorageInfo::MakeDeviceId( |
| 152 chrome::StorageInfo::FIXED_MASS_STORAGE, UTF16ToUTF8(guid)); | 152 chrome::StorageInfo::FIXED_MASS_STORAGE, UTF16ToUTF8(guid))); |
| 153 return true; | 153 return true; |
| 154 } | 154 } |
| 155 | 155 |
| 156 chrome::StorageInfo::Type type = | 156 chrome::StorageInfo::Type type = chrome::StorageInfo::FIXED_MASS_STORAGE; |
| 157 chrome::StorageInfo::FIXED_MASS_STORAGE; | |
| 158 if (device_type == REMOVABLE) { | 157 if (device_type == REMOVABLE) { |
| 159 type = chrome::StorageInfo::REMOVABLE_MASS_STORAGE_NO_DCIM; | 158 type = chrome::StorageInfo::REMOVABLE_MASS_STORAGE_NO_DCIM; |
| 160 if (chrome::MediaStorageUtil::HasDcim(base::FilePath(mount_point))) | 159 if (chrome::MediaStorageUtil::HasDcim(base::FilePath(mount_point))) |
| 161 type = chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM; | 160 type = chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM; |
| 162 } | 161 } |
| 163 | 162 |
| 164 // NOTE: experimentally, this function returns false if there is no volume | 163 // NOTE: experimentally, this function returns false if there is no volume |
| 165 // name set. | 164 // name set. |
| 166 string16 volume_label; | 165 string16 volume_label; |
| 167 GetVolumeInformationW(device_path.value().c_str(), | 166 GetVolumeInformationW(device_path.value().c_str(), |
| 168 WriteInto(&volume_label, kMaxPathBufLen), | 167 WriteInto(&volume_label, kMaxPathBufLen), |
| 169 kMaxPathBufLen, NULL, NULL, NULL, NULL, 0); | 168 kMaxPathBufLen, NULL, NULL, NULL, NULL, 0); |
| 170 | 169 |
| 171 info->location = mount_point; | 170 uint64 total_size_in_bytes = GetVolumeSize(mount_point); |
| 172 info->total_size_in_bytes = GetVolumeSize(mount_point); | 171 std::string device_id = |
| 173 info->device_id = chrome::StorageInfo::MakeDeviceId( | 172 chrome::StorageInfo::MakeDeviceId(type, UTF16ToUTF8(guid)); |
| 174 type, UTF16ToUTF8(guid)); | |
| 175 | 173 |
| 176 // TODO(gbillock): if volume_label.empty(), get the vendor/model information | 174 // TODO(gbillock): if volume_label.empty(), get the vendor/model information |
| 177 // for the volume. | 175 // for the volume. |
| 178 info->vendor_name = string16(); | 176 *info = chrome::StorageInfo(device_id, string16(), mount_point, |
| 179 info->model_name = string16(); | 177 volume_label, string16(), string16(), |
| 180 info->storage_label = volume_label; | 178 total_size_in_bytes); |
| 181 | |
| 182 return true; | 179 return true; |
| 183 } | 180 } |
| 184 | 181 |
| 185 // Returns a vector of all the removable mass storage devices that are | 182 // Returns a vector of all the removable mass storage devices that are |
| 186 // connected. | 183 // connected. |
| 187 std::vector<base::FilePath> GetAttachedDevices() { | 184 std::vector<base::FilePath> GetAttachedDevices() { |
| 188 std::vector<base::FilePath> result; | 185 std::vector<base::FilePath> result; |
| 189 string16 volume_name; | 186 string16 volume_name; |
| 190 HANDLE find_handle = FindFirstVolume(WriteInto(&volume_name, kMaxPathBufLen), | 187 HANDLE find_handle = FindFirstVolume(WriteInto(&volume_name, kMaxPathBufLen), |
| 191 kMaxPathBufLen); | 188 kMaxPathBufLen); |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 void VolumeMountWatcherWin::HandleDeviceAttachEventOnUIThread( | 486 void VolumeMountWatcherWin::HandleDeviceAttachEventOnUIThread( |
| 490 const base::FilePath& device_path, | 487 const base::FilePath& device_path, |
| 491 const StorageInfo& info) { | 488 const StorageInfo& info) { |
| 492 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 489 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 493 | 490 |
| 494 device_metadata_[device_path.value()] = info; | 491 device_metadata_[device_path.value()] = info; |
| 495 | 492 |
| 496 DeviceCheckComplete(device_path); | 493 DeviceCheckComplete(device_path); |
| 497 | 494 |
| 498 // Don't call removable storage observers for fixed volumes. | 495 // Don't call removable storage observers for fixed volumes. |
| 499 if (!StorageInfo::IsRemovableDevice(info.device_id)) | 496 if (!StorageInfo::IsRemovableDevice(info.device_id())) |
| 500 return; | 497 return; |
| 501 | 498 |
| 502 if (notifications_) | 499 if (notifications_) |
| 503 notifications_->ProcessAttach(info); | 500 notifications_->ProcessAttach(info); |
| 504 } | 501 } |
| 505 | 502 |
| 506 void VolumeMountWatcherWin::HandleDeviceDetachEventOnUIThread( | 503 void VolumeMountWatcherWin::HandleDeviceDetachEventOnUIThread( |
| 507 const string16& device_location) { | 504 const string16& device_location) { |
| 508 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 505 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 509 | 506 |
| 510 MountPointDeviceMetadataMap::const_iterator device_info = | 507 MountPointDeviceMetadataMap::const_iterator device_info = |
| 511 device_metadata_.find(device_location); | 508 device_metadata_.find(device_location); |
| 512 // If the device isn't type removable (like a CD), it won't be there. | 509 // If the device isn't type removable (like a CD), it won't be there. |
| 513 if (device_info == device_metadata_.end()) | 510 if (device_info == device_metadata_.end()) |
| 514 return; | 511 return; |
| 515 | 512 |
| 516 if (notifications_) | 513 if (notifications_) |
| 517 notifications_->ProcessDetach(device_info->second.device_id); | 514 notifications_->ProcessDetach(device_info->second.device_id()); |
| 518 device_metadata_.erase(device_info); | 515 device_metadata_.erase(device_info); |
| 519 } | 516 } |
| 520 | 517 |
| 521 void VolumeMountWatcherWin::EjectDevice( | 518 void VolumeMountWatcherWin::EjectDevice( |
| 522 const std::string& device_id, | 519 const std::string& device_id, |
| 523 base::Callback<void(StorageMonitor::EjectStatus)> callback) { | 520 base::Callback<void(StorageMonitor::EjectStatus)> callback) { |
| 524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 525 base::FilePath device = | 522 base::FilePath device = |
| 526 chrome::MediaStorageUtil::FindDevicePathById(device_id); | 523 chrome::MediaStorageUtil::FindDevicePathById(device_id); |
| 527 if (device.empty()) { | 524 if (device.empty()) { |
| 528 callback.Run(StorageMonitor::EJECT_FAILURE); | 525 callback.Run(StorageMonitor::EJECT_FAILURE); |
| 529 return; | 526 return; |
| 530 } | 527 } |
| 531 if (device_metadata_.erase(device.value()) == 0) { | 528 if (device_metadata_.erase(device.value()) == 0) { |
| 532 callback.Run(StorageMonitor::EJECT_FAILURE); | 529 callback.Run(StorageMonitor::EJECT_FAILURE); |
| 533 return; | 530 return; |
| 534 } | 531 } |
| 535 | 532 |
| 536 task_runner_->PostTask(FROM_HERE, | 533 task_runner_->PostTask(FROM_HERE, |
| 537 base::Bind(&EjectDeviceInThreadPool, device, callback, task_runner_, 0)); | 534 base::Bind(&EjectDeviceInThreadPool, device, callback, task_runner_, 0)); |
| 538 } | 535 } |
| 539 | 536 |
| 540 } // namespace chrome | 537 } // namespace chrome |
| OLD | NEW |