summaryrefslogtreecommitdiffstats
path: root/content/browser/system_message_window_win.cc
diff options
context:
space:
mode:
authortpayne@chromium.org <tpayne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-06 00:02:45 +0000
committertpayne@chromium.org <tpayne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-06 00:02:45 +0000
commit85538be95969a67c9969a2448e9a99caa70654d5 (patch)
tree792fc797c0146a16a1a0c49bb8e73c3e38133c5b /content/browser/system_message_window_win.cc
parentd30237313646c9636991f6cb0d278761dbe775fb (diff)
downloadchromium_src-85538be95969a67c9969a2448e9a99caa70654d5.zip
chromium_src-85538be95969a67c9969a2448e9a99caa70654d5.tar.gz
chromium_src-85538be95969a67c9969a2448e9a99caa70654d5.tar.bz2
Added win media notifier
BUG=110400 TEST=NONE Review URL: http://codereview.chromium.org/9348100 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125036 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/system_message_window_win.cc')
-rw-r--r--content/browser/system_message_window_win.cc72
1 files changed, 68 insertions, 4 deletions
diff --git a/content/browser/system_message_window_win.cc b/content/browser/system_message_window_win.cc
index c5a7633..1aca1c1 100644
--- a/content/browser/system_message_window_win.cc
+++ b/content/browser/system_message_window_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,13 +6,50 @@
#include <windows.h>
#include <dbt.h>
+#include <string>
+#include "base/file_path.h"
+#include "base/sys_string_conversions.h"
#include "base/system_monitor/system_monitor.h"
#include "base/win/wrapped_window_proc.h"
static const wchar_t* const WindowClassName = L"Chrome_SystemMessageWindow";
-SystemMessageWindowWin::SystemMessageWindowWin() {
+namespace {
+
+LRESULT GetVolumeName(LPCWSTR drive,
+ LPWSTR volume_name,
+ unsigned int volume_name_len) {
+ return GetVolumeInformation(drive, volume_name, volume_name_len, NULL, NULL,
+ NULL, NULL, 0);
+}
+
+// Returns 0 if the devicetype is not volume.
+DWORD GetVolumeBitMaskFromBroadcastHeader(DWORD data) {
+ PDEV_BROADCAST_HDR dev_broadcast_hdr =
+ reinterpret_cast<PDEV_BROADCAST_HDR>(data);
+ if (dev_broadcast_hdr->dbch_devicetype == DBT_DEVTYP_VOLUME) {
+ PDEV_BROADCAST_VOLUME dev_broadcast_volume =
+ reinterpret_cast<PDEV_BROADCAST_VOLUME>(dev_broadcast_hdr);
+ return dev_broadcast_volume->dbcv_unitmask;
+ }
+ return 0;
+}
+
+} // namespace
+
+
+SystemMessageWindowWin::SystemMessageWindowWin()
+ : volume_name_func_(&GetVolumeName) {
+ Init();
+}
+
+SystemMessageWindowWin::SystemMessageWindowWin(VolumeNameFunc volume_name_func)
+ : volume_name_func_(volume_name_func) {
+ Init();
+}
+
+void SystemMessageWindowWin::Init() {
HINSTANCE hinst = GetModuleHandle(NULL);
WNDCLASSEX wc = {0};
@@ -38,8 +75,35 @@ SystemMessageWindowWin::~SystemMessageWindowWin() {
LRESULT SystemMessageWindowWin::OnDeviceChange(UINT event_type, DWORD data) {
base::SystemMonitor* monitor = base::SystemMonitor::Get();
- if (monitor && event_type == DBT_DEVNODES_CHANGED)
- monitor->ProcessDevicesChanged();
+ switch (event_type) {
+ case DBT_DEVNODES_CHANGED:
+ monitor->ProcessDevicesChanged();
+ break;
+ case DBT_DEVICEARRIVAL: {
+ DWORD unitmask = GetVolumeBitMaskFromBroadcastHeader(data);
+ for (int i = 0; unitmask; ++i, unitmask >>= 1) {
+ if (unitmask & 0x01) {
+ FilePath::StringType drive(L"_:\\");
+ drive[0] = L'A' + i;
+ WCHAR volume_name[MAX_PATH + 1];
+ if ((*volume_name_func_)(drive.c_str(), volume_name, MAX_PATH + 1)) {
+ monitor->ProcessMediaDeviceAttached(
+ i, base::SysWideToUTF8(volume_name), FilePath(drive));
+ }
+ }
+ }
+ break;
+ }
+ case DBT_DEVICEREMOVECOMPLETE: {
+ DWORD unitmask = GetVolumeBitMaskFromBroadcastHeader(data);
+ for (int i = 0; unitmask; ++i, unitmask >>= 1) {
+ if (unitmask & 0x01) {
+ monitor->ProcessMediaDeviceDetached(i);
+ }
+ }
+ break;
+ }
+ }
return TRUE;
}