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 @@
namespace chrome {
namespace {
const char16 kWindowClassName[] = L"Chrome_StorageMonitorWindow";
} // namespace
// StorageMonitorWin -------------------------------------------------------
// static
......@@ -59,7 +52,7 @@ StorageMonitorWin::~StorageMonitorWin() {
void StorageMonitorWin::Init() {
WNDCLASSEX window_class;
base::win::InitializeWindowClass(
kWindowClassName,
L"Chrome_StorageMonitorWindow",
&base::win::WrappedWindowProc<StorageMonitorWin::WndProcThunk>,
0, 0, 0, NULL, NULL, NULL, NULL, NULL,
&window_class);
......@@ -125,8 +118,8 @@ void StorageMonitorWin::EjectDevice(
bool StorageMonitorWin::GetMTPStorageInfoFromDeviceId(
const std::string& storage_device_id,
string16* device_location,
string16* storage_object_id) const {
base::string16* device_location,
base::string16* storage_object_id) const {
StorageInfo::Type type;
StorageInfo::CrackDeviceId(storage_device_id, &type, NULL);
return ((type == StorageInfo::MTP_OR_PTP) &&
......@@ -159,6 +152,8 @@ LRESULT CALLBACK StorageMonitorWin::WndProc(HWND hwnd, UINT message,
bool StorageMonitorWin::GetDeviceInfo(const base::FilePath& device_path,
StorageInfo* info) const {
DCHECK(info);
// TODO(kmadhusu) Implement PortableDeviceWatcherWin::GetDeviceInfo()
// function when we have the functionality to add a sub directory of
// portable device as a media gallery.
......
......@@ -39,8 +39,8 @@ class StorageMonitorWin : public StorageMonitor {
StorageInfo* device_info) const OVERRIDE;
virtual bool GetMTPStorageInfoFromDeviceId(
const std::string& storage_device_id,
string16* device_location,
string16* storage_object_id) const OVERRIDE;
base::string16* device_location,
base::string16* storage_object_id) const OVERRIDE;
virtual void EjectDevice(
const std::string& device_id,
......@@ -57,8 +57,7 @@ class StorageMonitorWin : public StorageMonitor {
PortableDeviceWatcherWin* portable_device_watcher);
// Gets the removable storage information given a |device_path|. On success,
// returns true and fills in |device_location|, |unique_id|, |name| and
// |removable|, and |total_size_in_bytes|.
// returns true and fills in |info|.
bool GetDeviceInfo(const base::FilePath& device_path,
StorageInfo* info) const;
......
......@@ -54,14 +54,14 @@ class StorageMonitorWinTest : public testing::Test {
// Injects a device attach or detach change (depending on the value of
// |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|.
// On success, returns true and fills in |pnp_device_id| and
// |storage_object_id|.
bool GetMTPStorageInfo(const std::string& storage_device_id,
string16* pnp_device_id,
string16* storage_object_id);
base::string16* pnp_device_id,
base::string16* storage_object_id);
scoped_ptr<TestStorageMonitorWin> monitor_;
......@@ -198,7 +198,7 @@ void StorageMonitorWinTest::DoMassStorageDevicesDetachedTest(
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) {
GUID guidDevInterface = GUID_NULL;
HRESULT hr = CLSIDFromString(kWPDDevInterfaceGUID, &guidDevInterface);
......@@ -224,8 +224,8 @@ void StorageMonitorWinTest::DoMTPDeviceTest(const string16& pnp_device_id,
for (PortableDeviceWatcherWin::StorageObjectIDs::const_iterator it =
storage_object_ids.begin(); it != storage_object_ids.end(); ++it) {
std::string unique_id;
string16 name;
string16 location;
base::string16 name;
base::string16 location;
TestPortableDeviceWatcherWin::GetMTPStorageDetails(pnp_device_id, *it,
&location, &unique_id,
&name);
......@@ -246,8 +246,8 @@ void StorageMonitorWinTest::DoMTPDeviceTest(const string16& pnp_device_id,
bool StorageMonitorWinTest::GetMTPStorageInfo(
const std::string& storage_device_id,
string16* pnp_device_id,
string16* storage_object_id) {
base::string16* pnp_device_id,
base::string16* storage_object_id) {
return monitor_->GetMTPStorageInfoFromDeviceId(storage_device_id,
pnp_device_id,
storage_object_id);
......@@ -433,7 +433,7 @@ TEST_F(StorageMonitorWinTest, DuplicateAttachCheckSuppressed) {
volume_mount_watcher_->FlushWorkerPoolForTesting();
RunUntilIdle();
std::vector<base::FilePath> checked_devices =
const std::vector<base::FilePath>& checked_devices =
volume_mount_watcher_->devices_checked();
ASSERT_EQ(1u, checked_devices.size());
EXPECT_EQ(kAttachedDevicePath, checked_devices[0]);
......@@ -445,7 +445,6 @@ TEST_F(StorageMonitorWinTest, DuplicateAttachCheckSuppressed) {
volume_mount_watcher_->ReleaseDeviceCheck();
RunUntilIdle();
checked_devices = volume_mount_watcher_->devices_checked();
ASSERT_EQ(2u, checked_devices.size());
EXPECT_EQ(kAttachedDevicePath, checked_devices[0]);
EXPECT_EQ(kAttachedDevicePath, checked_devices[1]);
......@@ -529,12 +528,13 @@ TEST_F(StorageMonitorWinTest, GetMTPStorageInfoFromDeviceId) {
for (PortableDeviceWatcherWin::StorageObjects::const_iterator it =
storage_objects.begin();
it != storage_objects.end(); ++it) {
string16 pnp_device_id;
string16 storage_object_id;
base::string16 pnp_device_id;
base::string16 storage_object_id;
ASSERT_TRUE(GetMTPStorageInfo(it->object_persistent_id, &pnp_device_id,
&storage_object_id));
EXPECT_EQ(string16(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo),
pnp_device_id);
base::string16 expected(
TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo);
EXPECT_EQ(expected, pnp_device_id);
EXPECT_EQ(it->object_persistent_id,
TestPortableDeviceWatcherWin::GetMTPStorageUniqueId(
pnp_device_id, storage_object_id));
......
......@@ -76,9 +76,9 @@ bool GetMassStorageDeviceDetails(const base::FilePath& device_path,
"\\\\?\\Volume{00000000-0000-0000-0000-000000000000}\\";
unique_id[11] = device_path.value()[0];
std::string device_id = StorageInfo::MakeDeviceId(type, unique_id);
string16 storage_label = path.Append(L" Drive").LossyDisplayName();
*info = StorageInfo(device_id, string16(), path.value(), storage_label,
string16(), string16(), 1000000);
base::string16 storage_label = path.Append(L" Drive").LossyDisplayName();
*info = StorageInfo(device_id, base::string16(), path.value(), storage_label,
base::string16(), base::string16(), 1000000);
return true;
}
......@@ -96,10 +96,11 @@ TestVolumeMountWatcherWin::~TestVolumeMountWatcherWin() {
void TestVolumeMountWatcherWin::AddDeviceForTesting(
const base::FilePath& device_path,
const std::string& device_id,
const string16& device_name,
const base::string16& device_name,
uint64 total_size_in_bytes) {
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);
}
......@@ -128,9 +129,10 @@ void TestVolumeMountWatcherWin::ReleaseDeviceCheck() {
device_check_complete_event_->Signal();
}
// static
bool TestVolumeMountWatcherWin::GetDeviceRemovable(
const base::FilePath& device_path,
bool* removable) const {
bool* removable) {
StorageInfo info;
bool success = GetMassStorageDeviceDetails(device_path, &info);
*removable = StorageInfo::IsRemovableDevice(info.device_id());
......@@ -146,7 +148,6 @@ VolumeMountWatcherWin::GetAttachedDevicesCallbackType
TestVolumeMountWatcherWin::GetAttachedDevicesCallback() const {
if (attached_devices_fake_)
return base::Bind(&FakeGetAttachedDevices);
return base::Bind(&FakeGetSingleAttachedDevice);
}
......
......@@ -27,9 +27,12 @@ class TestVolumeMountWatcherWin : public VolumeMountWatcherWin {
TestVolumeMountWatcherWin();
virtual ~TestVolumeMountWatcherWin();
static bool GetDeviceRemovable(const base::FilePath& device_path,
bool* removable);
void AddDeviceForTesting(const base::FilePath& device_path,
const std::string& device_id,
const string16& device_name,
const base::string16& device_name,
uint64 total_size_in_bytes);
void SetAttachedDevicesFake();
......@@ -38,7 +41,7 @@ class TestVolumeMountWatcherWin : public VolumeMountWatcherWin {
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_;
}
......@@ -46,11 +49,7 @@ class TestVolumeMountWatcherWin : public VolumeMountWatcherWin {
void ReleaseDeviceCheck();
bool GetDeviceRemovable(const base::FilePath& device_path,
bool* removable) const;
// VolumeMountWatcherWin:
virtual GetAttachedDevicesCallbackType
GetAttachedDevicesCallback() const OVERRIDE;
virtual GetDeviceDetailsCallbackType
......
......@@ -44,7 +44,7 @@ class VolumeMountWatcherWin {
// Gets the information about the device mounted at |device_path|. On success,
// returns true and fills in |info|.
// 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;
// Processes DEV_BROADCAST_VOLUME messages and triggers a
......@@ -71,7 +71,7 @@ class VolumeMountWatcherWin {
const StorageInfo& info);
// 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.
void AddDevicesOnUIThread(std::vector<base::FilePath> removable_devices);
......@@ -81,7 +81,7 @@ class VolumeMountWatcherWin {
static void RetrieveInfoForDeviceAndAdd(
const base::FilePath& device_path,
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.
virtual void DeviceCheckComplete(const base::FilePath& device_path);
......@@ -100,7 +100,7 @@ class VolumeMountWatcherWin {
// Key: Mass storage device mount point.
// 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
// 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