| 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/extensions/file_browser_event_router.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 &source_url)) { | 326 &source_url)) { |
| 327 mount_info_value->SetString("sourceUrl", source_url.spec()); | 327 mount_info_value->SetString("sourceUrl", source_url.spec()); |
| 328 } | 328 } |
| 329 } else { | 329 } else { |
| 330 mount_info_value->SetString("sourceUrl", mount_info.source_path); | 330 mount_info_value->SetString("sourceUrl", mount_info.source_path); |
| 331 } | 331 } |
| 332 | 332 |
| 333 FilePath relative_mount_path; | 333 FilePath relative_mount_path; |
| 334 bool relative_mount_path_set = false; | 334 bool relative_mount_path_set = false; |
| 335 | 335 |
| 336 // If the device is corrupted but it's still possible to format it, it will | 336 // If there were no error or some special conditions occured, add mountPath |
| 337 // be fake mounted. | 337 // to the event. |
| 338 // TODO(sidor): Write more general condition when it will possible. | 338 if (error_code == chromeos::MOUNT_ERROR_NONE || |
| 339 bool mount_corrupted_device = | 339 mount_info.mount_condition) { |
| 340 (error_code == chromeos::MOUNT_ERROR_UNKNOWN_FILESYSTEM || | |
| 341 error_code == chromeos::MOUNT_ERROR_UNSUPORTED_FILESYSTEM) && | |
| 342 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE; | |
| 343 | |
| 344 // If there were no error, add mountPath to the event. | |
| 345 if (error_code == chromeos::MOUNT_ERROR_NONE || mount_corrupted_device) { | |
| 346 // Convert mount point path to relative path with the external file system | 340 // Convert mount point path to relative path with the external file system |
| 347 // exposed within File API. | 341 // exposed within File API. |
| 348 if (FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile_, | 342 if (FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile_, |
| 349 FilePath(mount_info.mount_path), | 343 FilePath(mount_info.mount_path), |
| 350 &relative_mount_path)) { | 344 &relative_mount_path)) { |
| 351 mount_info_value->SetString("mountPath", | 345 mount_info_value->SetString("mountPath", |
| 352 "/" + relative_mount_path.value()); | 346 "/" + relative_mount_path.value()); |
| 353 relative_mount_path_set = true; | 347 relative_mount_path_set = true; |
| 354 } | 348 } |
| 355 } | 349 } |
| 356 | 350 |
| 357 std::string args_json; | 351 std::string args_json; |
| 358 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); | 352 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); |
| 359 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 353 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
| 360 extension_event_names::kOnFileBrowserMountCompleted, args_json, NULL, | 354 extension_event_names::kOnFileBrowserMountCompleted, args_json, NULL, |
| 361 GURL()); | 355 GURL()); |
| 362 | 356 |
| 363 if (relative_mount_path_set && | 357 if (relative_mount_path_set && |
| 364 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && | 358 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && |
| 365 !mount_corrupted_device && // User should not be bothered by that. | 359 !mount_info.mount_condition && |
| 366 event == chromeos::MountLibrary::MOUNTING) { | 360 event == chromeos::MountLibrary::MOUNTING) { |
| 367 FileManagerUtil::ShowFullTabUrl(profile_, FilePath(mount_info.mount_path)); | 361 FileManagerUtil::ShowFullTabUrl(profile_, FilePath(mount_info.mount_path)); |
| 368 } | 362 } |
| 369 } | 363 } |
| 370 | 364 |
| 371 void ExtensionFileBrowserEventRouter::OnDiskAdded( | 365 void ExtensionFileBrowserEventRouter::OnDiskAdded( |
| 372 const chromeos::MountLibrary::Disk* disk) { | 366 const chromeos::MountLibrary::Disk* disk) { |
| 373 VLOG(1) << "Disk added: " << disk->device_path(); | 367 VLOG(1) << "Disk added: " << disk->device_path(); |
| 374 if (disk->device_path().empty()) { | 368 if (disk->device_path().empty()) { |
| 375 VLOG(1) << "Empty system path for " << disk->device_path(); | 369 VLOG(1) << "Empty system path for " << disk->device_path(); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 &FileWatcherDelegate::HandleFileWatchOnUIThread, | 528 &FileWatcherDelegate::HandleFileWatchOnUIThread, |
| 535 local_path, | 529 local_path, |
| 536 true)); // got_error | 530 true)); // got_error |
| 537 } | 531 } |
| 538 | 532 |
| 539 void | 533 void |
| 540 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread( | 534 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread( |
| 541 const FilePath& local_path, bool got_error) { | 535 const FilePath& local_path, bool got_error) { |
| 542 router_->HandleFileWatchNotification(local_path, got_error); | 536 router_->HandleFileWatchNotification(local_path, got_error); |
| 543 } | 537 } |
| OLD | NEW |