| 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/platform_file.h" | 7 #include "base/platform_file.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 CHECK(pos != std::string::npos); | 86 CHECK(pos != std::string::npos); |
| 87 return path.substr(pos + 1); | 87 return path.substr(pos + 1); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void IgnoreCloseCallback(base::PlatformFileError error_code) { | 90 void IgnoreCloseCallback(base::PlatformFileError error_code) { |
| 91 } | 91 } |
| 92 | 92 |
| 93 void GetFileInfoCallback( | 93 void GetFileInfoCallback( |
| 94 scoped_refptr<base::TaskRunner> task_runner, | 94 scoped_refptr<base::TaskRunner> task_runner, |
| 95 base::PlatformFile file, | 95 base::PlatformFile file, |
| 96 PP_FileInfo* info, | 96 linked_ptr<PP_FileInfo> info, |
| 97 scoped_refptr<TrackedCallback> callback, | 97 scoped_refptr<TrackedCallback> callback, |
| 98 base::PlatformFileError error_code, | 98 base::PlatformFileError error_code, |
| 99 const base::PlatformFileInfo& file_info) { | 99 const base::PlatformFileInfo& file_info) { |
| 100 base::FileUtilProxy::Close( | 100 base::FileUtilProxy::Close( |
| 101 task_runner, file, base::Bind(&IgnoreCloseCallback)); | 101 task_runner, file, base::Bind(&IgnoreCloseCallback)); |
| 102 | 102 |
| 103 if (!TrackedCallback::IsPending(callback)) | 103 if (!TrackedCallback::IsPending(callback)) |
| 104 return; | 104 return; |
| 105 | 105 |
| 106 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | 106 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); |
| 107 if (pp_error != PP_OK) | 107 if (pp_error != PP_OK) |
| 108 callback->Run(pp_error); | 108 callback->Run(pp_error); |
| 109 | 109 |
| 110 info->size = file_info.size; | 110 info->size = file_info.size; |
| 111 if (file_info.is_symbolic_link) | 111 if (file_info.is_symbolic_link) |
| 112 info->type = PP_FILETYPE_OTHER; | 112 info->type = PP_FILETYPE_OTHER; |
| 113 else if (file_info.is_directory) | 113 else if (file_info.is_directory) |
| 114 info->type = PP_FILETYPE_DIRECTORY; | 114 info->type = PP_FILETYPE_DIRECTORY; |
| 115 else | 115 else |
| 116 info->type = PP_FILETYPE_REGULAR; | 116 info->type = PP_FILETYPE_REGULAR; |
| 117 | 117 |
| 118 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; | 118 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; |
| 119 info->creation_time = file_info.creation_time.ToDoubleT(); | 119 info->creation_time = file_info.creation_time.ToDoubleT(); |
| 120 info->last_access_time = file_info.last_accessed.ToDoubleT(); | 120 info->last_access_time = file_info.last_accessed.ToDoubleT(); |
| 121 info->last_modified_time = file_info.last_modified.ToDoubleT(); | 121 info->last_modified_time = file_info.last_modified.ToDoubleT(); |
| 122 callback->Run(PP_OK); | 122 callback->Run(PP_OK); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void QueryCallback(scoped_refptr<base::TaskRunner> task_runner, | 125 void QueryCallback(scoped_refptr<base::TaskRunner> task_runner, |
| 126 PP_FileInfo* info, | 126 linked_ptr<PP_FileInfo> info, |
| 127 scoped_refptr<TrackedCallback> callback, | 127 scoped_refptr<TrackedCallback> callback, |
| 128 base::PlatformFileError error_code, | 128 base::PlatformFileError error_code, |
| 129 base::PassPlatformFile passed_file) { | 129 base::PassPlatformFile passed_file) { |
| 130 if (!TrackedCallback::IsPending(callback)) | 130 if (!TrackedCallback::IsPending(callback)) |
| 131 return; | 131 return; |
| 132 | 132 |
| 133 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | 133 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); |
| 134 if (pp_error != PP_OK) | 134 if (pp_error != PP_OK) |
| 135 callback->Run(pp_error); | 135 callback->Run(pp_error); |
| 136 base::PlatformFile file = passed_file.ReleaseValue(); | 136 base::PlatformFile file = passed_file.ReleaseValue(); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 PP_Bool make_ancestors, | 242 PP_Bool make_ancestors, |
| 243 scoped_refptr<TrackedCallback> callback) { | 243 scoped_refptr<TrackedCallback> callback) { |
| 244 if (!IsValidNonExternalFileSystem()) | 244 if (!IsValidNonExternalFileSystem()) |
| 245 return PP_ERROR_NOACCESS; | 245 return PP_ERROR_NOACCESS; |
| 246 | 246 |
| 247 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 247 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 248 if (!plugin_instance) | 248 if (!plugin_instance) |
| 249 return PP_ERROR_FAILED; | 249 return PP_ERROR_FAILED; |
| 250 if (!plugin_instance->delegate()->MakeDirectory( | 250 if (!plugin_instance->delegate()->MakeDirectory( |
| 251 GetFileSystemURL(), PP_ToBool(make_ancestors), | 251 GetFileSystemURL(), PP_ToBool(make_ancestors), |
| 252 new FileCallbacks(this, callback, NULL))) | 252 new FileCallbacks(this, callback))) |
| 253 return PP_ERROR_FAILED; | 253 return PP_ERROR_FAILED; |
| 254 return PP_OK_COMPLETIONPENDING; | 254 return PP_OK_COMPLETIONPENDING; |
| 255 } | 255 } |
| 256 | 256 |
| 257 int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, | 257 int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, |
| 258 PP_Time last_modified_time, | 258 PP_Time last_modified_time, |
| 259 scoped_refptr<TrackedCallback> callback) { | 259 scoped_refptr<TrackedCallback> callback) { |
| 260 if (!IsValidNonExternalFileSystem()) | 260 if (!IsValidNonExternalFileSystem()) |
| 261 return PP_ERROR_NOACCESS; | 261 return PP_ERROR_NOACCESS; |
| 262 | 262 |
| 263 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 263 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 264 if (!plugin_instance) | 264 if (!plugin_instance) |
| 265 return PP_ERROR_FAILED; | 265 return PP_ERROR_FAILED; |
| 266 if (!plugin_instance->delegate()->Touch( | 266 if (!plugin_instance->delegate()->Touch( |
| 267 GetFileSystemURL(), | 267 GetFileSystemURL(), |
| 268 PPTimeToTime(last_access_time), | 268 PPTimeToTime(last_access_time), |
| 269 PPTimeToTime(last_modified_time), | 269 PPTimeToTime(last_modified_time), |
| 270 new FileCallbacks(this, callback, NULL))) | 270 new FileCallbacks(this, callback))) |
| 271 return PP_ERROR_FAILED; | 271 return PP_ERROR_FAILED; |
| 272 return PP_OK_COMPLETIONPENDING; | 272 return PP_OK_COMPLETIONPENDING; |
| 273 } | 273 } |
| 274 | 274 |
| 275 int32_t PPB_FileRef_Impl::Delete(scoped_refptr<TrackedCallback> callback) { | 275 int32_t PPB_FileRef_Impl::Delete(scoped_refptr<TrackedCallback> callback) { |
| 276 if (!IsValidNonExternalFileSystem()) | 276 if (!IsValidNonExternalFileSystem()) |
| 277 return PP_ERROR_NOACCESS; | 277 return PP_ERROR_NOACCESS; |
| 278 | 278 |
| 279 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 279 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 280 if (!plugin_instance) | 280 if (!plugin_instance) |
| 281 return PP_ERROR_FAILED; | 281 return PP_ERROR_FAILED; |
| 282 if (!plugin_instance->delegate()->Delete( | 282 if (!plugin_instance->delegate()->Delete( |
| 283 GetFileSystemURL(), | 283 GetFileSystemURL(), |
| 284 new FileCallbacks(this, callback, NULL))) | 284 new FileCallbacks(this, callback))) |
| 285 return PP_ERROR_FAILED; | 285 return PP_ERROR_FAILED; |
| 286 return PP_OK_COMPLETIONPENDING; | 286 return PP_OK_COMPLETIONPENDING; |
| 287 } | 287 } |
| 288 | 288 |
| 289 int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, | 289 int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, |
| 290 scoped_refptr<TrackedCallback> callback) { | 290 scoped_refptr<TrackedCallback> callback) { |
| 291 EnterResourceNoLock<PPB_FileRef_API> enter(new_pp_file_ref, true); | 291 EnterResourceNoLock<PPB_FileRef_API> enter(new_pp_file_ref, true); |
| 292 if (enter.failed()) | 292 if (enter.failed()) |
| 293 return PP_ERROR_BADRESOURCE; | 293 return PP_ERROR_BADRESOURCE; |
| 294 PPB_FileRef_Impl* new_file_ref = | 294 PPB_FileRef_Impl* new_file_ref = |
| 295 static_cast<PPB_FileRef_Impl*>(enter.object()); | 295 static_cast<PPB_FileRef_Impl*>(enter.object()); |
| 296 | 296 |
| 297 if (!IsValidNonExternalFileSystem() || | 297 if (!IsValidNonExternalFileSystem() || |
| 298 file_system_ != new_file_ref->file_system_) | 298 file_system_ != new_file_ref->file_system_) |
| 299 return PP_ERROR_NOACCESS; | 299 return PP_ERROR_NOACCESS; |
| 300 | 300 |
| 301 // TODO(viettrungluu): Also cancel when the new file ref is destroyed? | 301 // TODO(viettrungluu): Also cancel when the new file ref is destroyed? |
| 302 // http://crbug.com/67624 | 302 // http://crbug.com/67624 |
| 303 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 303 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 304 if (!plugin_instance) | 304 if (!plugin_instance) |
| 305 return PP_ERROR_FAILED; | 305 return PP_ERROR_FAILED; |
| 306 if (!plugin_instance->delegate()->Rename( | 306 if (!plugin_instance->delegate()->Rename( |
| 307 GetFileSystemURL(), new_file_ref->GetFileSystemURL(), | 307 GetFileSystemURL(), new_file_ref->GetFileSystemURL(), |
| 308 new FileCallbacks(this, callback, NULL))) | 308 new FileCallbacks(this, callback))) |
| 309 return PP_ERROR_FAILED; | 309 return PP_ERROR_FAILED; |
| 310 return PP_OK_COMPLETIONPENDING; | 310 return PP_OK_COMPLETIONPENDING; |
| 311 } | 311 } |
| 312 | 312 |
| 313 PP_Var PPB_FileRef_Impl::GetAbsolutePath() { | 313 PP_Var PPB_FileRef_Impl::GetAbsolutePath() { |
| 314 if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) | 314 if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) |
| 315 return GetPath(); | 315 return GetPath(); |
| 316 if (!external_path_var_.get()) { | 316 if (!external_path_var_.get()) { |
| 317 external_path_var_ = new StringVar( | 317 external_path_var_ = new StringVar( |
| 318 external_file_system_path_.AsUTF8Unsafe()); | 318 external_file_system_path_.AsUTF8Unsafe()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 | 364 |
| 365 bool PPB_FileRef_Impl::HasValidFileSystem() const { | 365 bool PPB_FileRef_Impl::HasValidFileSystem() const { |
| 366 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 366 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 367 PluginDelegate* delegate = | 367 PluginDelegate* delegate = |
| 368 plugin_instance ? plugin_instance->delegate() : NULL; | 368 plugin_instance ? plugin_instance->delegate() : NULL; |
| 369 return delegate && delegate->IsFileSystemOpened(pp_instance(), file_system_); | 369 return delegate && delegate->IsFileSystemOpened(pp_instance(), file_system_); |
| 370 } | 370 } |
| 371 | 371 |
| 372 int32_t PPB_FileRef_Impl::Query(PP_FileInfo* info, | 372 int32_t PPB_FileRef_Impl::Query(PP_FileInfo* info, |
| 373 scoped_refptr<TrackedCallback> callback) { | 373 scoped_refptr<TrackedCallback> callback) { |
| 374 NOTREACHED(); |
| 375 return PP_ERROR_FAILED; |
| 376 } |
| 377 |
| 378 int32_t PPB_FileRef_Impl::QueryInHost( |
| 379 linked_ptr<PP_FileInfo> info, |
| 380 scoped_refptr<TrackedCallback> callback) { |
| 374 scoped_refptr<PluginInstance> plugin_instance = | 381 scoped_refptr<PluginInstance> plugin_instance = |
| 375 ResourceHelper::GetPluginInstance(this); | 382 ResourceHelper::GetPluginInstance(this); |
| 376 if (!plugin_instance.get()) | 383 if (!plugin_instance.get()) |
| 377 return PP_ERROR_FAILED; | 384 return PP_ERROR_FAILED; |
| 378 | 385 |
| 379 if (!file_system_) { | 386 if (!file_system_) { |
| 380 // External file system | 387 // External file system |
| 381 // We have to do something totally different for external file systems. | 388 // We have to do something totally different for external file systems. |
| 382 | 389 |
| 383 // TODO(teravest): Use the SequencedWorkerPool instead. | 390 // TODO(teravest): Use the SequencedWorkerPool instead. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 403 GetFileSystemURL(), | 410 GetFileSystemURL(), |
| 404 new FileCallbacks(this, callback, info, | 411 new FileCallbacks(this, callback, info, |
| 405 delegate->GetFileSystemType(pp_instance(), | 412 delegate->GetFileSystemType(pp_instance(), |
| 406 file_system_)))) | 413 file_system_)))) |
| 407 return PP_ERROR_FAILED; | 414 return PP_ERROR_FAILED; |
| 408 | 415 |
| 409 } | 416 } |
| 410 return PP_OK_COMPLETIONPENDING; | 417 return PP_OK_COMPLETIONPENDING; |
| 411 } | 418 } |
| 412 | 419 |
| 420 int32_t PPB_FileRef_Impl::ReadDirectoryEntries( |
| 421 const PP_ArrayOutput& output, |
| 422 scoped_refptr<TrackedCallback> callback) { |
| 423 NOTREACHED(); |
| 424 return PP_ERROR_FAILED; |
| 425 } |
| 426 |
| 427 int32_t PPB_FileRef_Impl::ReadDirectoryEntriesInHost( |
| 428 linked_ptr<std::vector< ::ppapi::PPB_FileRef_CreateInfo> > files, |
| 429 linked_ptr<std::vector<PP_FileType> > file_types, |
| 430 scoped_refptr<TrackedCallback> callback) { |
| 431 if (!IsValidNonExternalFileSystem()) |
| 432 return PP_ERROR_NOACCESS; |
| 433 |
| 434 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 435 if (!plugin_instance) |
| 436 return PP_ERROR_FAILED; |
| 437 |
| 438 FileCallbacks::ReadDirectoryEntriesParams params; |
| 439 params.dir_ref = this; |
| 440 params.files = files; |
| 441 params.file_types = file_types; |
| 442 |
| 443 if (!plugin_instance->delegate()->ReadDirectoryEntries( |
| 444 GetFileSystemURL(), |
| 445 new FileCallbacks(this, callback, params))) |
| 446 return PP_ERROR_FAILED; |
| 447 return PP_OK_COMPLETIONPENDING; |
| 448 } |
| 449 |
| 413 } // namespace ppapi | 450 } // namespace ppapi |
| 414 } // namespace webkit | 451 } // namespace webkit |
| OLD | NEW |