Index: chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.cc |
diff --git a/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.cc b/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.cc |
index e891b1cd92d9016a80a6b4d0b5fe49d7ab29820e..29b08b26c0724829f2facb3b4ccf3618dd6a746d 100644 |
--- a/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.cc |
+++ b/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.cc |
@@ -4,8 +4,12 @@ |
#include "chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.h" |
+#include <string> |
+ |
+#include "base/values.h" |
#include "chrome/browser/chromeos/file_system_provider/service.h" |
#include "chrome/common/extensions/api/file_system_provider.h" |
+#include "chrome/common/extensions/api/file_system_provider_internal.h" |
namespace extensions { |
namespace { |
@@ -16,8 +20,10 @@ const char kSecurityErrorName[] = "SecurityError"; |
// Error messages. |
const char kEmptyNameErrorMessage[] = "Empty display name is not allowed."; |
-const char kRegisteringFailedErrorMessage[] = |
- "Registering the file system failed."; |
+const char kMountFailedErrorMessage[] = "Mounting the file system failed."; |
+const char kUnmountFailedErrorMessage[] = "Unmounting the file system failed."; |
+const char kResponseFailedErrorMessage[] = |
+ "Sending a response for the request failed."; |
// Creates a dictionary, which looks like a DOMError. The returned dictionary |
// will be converted to a real DOMError object in |
@@ -30,10 +36,53 @@ base::DictionaryValue* CreateError(const std::string& name, |
return error; |
} |
+// Converts ProviderError to base::File::Error. This could be redundant, if it |
+// was possible to create DOMError instances in Javascript easily. |
+base::File::Error ProviderErrorToFileError( |
+ api::file_system_provider::ProviderError error) { |
+ switch (error) { |
+ case api::file_system_provider::PROVIDER_ERROR_OK: |
+ return base::File::FILE_OK; |
+ case api::file_system_provider::PROVIDER_ERROR_IN_USE: |
+ return base::File::FILE_ERROR_IN_USE; |
+ case api::file_system_provider::PROVIDER_ERROR_EXISTS: |
+ return base::File::FILE_ERROR_EXISTS; |
+ case api::file_system_provider::PROVIDER_ERROR_NOT_FOUND: |
+ return base::File::FILE_ERROR_NOT_FOUND; |
+ case api::file_system_provider::PROVIDER_ERROR_ACCESS_DENIED: |
+ return base::File::FILE_ERROR_ACCESS_DENIED; |
+ case api::file_system_provider::PROVIDER_ERROR_TOO_MANY_OPENED: |
+ return base::File::FILE_ERROR_TOO_MANY_OPENED; |
+ case api::file_system_provider::PROVIDER_ERROR_NO_MEMORY: |
+ return base::File::FILE_ERROR_NO_MEMORY; |
+ case api::file_system_provider::PROVIDER_ERROR_NO_SPACE: |
+ return base::File::FILE_ERROR_NO_SPACE; |
+ case api::file_system_provider::PROVIDER_ERROR_NOT_A_DIRECTORY: |
+ return base::File::FILE_ERROR_NOT_A_DIRECTORY; |
+ case api::file_system_provider::PROVIDER_ERROR_INVALID_OPERATION: |
+ return base::File::FILE_ERROR_INVALID_OPERATION; |
+ case api::file_system_provider::PROVIDER_ERROR_SECURITY: |
+ return base::File::FILE_ERROR_SECURITY; |
+ case api::file_system_provider::PROVIDER_ERROR_ABORT: |
+ return base::File::FILE_ERROR_ABORT; |
+ case api::file_system_provider::PROVIDER_ERROR_NOT_A_FILE: |
+ return base::File::FILE_ERROR_NOT_A_FILE; |
+ case api::file_system_provider::PROVIDER_ERROR_NOT_EMPTY: |
+ return base::File::FILE_ERROR_NOT_EMPTY; |
+ case api::file_system_provider::PROVIDER_ERROR_INVALID_URL: |
+ return base::File::FILE_ERROR_INVALID_URL; |
+ case api::file_system_provider::PROVIDER_ERROR_IO: |
+ return base::File::FILE_ERROR_IO; |
+ default: |
+ NOTREACHED(); |
+ } |
+ return base::File::FILE_ERROR_FAILED; |
+} |
+ |
} // namespace |
bool FileSystemProviderMountFunction::RunImpl() { |
- using extensions::api::file_system_provider::Mount::Params; |
+ using api::file_system_provider::Mount::Params; |
const scoped_ptr<Params> params(Params::Create(*args_)); |
EXTENSION_FUNCTION_VALIDATE(params); |
@@ -52,7 +101,7 @@ bool FileSystemProviderMountFunction::RunImpl() { |
DCHECK(service); |
int file_system_id = |
- service->RegisterFileSystem(extension_id(), params->display_name); |
+ service->MountFileSystem(extension_id(), params->display_name); |
// If the |file_system_id| is zero, then it means that registering the file |
// system failed. |
@@ -60,8 +109,7 @@ bool FileSystemProviderMountFunction::RunImpl() { |
if (!file_system_id) { |
base::ListValue* result = new base::ListValue(); |
result->Append(new base::FundamentalValue(0)); |
- result->Append( |
- CreateError(kSecurityErrorName, kRegisteringFailedErrorMessage)); |
+ result->Append(CreateError(kSecurityErrorName, kMountFailedErrorMessage)); |
SetResult(result); |
return false; |
} |
@@ -75,4 +123,90 @@ bool FileSystemProviderMountFunction::RunImpl() { |
return true; |
} |
+bool FileSystemProviderUnmountFunction::RunImpl() { |
+ using api::file_system_provider::Unmount::Params; |
+ const scoped_ptr<Params> params(Params::Create(*args_)); |
+ EXTENSION_FUNCTION_VALIDATE(params); |
+ |
+ chromeos::file_system_provider::Service* service = |
+ chromeos::file_system_provider::Service::Get(GetProfile()); |
+ DCHECK(service); |
+ |
+ if (!service->UnmountFileSystem(extension_id(), params->file_system_id)) { |
+ // TODO(mtomasz): Pass more detailed errors, rather than just a bool. |
+ base::ListValue* result = new base::ListValue(); |
+ result->Append(CreateError(kSecurityErrorName, kUnmountFailedErrorMessage)); |
+ SetResult(result); |
+ return false; |
+ } |
+ |
+ base::ListValue* result = new base::ListValue(); |
+ SetResult(result); |
+ SendResponse(true); |
+ return true; |
+} |
+ |
+bool FileSystemProviderInternalUnmountRequestedSuccessFunction::RunImpl() { |
+ using api::file_system_provider_internal::UnmountRequestedSuccess::Params; |
+ const scoped_ptr<Params> params(Params::Create(*args_)); |
+ EXTENSION_FUNCTION_VALIDATE(params); |
+ |
+ chromeos::file_system_provider::Service* service = |
+ chromeos::file_system_provider::Service::Get(GetProfile()); |
+ DCHECK(service); |
+ |
+ if (!service->FulfillRequest(extension_id(), |
+ params->file_system_id, |
+ params->request_id, |
+ scoped_ptr<base::DictionaryValue>(), |
+ false /* has_more */)) { |
+ // TODO(mtomasz): Pass more detailed errors, rather than just a bool. |
+ base::ListValue* result = new base::ListValue(); |
+ result->Append( |
+ CreateError(kSecurityErrorName, kResponseFailedErrorMessage)); |
+ SetResult(result); |
+ return false; |
+ } |
+ |
+ base::ListValue* result = new base::ListValue(); |
+ SetResult(result); |
+ SendResponse(true); |
+ return true; |
+} |
+ |
+bool FileSystemProviderInternalUnmountRequestedErrorFunction::RunImpl() { |
+ using api::file_system_provider_internal::UnmountRequestedError::Params; |
+ const scoped_ptr<Params> params(Params::Create(*args_)); |
+ EXTENSION_FUNCTION_VALIDATE(params); |
+ |
+ chromeos::file_system_provider::Service* service = |
+ chromeos::file_system_provider::Service::Get(GetProfile()); |
+ DCHECK(service); |
+ |
+ // Currently it is not possible to refer to types/enums defined in a different |
+ // IDL file. Therefore we need to convert DOMString to ProviderError, since |
+ // UnmountRequestedErrorFunction() is defined in a different namespace than |
+ // ProvidedError. |
+ // TODO(mtomasz): Remove this trick, once IDL supports namespaces correctly. |
+ const api::file_system_provider::ProviderError provider_error = |
+ api::file_system_provider::ParseProviderError(params->error); |
+ |
+ if (!service->RejectRequest(extension_id(), |
+ params->file_system_id, |
+ params->request_id, |
+ ProviderErrorToFileError(provider_error))) { |
+ // TODO(mtomasz): Pass more detailed errors, rather than just a bool. |
+ base::ListValue* result = new base::ListValue(); |
+ result->Append( |
+ CreateError(kSecurityErrorName, kResponseFailedErrorMessage)); |
+ SetResult(result); |
+ return false; |
+ } |
+ |
+ base::ListValue* result = new base::ListValue(); |
+ SetResult(result); |
+ SendResponse(true); |
+ return true; |
+} |
+ |
} // namespace extensions |