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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 &source_url)) { | 337 &source_url)) { |
338 mount_info_value->SetString("sourceUrl", source_url.spec()); | 338 mount_info_value->SetString("sourceUrl", source_url.spec()); |
339 } | 339 } |
340 } else { | 340 } else { |
341 mount_info_value->SetString("sourceUrl", mount_info.source_path); | 341 mount_info_value->SetString("sourceUrl", mount_info.source_path); |
342 } | 342 } |
343 | 343 |
344 FilePath relative_mount_path; | 344 FilePath relative_mount_path; |
345 bool relative_mount_path_set = false; | 345 bool relative_mount_path_set = false; |
346 | 346 |
347 // If the device is corrupted but it's still possible to format it, it will | 347 // If there were no error or some special conditions occured, add mountPath |
348 // be fake mounted. | 348 // to the event. |
349 // TODO(sidor): Write more general condition when it will possible. | 349 if (error_code == chromeos::MOUNT_ERROR_NONE || |
350 bool mount_corrupted_device = | 350 mount_info.mount_condition) { |
351 (error_code == chromeos::MOUNT_ERROR_UNKNOWN_FILESYSTEM || | |
352 error_code == chromeos::MOUNT_ERROR_UNSUPORTED_FILESYSTEM) && | |
353 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE; | |
354 | |
355 // If there were no error, add mountPath to the event. | |
356 if (error_code == chromeos::MOUNT_ERROR_NONE || mount_corrupted_device) { | |
357 // Convert mount point path to relative path with the external file system | 351 // Convert mount point path to relative path with the external file system |
358 // exposed within File API. | 352 // exposed within File API. |
359 if (FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile_, | 353 if (FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile_, |
360 FilePath(mount_info.mount_path), | 354 FilePath(mount_info.mount_path), |
361 &relative_mount_path)) { | 355 &relative_mount_path)) { |
362 mount_info_value->SetString("mountPath", | 356 mount_info_value->SetString("mountPath", |
363 "/" + relative_mount_path.value()); | 357 "/" + relative_mount_path.value()); |
364 relative_mount_path_set = true; | 358 relative_mount_path_set = true; |
365 } | 359 } |
366 } | 360 } |
367 | 361 |
368 std::string args_json; | 362 std::string args_json; |
369 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); | 363 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); |
370 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 364 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
371 extension_event_names::kOnFileBrowserMountCompleted, args_json, NULL, | 365 extension_event_names::kOnFileBrowserMountCompleted, args_json, NULL, |
372 GURL()); | 366 GURL()); |
373 | 367 |
374 if (relative_mount_path_set && | 368 if (relative_mount_path_set && |
375 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && | 369 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && |
376 !mount_corrupted_device && // User should not be bothered by that. | 370 !mount_info.mount_condition && |
377 event == chromeos::MountLibrary::MOUNTING) { | 371 event == chromeos::MountLibrary::MOUNTING) { |
378 FileManagerUtil::ShowFullTabUrl(profile_, FilePath(mount_info.mount_path)); | 372 FileManagerUtil::ShowFullTabUrl(profile_, FilePath(mount_info.mount_path)); |
379 } | 373 } |
380 } | 374 } |
381 | 375 |
382 void ExtensionFileBrowserEventRouter::OnDiskAdded( | 376 void ExtensionFileBrowserEventRouter::OnDiskAdded( |
383 const chromeos::MountLibrary::Disk* disk) { | 377 const chromeos::MountLibrary::Disk* disk) { |
384 VLOG(1) << "Disk added: " << disk->device_path(); | 378 VLOG(1) << "Disk added: " << disk->device_path(); |
385 if (disk->device_path().empty()) { | 379 if (disk->device_path().empty()) { |
386 VLOG(1) << "Empty system path for " << disk->device_path(); | 380 VLOG(1) << "Empty system path for " << disk->device_path(); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 &FileWatcherDelegate::HandleFileWatchOnUIThread, | 539 &FileWatcherDelegate::HandleFileWatchOnUIThread, |
546 local_path, | 540 local_path, |
547 true)); // got_error | 541 true)); // got_error |
548 } | 542 } |
549 | 543 |
550 void | 544 void |
551 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread( | 545 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread( |
552 const FilePath& local_path, bool got_error) { | 546 const FilePath& local_path, bool got_error) { |
553 router_->HandleFileWatchNotification(local_path, got_error); | 547 router_->HandleFileWatchNotification(local_path, got_error); |
554 } | 548 } |
OLD | NEW |