| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 pos++; | 155 pos++; |
| 155 std::string parent_path = virtual_path.substr(0, pos); | 156 std::string parent_path = virtual_path.substr(0, pos); |
| 156 | 157 |
| 157 scoped_refptr<PPB_FileRef_Impl> parent_ref( | 158 scoped_refptr<PPB_FileRef_Impl> parent_ref( |
| 158 CreateInternal(file_system_->pp_resource(), parent_path)); | 159 CreateInternal(file_system_->pp_resource(), parent_path)); |
| 159 if (!parent_ref.get()) | 160 if (!parent_ref.get()) |
| 160 return 0; | 161 return 0; |
| 161 return parent_ref->GetReference(); | 162 return parent_ref->GetReference(); |
| 162 } | 163 } |
| 163 | 164 |
| 164 int32_t PPB_FileRef_Impl::MakeDirectory(PP_Bool make_ancestors, | 165 int32_t PPB_FileRef_Impl::MakeDirectory( |
| 165 PP_CompletionCallback callback) { | 166 PP_Bool make_ancestors, |
| 166 if (!callback.func) | 167 scoped_refptr<TrackedCallback> callback) { |
| 167 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
| 168 if (!IsValidNonExternalFileSystem()) | 168 if (!IsValidNonExternalFileSystem()) |
| 169 return PP_ERROR_NOACCESS; | 169 return PP_ERROR_NOACCESS; |
| 170 | 170 |
| 171 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 171 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 172 if (!plugin_instance) | 172 if (!plugin_instance) |
| 173 return PP_ERROR_FAILED; | 173 return PP_ERROR_FAILED; |
| 174 if (!plugin_instance->delegate()->MakeDirectory( | 174 if (!plugin_instance->delegate()->MakeDirectory( |
| 175 GetFileSystemURL(), PP_ToBool(make_ancestors), | 175 GetFileSystemURL(), PP_ToBool(make_ancestors), |
| 176 new FileCallbacks(this, callback, NULL, NULL, NULL))) | 176 new FileCallbacks(this, callback, NULL, NULL, NULL))) |
| 177 return PP_ERROR_FAILED; | 177 return PP_ERROR_FAILED; |
| 178 return PP_OK_COMPLETIONPENDING; | 178 return PP_OK_COMPLETIONPENDING; |
| 179 } | 179 } |
| 180 | 180 |
| 181 int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, | 181 int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, |
| 182 PP_Time last_modified_time, | 182 PP_Time last_modified_time, |
| 183 PP_CompletionCallback callback) { | 183 scoped_refptr<TrackedCallback> callback) { |
| 184 if (!callback.func) | |
| 185 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
| 186 if (!IsValidNonExternalFileSystem()) | 184 if (!IsValidNonExternalFileSystem()) |
| 187 return PP_ERROR_NOACCESS; | 185 return PP_ERROR_NOACCESS; |
| 188 | 186 |
| 189 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 187 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 190 if (!plugin_instance) | 188 if (!plugin_instance) |
| 191 return PP_ERROR_FAILED; | 189 return PP_ERROR_FAILED; |
| 192 if (!plugin_instance->delegate()->Touch( | 190 if (!plugin_instance->delegate()->Touch( |
| 193 GetFileSystemURL(), | 191 GetFileSystemURL(), |
| 194 PPTimeToTime(last_access_time), | 192 PPTimeToTime(last_access_time), |
| 195 PPTimeToTime(last_modified_time), | 193 PPTimeToTime(last_modified_time), |
| 196 new FileCallbacks(this, callback, NULL, NULL, NULL))) | 194 new FileCallbacks(this, callback, NULL, NULL, NULL))) |
| 197 return PP_ERROR_FAILED; | 195 return PP_ERROR_FAILED; |
| 198 return PP_OK_COMPLETIONPENDING; | 196 return PP_OK_COMPLETIONPENDING; |
| 199 } | 197 } |
| 200 | 198 |
| 201 int32_t PPB_FileRef_Impl::Delete(PP_CompletionCallback callback) { | 199 int32_t PPB_FileRef_Impl::Delete(scoped_refptr<TrackedCallback> callback) { |
| 202 if (!callback.func) | |
| 203 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
| 204 if (!IsValidNonExternalFileSystem()) | 200 if (!IsValidNonExternalFileSystem()) |
| 205 return PP_ERROR_NOACCESS; | 201 return PP_ERROR_NOACCESS; |
| 206 | 202 |
| 207 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 203 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 208 if (!plugin_instance) | 204 if (!plugin_instance) |
| 209 return PP_ERROR_FAILED; | 205 return PP_ERROR_FAILED; |
| 210 if (!plugin_instance->delegate()->Delete( | 206 if (!plugin_instance->delegate()->Delete( |
| 211 GetFileSystemURL(), | 207 GetFileSystemURL(), |
| 212 new FileCallbacks(this, callback, NULL, NULL, NULL))) | 208 new FileCallbacks(this, callback, NULL, NULL, NULL))) |
| 213 return PP_ERROR_FAILED; | 209 return PP_ERROR_FAILED; |
| 214 return PP_OK_COMPLETIONPENDING; | 210 return PP_OK_COMPLETIONPENDING; |
| 215 } | 211 } |
| 216 | 212 |
| 217 int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, | 213 int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, |
| 218 PP_CompletionCallback callback) { | 214 scoped_refptr<TrackedCallback> callback) { |
| 219 if (!callback.func) | |
| 220 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
| 221 EnterResourceNoLock<PPB_FileRef_API> enter(new_pp_file_ref, true); | 215 EnterResourceNoLock<PPB_FileRef_API> enter(new_pp_file_ref, true); |
| 222 if (enter.failed()) | 216 if (enter.failed()) |
| 223 return PP_ERROR_BADRESOURCE; | 217 return PP_ERROR_BADRESOURCE; |
| 224 PPB_FileRef_Impl* new_file_ref = | 218 PPB_FileRef_Impl* new_file_ref = |
| 225 static_cast<PPB_FileRef_Impl*>(enter.object()); | 219 static_cast<PPB_FileRef_Impl*>(enter.object()); |
| 226 | 220 |
| 227 if (!IsValidNonExternalFileSystem() || | 221 if (!IsValidNonExternalFileSystem() || |
| 228 file_system_.get() != new_file_ref->file_system_.get()) | 222 file_system_.get() != new_file_ref->file_system_.get()) |
| 229 return PP_ERROR_NOACCESS; | 223 return PP_ERROR_NOACCESS; |
| 230 | 224 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 return file_system_ && file_system_->opened(); | 275 return file_system_ && file_system_->opened(); |
| 282 } | 276 } |
| 283 | 277 |
| 284 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { | 278 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { |
| 285 return file_system_ && file_system_->opened() && | 279 return file_system_ && file_system_->opened() && |
| 286 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; | 280 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; |
| 287 } | 281 } |
| 288 | 282 |
| 289 } // namespace ppapi | 283 } // namespace ppapi |
| 290 } // namespace webkit | 284 } // namespace webkit |
| OLD | NEW |