| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_system_provider/file_system_pr
ovider_api.h" | 5 #include "chrome/browser/chromeos/extensions/file_system_provider/file_system_pr
ovider_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" | 11 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" |
| 12 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" | 12 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" |
| 13 #include "chrome/browser/chromeos/file_system_provider/request_value.h" | 13 #include "chrome/browser/chromeos/file_system_provider/request_value.h" |
| 14 #include "chrome/browser/chromeos/file_system_provider/service.h" | 14 #include "chrome/browser/chromeos/file_system_provider/service.h" |
| 15 #include "chrome/common/extensions/api/file_system_provider.h" | 15 #include "chrome/common/extensions/api/file_system_provider.h" |
| 16 #include "chrome/common/extensions/api/file_system_provider_internal.h" | 16 #include "chrome/common/extensions/api/file_system_provider_internal.h" |
| 17 | 17 |
| 18 using chromeos::file_system_provider::ProvidedFileSystemInterface; | 18 using chromeos::file_system_provider::ProvidedFileSystemInterface; |
| 19 using chromeos::file_system_provider::RequestValue; | 19 using chromeos::file_system_provider::RequestValue; |
| 20 using chromeos::file_system_provider::Service; | 20 using chromeos::file_system_provider::Service; |
| 21 | 21 |
| 22 namespace extensions { | 22 namespace extensions { |
| 23 | 23 |
| 24 bool FileSystemProviderMountFunction::RunSync() { | 24 bool FileSystemProviderMountFunction::RunSync() { |
| 25 using api::file_system_provider::Mount::Params; | 25 using api::file_system_provider::Mount::Params; |
| 26 const scoped_ptr<Params> params(Params::Create(*args_)); | 26 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 27 EXTENSION_FUNCTION_VALIDATE(params); | 27 EXTENSION_FUNCTION_VALIDATE(params); |
| 28 | 28 |
| 29 // It's an error if the file system Id is empty. |
| 30 if (params->file_system_id.empty()) { |
| 31 base::ListValue* result = new base::ListValue(); |
| 32 result->Append(CreateError(kSecurityErrorName, kEmptyIdErrorMessage)); |
| 33 SetResult(result); |
| 34 return true; |
| 35 } |
| 36 |
| 29 // It's an error if the display name is empty. | 37 // It's an error if the display name is empty. |
| 30 if (params->display_name.empty()) { | 38 if (params->display_name.empty()) { |
| 31 base::ListValue* result = new base::ListValue(); | 39 base::ListValue* result = new base::ListValue(); |
| 32 result->Append(new base::StringValue("")); | |
| 33 result->Append(CreateError(kSecurityErrorName, | 40 result->Append(CreateError(kSecurityErrorName, |
| 34 kEmptyNameErrorMessage)); | 41 kEmptyNameErrorMessage)); |
| 35 SetResult(result); | 42 SetResult(result); |
| 36 return true; | 43 return true; |
| 37 } | 44 } |
| 38 | 45 |
| 39 Service* service = Service::Get(GetProfile()); | 46 Service* service = Service::Get(GetProfile()); |
| 40 DCHECK(service); | 47 DCHECK(service); |
| 41 if (!service) | 48 if (!service) |
| 42 return false; | 49 return false; |
| 43 | 50 |
| 44 int file_system_id = | |
| 45 service->MountFileSystem(extension_id(), params->display_name); | |
| 46 | |
| 47 // If the |file_system_id| is zero, then it means that registering the file | |
| 48 // system failed. | |
| 49 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. | 51 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. |
| 50 if (!file_system_id) { | 52 if (!service->MountFileSystem( |
| 53 extension_id(), params->file_system_id, params->display_name)) { |
| 51 base::ListValue* result = new base::ListValue(); | 54 base::ListValue* result = new base::ListValue(); |
| 52 result->Append(new base::FundamentalValue(0)); | |
| 53 result->Append(CreateError(kSecurityErrorName, kMountFailedErrorMessage)); | 55 result->Append(CreateError(kSecurityErrorName, kMountFailedErrorMessage)); |
| 54 SetResult(result); | 56 SetResult(result); |
| 55 return true; | 57 return true; |
| 56 } | 58 } |
| 57 | 59 |
| 58 base::ListValue* result = new base::ListValue(); | 60 base::ListValue* result = new base::ListValue(); |
| 59 result->Append(new base::FundamentalValue(file_system_id)); | |
| 60 // Don't append an error on success. | |
| 61 | |
| 62 SetResult(result); | 61 SetResult(result); |
| 63 return true; | 62 return true; |
| 64 } | 63 } |
| 65 | 64 |
| 66 bool FileSystemProviderUnmountFunction::RunSync() { | 65 bool FileSystemProviderUnmountFunction::RunSync() { |
| 67 using api::file_system_provider::Unmount::Params; | 66 using api::file_system_provider::Unmount::Params; |
| 68 scoped_ptr<Params> params(Params::Create(*args_)); | 67 scoped_ptr<Params> params(Params::Create(*args_)); |
| 69 EXTENSION_FUNCTION_VALIDATE(params); | 68 EXTENSION_FUNCTION_VALIDATE(params); |
| 70 | 69 |
| 71 Service* service = Service::Get(GetProfile()); | 70 Service* service = Service::Get(GetProfile()); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 bool FileSystemProviderInternalReadFileRequestedErrorFunction::RunWhenValid() { | 203 bool FileSystemProviderInternalReadFileRequestedErrorFunction::RunWhenValid() { |
| 205 using api::file_system_provider_internal::ReadFileRequestedError::Params; | 204 using api::file_system_provider_internal::ReadFileRequestedError::Params; |
| 206 const scoped_ptr<Params> params(Params::Create(*args_)); | 205 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 207 EXTENSION_FUNCTION_VALIDATE(params); | 206 EXTENSION_FUNCTION_VALIDATE(params); |
| 208 | 207 |
| 209 RejectRequest(ProviderErrorToFileError(params->error)); | 208 RejectRequest(ProviderErrorToFileError(params->error)); |
| 210 return true; | 209 return true; |
| 211 } | 210 } |
| 212 | 211 |
| 213 } // namespace extensions | 212 } // namespace extensions |
| OLD | NEW |