Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: components/storage_monitor/volume_mount_watcher_win.cc

Issue 231063002: Add notification for media changed, and notify volume mount watcher when it occurs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Name and constant change Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/storage_monitor/volume_mount_watcher_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « components/storage_monitor/volume_mount_watcher_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698