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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 the device is corrupted but it's still possible to format it, it will | 449 // If the device is corrupted but it's still possible to format it, it will |
439 // be fake mounted. | 450 // be fake mounted. |
440 // TODO(sidor): Write more general condition when it will possible. | 451 if ((error_code == MOUNT_ERROR_NONE || !mount_info.special_data.empty()) && |
441 bool mount_corrupted_device = | |
442 (error_code == MOUNT_ERROR_UNKNOWN_FILESYSTEM || | |
443 error_code == MOUNT_ERROR_UNSUPORTED_FILESYSTEM) && | |
444 mount_info.mount_type == MOUNT_TYPE_DEVICE; | |
445 | |
446 if ((error_code == MOUNT_ERROR_NONE || mount_corrupted_device) && | |
447 mount_points_.find(mount_info.mount_path) == mount_points_.end()) { | 452 mount_points_.find(mount_info.mount_path) == mount_points_.end()) { |
448 mount_points_.insert(MountPointMap::value_type( | 453 mount_points_.insert(MountPointMap::value_type( |
449 mount_info.mount_path.c_str(), | 454 mount_info.mount_path.c_str(), |
450 mount_info)); | 455 mount_info)); |
451 } | 456 } |
452 | 457 |
453 if ((error_code == MOUNT_ERROR_NONE || mount_corrupted_device) && | 458 if ((error_code == MOUNT_ERROR_NONE || !mount_info.special_data.empty()) && |
454 mount_info.mount_type == MOUNT_TYPE_DEVICE && | 459 mount_info.mount_type == MOUNT_TYPE_DEVICE && |
455 !mount_info.source_path.empty() && | 460 !mount_info.source_path.empty() && |
456 !mount_info.mount_path.empty()) { | 461 !mount_info.mount_path.empty()) { |
457 DiskMap::iterator iter = disks_.find(mount_info.source_path); | 462 DiskMap::iterator iter = disks_.find(mount_info.source_path); |
458 if (iter == disks_.end()) { | 463 if (iter == disks_.end()) { |
459 // disk might have been removed by now? | 464 // disk might have been removed by now? |
460 return; | 465 return; |
461 } | 466 } |
462 Disk* disk = iter->second; | 467 Disk* disk = iter->second; |
463 DCHECK(disk); | 468 DCHECK(disk); |
464 disk->set_mount_path(mount_info.mount_path.c_str()); | 469 disk->set_mount_path(mount_info.mount_path.c_str()); |
465 FireDiskStatusUpdate(MOUNT_DISK_MOUNTED, disk); | 470 FireDiskStatusUpdate(MOUNT_DISK_MOUNTED, disk); |
466 } | 471 } |
467 } | 472 } |
468 | 473 |
469 void OnUnmountPath(const char* mount_path, | 474 void OnUnmountPath(const char* mount_path, |
470 MountMethodErrorType error, | 475 MountMethodErrorType error, |
471 const char* error_message) { | 476 const char* error_message) { |
472 DCHECK(mount_path); | 477 DCHECK(mount_path); |
473 if (error == MOUNT_METHOD_ERROR_NONE && mount_path) { | 478 if (error == MOUNT_METHOD_ERROR_NONE && mount_path) { |
474 MountPointMap::iterator mount_points_it = mount_points_.find(mount_path); | 479 MountPointMap::iterator mount_points_it = mount_points_.find(mount_path); |
475 if (mount_points_it == mount_points_.end()) | 480 if (mount_points_it == mount_points_.end()) |
476 return; | 481 return; |
477 // TODO(tbarzic): Add separate, PathUnmounted event to Observer. | 482 // TODO(tbarzic): Add separate, PathUnmounted event to Observer. |
478 FireMountCompleted( | 483 FireMountCompleted( |
479 UNMOUNTING, | 484 UNMOUNTING, |
480 MOUNT_ERROR_NONE, | 485 MOUNT_ERROR_NONE, |
481 MountPointInfo(mount_points_it->second.source_path.c_str(), | 486 MountPointInfo(mount_points_it->second.source_path.c_str(), |
482 mount_points_it->second.mount_path.c_str(), | 487 mount_points_it->second.mount_path.c_str(), |
483 mount_points_it->second.mount_type)); | 488 mount_points_it->second.mount_type, |
| 489 mount_points_it->second.special_data.c_str())); |
484 std::string path(mount_points_it->second.source_path); | 490 std::string path(mount_points_it->second.source_path); |
485 mount_points_.erase(mount_points_it); | 491 mount_points_.erase(mount_points_it); |
486 DiskMap::iterator iter = disks_.find(path); | 492 DiskMap::iterator iter = disks_.find(path); |
487 if (iter == disks_.end()) { | 493 if (iter == disks_.end()) { |
488 // disk might have been removed by now. | 494 // disk might have been removed by now. |
489 return; | 495 return; |
490 } | 496 } |
491 Disk* disk = iter->second; | 497 Disk* disk = iter->second; |
492 DCHECK(disk); | 498 DCHECK(disk); |
493 disk->clear_mount_path(); | 499 disk->clear_mount_path(); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 else | 800 else |
795 return new MountLibraryImpl(); | 801 return new MountLibraryImpl(); |
796 } | 802 } |
797 | 803 |
798 } // namespace chromeos | 804 } // namespace chromeos |
799 | 805 |
800 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 806 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
801 // won't be deleted until it's last InvokeLater is run. | 807 // won't be deleted until it's last InvokeLater is run. |
802 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl); | 808 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl); |
803 | 809 |
OLD | NEW |