| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <windows.h> | 5 #include <windows.h> |
| 6 #include <dbt.h> | 6 #include <dbt.h> |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/free_deleter.h" | 14 #include "base/memory/free_deleter.h" |
| 14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
| 19 #include "components/storage_monitor/mock_removable_storage_observer.h" | 19 #include "components/storage_monitor/mock_removable_storage_observer.h" |
| 20 #include "components/storage_monitor/portable_device_watcher_win.h" | 20 #include "components/storage_monitor/portable_device_watcher_win.h" |
| 21 #include "components/storage_monitor/removable_device_constants.h" | 21 #include "components/storage_monitor/removable_device_constants.h" |
| 22 #include "components/storage_monitor/storage_info.h" | 22 #include "components/storage_monitor/storage_info.h" |
| 23 #include "components/storage_monitor/storage_monitor_win.h" | 23 #include "components/storage_monitor/storage_monitor_win.h" |
| 24 #include "components/storage_monitor/test_portable_device_watcher_win.h" | 24 #include "components/storage_monitor/test_portable_device_watcher_win.h" |
| 25 #include "components/storage_monitor/test_storage_monitor.h" | 25 #include "components/storage_monitor/test_storage_monitor.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // |test_attach|) and tests that the appropriate handler is called. | 61 // |test_attach|) and tests that the appropriate handler is called. |
| 62 void DoMTPDeviceTest(const base::string16& pnp_device_id, bool test_attach); | 62 void DoMTPDeviceTest(const base::string16& pnp_device_id, bool test_attach); |
| 63 | 63 |
| 64 // Gets the MTP details of the storage specified by the |storage_device_id|. | 64 // Gets the MTP details of the storage specified by the |storage_device_id|. |
| 65 // On success, returns true and fills in |pnp_device_id| and | 65 // On success, returns true and fills in |pnp_device_id| and |
| 66 // |storage_object_id|. | 66 // |storage_object_id|. |
| 67 bool GetMTPStorageInfo(const std::string& storage_device_id, | 67 bool GetMTPStorageInfo(const std::string& storage_device_id, |
| 68 base::string16* pnp_device_id, | 68 base::string16* pnp_device_id, |
| 69 base::string16* storage_object_id); | 69 base::string16* storage_object_id); |
| 70 | 70 |
| 71 scoped_ptr<TestStorageMonitorWin> monitor_; | 71 std::unique_ptr<TestStorageMonitorWin> monitor_; |
| 72 | 72 |
| 73 // Weak pointer; owned by the device notifications class. | 73 // Weak pointer; owned by the device notifications class. |
| 74 TestVolumeMountWatcherWin* volume_mount_watcher_; | 74 TestVolumeMountWatcherWin* volume_mount_watcher_; |
| 75 | 75 |
| 76 MockRemovableStorageObserver observer_; | 76 MockRemovableStorageObserver observer_; |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 content::TestBrowserThreadBundle thread_bundle_; | 79 content::TestBrowserThreadBundle thread_bundle_; |
| 80 | 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(StorageMonitorWinTest); | 81 DISALLOW_COPY_AND_ASSIGN(StorageMonitorWinTest); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 206 |
| 207 void StorageMonitorWinTest::DoMTPDeviceTest(const base::string16& pnp_device_id, | 207 void StorageMonitorWinTest::DoMTPDeviceTest(const base::string16& pnp_device_id, |
| 208 bool test_attach) { | 208 bool test_attach) { |
| 209 GUID guidDevInterface = GUID_NULL; | 209 GUID guidDevInterface = GUID_NULL; |
| 210 HRESULT hr = CLSIDFromString(kWPDDevInterfaceGUID, &guidDevInterface); | 210 HRESULT hr = CLSIDFromString(kWPDDevInterfaceGUID, &guidDevInterface); |
| 211 if (FAILED(hr)) | 211 if (FAILED(hr)) |
| 212 return; | 212 return; |
| 213 | 213 |
| 214 size_t device_id_size = pnp_device_id.size() * sizeof(base::char16); | 214 size_t device_id_size = pnp_device_id.size() * sizeof(base::char16); |
| 215 size_t size = sizeof(DEV_BROADCAST_DEVICEINTERFACE) + device_id_size; | 215 size_t size = sizeof(DEV_BROADCAST_DEVICEINTERFACE) + device_id_size; |
| 216 scoped_ptr<DEV_BROADCAST_DEVICEINTERFACE, base::FreeDeleter> | 216 std::unique_ptr<DEV_BROADCAST_DEVICEINTERFACE, base::FreeDeleter> |
| 217 dev_interface_broadcast( | 217 dev_interface_broadcast( |
| 218 static_cast<DEV_BROADCAST_DEVICEINTERFACE*>(malloc(size))); | 218 static_cast<DEV_BROADCAST_DEVICEINTERFACE*>(malloc(size))); |
| 219 DCHECK(dev_interface_broadcast.get()); | 219 DCHECK(dev_interface_broadcast.get()); |
| 220 ZeroMemory(dev_interface_broadcast.get(), size); | 220 ZeroMemory(dev_interface_broadcast.get(), size); |
| 221 dev_interface_broadcast->dbcc_size = size; | 221 dev_interface_broadcast->dbcc_size = size; |
| 222 dev_interface_broadcast->dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; | 222 dev_interface_broadcast->dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; |
| 223 dev_interface_broadcast->dbcc_classguid = guidDevInterface; | 223 dev_interface_broadcast->dbcc_classguid = guidDevInterface; |
| 224 memcpy(dev_interface_broadcast->dbcc_name, pnp_device_id.data(), | 224 memcpy(dev_interface_broadcast->dbcc_name, pnp_device_id.data(), |
| 225 device_id_size); | 225 device_id_size); |
| 226 | 226 |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo); | 542 TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo); |
| 543 EXPECT_EQ(expected, pnp_device_id); | 543 EXPECT_EQ(expected, pnp_device_id); |
| 544 EXPECT_EQ(it->object_persistent_id, | 544 EXPECT_EQ(it->object_persistent_id, |
| 545 TestPortableDeviceWatcherWin::GetMTPStorageUniqueId( | 545 TestPortableDeviceWatcherWin::GetMTPStorageUniqueId( |
| 546 pnp_device_id, storage_object_id)); | 546 pnp_device_id, storage_object_id)); |
| 547 } | 547 } |
| 548 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, false); | 548 DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, false); |
| 549 } | 549 } |
| 550 | 550 |
| 551 } // namespace storage_monitor | 551 } // namespace storage_monitor |
| OLD | NEW |