| 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/cros/mount_library.h" | 5 #include "chrome/browser/chromeos/cros/mount_library.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 166 virtual void RemoveObserver(Observer* observer) OVERRIDE { |
| 167 observers_.RemoveObserver(observer); | 167 observers_.RemoveObserver(observer); |
| 168 } | 168 } |
| 169 | 169 |
| 170 virtual void MountPath(const char* source_path, | 170 virtual void MountPath(const char* source_path, |
| 171 MountType type, | 171 MountType type, |
| 172 const MountPathOptions& options) OVERRIDE { | 172 const MountPathOptions& options) OVERRIDE { |
| 173 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 173 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 174 if (!CrosLibrary::Get()->EnsureLoaded()) { | 174 if (!CrosLibrary::Get()->EnsureLoaded()) { |
| 175 OnMountCompleted(MOUNT_ERROR_LIBRARY_NOT_LOADED, | 175 OnMountCompleted(MOUNT_ERROR_LIBRARY_NOT_LOADED, |
| 176 MountPointInfo(source_path, NULL, type)); | 176 MountPointInfo(source_path, NULL, type, NULL)); |
| 177 return; | 177 return; |
| 178 } | 178 } |
| 179 libcros_proxy_->CallMountPath(source_path, type, options, | 179 libcros_proxy_->CallMountPath(source_path, type, options, |
| 180 &MountCompletedHandler, this); | 180 &MountCompletedHandler, this); |
| 181 } | 181 } |
| 182 | 182 |
| 183 virtual void UnmountPath(const char* mount_path) OVERRIDE { | 183 virtual void UnmountPath(const char* mount_path) OVERRIDE { |
| 184 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 184 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 185 if (!CrosLibrary::Get()->EnsureLoaded()) { | 185 if (!CrosLibrary::Get()->EnsureLoaded()) { |
| 186 OnUnmountPath(mount_path, | 186 OnUnmountPath(mount_path, |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 &MonitorMountEventsHandler, &MountCompletedHandler, this); | 323 &MonitorMountEventsHandler, &MountCompletedHandler, this); |
| 324 } | 324 } |
| 325 private: | 325 private: |
| 326 // Callback for MountComplete signal and MountSourcePath method. | 326 // Callback for MountComplete signal and MountSourcePath method. |
| 327 static void MountCompletedHandler(void* object, | 327 static void MountCompletedHandler(void* object, |
| 328 MountError error_code, | 328 MountError error_code, |
| 329 const char* source_path, | 329 const char* source_path, |
| 330 MountType type, | 330 MountType type, |
| 331 const char* mount_path) { | 331 const char* mount_path) { |
| 332 DCHECK(object); | 332 DCHECK(object); |
| 333 std::string special_data; |
| 334 if (type == MOUNT_TYPE_DEVICE) { |
| 335 if (error_code == MOUNT_ERROR_UNKNOWN_FILESYSTEM) |
| 336 special_data = "unreadable_unknown_filesystem"; |
| 337 if (error_code == MOUNT_ERROR_UNSUPORTED_FILESYSTEM) |
| 338 special_data = "unreadable_unsupported_filesystem"; |
| 339 } |
| 340 |
| 333 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object); | 341 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object); |
| 334 self->OnMountCompleted(static_cast<MountError>(error_code), | 342 self->OnMountCompleted(static_cast<MountError>(error_code), |
| 335 MountPointInfo(source_path, mount_path, type)); | 343 MountPointInfo(source_path, |
| 344 mount_path, |
| 345 type, |
| 346 special_data.c_str())); |
| 336 } | 347 } |
| 337 | 348 |
| 338 // Callback for UnmountRemovableDevice method. | 349 // Callback for UnmountRemovableDevice method. |
| 339 static void UnmountMountPointCallback(void* object, | 350 static void UnmountMountPointCallback(void* object, |
| 340 const char* mount_path, | 351 const char* mount_path, |
| 341 MountMethodErrorType error, | 352 MountMethodErrorType error, |
| 342 const char* error_message) { | 353 const char* error_message) { |
| 343 DCHECK(object); | 354 DCHECK(object); |
| 344 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object); | 355 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object); |
| 345 self->OnUnmountPath(mount_path, error, error_message); | 356 self->OnUnmountPath(mount_path, error, error_message); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 self->OnMountEvent(evt, device_path); | 439 self->OnMountEvent(evt, device_path); |
| 429 } | 440 } |
| 430 | 441 |
| 431 | 442 |
| 432 void OnMountCompleted(MountError error_code, | 443 void OnMountCompleted(MountError error_code, |
| 433 const MountPointInfo& mount_info) { | 444 const MountPointInfo& mount_info) { |
| 434 DCHECK(!mount_info.source_path.empty()); | 445 DCHECK(!mount_info.source_path.empty()); |
| 435 | 446 |
| 436 FireMountCompleted(MOUNTING, error_code, mount_info); | 447 FireMountCompleted(MOUNTING, error_code, mount_info); |
| 437 | 448 |
| 438 if (error_code == MOUNT_ERROR_NONE && | 449 // If the device is corrupted but it's still possible to format it, it will |
| 450 // be fake mounted. |
| 451 |
| 452 if ((error_code == MOUNT_ERROR_NONE || !mount_info.special_data.empty()) && |
| 439 mount_points_.find(mount_info.mount_path) == mount_points_.end()) { | 453 mount_points_.find(mount_info.mount_path) == mount_points_.end()) { |
| 440 mount_points_.insert(MountPointMap::value_type( | 454 mount_points_.insert(MountPointMap::value_type( |
| 441 mount_info.mount_path.c_str(), | 455 mount_info.mount_path.c_str(), |
| 442 mount_info)); | 456 mount_info)); |
| 443 } | 457 } |
| 444 | 458 |
| 445 if (error_code == MOUNT_ERROR_NONE && | 459 if ((error_code == MOUNT_ERROR_NONE || !mount_info.special_data.empty()) && |
| 446 mount_info.mount_type == MOUNT_TYPE_DEVICE && | 460 mount_info.mount_type == MOUNT_TYPE_DEVICE && |
| 447 !mount_info.source_path.empty() && | 461 !mount_info.source_path.empty() && |
| 448 !mount_info.mount_path.empty()) { | 462 !mount_info.mount_path.empty()) { |
| 449 DiskMap::iterator iter = disks_.find(mount_info.source_path); | 463 DiskMap::iterator iter = disks_.find(mount_info.source_path); |
| 450 if (iter == disks_.end()) { | 464 if (iter == disks_.end()) { |
| 451 // disk might have been removed by now? | 465 // disk might have been removed by now? |
| 452 return; | 466 return; |
| 453 } | 467 } |
| 454 Disk* disk = iter->second; | 468 Disk* disk = iter->second; |
| 455 DCHECK(disk); | 469 DCHECK(disk); |
| 456 disk->set_mount_path(mount_info.mount_path.c_str()); | 470 disk->set_mount_path(mount_info.mount_path.c_str()); |
| 457 FireDiskStatusUpdate(MOUNT_DISK_MOUNTED, disk); | 471 FireDiskStatusUpdate(MOUNT_DISK_MOUNTED, disk); |
| 458 } | 472 } |
| 459 } | 473 } |
| 460 | 474 |
| 461 void OnUnmountPath(const char* mount_path, | 475 void OnUnmountPath(const char* mount_path, |
| 462 MountMethodErrorType error, | 476 MountMethodErrorType error, |
| 463 const char* error_message) { | 477 const char* error_message) { |
| 464 DCHECK(mount_path); | 478 DCHECK(mount_path); |
| 465 if (error == MOUNT_METHOD_ERROR_NONE && mount_path) { | 479 if (error == MOUNT_METHOD_ERROR_NONE && mount_path) { |
| 466 MountPointMap::iterator mount_points_it = mount_points_.find(mount_path); | 480 MountPointMap::iterator mount_points_it = mount_points_.find(mount_path); |
| 467 if (mount_points_it == mount_points_.end()) | 481 if (mount_points_it == mount_points_.end()) |
| 468 return; | 482 return; |
| 469 // TODO(tbarzic): Add separate, PathUnmounted event to Observer. | 483 // TODO(tbarzic): Add separate, PathUnmounted event to Observer. |
| 470 FireMountCompleted( | 484 FireMountCompleted( |
| 471 UNMOUNTING, | 485 UNMOUNTING, |
| 472 MOUNT_ERROR_NONE, | 486 MOUNT_ERROR_NONE, |
| 473 MountPointInfo(mount_points_it->second.source_path.c_str(), | 487 MountPointInfo(mount_points_it->second.source_path.c_str(), |
| 474 mount_points_it->second.mount_path.c_str(), | 488 mount_points_it->second.mount_path.c_str(), |
| 475 mount_points_it->second.mount_type)); | 489 mount_points_it->second.mount_type, |
| 490 mount_points_it->second.special_data.c_str())); |
| 476 std::string path(mount_points_it->second.source_path); | 491 std::string path(mount_points_it->second.source_path); |
| 477 mount_points_.erase(mount_points_it); | 492 mount_points_.erase(mount_points_it); |
| 478 DiskMap::iterator iter = disks_.find(path); | 493 DiskMap::iterator iter = disks_.find(path); |
| 479 if (iter == disks_.end()) { | 494 if (iter == disks_.end()) { |
| 480 // disk might have been removed by now. | 495 // disk might have been removed by now. |
| 481 return; | 496 return; |
| 482 } | 497 } |
| 483 Disk* disk = iter->second; | 498 Disk* disk = iter->second; |
| 484 DCHECK(disk); | 499 DCHECK(disk); |
| 485 disk->clear_mount_path(); | 500 disk->clear_mount_path(); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 else | 801 else |
| 787 return new MountLibraryImpl(); | 802 return new MountLibraryImpl(); |
| 788 } | 803 } |
| 789 | 804 |
| 790 } // namespace chromeos | 805 } // namespace chromeos |
| 791 | 806 |
| 792 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 807 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
| 793 // won't be deleted until it's last InvokeLater is run. | 808 // won't be deleted until it's last InvokeLater is run. |
| 794 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl); | 809 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl); |
| 795 | 810 |
| OLD | NEW |