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 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 } // namespace | 71 } // namespace |
72 | 72 |
73 bool FileSystemProviderMountFunction::RunSync() { | 73 bool FileSystemProviderMountFunction::RunSync() { |
74 using api::file_system_provider::Mount::Params; | 74 using api::file_system_provider::Mount::Params; |
75 const scoped_ptr<Params> params(Params::Create(*args_)); | 75 const scoped_ptr<Params> params(Params::Create(*args_)); |
76 EXTENSION_FUNCTION_VALIDATE(params); | 76 EXTENSION_FUNCTION_VALIDATE(params); |
77 | 77 |
78 // It's an error if the file system Id is empty. | 78 // It's an error if the file system Id is empty. |
79 if (params->options.file_system_id.empty()) { | 79 if (params->options.file_system_id.empty()) { |
80 SetError(FileErrorToString(base::File::FILE_ERROR_SECURITY)); | 80 SetError(FileErrorToString(base::File::FILE_ERROR_INVALID_OPERATION)); |
81 return false; | 81 return false; |
82 } | 82 } |
83 | 83 |
84 // It's an error if the display name is empty. | 84 // It's an error if the display name is empty. |
85 if (params->options.display_name.empty()) { | 85 if (params->options.display_name.empty()) { |
86 SetError(FileErrorToString(base::File::FILE_ERROR_SECURITY)); | 86 SetError(FileErrorToString(base::File::FILE_ERROR_INVALID_OPERATION)); |
87 return false; | 87 return false; |
88 } | 88 } |
89 | 89 |
90 Service* const service = Service::Get(GetProfile()); | 90 Service* const service = Service::Get(GetProfile()); |
91 DCHECK(service); | 91 DCHECK(service); |
92 | 92 |
93 MountOptions options; | 93 MountOptions options; |
94 options.file_system_id = params->options.file_system_id; | 94 options.file_system_id = params->options.file_system_id; |
95 options.display_name = params->options.display_name; | 95 options.display_name = params->options.display_name; |
96 options.writable = params->options.writable; | 96 options.writable = params->options.writable; |
97 options.supports_notify_tag = params->options.supports_notify_tag; | 97 options.supports_notify_tag = params->options.supports_notify_tag; |
98 | 98 |
99 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. | 99 const base::File::Error result = |
100 if (!service->MountFileSystem(extension_id(), options)) { | 100 service->MountFileSystem(extension_id(), options); |
101 SetError(FileErrorToString(base::File::FILE_ERROR_SECURITY)); | 101 if (result != base::File::FILE_OK) { |
| 102 SetError(FileErrorToString(result)); |
102 return false; | 103 return false; |
103 } | 104 } |
104 | 105 |
105 return true; | 106 return true; |
106 } | 107 } |
107 | 108 |
108 bool FileSystemProviderUnmountFunction::RunSync() { | 109 bool FileSystemProviderUnmountFunction::RunSync() { |
109 using api::file_system_provider::Unmount::Params; | 110 using api::file_system_provider::Unmount::Params; |
110 scoped_ptr<Params> params(Params::Create(*args_)); | 111 scoped_ptr<Params> params(Params::Create(*args_)); |
111 EXTENSION_FUNCTION_VALIDATE(params); | 112 EXTENSION_FUNCTION_VALIDATE(params); |
112 | 113 |
113 Service* const service = Service::Get(GetProfile()); | 114 Service* const service = Service::Get(GetProfile()); |
114 DCHECK(service); | 115 DCHECK(service); |
115 | 116 |
116 if (!service->UnmountFileSystem(extension_id(), | 117 const base::File::Error result = |
117 params->options.file_system_id, | 118 service->UnmountFileSystem(extension_id(), params->options.file_system_id, |
118 Service::UNMOUNT_REASON_USER)) { | 119 Service::UNMOUNT_REASON_USER); |
119 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. | 120 if (result != base::File::FILE_OK) { |
120 SetError(FileErrorToString(base::File::FILE_ERROR_SECURITY)); | 121 SetError(FileErrorToString(result)); |
121 return false; | 122 return false; |
122 } | 123 } |
123 | 124 |
124 return true; | 125 return true; |
125 } | 126 } |
126 | 127 |
127 bool FileSystemProviderGetAllFunction::RunSync() { | 128 bool FileSystemProviderGetAllFunction::RunSync() { |
128 using api::file_system_provider::FileSystemInfo; | 129 using api::file_system_provider::FileSystemInfo; |
129 using api::file_system_provider::Watcher; | 130 using api::file_system_provider::Watcher; |
130 Service* const service = Service::Get(GetProfile()); | 131 Service* const service = Service::Get(GetProfile()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 165 |
165 item->watchers = watcher_items; | 166 item->watchers = watcher_items; |
166 items.push_back(item); | 167 items.push_back(item); |
167 } | 168 } |
168 } | 169 } |
169 | 170 |
170 SetResultList(api::file_system_provider::GetAll::Results::Create(items)); | 171 SetResultList(api::file_system_provider::GetAll::Results::Create(items)); |
171 return true; | 172 return true; |
172 } | 173 } |
173 | 174 |
174 bool FileSystemProviderNotifyFunction::RunSync() { | 175 bool FileSystemProviderNotifyFunction::RunAsync() { |
175 using api::file_system_provider::Notify::Params; | 176 using api::file_system_provider::Notify::Params; |
176 scoped_ptr<Params> params(Params::Create(*args_)); | 177 scoped_ptr<Params> params(Params::Create(*args_)); |
177 EXTENSION_FUNCTION_VALIDATE(params); | 178 EXTENSION_FUNCTION_VALIDATE(params); |
178 | 179 |
179 Service* const service = Service::Get(GetProfile()); | 180 Service* const service = Service::Get(GetProfile()); |
180 DCHECK(service); | 181 DCHECK(service); |
181 | 182 |
182 ProvidedFileSystemInterface* const file_system = | 183 ProvidedFileSystemInterface* const file_system = |
183 service->GetProvidedFileSystem(extension_id(), | 184 service->GetProvidedFileSystem(extension_id(), |
184 params->options.file_system_id); | 185 params->options.file_system_id); |
185 if (!file_system) { | 186 if (!file_system) { |
186 SetError(FileErrorToString(base::File::FILE_ERROR_SECURITY)); | 187 SetError(FileErrorToString(base::File::FILE_ERROR_NOT_FOUND)); |
187 return false; | 188 return false; |
188 } | 189 } |
189 | 190 |
190 if (!file_system->Notify( | 191 file_system->Notify( |
191 base::FilePath::FromUTF8Unsafe(params->options.observed_path), | 192 base::FilePath::FromUTF8Unsafe(params->options.observed_path), |
192 params->options.recursive, | 193 params->options.recursive, ParseChangeType(params->options.change_type), |
193 ParseChangeType(params->options.change_type), | 194 params->options.changes.get() |
194 params->options.changes.get() | 195 ? ParseChanges(*params->options.changes.get()) |
195 ? ParseChanges(*params->options.changes.get()) | 196 : make_scoped_ptr(new ProvidedFileSystemObserver::Changes), |
196 : make_scoped_ptr(new ProvidedFileSystemObserver::Changes), | 197 params->options.tag.get() ? *params->options.tag.get() : "", |
197 params->options.tag.get() ? *params->options.tag.get() : "")) { | 198 base::Bind(&FileSystemProviderNotifyFunction::OnNotifyCompleted, this)); |
198 SetError(FileErrorToString(base::File::FILE_ERROR_SECURITY)); | 199 |
199 return false; | 200 return true; |
| 201 } |
| 202 |
| 203 void FileSystemProviderNotifyFunction::OnNotifyCompleted( |
| 204 base::File::Error result) { |
| 205 if (result != base::File::FILE_OK) { |
| 206 SetError(FileErrorToString(result)); |
| 207 SendResponse(false); |
| 208 return; |
200 } | 209 } |
201 | 210 |
202 return true; | 211 SendResponse(true); |
203 } | 212 } |
204 | 213 |
205 bool FileSystemProviderInternalUnmountRequestedSuccessFunction::RunWhenValid() { | 214 bool FileSystemProviderInternalUnmountRequestedSuccessFunction::RunWhenValid() { |
206 using api::file_system_provider_internal::UnmountRequestedSuccess::Params; | 215 using api::file_system_provider_internal::UnmountRequestedSuccess::Params; |
207 scoped_ptr<Params> params(Params::Create(*args_)); | 216 scoped_ptr<Params> params(Params::Create(*args_)); |
208 EXTENSION_FUNCTION_VALIDATE(params); | 217 EXTENSION_FUNCTION_VALIDATE(params); |
209 | 218 |
210 return FulfillRequest(RequestValue::CreateForUnmountSuccess(params.Pass()), | 219 return FulfillRequest(RequestValue::CreateForUnmountSuccess(params.Pass()), |
211 false /* has_more */); | 220 false /* has_more */); |
212 } | 221 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 using api::file_system_provider_internal::OperationRequestedError::Params; | 272 using api::file_system_provider_internal::OperationRequestedError::Params; |
264 scoped_ptr<Params> params(Params::Create(*args_)); | 273 scoped_ptr<Params> params(Params::Create(*args_)); |
265 EXTENSION_FUNCTION_VALIDATE(params); | 274 EXTENSION_FUNCTION_VALIDATE(params); |
266 | 275 |
267 const base::File::Error error = ProviderErrorToFileError(params->error); | 276 const base::File::Error error = ProviderErrorToFileError(params->error); |
268 return RejectRequest(RequestValue::CreateForOperationError(params.Pass()), | 277 return RejectRequest(RequestValue::CreateForOperationError(params.Pass()), |
269 error); | 278 error); |
270 } | 279 } |
271 | 280 |
272 } // namespace extensions | 281 } // namespace extensions |
OLD | NEW |