Chromium Code Reviews| 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 #include "components/storage_monitor/volume_mount_watcher_win.h" | 5 #include "components/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> |
| 11 #include <shlobj.h> | |
| 11 #include <winioctl.h> | 12 #include <winioctl.h> |
| 12 | 13 |
| 13 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 18 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/task_runner_util.h" | 21 #include "base/task_runner_util.h" |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 if (!(unitmask & 0x01)) | 466 if (!(unitmask & 0x01)) |
| 466 continue; | 467 continue; |
| 467 HandleDeviceDetachEventOnUIThread(DriveNumberToFilePath(i).value()); | 468 HandleDeviceDetachEventOnUIThread(DriveNumberToFilePath(i).value()); |
| 468 } | 469 } |
| 469 } | 470 } |
| 470 break; | 471 break; |
| 471 } | 472 } |
| 472 } | 473 } |
| 473 } | 474 } |
| 474 | 475 |
| 476 // Surprisingly, we have to define this ourselves. | |
| 477 typedef struct { | |
| 478 DWORD dwItem1; | |
| 479 DWORD dwItem2; | |
| 480 } SHNOTIFYSTRUCT; | |
|
vandebo (ex-Chrome)
2014/04/11 22:24:26
Can you figure out a better name for this.
Kevin Bailey
2014/04/22 15:43:03
Gone.
| |
| 481 | |
| 482 void VolumeMountWatcherWin::OnMediaChanged(WPARAM wparam, LPARAM lparam) { | |
| 483 SHNOTIFYSTRUCT* shns = reinterpret_cast<SHNOTIFYSTRUCT*>(wparam); | |
|
vandebo (ex-Chrome)
2014/04/11 22:24:26
Seem to only use dwItem1, should we just cast is t
Kevin Bailey
2014/04/22 15:43:03
Ya, got rid of it entirely, and simplified the fun
| |
| 484 switch (lparam) { | |
| 485 case SHCNE_MEDIAINSERTED: { | |
| 486 struct _ITEMIDLIST* pidl = reinterpret_cast<struct _ITEMIDLIST*>( | |
| 487 shns->dwItem1); | |
| 488 wchar_t sPath[MAX_PATH]; | |
| 489 if (SHGetPathFromIDList(pidl, sPath)) { | |
| 490 std::vector<base::FilePath> paths; | |
| 491 paths.push_back(base::FilePath(sPath)); | |
| 492 AddDevicesOnUIThread(paths); | |
| 493 } else { | |
| 494 DVLOG(1) << "MediaInserted: SHGetPathFromIDList failed"; | |
| 495 } | |
| 496 break; | |
| 497 } | |
| 498 case SHCNE_MEDIAREMOVED: { | |
| 499 struct _ITEMIDLIST* pidl = reinterpret_cast<struct _ITEMIDLIST*>( | |
| 500 shns->dwItem1); | |
| 501 wchar_t sPath[MAX_PATH]; | |
| 502 if (SHGetPathFromIDList(pidl, sPath)) { | |
| 503 HandleDeviceDetachEventOnUIThread(sPath); | |
| 504 } else { | |
| 505 DVLOG(1) << "MediaRemoved: SHGetPathFromIDList failed"; | |
| 506 } | |
| 507 break; | |
| 508 } | |
| 509 } | |
| 510 } | |
| 511 | |
| 475 void VolumeMountWatcherWin::SetNotifications( | 512 void VolumeMountWatcherWin::SetNotifications( |
| 476 StorageMonitor::Receiver* notifications) { | 513 StorageMonitor::Receiver* notifications) { |
| 477 notifications_ = notifications; | 514 notifications_ = notifications; |
| 478 } | 515 } |
| 479 | 516 |
| 480 VolumeMountWatcherWin::~VolumeMountWatcherWin() { | 517 VolumeMountWatcherWin::~VolumeMountWatcherWin() { |
| 481 weak_factory_.InvalidateWeakPtrs(); | 518 weak_factory_.InvalidateWeakPtrs(); |
| 482 device_info_worker_pool_->Shutdown(); | 519 device_info_worker_pool_->Shutdown(); |
| 483 } | 520 } |
| 484 | 521 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 callback.Run(StorageMonitor::EJECT_FAILURE); | 560 callback.Run(StorageMonitor::EJECT_FAILURE); |
| 524 return; | 561 return; |
| 525 } | 562 } |
| 526 | 563 |
| 527 task_runner_->PostTask( | 564 task_runner_->PostTask( |
| 528 FROM_HERE, | 565 FROM_HERE, |
| 529 base::Bind(&EjectDeviceInThreadPool, device, callback, task_runner_, 0)); | 566 base::Bind(&EjectDeviceInThreadPool, device, callback, task_runner_, 0)); |
| 530 } | 567 } |
| 531 | 568 |
| 532 } // namespace storage_monitor | 569 } // namespace storage_monitor |
| OLD | NEW |