OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/disk_mount_manager.h" | 5 #include "chrome/browser/chromeos/disks/disk_mount_manager.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include <sys/statvfs.h> | 10 #include <sys/statvfs.h> |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 if (iter == disks_.end()) { | 321 if (iter == disks_.end()) { |
322 // disk might have been removed by now. | 322 // disk might have been removed by now. |
323 return; | 323 return; |
324 } | 324 } |
325 Disk* disk = iter->second; | 325 Disk* disk = iter->second; |
326 DCHECK(disk); | 326 DCHECK(disk); |
327 disk->clear_mount_path(); | 327 disk->clear_mount_path(); |
328 // Check if there is a formatting scheduled. | 328 // Check if there is a formatting scheduled. |
329 PathMap::iterator it = formatting_pending_.find(disk->device_path()); | 329 PathMap::iterator it = formatting_pending_.find(disk->device_path()); |
330 if (it != formatting_pending_.end()) { | 330 if (it != formatting_pending_.end()) { |
331 const std::string& file_path = it->second; | 331 // Copy the string before it gets erased. |
| 332 const std::string file_path = it->second; |
332 formatting_pending_.erase(it); | 333 formatting_pending_.erase(it); |
333 FormatUnmountedDevice(file_path); | 334 FormatUnmountedDevice(file_path); |
334 } | 335 } |
335 } | 336 } |
336 | 337 |
337 // Callback for FormatDevice. | 338 // Callback for FormatDevice. |
338 void OnFormatDevice(const std::string& device_path, bool success) { | 339 void OnFormatDevice(const std::string& device_path, bool success) { |
339 if (success) { | 340 if (success) { |
340 NotifyDeviceStatusUpdate(MOUNT_FORMATTING_STARTED, device_path); | 341 NotifyDeviceStatusUpdate(MOUNT_FORMATTING_STARTED, device_path); |
341 } else { | 342 } else { |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 else if (type_str == "network") | 626 else if (type_str == "network") |
626 return MOUNT_TYPE_NETWORK_STORAGE; | 627 return MOUNT_TYPE_NETWORK_STORAGE; |
627 else if (type_str == "file") | 628 else if (type_str == "file") |
628 return MOUNT_TYPE_ARCHIVE; | 629 return MOUNT_TYPE_ARCHIVE; |
629 else | 630 else |
630 return MOUNT_TYPE_INVALID; | 631 return MOUNT_TYPE_INVALID; |
631 } | 632 } |
632 | 633 |
633 // static | 634 // static |
634 void DiskMountManager::Initialize() { | 635 void DiskMountManager::Initialize() { |
635 VLOG(1) << "DiskMountManager::Initialize"; | 636 if (g_disk_mount_manager) { |
636 DCHECK(!g_disk_mount_manager); | 637 LOG(WARNING) << "DiskMountManager was already initialized"; |
| 638 return; |
| 639 } |
637 g_disk_mount_manager = new DiskMountManagerImpl(); | 640 g_disk_mount_manager = new DiskMountManagerImpl(); |
638 DCHECK(g_disk_mount_manager); | 641 VLOG(1) << "DiskMountManager initialized"; |
| 642 } |
| 643 |
| 644 // static |
| 645 void DiskMountManager::InitializeForTesting( |
| 646 DiskMountManager* disk_mount_manager) { |
| 647 if (g_disk_mount_manager) { |
| 648 LOG(WARNING) << "DiskMountManager was already initialized"; |
| 649 return; |
| 650 } |
| 651 g_disk_mount_manager = disk_mount_manager; |
| 652 VLOG(1) << "DiskMountManager initialized"; |
639 } | 653 } |
640 | 654 |
641 // static | 655 // static |
642 void DiskMountManager::Shutdown() { | 656 void DiskMountManager::Shutdown() { |
643 VLOG(1) << "DiskMountManager::Shutdown"; | 657 if (!g_disk_mount_manager) { |
644 if (g_disk_mount_manager) { | 658 LOG(WARNING) << "DiskMountManager::Shutdown() called with NULL manager"; |
645 delete g_disk_mount_manager; | 659 return; |
646 g_disk_mount_manager = NULL; | |
647 } | 660 } |
| 661 delete g_disk_mount_manager; |
| 662 g_disk_mount_manager = NULL; |
| 663 VLOG(1) << "DiskMountManager Shutdown completed"; |
648 } | 664 } |
649 | 665 |
650 // static | 666 // static |
651 DiskMountManager* DiskMountManager::GetInstance() { | 667 DiskMountManager* DiskMountManager::GetInstance() { |
652 return g_disk_mount_manager; | 668 return g_disk_mount_manager; |
653 } | 669 } |
654 | 670 |
655 } // namespace disks | 671 } // namespace disks |
656 } // namespace chromeos | 672 } // namespace chromeos |
OLD | NEW |