From fb7bc5c917c063ec1a035a218a8596b6c6a88092 Mon Sep 17 00:00:00 2001 From: "thestig@chromium.org" Date: Wed, 22 May 2013 18:10:29 +0000 Subject: StorageMonitor: Remove more conditionals that are always true. Review URL: https://chromiumcodereview.appspot.com/15535009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201576 0039d316-1c4b-4281-b951-d872f2087c98 --- .../storage_monitor/storage_monitor_chromeos.cc | 23 +++++++-------- .../test_volume_mount_watcher_win.cc | 31 ++++++++++---------- .../storage_monitor/volume_mount_watcher_win.cc | 33 +++++++++------------- 3 files changed, 39 insertions(+), 48 deletions(-) diff --git a/chrome/browser/storage_monitor/storage_monitor_chromeos.cc b/chrome/browser/storage_monitor/storage_monitor_chromeos.cc index 8b26742..64341ad 100644 --- a/chrome/browser/storage_monitor/storage_monitor_chromeos.cc +++ b/chrome/browser/storage_monitor/storage_monitor_chromeos.cc @@ -50,6 +50,7 @@ std::string MakeDeviceUniqueId(const disks::DiskMountManager::Disk& disk) { bool GetDeviceInfo(const disks::DiskMountManager::MountPointInfo& mount_info, bool has_dcim, chrome::StorageInfo* info) { + DCHECK(info); std::string source_path = mount_info.source_path; const disks::DiskMountManager::Disk* disk = @@ -66,19 +67,15 @@ bool GetDeviceInfo(const disks::DiskMountManager::MountPointInfo& mount_info, if (unique_id.empty()) return false; - if (info) { - chrome::StorageInfo::Type type = has_dcim ? - chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM : - chrome::StorageInfo::REMOVABLE_MASS_STORAGE_NO_DCIM; - - info->device_id = chrome::StorageInfo::MakeDeviceId(type, unique_id); - info->location = mount_info.mount_path, - info->vendor_name = UTF8ToUTF16(disk->vendor_name()); - info->model_name = UTF8ToUTF16(disk->product_name()); - info->storage_label = device_label; - info->total_size_in_bytes = disk->total_size_in_bytes(); - } - + chrome::StorageInfo::Type type = has_dcim ? + chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM : + chrome::StorageInfo::REMOVABLE_MASS_STORAGE_NO_DCIM; + info->device_id = chrome::StorageInfo::MakeDeviceId(type, unique_id); + info->location = mount_info.mount_path; + info->vendor_name = UTF8ToUTF16(disk->vendor_name()); + info->model_name = UTF8ToUTF16(disk->product_name()); + info->storage_label = device_label; + info->total_size_in_bytes = disk->total_size_in_bytes(); return true; } diff --git a/chrome/browser/storage_monitor/test_volume_mount_watcher_win.cc b/chrome/browser/storage_monitor/test_volume_mount_watcher_win.cc index 3dc2952..eac7710 100644 --- a/chrome/browser/storage_monitor/test_volume_mount_watcher_win.cc +++ b/chrome/browser/storage_monitor/test_volume_mount_watcher_win.cc @@ -40,6 +40,8 @@ std::vector FakeGetAttachedDevices() { // 'C:\' is not removable (so that auto-added paths are correctly handled). bool GetMassStorageDeviceDetails(const base::FilePath& device_path, StorageInfo* info) { + DCHECK(info); + // Truncate to root path. base::FilePath path(device_path); if (device_path.value().length() > 3) { @@ -49,26 +51,23 @@ bool GetMassStorageDeviceDetails(const base::FilePath& device_path, return false; } - if (info) { - info->location = path.value(); - info->total_size_in_bytes = 1000000; - - std::string unique_id = - "\\\\?\\Volume{00000000-0000-0000-0000-000000000000}\\"; - unique_id[11] = device_path.value()[0]; - chrome::StorageInfo::Type type = chrome::StorageInfo::FIXED_MASS_STORAGE; - if (path.value() != ASCIIToUTF16("N:\\") && - path.value() != ASCIIToUTF16("C:\\")) { - type = chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM; - } - info->device_id = chrome::StorageInfo::MakeDeviceId(type, unique_id); - info->storage_label = path.Append(L" Drive").LossyDisplayName(); - } + info->location = path.value(); + info->total_size_in_bytes = 1000000; + std::string unique_id = + "\\\\?\\Volume{00000000-0000-0000-0000-000000000000}\\"; + unique_id[11] = device_path.value()[0]; + chrome::StorageInfo::Type type = chrome::StorageInfo::FIXED_MASS_STORAGE; + if (path.value() != ASCIIToUTF16("N:\\") && + path.value() != ASCIIToUTF16("C:\\")) { + type = chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM; + } + info->device_id = chrome::StorageInfo::MakeDeviceId(type, unique_id); + info->storage_label = path.Append(L" Drive").LossyDisplayName(); return true; } -} // namespace +} // namespace // TestVolumeMountWatcherWin --------------------------------------------------- diff --git a/chrome/browser/storage_monitor/volume_mount_watcher_win.cc b/chrome/browser/storage_monitor/volume_mount_watcher_win.cc index ec1c7d7..aa2d033 100644 --- a/chrome/browser/storage_monitor/volume_mount_watcher_win.cc +++ b/chrome/browser/storage_monitor/volume_mount_watcher_win.cc @@ -118,6 +118,8 @@ uint64 GetVolumeSize(const string16& mount_point) { // http://blogs.msdn.com/b/adioltean/archive/2005/04/16/408947.aspx. bool GetDeviceDetails(const base::FilePath& device_path, chrome::StorageInfo* info) { + DCHECK(info); + string16 mount_point; if (!GetVolumePathName(device_path.value().c_str(), WriteInto(&mount_point, kMaxPathBufLen), @@ -129,18 +131,16 @@ bool GetDeviceDetails(const base::FilePath& device_path, // Note: experimentally this code does not spin a floppy drive. It // returns a GUID associated with the device, not the volume. string16 guid; - if (info) { - if (!GetVolumeNameForVolumeMountPoint(mount_point.c_str(), - WriteInto(&guid, kMaxPathBufLen), - kMaxPathBufLen)) { - return false; - } - // In case it has two GUID's (see above mentioned blog), do it again. - if (!GetVolumeNameForVolumeMountPoint(guid.c_str(), - WriteInto(&guid, kMaxPathBufLen), - kMaxPathBufLen)) { - return false; - } + if (!GetVolumeNameForVolumeMountPoint(mount_point.c_str(), + WriteInto(&guid, kMaxPathBufLen), + kMaxPathBufLen)) { + return false; + } + // In case it has two GUID's (see above mentioned blog), do it again. + if (!GetVolumeNameForVolumeMountPoint(guid.c_str(), + WriteInto(&guid, kMaxPathBufLen), + kMaxPathBufLen)) { + return false; } // If we're adding a floppy drive, return without querying any more @@ -148,16 +148,11 @@ bool GetDeviceDetails(const base::FilePath& device_path, // Note: treats FLOPPY as FIXED_MASS_STORAGE. This is intentional. DeviceType device_type = GetDeviceType(mount_point); if (device_type == FLOPPY) { - if (info) { - info->device_id = chrome::StorageInfo::MakeDeviceId( - chrome::StorageInfo::FIXED_MASS_STORAGE, UTF16ToUTF8(guid)); - } + info->device_id = chrome::StorageInfo::MakeDeviceId( + chrome::StorageInfo::FIXED_MASS_STORAGE, UTF16ToUTF8(guid)); return true; } - if (!info) - return true; - chrome::StorageInfo::Type type = chrome::StorageInfo::FIXED_MASS_STORAGE; if (device_type == REMOVABLE) { -- cgit v1.1