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

Unified Diff: chrome/browser/storage_monitor/volume_mount_watcher_win.cc

Issue 16056002: Cleanup Various bits of Windows StorageMonitor classes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/storage_monitor/volume_mount_watcher_win.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/storage_monitor/volume_mount_watcher_win.cc
===================================================================
--- chrome/browser/storage_monitor/volume_mount_watcher_win.cc (revision 203027)
+++ chrome/browser/storage_monitor/volume_mount_watcher_win.cc (working copy)
@@ -27,6 +27,8 @@
using content::BrowserThread;
+namespace chrome {
+
namespace {
const DWORD kMaxPathBufLen = MAX_PATH + 1;
@@ -53,7 +55,7 @@
// on either floppy or removable volumes. The DRIVE_CDROM type is handled
// as a floppy, as are DRIVE_UNKNOWN and DRIVE_NO_ROOT_DIR, as there are
// reports that some floppy drives don't report as DRIVE_REMOVABLE.
-DeviceType GetDeviceType(const string16& mount_point) {
+DeviceType GetDeviceType(const base::string16& mount_point) {
UINT drive_type = GetDriveType(mount_point.c_str());
if (drive_type == DRIVE_FIXED || drive_type == DRIVE_REMOTE ||
drive_type == DRIVE_RAMDISK) {
@@ -64,22 +66,22 @@
// Check device strings of the form "X:" and "\\.\X:"
// For floppy drives, these will return strings like "/Device/Floppy0"
- string16 device = mount_point;
+ base::string16 device = mount_point;
if (EndsWith(mount_point, L"\\", false))
device = mount_point.substr(0, mount_point.length() - 1);
- string16 device_path;
- string16 device_path_slash;
+ base::string16 device_path;
+ base::string16 device_path_slash;
DWORD dos_device = QueryDosDevice(
device.c_str(), WriteInto(&device_path, kMaxPathBufLen), kMaxPathBufLen);
- string16 device_slash = string16(L"\\\\.\\");
+ base::string16 device_slash = base::string16(L"\\\\.\\");
device_slash += device;
DWORD dos_device_slash = QueryDosDevice(
device_slash.c_str(), WriteInto(&device_path_slash, kMaxPathBufLen),
kMaxPathBufLen);
if (dos_device == 0 && dos_device_slash == 0)
return FLOPPY;
- if (device_path.find(L"Floppy") != string16::npos ||
- device_path_slash.find(L"Floppy") != string16::npos) {
+ if (device_path.find(L"Floppy") != base::string16::npos ||
+ device_path_slash.find(L"Floppy") != base::string16::npos) {
return FLOPPY;
}
@@ -104,7 +106,7 @@
}
// Gets the total volume of the |mount_point| in bytes.
-uint64 GetVolumeSize(const string16& mount_point) {
+uint64 GetVolumeSize(const base::string16& mount_point) {
ULARGE_INTEGER total;
if (!GetDiskFreeSpaceExW(mount_point.c_str(), NULL, &total, NULL))
return 0;
@@ -116,11 +118,10 @@
// The following msdn blog entry is helpful for understanding disk volumes
// and how they are treated in Windows:
// http://blogs.msdn.com/b/adioltean/archive/2005/04/16/408947.aspx.
-bool GetDeviceDetails(const base::FilePath& device_path,
- chrome::StorageInfo* info) {
+bool GetDeviceDetails(const base::FilePath& device_path, StorageInfo* info) {
DCHECK(info);
- string16 mount_point;
+ base::string16 mount_point;
if (!GetVolumePathName(device_path.value().c_str(),
WriteInto(&mount_point, kMaxPathBufLen),
kMaxPathBufLen)) {
@@ -130,7 +131,7 @@
// Note: experimentally this code does not spin a floppy drive. It
// returns a GUID associated with the device, not the volume.
- string16 guid;
+ base::string16 guid;
if (!GetVolumeNameForVolumeMountPoint(mount_point.c_str(),
WriteInto(&guid, kMaxPathBufLen),
kMaxPathBufLen)) {
@@ -148,34 +149,33 @@
// Note: treats FLOPPY as FIXED_MASS_STORAGE. This is intentional.
DeviceType device_type = GetDeviceType(mount_point);
if (device_type == FLOPPY) {
- info->set_device_id(chrome::StorageInfo::MakeDeviceId(
- chrome::StorageInfo::FIXED_MASS_STORAGE, UTF16ToUTF8(guid)));
+ info->set_device_id(StorageInfo::MakeDeviceId(
+ StorageInfo::FIXED_MASS_STORAGE, UTF16ToUTF8(guid)));
return true;
}
- chrome::StorageInfo::Type type = chrome::StorageInfo::FIXED_MASS_STORAGE;
+ StorageInfo::Type type = StorageInfo::FIXED_MASS_STORAGE;
if (device_type == REMOVABLE) {
- type = chrome::StorageInfo::REMOVABLE_MASS_STORAGE_NO_DCIM;
- if (chrome::MediaStorageUtil::HasDcim(base::FilePath(mount_point)))
- type = chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM;
+ type = StorageInfo::REMOVABLE_MASS_STORAGE_NO_DCIM;
+ if (MediaStorageUtil::HasDcim(base::FilePath(mount_point)))
+ type = StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM;
}
// NOTE: experimentally, this function returns false if there is no volume
// name set.
- string16 volume_label;
+ base::string16 volume_label;
GetVolumeInformationW(device_path.value().c_str(),
WriteInto(&volume_label, kMaxPathBufLen),
kMaxPathBufLen, NULL, NULL, NULL, NULL, 0);
uint64 total_size_in_bytes = GetVolumeSize(mount_point);
- std::string device_id =
- chrome::StorageInfo::MakeDeviceId(type, UTF16ToUTF8(guid));
+ std::string device_id = StorageInfo::MakeDeviceId(type, UTF16ToUTF8(guid));
// TODO(gbillock): if volume_label.empty(), get the vendor/model information
// for the volume.
- *info = chrome::StorageInfo(device_id, string16(), mount_point,
- volume_label, string16(), string16(),
- total_size_in_bytes);
+ *info = StorageInfo(device_id, base::string16(), mount_point,
+ volume_label, base::string16(), base::string16(),
+ total_size_in_bytes);
return true;
}
@@ -183,14 +183,14 @@
// connected.
std::vector<base::FilePath> GetAttachedDevices() {
std::vector<base::FilePath> result;
- string16 volume_name;
+ base::string16 volume_name;
HANDLE find_handle = FindFirstVolume(WriteInto(&volume_name, kMaxPathBufLen),
kMaxPathBufLen);
if (find_handle == INVALID_HANDLE_VALUE)
return result;
while (true) {
- string16 volume_path;
+ base::string16 volume_path;
DWORD return_count;
if (GetVolumePathNamesForVolumeName(volume_name.c_str(),
WriteInto(&volume_path, kMaxPathBufLen),
@@ -217,7 +217,7 @@
// See http://support.microsoft.com/kb/165721
void EjectDeviceInThreadPool(
const base::FilePath& device,
- base::Callback<void(chrome::StorageMonitor::EjectStatus)> callback,
+ base::Callback<void(StorageMonitor::EjectStatus)> callback,
scoped_refptr<base::SequencedTaskRunner> task_runner,
int iteration) {
base::FilePath::StringType volume_name;
@@ -227,9 +227,9 @@
// at not-just-drive-letter paths.
if (drive_letter < L'A' || drive_letter > L'Z' ||
device != device.DirName()) {
- content::BrowserThread::PostTask(
- content::BrowserThread::UI, FROM_HERE,
- base::Bind(callback, chrome::StorageMonitor::EJECT_FAILURE));
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(callback, StorageMonitor::EJECT_FAILURE));
return;
}
base::SStringPrintf(&volume_name, L"\\\\.\\%lc:", drive_letter);
@@ -240,9 +240,9 @@
NULL, OPEN_EXISTING, 0, NULL));
if (!volume_handle.IsValid()) {
- content::BrowserThread::PostTask(
- content::BrowserThread::UI, FROM_HERE,
- base::Bind(callback, chrome::StorageMonitor::EJECT_FAILURE));
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(callback, StorageMonitor::EJECT_FAILURE));
return;
}
@@ -267,16 +267,16 @@
// Try again -- the lock may have been a transient one. This happens on
// things like AV disk lock for some reason, or another process
// transient disk lock.
- task_runner->PostDelayedTask(FROM_HERE,
+ task_runner->PostDelayedTask(
+ FROM_HERE,
base::Bind(&EjectDeviceInThreadPool,
device, callback, task_runner, iteration + 1),
kLockRetryInterval);
return;
}
- content::BrowserThread::PostTask(
- content::BrowserThread::UI, FROM_HERE,
- base::Bind(callback, chrome::StorageMonitor::EJECT_IN_USE));
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(callback, StorageMonitor::EJECT_IN_USE));
return;
}
@@ -291,9 +291,8 @@
if (!dismounted) {
DeviceIoControl(volume_handle, FSCTL_UNLOCK_VOLUME,
NULL, 0, NULL, 0, &bytes_returned, NULL);
- content::BrowserThread::PostTask(
- content::BrowserThread::UI, FROM_HERE,
- base::Bind(callback, chrome::StorageMonitor::EJECT_OK));
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(callback, StorageMonitor::EJECT_OK));
return;
}
@@ -303,30 +302,27 @@
if (!DeviceIoControl(volume_handle, IOCTL_STORAGE_MEDIA_REMOVAL,
&pmr_buffer, sizeof(PREVENT_MEDIA_REMOVAL),
NULL, 0, &bytes_returned, NULL)) {
- content::BrowserThread::PostTask(
- content::BrowserThread::UI, FROM_HERE,
- base::Bind(callback, chrome::StorageMonitor::EJECT_FAILURE));
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(callback, StorageMonitor::EJECT_FAILURE));
return;
}
// Physically eject or soft-eject the device.
if (!DeviceIoControl(volume_handle, IOCTL_STORAGE_EJECT_MEDIA,
NULL, 0, NULL, 0, &bytes_returned, NULL)) {
- content::BrowserThread::PostTask(
- content::BrowserThread::UI, FROM_HERE,
- base::Bind(callback, chrome::StorageMonitor::EJECT_FAILURE));
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(callback, StorageMonitor::EJECT_FAILURE));
return;
}
- content::BrowserThread::PostTask(
- content::BrowserThread::UI, FROM_HERE,
- base::Bind(callback, chrome::StorageMonitor::EJECT_OK));
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(callback, StorageMonitor::EJECT_OK));
}
} // namespace
-namespace chrome {
-
const int kWorkerPoolNumThreads = 3;
const char* kWorkerPoolNamePrefix = "DeviceInfoPool";
@@ -345,7 +341,7 @@
base::FilePath VolumeMountWatcherWin::DriveNumberToFilePath(int drive_number) {
if (drive_number < 0 || drive_number > 25)
return base::FilePath();
- string16 path(L"_:\\");
+ base::string16 path(L"_:\\");
path[0] = L'A' + drive_number;
return base::FilePath(path);
}
@@ -377,10 +373,11 @@
if (ContainsKey(pending_device_checks_, removable_devices[i]))
continue;
pending_device_checks_.insert(removable_devices[i]);
- task_runner_->PostTask(FROM_HERE, base::Bind(
- &VolumeMountWatcherWin::RetrieveInfoForDeviceAndAdd,
- removable_devices[i], GetDeviceDetailsCallback(),
- weak_factory_.GetWeakPtr()));
+ task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&VolumeMountWatcherWin::RetrieveInfoForDeviceAndAdd,
+ removable_devices[i], GetDeviceDetailsCallback(),
+ weak_factory_.GetWeakPtr()));
}
}
@@ -388,18 +385,20 @@
void VolumeMountWatcherWin::RetrieveInfoForDeviceAndAdd(
const base::FilePath& device_path,
const GetDeviceDetailsCallbackType& get_device_details_callback,
- base::WeakPtr<chrome::VolumeMountWatcherWin> volume_watcher) {
+ base::WeakPtr<VolumeMountWatcherWin> volume_watcher) {
StorageInfo info;
if (!get_device_details_callback.Run(device_path, &info)) {
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
- &chrome::VolumeMountWatcherWin::DeviceCheckComplete,
- volume_watcher, device_path));
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&VolumeMountWatcherWin::DeviceCheckComplete,
+ volume_watcher, device_path));
return;
}
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
- &chrome::VolumeMountWatcherWin::HandleDeviceAttachEventOnUIThread,
- volume_watcher, device_path, info));
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&VolumeMountWatcherWin::HandleDeviceAttachEventOnUIThread,
+ volume_watcher, device_path, info));
}
void VolumeMountWatcherWin::DeviceCheckComplete(
@@ -426,6 +425,7 @@
bool VolumeMountWatcherWin::GetDeviceInfo(const base::FilePath& device_path,
StorageInfo* info) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(info);
base::FilePath path(device_path);
MountPointDeviceMetadataMap::const_iterator iter =
device_metadata_.find(path.value());
@@ -437,9 +437,7 @@
if (iter == device_metadata_.end())
return false;
- if (info)
- *info = iter->second;
-
+ *info = iter->second;
return true;
}
@@ -501,7 +499,7 @@
}
void VolumeMountWatcherWin::HandleDeviceDetachEventOnUIThread(
- const string16& device_location) {
+ const base::string16& device_location) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
MountPointDeviceMetadataMap::const_iterator device_info =
@@ -519,8 +517,7 @@
const std::string& device_id,
base::Callback<void(StorageMonitor::EjectStatus)> callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- base::FilePath device =
- chrome::MediaStorageUtil::FindDevicePathById(device_id);
+ base::FilePath device = MediaStorageUtil::FindDevicePathById(device_id);
if (device.empty()) {
callback.Run(StorageMonitor::EJECT_FAILURE);
return;
@@ -530,7 +527,8 @@
return;
}
- task_runner_->PostTask(FROM_HERE,
+ task_runner_->PostTask(
+ FROM_HERE,
base::Bind(&EjectDeviceInThreadPool, device, callback, task_runner_, 0));
}
« no previous file with comments | « chrome/browser/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