| 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 // RemovableDeviceNotificationsLinux implementation. | 5 // RemovableDeviceNotificationsLinux implementation. |
| 6 | 6 |
| 7 #include "chrome/browser/system_monitor/removable_device_notifications_linux.h" | 7 #include "chrome/browser/system_monitor/removable_device_notifications_linux.h" |
| 8 | 8 |
| 9 #include <libudev.h> | 9 #include <libudev.h> |
| 10 #include <mntent.h> | 10 #include <mntent.h> |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 271 |
| 272 // Put |kKnownFileSystems| in std::set to get O(log N) access time. | 272 // Put |kKnownFileSystems| in std::set to get O(log N) access time. |
| 273 for (size_t i = 0; i < arraysize(kKnownFileSystems); ++i) | 273 for (size_t i = 0; i < arraysize(kKnownFileSystems); ++i) |
| 274 known_file_systems_.insert(kKnownFileSystems[i]); | 274 known_file_systems_.insert(kKnownFileSystems[i]); |
| 275 | 275 |
| 276 BrowserThread::PostTask( | 276 BrowserThread::PostTask( |
| 277 BrowserThread::FILE, FROM_HERE, | 277 BrowserThread::FILE, FROM_HERE, |
| 278 base::Bind(&RemovableDeviceNotificationsLinux::InitOnFileThread, this)); | 278 base::Bind(&RemovableDeviceNotificationsLinux::InitOnFileThread, this)); |
| 279 } | 279 } |
| 280 | 280 |
| 281 FilePath RemovableDeviceNotificationsLinux::GetDeviceMountPoint( | |
| 282 const std::string& device_id) const { | |
| 283 | |
| 284 MediaStorageUtil::Type type; | |
| 285 MediaStorageUtil::CrackDeviceId(device_id, &type, NULL); | |
| 286 if (type == MediaStorageUtil::MTP_OR_PTP) | |
| 287 return FilePath(); | |
| 288 DCHECK(type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM || | |
| 289 type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM || | |
| 290 type == MediaStorageUtil::FIXED_MASS_STORAGE); | |
| 291 | |
| 292 FilePath mount_device; | |
| 293 for (MountMap::const_iterator it = mount_info_map_.begin(); | |
| 294 it != mount_info_map_.end(); | |
| 295 ++it) { | |
| 296 if (it->second.device_id == device_id) { | |
| 297 mount_device = it->second.mount_device; | |
| 298 break; | |
| 299 } | |
| 300 } | |
| 301 if (mount_device.empty()) | |
| 302 return mount_device; | |
| 303 | |
| 304 const ReferencedMountPoint& referenced_info = | |
| 305 mount_priority_map_.find(mount_device)->second; | |
| 306 for (ReferencedMountPoint::const_iterator it = referenced_info.begin(); | |
| 307 it != referenced_info.end(); | |
| 308 ++it) { | |
| 309 if (it->second) | |
| 310 return it->first; | |
| 311 } | |
| 312 // If none of them are default, just return the first. | |
| 313 return FilePath(referenced_info.begin()->first); | |
| 314 } | |
| 315 | |
| 316 bool RemovableDeviceNotificationsLinux::GetDeviceInfoForPath( | 281 bool RemovableDeviceNotificationsLinux::GetDeviceInfoForPath( |
| 317 const FilePath& path, | 282 const FilePath& path, |
| 318 SystemMonitor::RemovableStorageInfo* device_info) const { | 283 SystemMonitor::RemovableStorageInfo* device_info) const { |
| 319 if (!path.IsAbsolute()) | 284 if (!path.IsAbsolute()) |
| 320 return false; | 285 return false; |
| 321 | 286 |
| 322 FilePath current = path; | 287 FilePath current = path; |
| 323 while (!ContainsKey(mount_info_map_, current) && current != current.DirName()) | 288 while (!ContainsKey(mount_info_map_, current) && current != current.DirName()) |
| 324 current = current.DirName(); | 289 current = current.DirName(); |
| 325 | 290 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 mount_info_map_[mount_point] = mount_point_info; | 465 mount_info_map_[mount_point] = mount_point_info; |
| 501 mount_priority_map_[mount_device][mount_point] = removable; | 466 mount_priority_map_[mount_device][mount_point] = removable; |
| 502 | 467 |
| 503 if (removable) { | 468 if (removable) { |
| 504 SystemMonitor::Get()->ProcessRemovableStorageAttached(device_id, name, | 469 SystemMonitor::Get()->ProcessRemovableStorageAttached(device_id, name, |
| 505 mount_point.value()); | 470 mount_point.value()); |
| 506 } | 471 } |
| 507 } | 472 } |
| 508 | 473 |
| 509 } // namespace chrome | 474 } // namespace chrome |
| OLD | NEW |