| 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 <mntent.h> | 9 #include <mntent.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| 11 | 11 |
| 12 #include <list> | 12 #include <list> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/file_path.h" | 16 #include "base/file_path.h" |
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 19 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
| 20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 21 #include "base/system_monitor/system_monitor.h" | |
| 22 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| 23 #include "chrome/browser/system_monitor/media_device_notifications_utils.h" | 22 #include "chrome/browser/system_monitor/media_device_notifications_utils.h" |
| 24 #include "chrome/browser/system_monitor/media_storage_util.h" | 23 #include "chrome/browser/system_monitor/media_storage_util.h" |
| 25 #include "chrome/browser/system_monitor/removable_device_constants.h" | 24 #include "chrome/browser/system_monitor/removable_device_constants.h" |
| 26 #include "chrome/browser/system_monitor/udev_util_linux.h" | 25 #include "chrome/browser/system_monitor/udev_util_linux.h" |
| 27 | 26 |
| 28 namespace chrome { | 27 namespace chrome { |
| 29 | 28 |
| 30 using content::BrowserThread; | 29 using content::BrowserThread; |
| 31 | 30 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 for (size_t i = 0; i < arraysize(kKnownFileSystems); ++i) | 259 for (size_t i = 0; i < arraysize(kKnownFileSystems); ++i) |
| 261 known_file_systems_.insert(kKnownFileSystems[i]); | 260 known_file_systems_.insert(kKnownFileSystems[i]); |
| 262 | 261 |
| 263 BrowserThread::PostTask( | 262 BrowserThread::PostTask( |
| 264 BrowserThread::FILE, FROM_HERE, | 263 BrowserThread::FILE, FROM_HERE, |
| 265 base::Bind(&RemovableDeviceNotificationsLinux::InitOnFileThread, this)); | 264 base::Bind(&RemovableDeviceNotificationsLinux::InitOnFileThread, this)); |
| 266 } | 265 } |
| 267 | 266 |
| 268 bool RemovableDeviceNotificationsLinux::GetDeviceInfoForPath( | 267 bool RemovableDeviceNotificationsLinux::GetDeviceInfoForPath( |
| 269 const FilePath& path, | 268 const FilePath& path, |
| 270 base::SystemMonitor::RemovableStorageInfo* device_info) const { | 269 RemovableStorageInfo* device_info) const { |
| 271 if (!path.IsAbsolute()) | 270 if (!path.IsAbsolute()) |
| 272 return false; | 271 return false; |
| 273 | 272 |
| 274 FilePath current = path; | 273 FilePath current = path; |
| 275 while (!ContainsKey(mount_info_map_, current) && current != current.DirName()) | 274 while (!ContainsKey(mount_info_map_, current) && current != current.DirName()) |
| 276 current = current.DirName(); | 275 current = current.DirName(); |
| 277 | 276 |
| 278 MountMap::const_iterator mount_info = mount_info_map_.find(current); | 277 MountMap::const_iterator mount_info = mount_info_map_.find(current); |
| 279 if (mount_info == mount_info_map_.end()) | 278 if (mount_info == mount_info_map_.end()) |
| 280 return false; | 279 return false; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 // |mount_point|. | 353 // |mount_point|. |
| 355 if (new_iter == new_mtab.end() || (new_iter->second != mount_device)) { | 354 if (new_iter == new_mtab.end() || (new_iter->second != mount_device)) { |
| 356 MountPriorityMap::iterator priority = | 355 MountPriorityMap::iterator priority = |
| 357 mount_priority_map_.find(mount_device); | 356 mount_priority_map_.find(mount_device); |
| 358 DCHECK(priority != mount_priority_map_.end()); | 357 DCHECK(priority != mount_priority_map_.end()); |
| 359 ReferencedMountPoint::const_iterator has_priority = | 358 ReferencedMountPoint::const_iterator has_priority = |
| 360 priority->second.find(mount_point); | 359 priority->second.find(mount_point); |
| 361 if (MediaStorageUtil::IsRemovableDevice(old_iter->second.device_id)) { | 360 if (MediaStorageUtil::IsRemovableDevice(old_iter->second.device_id)) { |
| 362 DCHECK(has_priority != priority->second.end()); | 361 DCHECK(has_priority != priority->second.end()); |
| 363 if (has_priority->second) { | 362 if (has_priority->second) { |
| 364 base::SystemMonitor::Get()->ProcessRemovableStorageDetached( | 363 ProcessRemovableStorageDetached( |
| 365 old_iter->second.device_id); | 364 old_iter->second.device_id); |
| 366 } | 365 } |
| 367 if (priority->second.size() > 1) | 366 if (priority->second.size() > 1) |
| 368 multiple_mounted_devices_needing_reattachment.push_back(mount_device); | 367 multiple_mounted_devices_needing_reattachment.push_back(mount_device); |
| 369 } | 368 } |
| 370 priority->second.erase(mount_point); | 369 priority->second.erase(mount_point); |
| 371 if (priority->second.empty()) | 370 if (priority->second.empty()) |
| 372 mount_priority_map_.erase(mount_device); | 371 mount_priority_map_.erase(mount_device); |
| 373 mount_points_to_erase.push_back(mount_point); | 372 mount_points_to_erase.push_back(mount_point); |
| 374 } | 373 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 391 it != multiple_mounted_devices_needing_reattachment.end(); | 390 it != multiple_mounted_devices_needing_reattachment.end(); |
| 392 ++it) { | 391 ++it) { |
| 393 ReferencedMountPoint::iterator first_mount_point_info = | 392 ReferencedMountPoint::iterator first_mount_point_info = |
| 394 mount_priority_map_.find(*it)->second.begin(); | 393 mount_priority_map_.find(*it)->second.begin(); |
| 395 const FilePath& mount_point = first_mount_point_info->first; | 394 const FilePath& mount_point = first_mount_point_info->first; |
| 396 first_mount_point_info->second = true; | 395 first_mount_point_info->second = true; |
| 397 | 396 |
| 398 const MountPointInfo& mount_info = | 397 const MountPointInfo& mount_info = |
| 399 mount_info_map_.find(mount_point)->second; | 398 mount_info_map_.find(mount_point)->second; |
| 400 DCHECK(MediaStorageUtil::IsRemovableDevice(mount_info.device_id)); | 399 DCHECK(MediaStorageUtil::IsRemovableDevice(mount_info.device_id)); |
| 401 base::SystemMonitor::Get()->ProcessRemovableStorageAttached( | 400 ProcessRemovableStorageAttached( |
| 402 mount_info.device_id, mount_info.device_name, mount_point.value()); | 401 mount_info.device_id, mount_info.device_name, mount_point.value()); |
| 403 } | 402 } |
| 404 | 403 |
| 405 // Check new mtab entries against existing ones. | 404 // Check new mtab entries against existing ones. |
| 406 for (MountPointDeviceMap::iterator new_iter = new_mtab.begin(); | 405 for (MountPointDeviceMap::iterator new_iter = new_mtab.begin(); |
| 407 new_iter != new_mtab.end(); ++new_iter) { | 406 new_iter != new_mtab.end(); ++new_iter) { |
| 408 const FilePath& mount_point = new_iter->first; | 407 const FilePath& mount_point = new_iter->first; |
| 409 const FilePath& mount_device = new_iter->second; | 408 const FilePath& mount_device = new_iter->second; |
| 410 MountMap::iterator old_iter = mount_info_map_.find(mount_point); | 409 MountMap::iterator old_iter = mount_info_map_.find(mount_point); |
| 411 if (old_iter == mount_info_map_.end() || | 410 if (old_iter == mount_info_map_.end() || |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 MountPointInfo mount_point_info; | 456 MountPointInfo mount_point_info; |
| 458 mount_point_info.mount_device = mount_device; | 457 mount_point_info.mount_device = mount_device; |
| 459 mount_point_info.device_id = device_id; | 458 mount_point_info.device_id = device_id; |
| 460 mount_point_info.device_name = name; | 459 mount_point_info.device_name = name; |
| 461 mount_point_info.partition_size_in_bytes = partition_size_in_bytes; | 460 mount_point_info.partition_size_in_bytes = partition_size_in_bytes; |
| 462 | 461 |
| 463 mount_info_map_[mount_point] = mount_point_info; | 462 mount_info_map_[mount_point] = mount_point_info; |
| 464 mount_priority_map_[mount_device][mount_point] = removable; | 463 mount_priority_map_[mount_device][mount_point] = removable; |
| 465 | 464 |
| 466 if (removable) { | 465 if (removable) { |
| 467 base::SystemMonitor::Get()->ProcessRemovableStorageAttached( | 466 ProcessRemovableStorageAttached( |
| 468 device_id, GetDisplayNameForDevice(partition_size_in_bytes, name), | 467 device_id, GetDisplayNameForDevice(partition_size_in_bytes, name), |
| 469 mount_point.value()); | 468 mount_point.value()); |
| 470 } | 469 } |
| 471 } | 470 } |
| 472 | 471 |
| 473 // static | 472 // static |
| 474 RemovableStorageNotifications* RemovableStorageNotifications::GetInstance() { | 473 RemovableStorageNotifications* RemovableStorageNotifications::GetInstance() { |
| 475 DCHECK(g_removable_device_notifications_linux != NULL); | 474 DCHECK(g_removable_device_notifications_linux != NULL); |
| 476 return g_removable_device_notifications_linux; | 475 return g_removable_device_notifications_linux; |
| 477 } | 476 } |
| 478 | 477 |
| 479 } // namespace chrome | 478 } // namespace chrome |
| OLD | NEW |