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 void VolumeMountWatcherWin::OnMediaChange(WPARAM wparam, LPARAM lparam) { |
| 477 if (lparam == SHCNE_MEDIAINSERTED || lparam == SHCNE_MEDIAREMOVED) { |
| 478 struct _ITEMIDLIST* pidl = *reinterpret_cast<struct _ITEMIDLIST**>( |
| 479 wparam); |
| 480 wchar_t sPath[MAX_PATH]; |
| 481 if (!SHGetPathFromIDList(pidl, sPath)) { |
| 482 DVLOG(1) << "MediaInserted: SHGetPathFromIDList failed"; |
| 483 return; |
| 484 } |
| 485 switch (lparam) { |
| 486 case SHCNE_MEDIAINSERTED: { |
| 487 std::vector<base::FilePath> paths; |
| 488 paths.push_back(base::FilePath(sPath)); |
| 489 AddDevicesOnUIThread(paths); |
| 490 break; |
| 491 } |
| 492 case SHCNE_MEDIAREMOVED: { |
| 493 HandleDeviceDetachEventOnUIThread(sPath); |
| 494 break; |
| 495 } |
| 496 } |
| 497 } |
| 498 } |
| 499 |
475 void VolumeMountWatcherWin::SetNotifications( | 500 void VolumeMountWatcherWin::SetNotifications( |
476 StorageMonitor::Receiver* notifications) { | 501 StorageMonitor::Receiver* notifications) { |
477 notifications_ = notifications; | 502 notifications_ = notifications; |
478 } | 503 } |
479 | 504 |
480 VolumeMountWatcherWin::~VolumeMountWatcherWin() { | 505 VolumeMountWatcherWin::~VolumeMountWatcherWin() { |
481 weak_factory_.InvalidateWeakPtrs(); | 506 weak_factory_.InvalidateWeakPtrs(); |
482 device_info_worker_pool_->Shutdown(); | 507 device_info_worker_pool_->Shutdown(); |
483 } | 508 } |
484 | 509 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 callback.Run(StorageMonitor::EJECT_FAILURE); | 548 callback.Run(StorageMonitor::EJECT_FAILURE); |
524 return; | 549 return; |
525 } | 550 } |
526 | 551 |
527 task_runner_->PostTask( | 552 task_runner_->PostTask( |
528 FROM_HERE, | 553 FROM_HERE, |
529 base::Bind(&EjectDeviceInThreadPool, device, callback, task_runner_, 0)); | 554 base::Bind(&EjectDeviceInThreadPool, device, callback, task_runner_, 0)); |
530 } | 555 } |
531 | 556 |
532 } // namespace storage_monitor | 557 } // namespace storage_monitor |
OLD | NEW |