Commit 048048dd authored by thestig@chromium.org's avatar thestig@chromium.org

Cleanup Various bits of Windows StorageMonitor classes.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203114 0039d316-1c4b-4281-b951-d872f2087c98
parent db88c700
...@@ -16,13 +16,6 @@ ...@@ -16,13 +16,6 @@
namespace chrome { namespace chrome {
namespace {
const char16 kWindowClassName[] = L"Chrome_StorageMonitorWindow";
} // namespace
// StorageMonitorWin ------------------------------------------------------- // StorageMonitorWin -------------------------------------------------------
// static // static
...@@ -59,7 +52,7 @@ StorageMonitorWin::~StorageMonitorWin() { ...@@ -59,7 +52,7 @@ StorageMonitorWin::~StorageMonitorWin() {
void StorageMonitorWin::Init() { void StorageMonitorWin::Init() {
WNDCLASSEX window_class; WNDCLASSEX window_class;
base::win::InitializeWindowClass( base::win::InitializeWindowClass(
kWindowClassName, L"Chrome_StorageMonitorWindow",
&base::win::WrappedWindowProc<StorageMonitorWin::WndProcThunk>, &base::win::WrappedWindowProc<StorageMonitorWin::WndProcThunk>,
0, 0, 0, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL,
&window_class); &window_class);
...@@ -125,8 +118,8 @@ void StorageMonitorWin::EjectDevice( ...@@ -125,8 +118,8 @@ void StorageMonitorWin::EjectDevice(
bool StorageMonitorWin::GetMTPStorageInfoFromDeviceId( bool StorageMonitorWin::GetMTPStorageInfoFromDeviceId(
const std::string& storage_device_id, const std::string& storage_device_id,
string16* device_location, base::string16* device_location,
string16* storage_object_id) const { base::string16* storage_object_id) const {
StorageInfo::Type type; StorageInfo::Type type;
StorageInfo::CrackDeviceId(storage_device_id, &type, NULL); StorageInfo::CrackDeviceId(storage_device_id, &type, NULL);
return ((type == StorageInfo::MTP_OR_PTP) && return ((type == StorageInfo::MTP_OR_PTP) &&
...@@ -159,6 +152,8 @@ LRESULT CALLBACK StorageMonitorWin::WndProc(HWND hwnd, UINT message, ...@@ -159,6 +152,8 @@ LRESULT CALLBACK StorageMonitorWin::WndProc(HWND hwnd, UINT message,
bool StorageMonitorWin::GetDeviceInfo(const base::FilePath& device_path, bool StorageMonitorWin::GetDeviceInfo(const base::FilePath& device_path,
StorageInfo* info) const { StorageInfo* info) const {
DCHECK(info);
// TODO(kmadhusu) Implement PortableDeviceWatcherWin::GetDeviceInfo() // TODO(kmadhusu) Implement PortableDeviceWatcherWin::GetDeviceInfo()
// function when we have the functionality to add a sub directory of // function when we have the functionality to add a sub directory of
// portable device as a media gallery. // portable device as a media gallery.
......
...@@ -39,8 +39,8 @@ class StorageMonitorWin : public StorageMonitor { ...@@ -39,8 +39,8 @@ class StorageMonitorWin : public StorageMonitor {
StorageInfo* device_info) const OVERRIDE; StorageInfo* device_info) const OVERRIDE;
virtual bool GetMTPStorageInfoFromDeviceId( virtual bool GetMTPStorageInfoFromDeviceId(
const std::string& storage_device_id, const std::string& storage_device_id,
string16* device_location, base::string16* device_location,
string16* storage_object_id) const OVERRIDE; base::string16* storage_object_id) const OVERRIDE;
virtual void EjectDevice( virtual void EjectDevice(
const std::string& device_id, const std::string& device_id,
...@@ -57,8 +57,7 @@ class StorageMonitorWin : public StorageMonitor { ...@@ -57,8 +57,7 @@ class StorageMonitorWin : public StorageMonitor {
PortableDeviceWatcherWin* portable_device_watcher); PortableDeviceWatcherWin* portable_device_watcher);
// Gets the removable storage information given a |device_path|. On success, // Gets the removable storage information given a |device_path|. On success,
// returns true and fills in |device_location|, |unique_id|, |name| and // returns true and fills in |info|.
// |removable|, and |total_size_in_bytes|.
bool GetDeviceInfo(const base::FilePath& device_path, bool GetDeviceInfo(const base::FilePath& device_path,
StorageInfo* info) const; StorageInfo* info) const;
......
...@@ -54,14 +54,14 @@ class StorageMonitorWinTest : public testing::Test { ...@@ -54,14 +54,14 @@ class StorageMonitorWinTest : public testing::Test {
// Injects a device attach or detach change (depending on the value of // Injects a device attach or detach change (depending on the value of
// |test_attach|) and tests that the appropriate handler is called. // |test_attach|) and tests that the appropriate handler is called.
void DoMTPDeviceTest(const string16& pnp_device_id, bool test_attach); void DoMTPDeviceTest(const base::string16& pnp_device_id, bool test_attach);
// Gets the MTP details of the storage specified by the |storage_device_id|. // Gets the MTP details of the storage specified by the |storage_device_id|.
// On success, returns true and fills in |pnp_device_id| and // On success, returns true and fills in |pnp_device_id| and
// |storage_object_id|. // |storage_object_id|.
bool GetMTPStorageInfo(const std::string& storage_device_id, bool GetMTPStorageInfo(const std::string& storage_device_id,
string16* pnp_device_id, base::string16* pnp_device_id,
string16* storage_object_id); base::string16* storage_object_id);
scoped_ptr<TestStorageMonitorWin> monitor_; scoped_ptr<TestStorageMonitorWin> monitor_;
...@@ -198,7 +198,7 @@ void StorageMonitorWinTest::DoMassStorageDevicesDetachedTest( ...@@ -198,7 +198,7 @@ void StorageMonitorWinTest::DoMassStorageDevicesDetachedTest(
EXPECT_EQ(expect_detach_calls, observer_.detach_calls()); EXPECT_EQ(expect_detach_calls, observer_.detach_calls());
} }
void StorageMonitorWinTest::DoMTPDeviceTest(const string16& pnp_device_id, void StorageMonitorWinTest::DoMTPDeviceTest(const base::string16& pnp_device_id,
bool test_attach) { bool test_attach) {
GUID guidDevInterface = GUID_NULL; GUID guidDevInterface = GUID_NULL;
HRESULT hr = CLSIDFromString(kWPDDevInterfaceGUID, &guidDevInterface); HRESULT hr = CLSIDFromString(kWPDDevInterfaceGUID, &guidDevInterface);
...@@ -224,8 +224,8 @@ void StorageMonitorWinTest::DoMTPDeviceTest(const string16& pnp_device_id, ...@@ -224,8 +224,8 @@ void StorageMonitorWinTest::DoMTPDeviceTest(const string16& pnp_device_id,
for (PortableDeviceWatcherWin::StorageObjectIDs::const_iterator it = for (PortableDeviceWatcherWin::StorageObjectIDs::const_iterator it =
storage_object_ids.begin(); it != storage_object_ids.end(); ++it) { storage_object_ids.begin(); it != storage_object_ids.end(); ++it) {
std::string unique_id; std::string unique_id;
string16 name; base::string16 name;
string16 location; base::string16 location;
TestPortableDeviceWatcherWin::GetMTPStorageDetails(pnp_device_id, *it, TestPortableDeviceWatcherWin::GetMTPStorageDetails(pnp_device_id, *it,
&location, &unique_id, &location, &unique_id,
&name); &name);
...@@ -246,8 +246,8 @@ void StorageMonitorWinTest::DoMTPDeviceTest(const string16& pnp_device_id, ...@@ -246,8 +246,8 @@ void StorageMonitorWinTest::DoMTPDeviceTest(const string16& pnp_device_id,
bool StorageMonitorWinTest::GetMTPStorageInfo( bool StorageMonitorWinTest::GetMTPStorageInfo(
const std::string& storage_device_id, const std::string& storage_device_id,
string16* pnp_device_id, base::string16* pnp_device_id,
string16* storage_object_id) { base::string16* storage_object_id) {
return monitor_->GetMTPStorageInfoFromDeviceId(storage_device_id, return monitor_->GetMTPStorageInfoFromDeviceId(storage_device_id,
pnp_device_id, pnp_device_id,
storage_object_id); storage_object_id);
...@@ -433,7 +433,7 @@ TEST_F(StorageMonitorWinTest, DuplicateAttachCheckSuppressed) { ...@@ -433,7 +433,7 @@ TEST_F(StorageMonitorWinTest, DuplicateAttachCheckSuppressed) {
volume_mount_watcher_->FlushWorkerPoolForTesting(); volume_mount_watcher_->FlushWorkerPoolForTesting();
RunUntilIdle(); RunUntilIdle();
std::vector<base::FilePath> checked_devices = const std::vector<base::FilePath>& checked_devices =
volume_mount_watcher_->devices_checked(); volume_mount_watcher_->devices_checked();
ASSERT_EQ(1u, checked_devices.size()); ASSERT_EQ(1u, checked_devices.size());
EXPECT_EQ(kAttachedDevicePath, checked_devices[0]); EXPECT_EQ(kAttachedDevicePath, checked_devices[0]);
...@@ -445,7 +445,6 @@ TEST_F(StorageMonitorWinTest, DuplicateAttachCheckSuppressed) { ...@@ -445,7 +445,6 @@ TEST_F(StorageMonitorWinTest, DuplicateAttachCheckSuppressed) {
volume_mount_watcher_->ReleaseDeviceCheck(); volume_mount_watcher_->ReleaseDeviceCheck();
RunUntilIdle(); RunUntilIdle();
checked_devices = volume_mount_watcher_->devices_checked();
ASSERT_EQ(2u, checked_devices.size()); ASSERT_EQ(2u, checked_devices.size());
EXPECT_EQ(kAttachedDevicePath, checked_devices[0]); EXPECT_EQ(kAttachedDevicePath, checked_devices[0]);
EXPECT_EQ(kAttachedDevicePath, checked_devices[1]); EXPECT_EQ(kAttachedDevicePath, checked_devices[1]);
...@@ -529,12 +528,13 @@ TEST_F(StorageMonitorWinTest, GetMTPStorageInfoFromDeviceId) { ...@@ -529,12 +528,13 @@ TEST_F(StorageMonitorWinTest, GetMTPStorageInfoFromDeviceId) {
for (PortableDeviceWatcherWin::StorageObjects::const_iterator it = for (PortableDeviceWatcherWin::StorageObjects::const_iterator it =
storage_objects.begin(); storage_objects.begin();
it != storage_objects.end(); ++it) { it != storage_objects.end(); ++it) {
string16 pnp_device_id; base::string16 pnp_device_id;
string16 storage_object_id; base::string16 storage_object_id;
ASSERT_TRUE(GetMTPStorageInfo(it->object_persistent_id, &pnp_device_id, ASSERT_TRUE(GetMTPStorageInfo(it->object_persistent_id, &pnp_device_id,
&storage_object_id)); &storage_object_id));
EXPECT_EQ(string16(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo), base::string16 expected(
pnp_device_id); TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo);
EXPECT_EQ(expected, pnp_device_id);
EXPECT_EQ(it->object_persistent_id, EXPECT_EQ(it->object_persistent_id,
TestPortableDeviceWatcherWin::GetMTPStorageUniqueId( TestPortableDeviceWatcherWin::GetMTPStorageUniqueId(
pnp_device_id, storage_object_id)); pnp_device_id, storage_object_id));
......
...@@ -76,9 +76,9 @@ bool GetMassStorageDeviceDetails(const base::FilePath& device_path, ...@@ -76,9 +76,9 @@ bool GetMassStorageDeviceDetails(const base::FilePath& device_path,
"\\\\?\\Volume{00000000-0000-0000-0000-000000000000}\\"; "\\\\?\\Volume{00000000-0000-0000-0000-000000000000}\\";
unique_id[11] = device_path.value()[0]; unique_id[11] = device_path.value()[0];
std::string device_id = StorageInfo::MakeDeviceId(type, unique_id); std::string device_id = StorageInfo::MakeDeviceId(type, unique_id);
string16 storage_label = path.Append(L" Drive").LossyDisplayName(); base::string16 storage_label = path.Append(L" Drive").LossyDisplayName();
*info = StorageInfo(device_id, string16(), path.value(), storage_label, *info = StorageInfo(device_id, base::string16(), path.value(), storage_label,
string16(), string16(), 1000000); base::string16(), base::string16(), 1000000);
return true; return true;
} }
...@@ -96,10 +96,11 @@ TestVolumeMountWatcherWin::~TestVolumeMountWatcherWin() { ...@@ -96,10 +96,11 @@ TestVolumeMountWatcherWin::~TestVolumeMountWatcherWin() {
void TestVolumeMountWatcherWin::AddDeviceForTesting( void TestVolumeMountWatcherWin::AddDeviceForTesting(
const base::FilePath& device_path, const base::FilePath& device_path,
const std::string& device_id, const std::string& device_id,
const string16& device_name, const base::string16& device_name,
uint64 total_size_in_bytes) { uint64 total_size_in_bytes) {
StorageInfo info(device_id, device_name, device_path.value(), StorageInfo info(device_id, device_name, device_path.value(),
string16(), string16(), string16(), total_size_in_bytes); base::string16(), base::string16(), base::string16(),
total_size_in_bytes);
HandleDeviceAttachEventOnUIThread(device_path, info); HandleDeviceAttachEventOnUIThread(device_path, info);
} }
...@@ -128,9 +129,10 @@ void TestVolumeMountWatcherWin::ReleaseDeviceCheck() { ...@@ -128,9 +129,10 @@ void TestVolumeMountWatcherWin::ReleaseDeviceCheck() {
device_check_complete_event_->Signal(); device_check_complete_event_->Signal();
} }
// static
bool TestVolumeMountWatcherWin::GetDeviceRemovable( bool TestVolumeMountWatcherWin::GetDeviceRemovable(
const base::FilePath& device_path, const base::FilePath& device_path,
bool* removable) const { bool* removable) {
StorageInfo info; StorageInfo info;
bool success = GetMassStorageDeviceDetails(device_path, &info); bool success = GetMassStorageDeviceDetails(device_path, &info);
*removable = StorageInfo::IsRemovableDevice(info.device_id()); *removable = StorageInfo::IsRemovableDevice(info.device_id());
...@@ -146,7 +148,6 @@ VolumeMountWatcherWin::GetAttachedDevicesCallbackType ...@@ -146,7 +148,6 @@ VolumeMountWatcherWin::GetAttachedDevicesCallbackType
TestVolumeMountWatcherWin::GetAttachedDevicesCallback() const { TestVolumeMountWatcherWin::GetAttachedDevicesCallback() const {
if (attached_devices_fake_) if (attached_devices_fake_)
return base::Bind(&FakeGetAttachedDevices); return base::Bind(&FakeGetAttachedDevices);
return base::Bind(&FakeGetSingleAttachedDevice); return base::Bind(&FakeGetSingleAttachedDevice);
} }
......
...@@ -27,9 +27,12 @@ class TestVolumeMountWatcherWin : public VolumeMountWatcherWin { ...@@ -27,9 +27,12 @@ class TestVolumeMountWatcherWin : public VolumeMountWatcherWin {
TestVolumeMountWatcherWin(); TestVolumeMountWatcherWin();
virtual ~TestVolumeMountWatcherWin(); virtual ~TestVolumeMountWatcherWin();
static bool GetDeviceRemovable(const base::FilePath& device_path,
bool* removable);
void AddDeviceForTesting(const base::FilePath& device_path, void AddDeviceForTesting(const base::FilePath& device_path,
const std::string& device_id, const std::string& device_id,
const string16& device_name, const base::string16& device_name,
uint64 total_size_in_bytes); uint64 total_size_in_bytes);
void SetAttachedDevicesFake(); void SetAttachedDevicesFake();
...@@ -38,7 +41,7 @@ class TestVolumeMountWatcherWin : public VolumeMountWatcherWin { ...@@ -38,7 +41,7 @@ class TestVolumeMountWatcherWin : public VolumeMountWatcherWin {
virtual void DeviceCheckComplete(const base::FilePath& device_path); virtual void DeviceCheckComplete(const base::FilePath& device_path);
std::vector<base::FilePath> devices_checked() const { const std::vector<base::FilePath>& devices_checked() const {
return devices_checked_; return devices_checked_;
} }
...@@ -46,11 +49,7 @@ class TestVolumeMountWatcherWin : public VolumeMountWatcherWin { ...@@ -46,11 +49,7 @@ class TestVolumeMountWatcherWin : public VolumeMountWatcherWin {
void ReleaseDeviceCheck(); void ReleaseDeviceCheck();
bool GetDeviceRemovable(const base::FilePath& device_path,
bool* removable) const;
// VolumeMountWatcherWin: // VolumeMountWatcherWin:
virtual GetAttachedDevicesCallbackType virtual GetAttachedDevicesCallbackType
GetAttachedDevicesCallback() const OVERRIDE; GetAttachedDevicesCallback() const OVERRIDE;
virtual GetDeviceDetailsCallbackType virtual GetDeviceDetailsCallbackType
......
...@@ -44,8 +44,8 @@ class VolumeMountWatcherWin { ...@@ -44,8 +44,8 @@ class VolumeMountWatcherWin {
// Gets the information about the device mounted at |device_path|. On success, // Gets the information about the device mounted at |device_path|. On success,
// returns true and fills in |info|. // returns true and fills in |info|.
// Can block during startup while device info is still loading. // Can block during startup while device info is still loading.
virtual bool GetDeviceInfo(const base::FilePath& device_path, bool GetDeviceInfo(const base::FilePath& device_path,
StorageInfo* info) const; StorageInfo* info) const;
// Processes DEV_BROADCAST_VOLUME messages and triggers a // Processes DEV_BROADCAST_VOLUME messages and triggers a
// notification if appropriate. // notification if appropriate.
...@@ -71,7 +71,7 @@ class VolumeMountWatcherWin { ...@@ -71,7 +71,7 @@ class VolumeMountWatcherWin {
const StorageInfo& info); const StorageInfo& info);
// Handles mass storage device detach event on UI thread. // Handles mass storage device detach event on UI thread.
void HandleDeviceDetachEventOnUIThread(const string16& device_location); void HandleDeviceDetachEventOnUIThread(const base::string16& device_location);
// UI thread delegate to set up adding storage devices. // UI thread delegate to set up adding storage devices.
void AddDevicesOnUIThread(std::vector<base::FilePath> removable_devices); void AddDevicesOnUIThread(std::vector<base::FilePath> removable_devices);
...@@ -81,7 +81,7 @@ class VolumeMountWatcherWin { ...@@ -81,7 +81,7 @@ class VolumeMountWatcherWin {
static void RetrieveInfoForDeviceAndAdd( static void RetrieveInfoForDeviceAndAdd(
const base::FilePath& device_path, const base::FilePath& device_path,
const GetDeviceDetailsCallbackType& get_device_details_callback, const GetDeviceDetailsCallbackType& get_device_details_callback,
base::WeakPtr<chrome::VolumeMountWatcherWin> volume_watcher); base::WeakPtr<VolumeMountWatcherWin> volume_watcher);
// Mark that a device we started a metadata check for has completed. // Mark that a device we started a metadata check for has completed.
virtual void DeviceCheckComplete(const base::FilePath& device_path); virtual void DeviceCheckComplete(const base::FilePath& device_path);
...@@ -100,7 +100,7 @@ class VolumeMountWatcherWin { ...@@ -100,7 +100,7 @@ class VolumeMountWatcherWin {
// Key: Mass storage device mount point. // Key: Mass storage device mount point.
// Value: Mass storage device metadata. // Value: Mass storage device metadata.
typedef std::map<string16, StorageInfo> MountPointDeviceMetadataMap; typedef std::map<base::string16, StorageInfo> MountPointDeviceMetadataMap;
// Maintain a set of device attribute check calls in-flight. Only accessed // Maintain a set of device attribute check calls in-flight. Only accessed
// on the UI thread. This is to try and prevent the same device from // on the UI thread. This is to try and prevent the same device from
......
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