| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // TestVolumeMountWatcherWin implementation. | 5 // TestVolumeMountWatcherWin implementation. |
| 6 | 6 |
| 7 #include "chrome/browser/storage_monitor/test_volume_mount_watcher_win.h" | 7 #include "chrome/browser/storage_monitor/test_volume_mount_watcher_win.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 // Gets the details of the mass storage device specified by the |device_path|. | 38 // Gets the details of the mass storage device specified by the |device_path|. |
| 39 // |device_path| inputs of 'A:\' - 'Z:\' are valid. 'N:\' is not removable. | 39 // |device_path| inputs of 'A:\' - 'Z:\' are valid. 'N:\' is not removable. |
| 40 // 'C:\' is not removable (so that auto-added paths are correctly handled). | 40 // 'C:\' is not removable (so that auto-added paths are correctly handled). |
| 41 bool GetMassStorageDeviceDetails(const base::FilePath& device_path, | 41 bool GetMassStorageDeviceDetails(const base::FilePath& device_path, |
| 42 StorageInfo* info) { | 42 StorageInfo* info) { |
| 43 DCHECK(info); | 43 DCHECK(info); |
| 44 | 44 |
| 45 // Truncate to root path. | 45 // Truncate to root path. |
| 46 base::FilePath path(device_path); | 46 base::FilePath path(device_path); |
| 47 if (device_path.value().length() > 3) { | 47 if (device_path.value().length() > 3) |
| 48 path = base::FilePath(device_path.value().substr(0, 3)); | 48 path = base::FilePath(device_path.value().substr(0, 3)); |
| 49 if (path.value()[0] < L'A' || path.value()[0] > L'Z') |
| 50 return false; |
| 51 |
| 52 StorageInfo::Type type = StorageInfo::FIXED_MASS_STORAGE; |
| 53 if (path.value() != ASCIIToUTF16("N:\\") && |
| 54 path.value() != ASCIIToUTF16("C:\\")) { |
| 55 type = StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM; |
| 49 } | 56 } |
| 50 if (path.value()[0] < L'A' || path.value()[0] > L'Z') { | |
| 51 return false; | |
| 52 } | |
| 53 | |
| 54 info->location = path.value(); | |
| 55 info->total_size_in_bytes = 1000000; | |
| 56 | |
| 57 std::string unique_id = | 57 std::string unique_id = |
| 58 "\\\\?\\Volume{00000000-0000-0000-0000-000000000000}\\"; | 58 "\\\\?\\Volume{00000000-0000-0000-0000-000000000000}\\"; |
| 59 unique_id[11] = device_path.value()[0]; | 59 unique_id[11] = device_path.value()[0]; |
| 60 chrome::StorageInfo::Type type = chrome::StorageInfo::FIXED_MASS_STORAGE; | 60 std::string device_id = StorageInfo::MakeDeviceId(type, unique_id); |
| 61 if (path.value() != ASCIIToUTF16("N:\\") && | 61 string16 storage_label = path.Append(L" Drive").LossyDisplayName(); |
| 62 path.value() != ASCIIToUTF16("C:\\")) { | 62 *info = StorageInfo(device_id, string16(), path.value(), storage_label, |
| 63 type = chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM; | 63 string16(), string16(), 1000000); |
| 64 } | 64 |
| 65 info->device_id = chrome::StorageInfo::MakeDeviceId(type, unique_id); | |
| 66 info->storage_label = path.Append(L" Drive").LossyDisplayName(); | |
| 67 return true; | 65 return true; |
| 68 } | 66 } |
| 69 | 67 |
| 70 } // namespace | 68 } // namespace |
| 71 | 69 |
| 72 // TestVolumeMountWatcherWin --------------------------------------------------- | 70 // TestVolumeMountWatcherWin --------------------------------------------------- |
| 73 | 71 |
| 74 TestVolumeMountWatcherWin::TestVolumeMountWatcherWin() | 72 TestVolumeMountWatcherWin::TestVolumeMountWatcherWin() |
| 75 : attached_devices_fake_(false) {} | 73 : attached_devices_fake_(false) {} |
| 76 | 74 |
| 77 TestVolumeMountWatcherWin::~TestVolumeMountWatcherWin() { | 75 TestVolumeMountWatcherWin::~TestVolumeMountWatcherWin() { |
| 78 } | 76 } |
| 79 | 77 |
| 80 void TestVolumeMountWatcherWin::AddDeviceForTesting( | 78 void TestVolumeMountWatcherWin::AddDeviceForTesting( |
| 81 const base::FilePath& device_path, | 79 const base::FilePath& device_path, |
| 82 const std::string& device_id, | 80 const std::string& device_id, |
| 83 const string16& device_name, | 81 const string16& device_name, |
| 84 uint64 total_size_in_bytes) { | 82 uint64 total_size_in_bytes) { |
| 85 StorageInfo info; | 83 StorageInfo info(device_id, device_name, device_path.value(), |
| 86 info.device_id = device_id; | 84 string16(), string16(), string16(), total_size_in_bytes); |
| 87 info.location = device_path.value(); | |
| 88 info.name = device_name; | |
| 89 info.total_size_in_bytes = total_size_in_bytes; | |
| 90 HandleDeviceAttachEventOnUIThread(device_path, info); | 85 HandleDeviceAttachEventOnUIThread(device_path, info); |
| 91 } | 86 } |
| 92 | 87 |
| 93 void TestVolumeMountWatcherWin::SetAttachedDevicesFake() { | 88 void TestVolumeMountWatcherWin::SetAttachedDevicesFake() { |
| 94 attached_devices_fake_ = true; | 89 attached_devices_fake_ = true; |
| 95 } | 90 } |
| 96 | 91 |
| 97 void TestVolumeMountWatcherWin::FlushWorkerPoolForTesting() { | 92 void TestVolumeMountWatcherWin::FlushWorkerPoolForTesting() { |
| 98 device_info_worker_pool_->FlushForTesting(); | 93 device_info_worker_pool_->FlushForTesting(); |
| 99 } | 94 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 113 | 108 |
| 114 void TestVolumeMountWatcherWin::ReleaseDeviceCheck() { | 109 void TestVolumeMountWatcherWin::ReleaseDeviceCheck() { |
| 115 device_check_complete_event_->Signal(); | 110 device_check_complete_event_->Signal(); |
| 116 } | 111 } |
| 117 | 112 |
| 118 bool TestVolumeMountWatcherWin::GetDeviceRemovable( | 113 bool TestVolumeMountWatcherWin::GetDeviceRemovable( |
| 119 const base::FilePath& device_path, | 114 const base::FilePath& device_path, |
| 120 bool* removable) const { | 115 bool* removable) const { |
| 121 StorageInfo info; | 116 StorageInfo info; |
| 122 bool success = GetMassStorageDeviceDetails(device_path, &info); | 117 bool success = GetMassStorageDeviceDetails(device_path, &info); |
| 123 *removable = StorageInfo::IsRemovableDevice(info.device_id); | 118 *removable = StorageInfo::IsRemovableDevice(info.device_id()); |
| 124 return success; | 119 return success; |
| 125 } | 120 } |
| 126 | 121 |
| 127 VolumeMountWatcherWin::GetDeviceDetailsCallbackType | 122 VolumeMountWatcherWin::GetDeviceDetailsCallbackType |
| 128 TestVolumeMountWatcherWin::GetDeviceDetailsCallback() const { | 123 TestVolumeMountWatcherWin::GetDeviceDetailsCallback() const { |
| 129 return base::Bind(&GetMassStorageDeviceDetails); | 124 return base::Bind(&GetMassStorageDeviceDetails); |
| 130 } | 125 } |
| 131 | 126 |
| 132 VolumeMountWatcherWin::GetAttachedDevicesCallbackType | 127 VolumeMountWatcherWin::GetAttachedDevicesCallbackType |
| 133 TestVolumeMountWatcherWin::GetAttachedDevicesCallback() const { | 128 TestVolumeMountWatcherWin::GetAttachedDevicesCallback() const { |
| 134 if (attached_devices_fake_) | 129 if (attached_devices_fake_) |
| 135 return base::Bind(&FakeGetAttachedDevices); | 130 return base::Bind(&FakeGetAttachedDevices); |
| 136 | 131 |
| 137 return base::Bind(&FakeGetSingleAttachedDevice); | 132 return base::Bind(&FakeGetSingleAttachedDevice); |
| 138 } | 133 } |
| 139 | 134 |
| 140 void TestVolumeMountWatcherWin::ShutdownWorkerPool() { | 135 void TestVolumeMountWatcherWin::ShutdownWorkerPool() { |
| 141 device_info_worker_pool_->Shutdown(); | 136 device_info_worker_pool_->Shutdown(); |
| 142 } | 137 } |
| 143 | 138 |
| 144 } // namespace test | 139 } // namespace test |
| 145 } // namespace chrome | 140 } // namespace chrome |
| OLD | NEW |