Commit f282ad0d authored by gbillock@chromium.org's avatar gbillock@chromium.org

[StorageMonitor] Remove GetStorageSize.

Use GetStorageInfoForPath to get volume size.

R=thestig@chromium.org
BUG=None


Review URL: https://chromiumcodereview.appspot.com/13524003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192978 0039d316-1c4b-4281-b951-d872f2087c98
parent 6f346127
...@@ -312,7 +312,7 @@ bool MediaStorageUtil::GetDeviceInfoFromPath(const base::FilePath& path, ...@@ -312,7 +312,7 @@ bool MediaStorageUtil::GetDeviceInfoFromPath(const base::FilePath& path,
// TODO(gbillock): Don't do this. Leave for clients to do. // TODO(gbillock): Don't do this. Leave for clients to do.
#if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) // Implies OS_CHROMEOS #if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) // Implies OS_CHROMEOS
info.name = GetDisplayNameForDevice( info.name = GetDisplayNameForDevice(
monitor->GetStorageSize(info.location), info.total_size_in_bytes,
GetDisplayNameForSubFolder(info.name, sub_folder_path)); GetDisplayNameForSubFolder(info.name, sub_folder_path));
#endif #endif
......
...@@ -65,12 +65,6 @@ class StorageMonitor { ...@@ -65,12 +65,6 @@ class StorageMonitor {
const base::FilePath& path, const base::FilePath& path,
StorageInfo* device_info) const = 0; StorageInfo* device_info) const = 0;
// Returns the storage size of the device present at |location|. If the
// device information is unavailable, returns zero.
// TODO(gbillock): delete this in favor of GetStorageInfoForPath.
virtual uint64 GetStorageSize(
const base::FilePath::StringType& location) const = 0;
// TODO(gbillock): make this either unnecessary (implementation-specific) or // TODO(gbillock): make this either unnecessary (implementation-specific) or
// platform-independent. // platform-independent.
#if defined(OS_WIN) #if defined(OS_WIN)
......
...@@ -232,13 +232,6 @@ bool StorageMonitorCros::GetStorageInfoForPath( ...@@ -232,13 +232,6 @@ bool StorageMonitorCros::GetStorageInfoForPath(
return true; return true;
} }
uint64 StorageMonitorCros::GetStorageSize(
const std::string& device_location) const {
MountMap::const_iterator info_it = mount_map_.find(device_location);
return (info_it != mount_map_.end()) ?
info_it->second.total_size_in_bytes : 0;
}
// Callback executed when the unmount call is run by DiskMountManager. // Callback executed when the unmount call is run by DiskMountManager.
// Forwards result to |EjectDevice| caller. // Forwards result to |EjectDevice| caller.
void NotifyUnmountResult( void NotifyUnmountResult(
......
...@@ -57,10 +57,6 @@ class StorageMonitorCros ...@@ -57,10 +57,6 @@ class StorageMonitorCros
const base::FilePath& path, const base::FilePath& path,
chrome::StorageInfo* device_info) const OVERRIDE; chrome::StorageInfo* device_info) const OVERRIDE;
// Returns the storage size of the device present at |location|. If the
// device information is unavailable, returns zero.
virtual uint64 GetStorageSize(const std::string& location) const OVERRIDE;
virtual void EjectDevice( virtual void EjectDevice(
const std::string& device_id, const std::string& device_id,
base::Callback<void(EjectStatus)> callback) OVERRIDE; base::Callback<void(EjectStatus)> callback) OVERRIDE;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "chrome/browser/storage_monitor/media_storage_util.h" #include "chrome/browser/storage_monitor/media_storage_util.h"
#include "chrome/browser/storage_monitor/mock_removable_storage_observer.h" #include "chrome/browser/storage_monitor/mock_removable_storage_observer.h"
#include "chrome/browser/storage_monitor/removable_device_constants.h" #include "chrome/browser/storage_monitor/removable_device_constants.h"
#include "chrome/browser/storage_monitor/storage_info.h"
#include "chromeos/disks/mock_disk_mount_manager.h" #include "chromeos/disks/mock_disk_mount_manager.h"
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -184,7 +185,11 @@ void StorageMonitorCrosTest::UnmountDevice( ...@@ -184,7 +185,11 @@ void StorageMonitorCrosTest::UnmountDevice(
uint64 StorageMonitorCrosTest::GetDeviceStorageSize( uint64 StorageMonitorCrosTest::GetDeviceStorageSize(
const std::string& device_location) { const std::string& device_location) {
return monitor_->GetStorageSize(device_location); chrome::StorageInfo info;
if (!monitor_->GetStorageInfoForPath(base::FilePath(device_location), &info))
return 0;
return info.total_size_in_bytes;
} }
base::FilePath StorageMonitorCrosTest::CreateMountPoint( base::FilePath StorageMonitorCrosTest::CreateMountPoint(
......
...@@ -290,15 +290,6 @@ bool StorageMonitorLinux::GetStorageInfoForPath( ...@@ -290,15 +290,6 @@ bool StorageMonitorLinux::GetStorageInfoForPath(
return true; return true;
} }
uint64 StorageMonitorLinux::GetStorageSize(const std::string& location) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
MountMap::const_iterator mount_info = mount_info_map_.find(
base::FilePath(location));
return (mount_info != mount_info_map_.end()) ?
mount_info->second.storage_info.total_size_in_bytes : 0;
}
void StorageMonitorLinux::SetGetDeviceInfoCallbackForTest( void StorageMonitorLinux::SetGetDeviceInfoCallbackForTest(
const GetDeviceInfoCallback& get_device_info_callback) { const GetDeviceInfoCallback& get_device_info_callback) {
get_device_info_callback_ = get_device_info_callback; get_device_info_callback_ = get_device_info_callback;
......
...@@ -47,10 +47,6 @@ class StorageMonitorLinux : public StorageMonitor, ...@@ -47,10 +47,6 @@ class StorageMonitorLinux : public StorageMonitor,
const base::FilePath& path, const base::FilePath& path,
StorageInfo* device_info) const OVERRIDE; StorageInfo* device_info) const OVERRIDE;
// Returns the storage partition size of the device present at |location|.
// If the requested information is unavailable, returns 0.
virtual uint64 GetStorageSize(const std::string& location) const OVERRIDE;
protected: protected:
// Gets device information given a |device_path| and |mount_point|. // Gets device information given a |device_path| and |mount_point|.
typedef base::Callback<scoped_ptr<StorageInfo>( typedef base::Callback<scoped_ptr<StorageInfo>(
......
...@@ -261,6 +261,14 @@ class StorageMonitorLinuxTest : public testing::Test { ...@@ -261,6 +261,14 @@ class StorageMonitorLinuxTest : public testing::Test {
return monitor_.get(); return monitor_.get();
} }
uint64 GetStorageSize(const base::FilePath& path) {
StorageInfo info;
if (!notifier()->GetStorageInfoForPath(path, &info))
return 0;
return info.total_size_in_bytes;
}
private: private:
// Create a directory named |dir| relative to the test directory. // Create a directory named |dir| relative to the test directory.
// Set |with_dcim_dir| to true if the created directory will have a "DCIM" // Set |with_dcim_dir| to true if the created directory will have a "DCIM"
...@@ -694,11 +702,11 @@ TEST_F(StorageMonitorLinuxTest, DevicePartitionSize) { ...@@ -694,11 +702,11 @@ TEST_F(StorageMonitorLinuxTest, DevicePartitionSize) {
EXPECT_EQ(0, observer().detach_calls()); EXPECT_EQ(0, observer().detach_calls());
EXPECT_EQ(GetDevicePartitionSize(kDeviceDCIM1), EXPECT_EQ(GetDevicePartitionSize(kDeviceDCIM1),
notifier()->GetStorageSize(test_path_a.value())); GetStorageSize(test_path_a));
EXPECT_EQ(GetDevicePartitionSize(kDeviceNoDCIM), EXPECT_EQ(GetDevicePartitionSize(kDeviceNoDCIM),
notifier()->GetStorageSize(test_path_b.value())); GetStorageSize(test_path_b));
EXPECT_EQ(GetDevicePartitionSize(kInvalidPath), EXPECT_EQ(GetDevicePartitionSize(kInvalidPath),
notifier()->GetStorageSize(kInvalidPath)); GetStorageSize(base::FilePath(kInvalidPath)));
} }
} // namespace } // namespace
......
...@@ -42,11 +42,6 @@ class StorageMonitorMac : public StorageMonitor, ...@@ -42,11 +42,6 @@ class StorageMonitorMac : public StorageMonitor,
const base::FilePath& path, const base::FilePath& path,
StorageInfo* device_info) const OVERRIDE; StorageInfo* device_info) const OVERRIDE;
// Returns the storage size of the device present at |location|. If the
// device information is unavailable, returns zero. |location| must be a
// top-level mount point.
virtual uint64 GetStorageSize(const std::string& location) const OVERRIDE;
virtual void EjectDevice( virtual void EjectDevice(
const std::string& device_id, const std::string& device_id,
base::Callback<void(EjectStatus)> callback) OVERRIDE; base::Callback<void(EjectStatus)> callback) OVERRIDE;
......
...@@ -287,13 +287,6 @@ bool StorageMonitorMac::GetStorageInfoForPath(const base::FilePath& path, ...@@ -287,13 +287,6 @@ bool StorageMonitorMac::GetStorageInfoForPath(const base::FilePath& path,
return false; return false;
} }
uint64 StorageMonitorMac::GetStorageSize(const std::string& location) const {
StorageInfo info;
if (!FindDiskWithMountPoint(base::FilePath(location), &info))
return 0;
return info.total_size_in_bytes;
}
void StorageMonitorMac::EjectDevice( void StorageMonitorMac::EjectDevice(
const std::string& device_id, const std::string& device_id,
base::Callback<void(EjectStatus)> callback) { base::Callback<void(EjectStatus)> callback) {
......
...@@ -168,20 +168,12 @@ TEST_F(StorageMonitorMacTest, GetStorageInfo) { ...@@ -168,20 +168,12 @@ TEST_F(StorageMonitorMacTest, GetStorageInfo) {
EXPECT_EQ(device_id_, info.device_id); EXPECT_EQ(device_id_, info.device_id);
EXPECT_EQ(ASCIIToUTF16("977 KB Test Display Name"), info.name); EXPECT_EQ(ASCIIToUTF16("977 KB Test Display Name"), info.name);
EXPECT_EQ(mount_point_.value(), info.location); EXPECT_EQ(mount_point_.value(), info.location);
EXPECT_EQ(1000000ULL, info.total_size_in_bytes); EXPECT_EQ(kTestSize, info.total_size_in_bytes);
EXPECT_FALSE(monitor_->GetStorageInfoForPath( EXPECT_FALSE(monitor_->GetStorageInfoForPath(
base::FilePath("/non/matching/path"), &info)); base::FilePath("/non/matching/path"), &info));
} }
TEST_F(StorageMonitorMacTest, GetStorageSize) {
UpdateDisk(disk_info_, StorageMonitorMac::UPDATE_DEVICE_ADDED);
EXPECT_EQ(1, mock_storage_observer_->attach_calls());
EXPECT_EQ(kTestSize,
monitor_->GetStorageSize("/unused_test_directory"));
}
// Test that mounting a DMG doesn't send a notification. // Test that mounting a DMG doesn't send a notification.
TEST_F(StorageMonitorMacTest, DMG) { TEST_F(StorageMonitorMacTest, DMG) {
StorageInfo info = CreateStorageInfo( StorageInfo info = CreateStorageInfo(
......
...@@ -79,8 +79,8 @@ bool StorageMonitorWin::GetStorageInfoForPath(const base::FilePath& path, ...@@ -79,8 +79,8 @@ bool StorageMonitorWin::GetStorageInfoForPath(const base::FilePath& path,
string16 location; string16 location;
std::string unique_id; std::string unique_id;
string16 name; string16 name;
bool removable; bool removable = false;
uint64 total_size_in_bytes; uint64 total_size_in_bytes = 0;
if (!GetDeviceInfo(path, &location, &unique_id, &name, &removable, if (!GetDeviceInfo(path, &location, &unique_id, &name, &removable,
&total_size_in_bytes)) { &total_size_in_bytes)) {
return false; return false;
...@@ -116,15 +116,11 @@ bool StorageMonitorWin::GetStorageInfoForPath(const base::FilePath& path, ...@@ -116,15 +116,11 @@ bool StorageMonitorWin::GetStorageInfoForPath(const base::FilePath& path,
device_info->device_id = device_id; device_info->device_id = device_id;
device_info->name = name; device_info->name = name;
device_info->location = location; device_info->location = location;
device_info->total_size_in_bytes = total_size_in_bytes;
} }
return true; return true;
} }
uint64 StorageMonitorWin::GetStorageSize(
const base::FilePath::StringType& location) const {
return volume_mount_watcher_->GetStorageSize(location);
}
bool StorageMonitorWin::GetMTPStorageInfoFromDeviceId( bool StorageMonitorWin::GetMTPStorageInfoFromDeviceId(
const std::string& storage_device_id, const std::string& storage_device_id,
string16* device_location, string16* device_location,
......
...@@ -42,9 +42,6 @@ class StorageMonitorWin : public StorageMonitor { ...@@ -42,9 +42,6 @@ class StorageMonitorWin : public StorageMonitor {
string16* device_location, string16* device_location,
string16* storage_object_id) const OVERRIDE; string16* storage_object_id) const OVERRIDE;
virtual uint64 GetStorageSize(
const base::FilePath::StringType& location) const OVERRIDE;
private: private:
class PortableDeviceNotifications; class PortableDeviceNotifications;
friend class test::TestStorageMonitorWin; friend class test::TestStorageMonitorWin;
......
...@@ -31,15 +31,11 @@ bool TestStorageMonitor::GetStorageInfoForPath( ...@@ -31,15 +31,11 @@ bool TestStorageMonitor::GetStorageInfoForPath(
MediaStorageUtil::FIXED_MASS_STORAGE, path.AsUTF8Unsafe()); MediaStorageUtil::FIXED_MASS_STORAGE, path.AsUTF8Unsafe());
device_info->name = path.BaseName().LossyDisplayName(); device_info->name = path.BaseName().LossyDisplayName();
device_info->location = path.value(); device_info->location = path.value();
device_info->total_size_in_bytes = 0;
} }
return true; return true;
} }
uint64 TestStorageMonitor::GetStorageSize(
const base::FilePath::StringType& location) const {
return 0;
}
#if defined(OS_WIN) #if defined(OS_WIN)
bool TestStorageMonitor::GetMTPStorageInfoFromDeviceId( bool TestStorageMonitor::GetMTPStorageInfoFromDeviceId(
const std::string& storage_device_id, const std::string& storage_device_id,
......
...@@ -23,9 +23,6 @@ class TestStorageMonitor : public chrome::StorageMonitor { ...@@ -23,9 +23,6 @@ class TestStorageMonitor : public chrome::StorageMonitor {
const base::FilePath& path, const base::FilePath& path,
StorageInfo* device_info) const OVERRIDE; StorageInfo* device_info) const OVERRIDE;
virtual uint64 GetStorageSize(
const base::FilePath::StringType& location) const OVERRIDE;
#if defined(OS_WIN) #if defined(OS_WIN)
virtual bool GetMTPStorageInfoFromDeviceId( virtual bool GetMTPStorageInfoFromDeviceId(
const std::string& storage_device_id, const std::string& storage_device_id,
......
...@@ -322,15 +322,6 @@ bool VolumeMountWatcherWin::GetDeviceInfo(const base::FilePath& device_path, ...@@ -322,15 +322,6 @@ bool VolumeMountWatcherWin::GetDeviceInfo(const base::FilePath& device_path,
return true; return true;
} }
uint64 VolumeMountWatcherWin::GetStorageSize(
const base::FilePath::StringType& mount_point) const {
MountPointDeviceMetadataMap::const_iterator iter =
device_metadata_.find(mount_point);
if (iter != device_metadata_.end())
return iter->second.total_size_in_bytes;
return 0;
}
void VolumeMountWatcherWin::OnWindowMessage(UINT event_type, LPARAM data) { void VolumeMountWatcherWin::OnWindowMessage(UINT event_type, LPARAM data) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
switch (event_type) { switch (event_type) {
......
...@@ -47,10 +47,6 @@ class VolumeMountWatcherWin { ...@@ -47,10 +47,6 @@ class VolumeMountWatcherWin {
bool* removable, bool* removable,
uint64* total_size_in_bytes) const; uint64* total_size_in_bytes) const;
// Returns the partition size of the given mount location. Returns 0 if the
// location is unknown.
uint64 GetStorageSize(const base::FilePath::StringType& mount_point) const;
// Processes DEV_BROADCAST_VOLUME messages and triggers a // Processes DEV_BROADCAST_VOLUME messages and triggers a
// notification if appropriate. // notification if appropriate.
void OnWindowMessage(UINT event_type, LPARAM data); void OnWindowMessage(UINT event_type, LPARAM data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment