| 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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 VolumeMountWatcherWin::GetDeviceDetailsCallback() const { | 421 VolumeMountWatcherWin::GetDeviceDetailsCallback() const { |
| 422 return base::Bind(&GetDeviceDetails); | 422 return base::Bind(&GetDeviceDetails); |
| 423 } | 423 } |
| 424 | 424 |
| 425 bool VolumeMountWatcherWin::GetDeviceInfo(const base::FilePath& device_path, | 425 bool VolumeMountWatcherWin::GetDeviceInfo(const base::FilePath& device_path, |
| 426 StorageInfo* info) const { | 426 StorageInfo* info) const { |
| 427 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 427 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 428 DCHECK(info); | 428 DCHECK(info); |
| 429 base::FilePath path(device_path); | 429 base::FilePath path(device_path); |
| 430 MountPointDeviceMetadataMap::const_iterator iter = | 430 MountPointDeviceMetadataMap::const_iterator iter = |
| 431 device_metadata_.find(path.value()); | 431 device_metadata_.find(path); |
| 432 while (iter == device_metadata_.end() && path.DirName() != path) { | 432 while (iter == device_metadata_.end() && path.DirName() != path) { |
| 433 path = path.DirName(); | 433 path = path.DirName(); |
| 434 iter = device_metadata_.find(path.value()); | 434 iter = device_metadata_.find(path); |
| 435 } | 435 } |
| 436 | 436 |
| 437 if (iter == device_metadata_.end()) | 437 if (iter == device_metadata_.end()) |
| 438 return false; | 438 return false; |
| 439 | 439 |
| 440 *info = iter->second; | 440 *info = iter->second; |
| 441 return true; | 441 return true; |
| 442 } | 442 } |
| 443 | 443 |
| 444 void VolumeMountWatcherWin::OnWindowMessage(UINT event_type, LPARAM data) { | 444 void VolumeMountWatcherWin::OnWindowMessage(UINT event_type, LPARAM data) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 VolumeMountWatcherWin::~VolumeMountWatcherWin() { | 479 VolumeMountWatcherWin::~VolumeMountWatcherWin() { |
| 480 weak_factory_.InvalidateWeakPtrs(); | 480 weak_factory_.InvalidateWeakPtrs(); |
| 481 device_info_worker_pool_->Shutdown(); | 481 device_info_worker_pool_->Shutdown(); |
| 482 } | 482 } |
| 483 | 483 |
| 484 void VolumeMountWatcherWin::HandleDeviceAttachEventOnUIThread( | 484 void VolumeMountWatcherWin::HandleDeviceAttachEventOnUIThread( |
| 485 const base::FilePath& device_path, | 485 const base::FilePath& device_path, |
| 486 const StorageInfo& info) { | 486 const StorageInfo& info) { |
| 487 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 487 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 488 | 488 |
| 489 device_metadata_[device_path.value()] = info; | 489 device_metadata_[device_path] = info; |
| 490 | 490 |
| 491 DeviceCheckComplete(device_path); | 491 DeviceCheckComplete(device_path); |
| 492 | 492 |
| 493 // Don't call removable storage observers for fixed volumes. | 493 // Don't call removable storage observers for fixed volumes. |
| 494 if (!StorageInfo::IsRemovableDevice(info.device_id())) | 494 if (!StorageInfo::IsRemovableDevice(info.device_id())) |
| 495 return; | 495 return; |
| 496 | 496 |
| 497 if (notifications_) | 497 if (notifications_) |
| 498 notifications_->ProcessAttach(info); | 498 notifications_->ProcessAttach(info); |
| 499 } | 499 } |
| 500 | 500 |
| 501 void VolumeMountWatcherWin::HandleDeviceDetachEventOnUIThread( | 501 void VolumeMountWatcherWin::HandleDeviceDetachEventOnUIThread( |
| 502 const base::string16& device_location) { | 502 const base::string16& device_location) { |
| 503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 504 | 504 |
| 505 MountPointDeviceMetadataMap::const_iterator device_info = | 505 MountPointDeviceMetadataMap::const_iterator device_info = |
| 506 device_metadata_.find(device_location); | 506 device_metadata_.find(base::FilePath(device_location)); |
| 507 // If the device isn't type removable (like a CD), it won't be there. | 507 // If the device isn't type removable (like a CD), it won't be there. |
| 508 if (device_info == device_metadata_.end()) | 508 if (device_info == device_metadata_.end()) |
| 509 return; | 509 return; |
| 510 | 510 |
| 511 if (notifications_) | 511 if (notifications_) |
| 512 notifications_->ProcessDetach(device_info->second.device_id()); | 512 notifications_->ProcessDetach(device_info->second.device_id()); |
| 513 device_metadata_.erase(device_info); | 513 device_metadata_.erase(device_info); |
| 514 } | 514 } |
| 515 | 515 |
| 516 void VolumeMountWatcherWin::EjectDevice( | 516 void VolumeMountWatcherWin::EjectDevice( |
| 517 const std::string& device_id, | 517 const std::string& device_id, |
| 518 base::Callback<void(StorageMonitor::EjectStatus)> callback) { | 518 base::Callback<void(StorageMonitor::EjectStatus)> callback) { |
| 519 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 519 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 520 base::FilePath device = MediaStorageUtil::FindDevicePathById(device_id); | 520 base::FilePath device = MediaStorageUtil::FindDevicePathById(device_id); |
| 521 if (device.empty()) { | 521 if (device.empty()) { |
| 522 callback.Run(StorageMonitor::EJECT_FAILURE); | 522 callback.Run(StorageMonitor::EJECT_FAILURE); |
| 523 return; | 523 return; |
| 524 } | 524 } |
| 525 if (device_metadata_.erase(device.value()) == 0) { | 525 if (device_metadata_.erase(device) == 0) { |
| 526 callback.Run(StorageMonitor::EJECT_FAILURE); | 526 callback.Run(StorageMonitor::EJECT_FAILURE); |
| 527 return; | 527 return; |
| 528 } | 528 } |
| 529 | 529 |
| 530 task_runner_->PostTask( | 530 task_runner_->PostTask( |
| 531 FROM_HERE, | 531 FROM_HERE, |
| 532 base::Bind(&EjectDeviceInThreadPool, device, callback, task_runner_, 0)); | 532 base::Bind(&EjectDeviceInThreadPool, device, callback, task_runner_, 0)); |
| 533 } | 533 } |
| 534 | 534 |
| 535 } // namespace chrome | 535 } // namespace chrome |
| OLD | NEW |