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/media_gallery/removable_device_notifications_linux.h" | 7 #include "chrome/browser/media_gallery/removable_device_notifications_linux.h" |
8 | 8 |
9 #include <libudev.h> | 9 #include <libudev.h> |
10 #include <mntent.h> | 10 #include <mntent.h> |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 const FilePath& mount_device = old_iter->second.mount_device; | 378 const FilePath& mount_device = old_iter->second.mount_device; |
379 MountPointDeviceMap::iterator new_iter = new_mtab.find(mount_point); | 379 MountPointDeviceMap::iterator new_iter = new_mtab.find(mount_point); |
380 // |mount_point| not in |new_mtab| or |mount_device| is no longer mounted at | 380 // |mount_point| not in |new_mtab| or |mount_device| is no longer mounted at |
381 // |mount_point|. | 381 // |mount_point|. |
382 if (new_iter == new_mtab.end() || (new_iter->second != mount_device)) { | 382 if (new_iter == new_mtab.end() || (new_iter->second != mount_device)) { |
383 MountPriorityMap::iterator priority = | 383 MountPriorityMap::iterator priority = |
384 mount_priority_map_.find(mount_device); | 384 mount_priority_map_.find(mount_device); |
385 DCHECK(priority != mount_priority_map_.end()); | 385 DCHECK(priority != mount_priority_map_.end()); |
386 ReferencedMountPoint::const_iterator has_priority = | 386 ReferencedMountPoint::const_iterator has_priority = |
387 priority->second.find(mount_point); | 387 priority->second.find(mount_point); |
388 if (old_iter->second.has_dcim) { | 388 if (MediaStorageUtil::IsRemovableDevice(old_iter->second.device_id)) { |
389 DCHECK(has_priority != priority->second.end()); | 389 DCHECK(has_priority != priority->second.end()); |
390 if (has_priority->second) | 390 if (has_priority->second) { |
391 RemoveMediaMount(old_iter->second.device_id); | 391 SystemMonitor::Get()->ProcessRemovableStorageDetached( |
| 392 old_iter->second.device_id); |
| 393 } |
392 if (priority->second.size() > 1) | 394 if (priority->second.size() > 1) |
393 multiple_mounted_devices_needing_reattachment.push_back(mount_device); | 395 multiple_mounted_devices_needing_reattachment.push_back(mount_device); |
394 } | 396 } |
395 priority->second.erase(mount_point); | 397 priority->second.erase(mount_point); |
396 if (priority->second.empty()) | 398 if (priority->second.empty()) |
397 mount_priority_map_.erase(mount_device); | 399 mount_priority_map_.erase(mount_device); |
398 mount_points_to_erase.push_back(mount_point); | 400 mount_points_to_erase.push_back(mount_point); |
399 } | 401 } |
400 } | 402 } |
401 | 403 |
(...skipping 13 matching lines...) Expand all Loading... |
415 multiple_mounted_devices_needing_reattachment.begin(); | 417 multiple_mounted_devices_needing_reattachment.begin(); |
416 it != multiple_mounted_devices_needing_reattachment.end(); | 418 it != multiple_mounted_devices_needing_reattachment.end(); |
417 ++it) { | 419 ++it) { |
418 ReferencedMountPoint::iterator first_mount_point_info = | 420 ReferencedMountPoint::iterator first_mount_point_info = |
419 mount_priority_map_.find(*it)->second.begin(); | 421 mount_priority_map_.find(*it)->second.begin(); |
420 const FilePath& mount_point = first_mount_point_info->first; | 422 const FilePath& mount_point = first_mount_point_info->first; |
421 first_mount_point_info->second = true; | 423 first_mount_point_info->second = true; |
422 | 424 |
423 const MountPointInfo& mount_info = | 425 const MountPointInfo& mount_info = |
424 mount_info_map_.find(mount_point)->second; | 426 mount_info_map_.find(mount_point)->second; |
425 DCHECK(mount_info.has_dcim); | 427 DCHECK(MediaStorageUtil::IsRemovableDevice(mount_info.device_id)); |
426 base::SystemMonitor::Get()->ProcessRemovableStorageAttached( | 428 base::SystemMonitor::Get()->ProcessRemovableStorageAttached( |
427 mount_info.device_id, mount_info.device_name, mount_point.value()); | 429 mount_info.device_id, mount_info.device_name, mount_point.value()); |
428 } | 430 } |
429 | 431 |
430 // Check new mtab entries against existing ones. | 432 // Check new mtab entries against existing ones. |
431 for (MountPointDeviceMap::iterator new_iter = new_mtab.begin(); | 433 for (MountPointDeviceMap::iterator new_iter = new_mtab.begin(); |
432 new_iter != new_mtab.end(); ++new_iter) { | 434 new_iter != new_mtab.end(); ++new_iter) { |
433 const FilePath& mount_point = new_iter->first; | 435 const FilePath& mount_point = new_iter->first; |
434 const FilePath& mount_device = new_iter->second; | 436 const FilePath& mount_device = new_iter->second; |
435 MountMap::iterator old_iter = mount_info_map_.find(mount_point); | 437 MountMap::iterator old_iter = mount_info_map_.find(mount_point); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 } | 488 } |
487 } else { | 489 } else { |
488 type = MediaStorageUtil::FIXED_MASS_STORAGE; | 490 type = MediaStorageUtil::FIXED_MASS_STORAGE; |
489 } | 491 } |
490 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); | 492 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); |
491 | 493 |
492 MountPointInfo mount_point_info; | 494 MountPointInfo mount_point_info; |
493 mount_point_info.mount_device = mount_device; | 495 mount_point_info.mount_device = mount_device; |
494 mount_point_info.device_id = device_id; | 496 mount_point_info.device_id = device_id; |
495 mount_point_info.device_name = name; | 497 mount_point_info.device_name = name; |
496 mount_point_info.has_dcim = has_dcim; | |
497 | 498 |
498 mount_info_map_[mount_point] = mount_point_info; | 499 mount_info_map_[mount_point] = mount_point_info; |
499 mount_priority_map_[mount_device][mount_point] = has_dcim; | 500 mount_priority_map_[mount_device][mount_point] = removable; |
500 | 501 |
501 if (mount_point_info.has_dcim) { | 502 if (removable) { |
502 SystemMonitor::Get()->ProcessRemovableStorageAttached(device_id, name, | 503 SystemMonitor::Get()->ProcessRemovableStorageAttached(device_id, name, |
503 mount_point.value()); | 504 mount_point.value()); |
504 } | 505 } |
505 } | 506 } |
506 | 507 |
507 void RemovableDeviceNotificationsLinux::RemoveMediaMount( | |
508 const std::string& device_id) { | |
509 SystemMonitor::Get()->ProcessRemovableStorageDetached(device_id); | |
510 } | |
511 | |
512 } // namespace chrome | 508 } // namespace chrome |
OLD | NEW |