OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/plugins/ppapi/ppb_file_ref_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
11 #include "ppapi/thunk/enter.h" | 11 #include "ppapi/thunk/enter.h" |
12 #include "ppapi/thunk/ppb_file_system_api.h" | 12 #include "ppapi/thunk/ppb_file_system_api.h" |
13 #include "ppapi/shared_impl/time_conversion.h" | 13 #include "ppapi/shared_impl/time_conversion.h" |
14 #include "ppapi/shared_impl/var.h" | 14 #include "ppapi/shared_impl/var.h" |
15 #include "webkit/plugins/ppapi/common.h" | 15 #include "webkit/plugins/ppapi/common.h" |
16 #include "webkit/plugins/ppapi/file_callbacks.h" | 16 #include "webkit/plugins/ppapi/file_callbacks.h" |
17 #include "webkit/plugins/ppapi/plugin_delegate.h" | 17 #include "webkit/plugins/ppapi/plugin_delegate.h" |
18 #include "webkit/plugins/ppapi/plugin_module.h" | 18 #include "webkit/plugins/ppapi/plugin_module.h" |
19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
20 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" | 20 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" |
21 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" | 21 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" |
22 #include "webkit/plugins/ppapi/resource_helper.h" | 22 #include "webkit/plugins/ppapi/resource_helper.h" |
23 | 23 |
24 using ppapi::HostResource; | 24 using ppapi::HostResource; |
25 using ppapi::PPB_FileRef_CreateInfo; | 25 using ppapi::PPB_FileRef_CreateInfo; |
26 using ppapi::PPTimeToTime; | 26 using ppapi::PPTimeToTime; |
27 using ppapi::StringVar; | 27 using ppapi::StringVar; |
| 28 using ppapi::TrackedCallback; |
28 using ppapi::thunk::EnterResourceNoLock; | 29 using ppapi::thunk::EnterResourceNoLock; |
29 using ppapi::thunk::PPB_FileRef_API; | 30 using ppapi::thunk::PPB_FileRef_API; |
30 using ppapi::thunk::PPB_FileSystem_API; | 31 using ppapi::thunk::PPB_FileSystem_API; |
31 | 32 |
32 namespace webkit { | 33 namespace webkit { |
33 namespace ppapi { | 34 namespace ppapi { |
34 | 35 |
35 namespace { | 36 namespace { |
36 | 37 |
37 bool IsValidLocalPath(const std::string& path) { | 38 bool IsValidLocalPath(const std::string& path) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 pos++; | 159 pos++; |
159 std::string parent_path = virtual_path.substr(0, pos); | 160 std::string parent_path = virtual_path.substr(0, pos); |
160 | 161 |
161 scoped_refptr<PPB_FileRef_Impl> parent_ref( | 162 scoped_refptr<PPB_FileRef_Impl> parent_ref( |
162 CreateInternal(file_system_->pp_resource(), parent_path)); | 163 CreateInternal(file_system_->pp_resource(), parent_path)); |
163 if (!parent_ref.get()) | 164 if (!parent_ref.get()) |
164 return 0; | 165 return 0; |
165 return parent_ref->GetReference(); | 166 return parent_ref->GetReference(); |
166 } | 167 } |
167 | 168 |
168 int32_t PPB_FileRef_Impl::MakeDirectory(PP_Bool make_ancestors, | 169 int32_t PPB_FileRef_Impl::MakeDirectory( |
169 PP_CompletionCallback callback) { | 170 PP_Bool make_ancestors, |
170 if (!callback.func) | 171 scoped_refptr<TrackedCallback> callback) { |
171 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
172 if (!IsValidNonExternalFileSystem()) | 172 if (!IsValidNonExternalFileSystem()) |
173 return PP_ERROR_NOACCESS; | 173 return PP_ERROR_NOACCESS; |
174 | 174 |
175 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 175 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
176 if (!plugin_instance) | 176 if (!plugin_instance) |
177 return PP_ERROR_FAILED; | 177 return PP_ERROR_FAILED; |
178 if (!plugin_instance->delegate()->MakeDirectory( | 178 if (!plugin_instance->delegate()->MakeDirectory( |
179 GetFileSystemURL(), PP_ToBool(make_ancestors), | 179 GetFileSystemURL(), PP_ToBool(make_ancestors), |
180 new FileCallbacks(this, callback, NULL, NULL, NULL))) | 180 new FileCallbacks(this, callback, NULL, NULL, NULL))) |
181 return PP_ERROR_FAILED; | 181 return PP_ERROR_FAILED; |
182 return PP_OK_COMPLETIONPENDING; | 182 return PP_OK_COMPLETIONPENDING; |
183 } | 183 } |
184 | 184 |
185 int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, | 185 int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, |
186 PP_Time last_modified_time, | 186 PP_Time last_modified_time, |
187 PP_CompletionCallback callback) { | 187 scoped_refptr<TrackedCallback> callback) { |
188 if (!callback.func) | |
189 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
190 if (!IsValidNonExternalFileSystem()) | 188 if (!IsValidNonExternalFileSystem()) |
191 return PP_ERROR_NOACCESS; | 189 return PP_ERROR_NOACCESS; |
192 | 190 |
193 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 191 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
194 if (!plugin_instance) | 192 if (!plugin_instance) |
195 return PP_ERROR_FAILED; | 193 return PP_ERROR_FAILED; |
196 if (!plugin_instance->delegate()->Touch( | 194 if (!plugin_instance->delegate()->Touch( |
197 GetFileSystemURL(), | 195 GetFileSystemURL(), |
198 PPTimeToTime(last_access_time), | 196 PPTimeToTime(last_access_time), |
199 PPTimeToTime(last_modified_time), | 197 PPTimeToTime(last_modified_time), |
200 new FileCallbacks(this, callback, NULL, NULL, NULL))) | 198 new FileCallbacks(this, callback, NULL, NULL, NULL))) |
201 return PP_ERROR_FAILED; | 199 return PP_ERROR_FAILED; |
202 return PP_OK_COMPLETIONPENDING; | 200 return PP_OK_COMPLETIONPENDING; |
203 } | 201 } |
204 | 202 |
205 int32_t PPB_FileRef_Impl::Delete(PP_CompletionCallback callback) { | 203 int32_t PPB_FileRef_Impl::Delete(scoped_refptr<TrackedCallback> callback) { |
206 if (!callback.func) | |
207 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
208 if (!IsValidNonExternalFileSystem()) | 204 if (!IsValidNonExternalFileSystem()) |
209 return PP_ERROR_NOACCESS; | 205 return PP_ERROR_NOACCESS; |
210 | 206 |
211 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 207 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
212 if (!plugin_instance) | 208 if (!plugin_instance) |
213 return PP_ERROR_FAILED; | 209 return PP_ERROR_FAILED; |
214 if (!plugin_instance->delegate()->Delete( | 210 if (!plugin_instance->delegate()->Delete( |
215 GetFileSystemURL(), | 211 GetFileSystemURL(), |
216 new FileCallbacks(this, callback, NULL, NULL, NULL))) | 212 new FileCallbacks(this, callback, NULL, NULL, NULL))) |
217 return PP_ERROR_FAILED; | 213 return PP_ERROR_FAILED; |
218 return PP_OK_COMPLETIONPENDING; | 214 return PP_OK_COMPLETIONPENDING; |
219 } | 215 } |
220 | 216 |
221 int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, | 217 int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, |
222 PP_CompletionCallback callback) { | 218 scoped_refptr<TrackedCallback> callback) { |
223 if (!callback.func) | |
224 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
225 EnterResourceNoLock<PPB_FileRef_API> enter(new_pp_file_ref, true); | 219 EnterResourceNoLock<PPB_FileRef_API> enter(new_pp_file_ref, true); |
226 if (enter.failed()) | 220 if (enter.failed()) |
227 return PP_ERROR_BADRESOURCE; | 221 return PP_ERROR_BADRESOURCE; |
228 PPB_FileRef_Impl* new_file_ref = | 222 PPB_FileRef_Impl* new_file_ref = |
229 static_cast<PPB_FileRef_Impl*>(enter.object()); | 223 static_cast<PPB_FileRef_Impl*>(enter.object()); |
230 | 224 |
231 if (!IsValidNonExternalFileSystem() || | 225 if (!IsValidNonExternalFileSystem() || |
232 file_system_.get() != new_file_ref->file_system_.get()) | 226 file_system_.get() != new_file_ref->file_system_.get()) |
233 return PP_ERROR_NOACCESS; | 227 return PP_ERROR_NOACCESS; |
234 | 228 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 return file_system_ && file_system_->opened(); | 279 return file_system_ && file_system_->opened(); |
286 } | 280 } |
287 | 281 |
288 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { | 282 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { |
289 return file_system_ && file_system_->opened() && | 283 return file_system_ && file_system_->opened() && |
290 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; | 284 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; |
291 } | 285 } |
292 | 286 |
293 } // namespace ppapi | 287 } // namespace ppapi |
294 } // namespace webkit | 288 } // namespace webkit |
OLD | NEW |