| 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 #include <dbt.h> | 8 #include <dbt.h> |
| 9 #include <fileapi.h> | 9 #include <fileapi.h> |
| 10 | 10 |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" | |
| 16 #include "chrome/browser/storage_monitor/media_storage_util.h" | 15 #include "chrome/browser/storage_monitor/media_storage_util.h" |
| 17 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 18 | 17 |
| 19 using content::BrowserThread; | 18 using content::BrowserThread; |
| 20 | 19 |
| 21 namespace { | 20 namespace { |
| 22 | 21 |
| 23 const DWORD kMaxPathBufLen = MAX_PATH + 1; | 22 const DWORD kMaxPathBufLen = MAX_PATH + 1; |
| 24 | 23 |
| 25 bool IsRemovable(const string16& mount_point) { | 24 bool IsRemovable(const string16& mount_point) { |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 &unique_id, &device_name, &removable, | 246 &unique_id, &device_name, &removable, |
| 248 &total_size_in_bytes)) { | 247 &total_size_in_bytes)) { |
| 249 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 248 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
| 250 &chrome::VolumeMountWatcherWin::DeviceCheckComplete, | 249 &chrome::VolumeMountWatcherWin::DeviceCheckComplete, |
| 251 volume_watcher, device_path)); | 250 volume_watcher, device_path)); |
| 252 return; | 251 return; |
| 253 } | 252 } |
| 254 | 253 |
| 255 chrome::MediaStorageUtil::Type type = | 254 chrome::MediaStorageUtil::Type type = |
| 256 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; | 255 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; |
| 257 if (chrome::IsMediaDevice(device_path.value())) | 256 if (MediaStorageUtil::HasDcim(device_path.value())) |
| 258 type = chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM; | 257 type = chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM; |
| 259 std::string device_id = | 258 std::string device_id = |
| 260 chrome::MediaStorageUtil::MakeDeviceId(type, unique_id); | 259 chrome::MediaStorageUtil::MakeDeviceId(type, unique_id); |
| 261 | 260 |
| 262 chrome::VolumeMountWatcherWin::MountPointInfo info; | 261 chrome::VolumeMountWatcherWin::MountPointInfo info; |
| 263 info.device_id = device_id; | 262 info.device_id = device_id; |
| 264 info.location = device_location; | 263 info.location = device_location; |
| 265 info.unique_id = unique_id; | 264 info.unique_id = unique_id; |
| 266 info.name = device_name; | 265 info.name = device_name; |
| 267 info.removable = removable; | 266 info.removable = removable; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 | 365 |
| 367 device_metadata_[device_path.value()] = info; | 366 device_metadata_[device_path.value()] = info; |
| 368 | 367 |
| 369 DeviceCheckComplete(device_path); | 368 DeviceCheckComplete(device_path); |
| 370 | 369 |
| 371 // Don't call removable storage observers for fixed volumes. | 370 // Don't call removable storage observers for fixed volumes. |
| 372 if (!info.removable) | 371 if (!info.removable) |
| 373 return; | 372 return; |
| 374 | 373 |
| 375 if (notifications_) { | 374 if (notifications_) { |
| 376 string16 display_name = | 375 string16 display_name = MediaStorageUtil::GetDisplayNameForDevice( |
| 377 GetDisplayNameForDevice(info.total_size_in_bytes, info.name); | 376 info.total_size_in_bytes, info.name); |
| 378 notifications_->ProcessAttach(StorageInfo(info.device_id, display_name, | 377 |
| 379 device_path.value())); | 378 StorageInfo storage_info(info.device_id, display_name, device_path.value()); |
| 379 notifications_->ProcessAttach(storage_info); |
| 380 } | 380 } |
| 381 } | 381 } |
| 382 | 382 |
| 383 void VolumeMountWatcherWin::HandleDeviceDetachEventOnUIThread( | 383 void VolumeMountWatcherWin::HandleDeviceDetachEventOnUIThread( |
| 384 const string16& device_location) { | 384 const string16& device_location) { |
| 385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 386 | 386 |
| 387 MountPointDeviceMetadataMap::const_iterator device_info = | 387 MountPointDeviceMetadataMap::const_iterator device_info = |
| 388 device_metadata_.find(device_location); | 388 device_metadata_.find(device_location); |
| 389 // If the device isn't type removable (like a CD), it won't be there. | 389 // If the device isn't type removable (like a CD), it won't be there. |
| 390 if (device_info == device_metadata_.end()) | 390 if (device_info == device_metadata_.end()) |
| 391 return; | 391 return; |
| 392 | 392 |
| 393 if (notifications_) | 393 if (notifications_) |
| 394 notifications_->ProcessDetach(device_info->second.device_id); | 394 notifications_->ProcessDetach(device_info->second.device_id); |
| 395 device_metadata_.erase(device_info); | 395 device_metadata_.erase(device_info); |
| 396 } | 396 } |
| 397 | 397 |
| 398 } // namespace chrome | 398 } // namespace chrome |
| OLD | NEW |