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 16 matching lines...) Expand all Loading... |
27 case MOUNT_TYPE_NETWORK_STORAGE: | 27 case MOUNT_TYPE_NETWORK_STORAGE: |
28 return "network"; | 28 return "network"; |
29 case MOUNT_TYPE_INVALID: | 29 case MOUNT_TYPE_INVALID: |
30 return "invalid"; | 30 return "invalid"; |
31 default: | 31 default: |
32 NOTREACHED(); | 32 NOTREACHED(); |
33 } | 33 } |
34 return ""; | 34 return ""; |
35 } | 35 } |
36 | 36 |
| 37 std::string MountLibrary::MountConditionToString(MountCondition condition) { |
| 38 switch (condition) { |
| 39 case MOUNT_CONDITION_NONE: |
| 40 return ""; |
| 41 case MOUNT_CONDITION_UNKNOWN_FILESYSTEM: |
| 42 return "unknown_filesystem"; |
| 43 case MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM: |
| 44 return "unsupported_filesystem"; |
| 45 default: |
| 46 NOTREACHED(); |
| 47 } |
| 48 return ""; |
| 49 } |
| 50 |
37 // static | 51 // static |
38 MountType MountLibrary::MountTypeFromString( | 52 MountType MountLibrary::MountTypeFromString( |
39 const std::string& type_str) { | 53 const std::string& type_str) { |
40 if (type_str == "device") { | 54 if (type_str == "device") { |
41 return MOUNT_TYPE_DEVICE; | 55 return MOUNT_TYPE_DEVICE; |
42 } else if (type_str == "network") { | 56 } else if (type_str == "network") { |
43 return MOUNT_TYPE_NETWORK_STORAGE; | 57 return MOUNT_TYPE_NETWORK_STORAGE; |
44 } else if (type_str == "file") { | 58 } else if (type_str == "file") { |
45 return MOUNT_TYPE_ARCHIVE; | 59 return MOUNT_TYPE_ARCHIVE; |
46 } else { | 60 } else { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 180 virtual void RemoveObserver(Observer* observer) OVERRIDE { |
167 observers_.RemoveObserver(observer); | 181 observers_.RemoveObserver(observer); |
168 } | 182 } |
169 | 183 |
170 virtual void MountPath(const char* source_path, | 184 virtual void MountPath(const char* source_path, |
171 MountType type, | 185 MountType type, |
172 const MountPathOptions& options) OVERRIDE { | 186 const MountPathOptions& options) OVERRIDE { |
173 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 187 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
174 if (!CrosLibrary::Get()->EnsureLoaded()) { | 188 if (!CrosLibrary::Get()->EnsureLoaded()) { |
175 OnMountCompleted(MOUNT_ERROR_LIBRARY_NOT_LOADED, | 189 OnMountCompleted(MOUNT_ERROR_LIBRARY_NOT_LOADED, |
176 MountPointInfo(source_path, NULL, type)); | 190 MountPointInfo(source_path, |
| 191 NULL, |
| 192 type, |
| 193 MOUNT_CONDITION_NONE)); |
177 return; | 194 return; |
178 } | 195 } |
179 libcros_proxy_->CallMountPath(source_path, type, options, | 196 libcros_proxy_->CallMountPath(source_path, type, options, |
180 &MountCompletedHandler, this); | 197 &MountCompletedHandler, this); |
181 } | 198 } |
182 | 199 |
183 virtual void UnmountPath(const char* mount_path) OVERRIDE { | 200 virtual void UnmountPath(const char* mount_path) OVERRIDE { |
184 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 201 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
185 if (!CrosLibrary::Get()->EnsureLoaded()) { | 202 if (!CrosLibrary::Get()->EnsureLoaded()) { |
186 OnUnmountPath(mount_path, | 203 OnUnmountPath(mount_path, |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 &MonitorMountEventsHandler, &MountCompletedHandler, this); | 340 &MonitorMountEventsHandler, &MountCompletedHandler, this); |
324 } | 341 } |
325 private: | 342 private: |
326 // Callback for MountComplete signal and MountSourcePath method. | 343 // Callback for MountComplete signal and MountSourcePath method. |
327 static void MountCompletedHandler(void* object, | 344 static void MountCompletedHandler(void* object, |
328 MountError error_code, | 345 MountError error_code, |
329 const char* source_path, | 346 const char* source_path, |
330 MountType type, | 347 MountType type, |
331 const char* mount_path) { | 348 const char* mount_path) { |
332 DCHECK(object); | 349 DCHECK(object); |
| 350 MountCondition mount_condition = MOUNT_CONDITION_NONE; |
| 351 if (type == MOUNT_TYPE_DEVICE) { |
| 352 if (error_code == MOUNT_ERROR_UNKNOWN_FILESYSTEM) |
| 353 mount_condition = MOUNT_CONDITION_UNKNOWN_FILESYSTEM; |
| 354 if (error_code == MOUNT_ERROR_UNSUPORTED_FILESYSTEM) |
| 355 mount_condition = MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM; |
| 356 } |
| 357 |
333 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object); | 358 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object); |
334 self->OnMountCompleted(static_cast<MountError>(error_code), | 359 self->OnMountCompleted(static_cast<MountError>(error_code), |
335 MountPointInfo(source_path, mount_path, type)); | 360 MountPointInfo(source_path, |
| 361 mount_path, |
| 362 type, |
| 363 mount_condition)); |
336 } | 364 } |
337 | 365 |
338 // Callback for UnmountRemovableDevice method. | 366 // Callback for UnmountRemovableDevice method. |
339 static void UnmountMountPointCallback(void* object, | 367 static void UnmountMountPointCallback(void* object, |
340 const char* mount_path, | 368 const char* mount_path, |
341 MountMethodErrorType error, | 369 MountMethodErrorType error, |
342 const char* error_message) { | 370 const char* error_message) { |
343 DCHECK(object); | 371 DCHECK(object); |
344 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object); | 372 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object); |
345 self->OnUnmountPath(mount_path, error, error_message); | 373 self->OnUnmountPath(mount_path, error, error_message); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 | 458 |
431 | 459 |
432 void OnMountCompleted(MountError error_code, | 460 void OnMountCompleted(MountError error_code, |
433 const MountPointInfo& mount_info) { | 461 const MountPointInfo& mount_info) { |
434 DCHECK(!mount_info.source_path.empty()); | 462 DCHECK(!mount_info.source_path.empty()); |
435 | 463 |
436 FireMountCompleted(MOUNTING, error_code, mount_info); | 464 FireMountCompleted(MOUNTING, error_code, mount_info); |
437 | 465 |
438 // If the device is corrupted but it's still possible to format it, it will | 466 // If the device is corrupted but it's still possible to format it, it will |
439 // be fake mounted. | 467 // be fake mounted. |
440 // TODO(sidor): Write more general condition when it will possible. | 468 if ((error_code == MOUNT_ERROR_NONE || mount_info.mount_condition) && |
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()) { | 469 mount_points_.find(mount_info.mount_path) == mount_points_.end()) { |
448 mount_points_.insert(MountPointMap::value_type( | 470 mount_points_.insert(MountPointMap::value_type( |
449 mount_info.mount_path.c_str(), | 471 mount_info.mount_path.c_str(), |
450 mount_info)); | 472 mount_info)); |
451 } | 473 } |
452 | 474 |
453 if ((error_code == MOUNT_ERROR_NONE || mount_corrupted_device) && | 475 if ((error_code == MOUNT_ERROR_NONE || mount_info.mount_condition) && |
454 mount_info.mount_type == MOUNT_TYPE_DEVICE && | 476 mount_info.mount_type == MOUNT_TYPE_DEVICE && |
455 !mount_info.source_path.empty() && | 477 !mount_info.source_path.empty() && |
456 !mount_info.mount_path.empty()) { | 478 !mount_info.mount_path.empty()) { |
457 DiskMap::iterator iter = disks_.find(mount_info.source_path); | 479 DiskMap::iterator iter = disks_.find(mount_info.source_path); |
458 if (iter == disks_.end()) { | 480 if (iter == disks_.end()) { |
459 // disk might have been removed by now? | 481 // disk might have been removed by now? |
460 return; | 482 return; |
461 } | 483 } |
462 Disk* disk = iter->second; | 484 Disk* disk = iter->second; |
463 DCHECK(disk); | 485 DCHECK(disk); |
464 disk->set_mount_path(mount_info.mount_path.c_str()); | 486 disk->set_mount_path(mount_info.mount_path.c_str()); |
465 FireDiskStatusUpdate(MOUNT_DISK_MOUNTED, disk); | 487 FireDiskStatusUpdate(MOUNT_DISK_MOUNTED, disk); |
466 } | 488 } |
467 } | 489 } |
468 | 490 |
469 void OnUnmountPath(const char* mount_path, | 491 void OnUnmountPath(const char* mount_path, |
470 MountMethodErrorType error, | 492 MountMethodErrorType error, |
471 const char* error_message) { | 493 const char* error_message) { |
472 DCHECK(mount_path); | 494 DCHECK(mount_path); |
473 if (error == MOUNT_METHOD_ERROR_NONE && mount_path) { | 495 if (error == MOUNT_METHOD_ERROR_NONE && mount_path) { |
474 MountPointMap::iterator mount_points_it = mount_points_.find(mount_path); | 496 MountPointMap::iterator mount_points_it = mount_points_.find(mount_path); |
475 if (mount_points_it == mount_points_.end()) | 497 if (mount_points_it == mount_points_.end()) |
476 return; | 498 return; |
477 // TODO(tbarzic): Add separate, PathUnmounted event to Observer. | 499 // TODO(tbarzic): Add separate, PathUnmounted event to Observer. |
478 FireMountCompleted( | 500 FireMountCompleted( |
479 UNMOUNTING, | 501 UNMOUNTING, |
480 MOUNT_ERROR_NONE, | 502 MOUNT_ERROR_NONE, |
481 MountPointInfo(mount_points_it->second.source_path.c_str(), | 503 MountPointInfo(mount_points_it->second.source_path.c_str(), |
482 mount_points_it->second.mount_path.c_str(), | 504 mount_points_it->second.mount_path.c_str(), |
483 mount_points_it->second.mount_type)); | 505 mount_points_it->second.mount_type, |
| 506 mount_points_it->second.mount_condition)); |
484 std::string path(mount_points_it->second.source_path); | 507 std::string path(mount_points_it->second.source_path); |
485 mount_points_.erase(mount_points_it); | 508 mount_points_.erase(mount_points_it); |
486 DiskMap::iterator iter = disks_.find(path); | 509 DiskMap::iterator iter = disks_.find(path); |
487 if (iter == disks_.end()) { | 510 if (iter == disks_.end()) { |
488 // disk might have been removed by now. | 511 // disk might have been removed by now. |
489 return; | 512 return; |
490 } | 513 } |
491 Disk* disk = iter->second; | 514 Disk* disk = iter->second; |
492 DCHECK(disk); | 515 DCHECK(disk); |
493 disk->clear_mount_path(); | 516 disk->clear_mount_path(); |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 else | 823 else |
801 return new MountLibraryImpl(); | 824 return new MountLibraryImpl(); |
802 } | 825 } |
803 | 826 |
804 } // namespace chromeos | 827 } // namespace chromeos |
805 | 828 |
806 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 829 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
807 // won't be deleted until it's last InvokeLater is run. | 830 // won't be deleted until it's last InvokeLater is run. |
808 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl); | 831 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl); |
809 | 832 |
OLD | NEW |