OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/disks/mock_disk_mount_manager.h" | 5 #include "chrome/browser/chromeos/disks/mock_disk_mount_manager.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
8 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
9 #include "base/string_util.h" | 11 #include "base/string_util.h" |
10 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
11 | 13 |
12 using content::BrowserThread; | 14 using content::BrowserThread; |
13 using testing::_; | 15 using testing::_; |
14 using testing::AnyNumber; | 16 using testing::AnyNumber; |
15 using testing::Invoke; | 17 using testing::Invoke; |
16 using testing::ReturnRef; | 18 using testing::ReturnRef; |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 std::string(), // drive_label | 168 std::string(), // drive_label |
167 device_id, // fs_uuid | 169 device_id, // fs_uuid |
168 std::string(), // system_path_prefix | 170 std::string(), // system_path_prefix |
169 DEVICE_TYPE_USB, // device_type | 171 DEVICE_TYPE_USB, // device_type |
170 1073741824, // total_size_in_bytes | 172 1073741824, // total_size_in_bytes |
171 false, // is_parent | 173 false, // is_parent |
172 false, // is_read_only | 174 false, // is_read_only |
173 true, // has_media | 175 true, // has_media |
174 false, // on_boot_device | 176 false, // on_boot_device |
175 false); // is_hidden | 177 false); // is_hidden |
176 disks_.insert(std::pair<std::string, DiskMountManager::Disk*>( | 178 DiskMountManager::DiskMap::iterator it = disks_.find(mount_info.source_path); |
177 std::string(mount_info.source_path), disk)); | 179 if (it == disks_.end()) { |
| 180 disks_.insert(std::make_pair(std::string(mount_info.source_path), disk)); |
| 181 } else { |
| 182 delete it->second; |
| 183 it->second = disk; |
| 184 } |
178 } | 185 } |
179 | 186 |
180 void MockDiskMountManager::RemoveDiskEntryForMountDevice( | 187 void MockDiskMountManager::RemoveDiskEntryForMountDevice( |
181 const DiskMountManager::MountPointInfo& mount_info) { | 188 const DiskMountManager::MountPointInfo& mount_info) { |
182 DiskMountManager::DiskMap::iterator it = disks_.find(mount_info.source_path); | 189 DiskMountManager::DiskMap::iterator it = disks_.find(mount_info.source_path); |
183 if (it != disks_.end()) { | 190 if (it != disks_.end()) { |
184 delete it->second; | 191 delete it->second; |
185 disks_.erase(it); | 192 disks_.erase(it); |
186 } | 193 } |
187 } | 194 } |
188 | 195 |
189 void MockDiskMountManager::NotifyDiskChanged(DiskMountManagerEventType event, | 196 void MockDiskMountManager::NotifyDiskChanged( |
190 const DiskMountManager::Disk* disk) | 197 DiskMountManagerEventType event, |
191 { | 198 const DiskMountManager::Disk* disk) { |
192 // Make sure we run on UI thread. | 199 // Make sure we run on UI thread. |
193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
194 | 201 |
195 FOR_EACH_OBSERVER(Observer, observers_, DiskChanged(event, disk)); | 202 FOR_EACH_OBSERVER(Observer, observers_, DiskChanged(event, disk)); |
196 } | 203 } |
197 | 204 |
198 void MockDiskMountManager::NotifyDeviceChanged(DiskMountManagerEventType event, | 205 void MockDiskMountManager::NotifyDeviceChanged(DiskMountManagerEventType event, |
199 const std::string& path) { | 206 const std::string& path) { |
200 // Make sure we run on UI thread. | 207 // Make sure we run on UI thread. |
201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
202 | 209 |
203 FOR_EACH_OBSERVER(Observer, observers_, DeviceChanged(event, path)); | 210 FOR_EACH_OBSERVER(Observer, observers_, DeviceChanged(event, path)); |
204 } | 211 } |
205 | 212 |
206 } // namespace disks | 213 } // namespace disks |
207 } // namespace chromeos | 214 } // namespace chromeos |
OLD | NEW |