Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: chrome/browser/storage_monitor/storage_monitor_linux.cc

Issue 15294020: StorageMonitor: Make StorageInfo a real class. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: address nits Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // StorageMonitorLinux implementation. 5 // StorageMonitorLinux implementation.
6 6
7 #include "chrome/browser/storage_monitor/storage_monitor_linux.h" 7 #include "chrome/browser/storage_monitor/storage_monitor_linux.h"
8 8
9 #include <mntent.h> 9 #include <mntent.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 } 338 }
339 339
340 void StorageMonitorLinux::EjectDevice( 340 void StorageMonitorLinux::EjectDevice(
341 const std::string& device_id, 341 const std::string& device_id,
342 base::Callback<void(EjectStatus)> callback) { 342 base::Callback<void(EjectStatus)> callback) {
343 // Find the mount point for the given device ID. 343 // Find the mount point for the given device ID.
344 base::FilePath path; 344 base::FilePath path;
345 base::FilePath device; 345 base::FilePath device;
346 for (MountMap::iterator mount_info = mount_info_map_.begin(); 346 for (MountMap::iterator mount_info = mount_info_map_.begin();
347 mount_info != mount_info_map_.end(); ++mount_info) { 347 mount_info != mount_info_map_.end(); ++mount_info) {
348 if (mount_info->second.storage_info.device_id == device_id) { 348 if (mount_info->second.storage_info.device_id() == device_id) {
349 path = mount_info->first; 349 path = mount_info->first;
350 device = mount_info->second.mount_device; 350 device = mount_info->second.mount_device;
351 mount_info_map_.erase(mount_info); 351 mount_info_map_.erase(mount_info);
352 break; 352 break;
353 } 353 }
354 } 354 }
355 355
356 if (path.empty()) { 356 if (path.empty()) {
357 callback.Run(EJECT_NO_SUCH_DEVICE); 357 callback.Run(EJECT_NO_SUCH_DEVICE);
358 return; 358 return;
(...skipping 26 matching lines...) Expand all
385 MountPointDeviceMap::const_iterator new_iter = new_mtab.find(mount_point); 385 MountPointDeviceMap::const_iterator new_iter = new_mtab.find(mount_point);
386 // |mount_point| not in |new_mtab| or |mount_device| is no longer mounted at 386 // |mount_point| not in |new_mtab| or |mount_device| is no longer mounted at
387 // |mount_point|. 387 // |mount_point|.
388 if (new_iter == new_mtab.end() || (new_iter->second != mount_device)) { 388 if (new_iter == new_mtab.end() || (new_iter->second != mount_device)) {
389 MountPriorityMap::iterator priority = 389 MountPriorityMap::iterator priority =
390 mount_priority_map_.find(mount_device); 390 mount_priority_map_.find(mount_device);
391 DCHECK(priority != mount_priority_map_.end()); 391 DCHECK(priority != mount_priority_map_.end());
392 ReferencedMountPoint::const_iterator has_priority = 392 ReferencedMountPoint::const_iterator has_priority =
393 priority->second.find(mount_point); 393 priority->second.find(mount_point);
394 if (StorageInfo::IsRemovableDevice( 394 if (StorageInfo::IsRemovableDevice(
395 old_iter->second.storage_info.device_id)) { 395 old_iter->second.storage_info.device_id())) {
396 DCHECK(has_priority != priority->second.end()); 396 DCHECK(has_priority != priority->second.end());
397 if (has_priority->second) { 397 if (has_priority->second) {
398 receiver()->ProcessDetach(old_iter->second.storage_info.device_id); 398 receiver()->ProcessDetach(old_iter->second.storage_info.device_id());
399 } 399 }
400 if (priority->second.size() > 1) 400 if (priority->second.size() > 1)
401 multiple_mounted_devices_needing_reattachment.push_back(mount_device); 401 multiple_mounted_devices_needing_reattachment.push_back(mount_device);
402 } 402 }
403 priority->second.erase(mount_point); 403 priority->second.erase(mount_point);
404 if (priority->second.empty()) 404 if (priority->second.empty())
405 mount_priority_map_.erase(mount_device); 405 mount_priority_map_.erase(mount_device);
406 mount_points_to_erase.push_back(mount_point); 406 mount_points_to_erase.push_back(mount_point);
407 } 407 }
408 } 408 }
(...skipping 15 matching lines...) Expand all
424 multiple_mounted_devices_needing_reattachment.begin(); 424 multiple_mounted_devices_needing_reattachment.begin();
425 it != multiple_mounted_devices_needing_reattachment.end(); 425 it != multiple_mounted_devices_needing_reattachment.end();
426 ++it) { 426 ++it) {
427 ReferencedMountPoint::iterator first_mount_point_info = 427 ReferencedMountPoint::iterator first_mount_point_info =
428 mount_priority_map_.find(*it)->second.begin(); 428 mount_priority_map_.find(*it)->second.begin();
429 const base::FilePath& mount_point = first_mount_point_info->first; 429 const base::FilePath& mount_point = first_mount_point_info->first;
430 first_mount_point_info->second = true; 430 first_mount_point_info->second = true;
431 431
432 const StorageInfo& mount_info = 432 const StorageInfo& mount_info =
433 mount_info_map_.find(mount_point)->second.storage_info; 433 mount_info_map_.find(mount_point)->second.storage_info;
434 DCHECK(StorageInfo::IsRemovableDevice(mount_info.device_id)); 434 DCHECK(StorageInfo::IsRemovableDevice(mount_info.device_id()));
435 receiver()->ProcessAttach(mount_info); 435 receiver()->ProcessAttach(mount_info);
436 } 436 }
437 437
438 // Check new mtab entries against existing ones. 438 // Check new mtab entries against existing ones.
439 for (MountPointDeviceMap::const_iterator new_iter = new_mtab.begin(); 439 for (MountPointDeviceMap::const_iterator new_iter = new_mtab.begin();
440 new_iter != new_mtab.end(); ++new_iter) { 440 new_iter != new_mtab.end(); ++new_iter) {
441 const base::FilePath& mount_point = new_iter->first; 441 const base::FilePath& mount_point = new_iter->first;
442 const base::FilePath& mount_device = new_iter->second; 442 const base::FilePath& mount_device = new_iter->second;
443 MountMap::iterator old_iter = mount_info_map_.find(mount_point); 443 MountMap::iterator old_iter = mount_info_map_.find(mount_point);
444 if (old_iter == mount_info_map_.end() || 444 if (old_iter == mount_info_map_.end() ||
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 mount_info_map_.find(other_mount_point)->second; 490 mount_info_map_.find(other_mount_point)->second;
491 } 491 }
492 492
493 void StorageMonitorLinux::AddNewMount(const base::FilePath& mount_device, 493 void StorageMonitorLinux::AddNewMount(const base::FilePath& mount_device,
494 scoped_ptr<StorageInfo> storage_info) { 494 scoped_ptr<StorageInfo> storage_info) {
495 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 495 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
496 496
497 if (!storage_info) 497 if (!storage_info)
498 return; 498 return;
499 499
500 DCHECK(!storage_info->device_id.empty()); 500 DCHECK(!storage_info->device_id().empty());
501 501
502 bool removable = StorageInfo::IsRemovableDevice(storage_info->device_id); 502 bool removable = StorageInfo::IsRemovableDevice(storage_info->device_id());
503 const base::FilePath mount_point(storage_info->location); 503 const base::FilePath mount_point(storage_info->location());
504 504
505 MountPointInfo mount_point_info; 505 MountPointInfo mount_point_info;
506 mount_point_info.mount_device = mount_device; 506 mount_point_info.mount_device = mount_device;
507 mount_point_info.storage_info = *storage_info; 507 mount_point_info.storage_info = *storage_info;
508 mount_info_map_[mount_point] = mount_point_info; 508 mount_info_map_[mount_point] = mount_point_info;
509 mount_priority_map_[mount_device][mount_point] = removable; 509 mount_priority_map_[mount_device][mount_point] = removable;
510 if (removable) 510 if (removable)
511 receiver()->ProcessAttach(*storage_info); 511 receiver()->ProcessAttach(*storage_info);
512 } 512 }
513 513
514 } // namespace chrome 514 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698