Chromium Code Reviews| Index: chrome/browser/chromeos/extensions/file_browser_event_router.cc |
| =================================================================== |
| --- chrome/browser/chromeos/extensions/file_browser_event_router.cc (revision 93425) |
| +++ chrome/browser/chromeos/extensions/file_browser_event_router.cc (working copy) |
| @@ -55,6 +55,28 @@ |
| return result; |
| } |
| +const char* MountErrorToString(chromeos::MountError error) { |
| + switch (error) { |
| + case chromeos::MOUNT_ERROR_NONE: |
| + return "success"; |
| + case chromeos::MOUNT_ERROR_UNKNOWN: |
| + return "error_unknown"; |
| + case chromeos::MOUNT_ERROR_INTERNAL: |
| + return "error_internal"; |
| + case chromeos::MOUNT_ERROR_UNKNOWN_FILESYSTEM: |
| + return "error_unknown_filesystem"; |
| + case chromeos::MOUNT_ERROR_UNSUPORTED_FILESYSTEM: |
| + return "error_unsuported_filesystem"; |
| + case chromeos::MOUNT_ERROR_INVALID_ARCHIVE: |
| + return "error_invalid_archive"; |
| + case chromeos::MOUNT_ERROR_LIBRARY_NOT_LOADED: |
| + return "error_libcros_missing"; |
| + default: |
| + NOTREACHED(); |
| + } |
| + return ""; |
| +} |
| + |
| ExtensionFileBrowserEventRouter::ExtensionFileBrowserEventRouter() |
| : delegate_(new ExtensionFileBrowserEventRouter::FileWatcherDelegate()), |
| profile_(NULL) { |
| @@ -168,6 +190,16 @@ |
| } |
| } |
| +void ExtensionFileBrowserEventRouter::MountCompleted( |
| + chromeos::MountLibrary::MountEvent event_type, |
| + chromeos::MountError error_code, |
| + const std::string& source_path, |
| + chromeos::MountType type, |
| + const std::string& mount_path) { |
| + DispatchMountCompletedEvent(event_type, error_code, source_path, type, |
| + mount_path); |
| +} |
| + |
| void ExtensionFileBrowserEventRouter::HandleFileWatchNotification( |
| const FilePath& local_path, bool got_error) { |
| base::AutoLock lock(lock_); |
| @@ -233,6 +265,36 @@ |
| GURL()); |
| } |
| +void ExtensionFileBrowserEventRouter::DispatchMountCompletedEvent( |
| + chromeos::MountLibrary::MountEvent event, |
| + chromeos::MountError error_code, const std::string& source_path, |
| + chromeos::MountType type, const std::string& mount_path ) { |
| + if (!profile_ || type == chromeos::MOUNT_TYPE_INVALID) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + |
| + ListValue args; |
| + DictionaryValue* mount_info = new DictionaryValue(); |
| + args.Append(mount_info); |
| + mount_info->SetString("sourcePath", source_path); |
| + if (event == chromeos::MountLibrary::MOUNTING) { |
| + mount_info->SetString("eventType", "mounting"); |
|
zel
2011/07/22 22:24:06
this does not match extension_api.json values
tbarzic
2011/07/22 22:27:41
Done.
|
| + } else { |
| + mount_info->SetString("eventType", "unmounting"); |
|
zel
2011/07/22 22:24:06
same here
tbarzic
2011/07/22 22:27:41
Done.
|
| + } |
| + mount_info->SetString("status", MountErrorToString(error_code)); |
| + chromeos::MountLibrary* lib = chromeos::CrosLibrary::Get()->GetMountLibrary(); |
| + mount_info->SetString("mountType", lib->MountTypeToString(type)); |
| + mount_info->SetString("mountPath", mount_path); |
| + |
| + std::string args_json; |
| + base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); |
| + profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
| + extension_event_names::kOnFileBrowserMountCompleted, args_json, NULL, |
| + GURL()); |
| +} |
| + |
| void ExtensionFileBrowserEventRouter::OnDiskAdded( |
| const chromeos::MountLibrary::Disk* disk) { |
| VLOG(1) << "Disk added: " << disk->device_path(); |
| @@ -252,7 +314,9 @@ |
| // Initiate disk mount operation. |
| chromeos::MountLibrary* lib = |
| chromeos::CrosLibrary::Get()->GetMountLibrary(); |
| - lib->MountPath(disk->device_path().c_str()); |
| + lib->MountPath(disk->device_path().c_str(), |
| + chromeos::MOUNT_TYPE_DEVICE, |
| + chromeos::MountPathOptions()); // Unused. |
| } |
| } |