| 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 PP_Bool make_ancestors, | 243 PP_Bool make_ancestors, |
| 244 scoped_refptr<TrackedCallback> callback) { | 244 scoped_refptr<TrackedCallback> callback) { |
| 245 if (!IsValidNonExternalFileSystem()) | 245 if (!IsValidNonExternalFileSystem()) |
| 246 return PP_ERROR_NOACCESS; | 246 return PP_ERROR_NOACCESS; |
| 247 | 247 |
| 248 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 248 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 249 if (!plugin_instance) | 249 if (!plugin_instance) |
| 250 return PP_ERROR_FAILED; | 250 return PP_ERROR_FAILED; |
| 251 if (!plugin_instance->delegate()->MakeDirectory( | 251 if (!plugin_instance->delegate()->MakeDirectory( |
| 252 GetFileSystemURL(), PP_ToBool(make_ancestors), | 252 GetFileSystemURL(), PP_ToBool(make_ancestors), |
| 253 new FileCallbacks(this, callback))) | 253 base::Bind(&FileCallbacks::DidFinish, |
| 254 base::Owned(new FileCallbacks(this, callback))))) |
| 254 return PP_ERROR_FAILED; | 255 return PP_ERROR_FAILED; |
| 255 return PP_OK_COMPLETIONPENDING; | 256 return PP_OK_COMPLETIONPENDING; |
| 256 } | 257 } |
| 257 | 258 |
| 258 int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, | 259 int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, |
| 259 PP_Time last_modified_time, | 260 PP_Time last_modified_time, |
| 260 scoped_refptr<TrackedCallback> callback) { | 261 scoped_refptr<TrackedCallback> callback) { |
| 261 if (!IsValidNonExternalFileSystem()) | 262 if (!IsValidNonExternalFileSystem()) |
| 262 return PP_ERROR_NOACCESS; | 263 return PP_ERROR_NOACCESS; |
| 263 | 264 |
| 264 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 265 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 265 if (!plugin_instance) | 266 if (!plugin_instance) |
| 266 return PP_ERROR_FAILED; | 267 return PP_ERROR_FAILED; |
| 267 if (!plugin_instance->delegate()->Touch( | 268 if (!plugin_instance->delegate()->Touch( |
| 268 GetFileSystemURL(), | 269 GetFileSystemURL(), |
| 269 PPTimeToTime(last_access_time), | 270 PPTimeToTime(last_access_time), |
| 270 PPTimeToTime(last_modified_time), | 271 PPTimeToTime(last_modified_time), |
| 271 new FileCallbacks(this, callback))) | 272 base::Bind(&FileCallbacks::DidFinish, |
| 273 base::Owned(new FileCallbacks(this, callback))))) |
| 272 return PP_ERROR_FAILED; | 274 return PP_ERROR_FAILED; |
| 273 return PP_OK_COMPLETIONPENDING; | 275 return PP_OK_COMPLETIONPENDING; |
| 274 } | 276 } |
| 275 | 277 |
| 276 int32_t PPB_FileRef_Impl::Delete(scoped_refptr<TrackedCallback> callback) { | 278 int32_t PPB_FileRef_Impl::Delete(scoped_refptr<TrackedCallback> callback) { |
| 277 if (!IsValidNonExternalFileSystem()) | 279 if (!IsValidNonExternalFileSystem()) |
| 278 return PP_ERROR_NOACCESS; | 280 return PP_ERROR_NOACCESS; |
| 279 | 281 |
| 280 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 282 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 281 if (!plugin_instance) | 283 if (!plugin_instance) |
| 282 return PP_ERROR_FAILED; | 284 return PP_ERROR_FAILED; |
| 283 if (!plugin_instance->delegate()->Delete( | 285 if (!plugin_instance->delegate()->Delete( |
| 284 GetFileSystemURL(), | 286 GetFileSystemURL(), |
| 285 new FileCallbacks(this, callback))) | 287 base::Bind(&FileCallbacks::DidFinish, |
| 288 base::Owned(new FileCallbacks(this, callback))))) |
| 286 return PP_ERROR_FAILED; | 289 return PP_ERROR_FAILED; |
| 287 return PP_OK_COMPLETIONPENDING; | 290 return PP_OK_COMPLETIONPENDING; |
| 288 } | 291 } |
| 289 | 292 |
| 290 int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, | 293 int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, |
| 291 scoped_refptr<TrackedCallback> callback) { | 294 scoped_refptr<TrackedCallback> callback) { |
| 292 EnterResourceNoLock<PPB_FileRef_API> enter(new_pp_file_ref, true); | 295 EnterResourceNoLock<PPB_FileRef_API> enter(new_pp_file_ref, true); |
| 293 if (enter.failed()) | 296 if (enter.failed()) |
| 294 return PP_ERROR_BADRESOURCE; | 297 return PP_ERROR_BADRESOURCE; |
| 295 PPB_FileRef_Impl* new_file_ref = | 298 PPB_FileRef_Impl* new_file_ref = |
| 296 static_cast<PPB_FileRef_Impl*>(enter.object()); | 299 static_cast<PPB_FileRef_Impl*>(enter.object()); |
| 297 | 300 |
| 298 if (!IsValidNonExternalFileSystem() || | 301 if (!IsValidNonExternalFileSystem() || |
| 299 file_system_ != new_file_ref->file_system_) | 302 file_system_ != new_file_ref->file_system_) |
| 300 return PP_ERROR_NOACCESS; | 303 return PP_ERROR_NOACCESS; |
| 301 | 304 |
| 302 // TODO(viettrungluu): Also cancel when the new file ref is destroyed? | 305 // TODO(viettrungluu): Also cancel when the new file ref is destroyed? |
| 303 // http://crbug.com/67624 | 306 // http://crbug.com/67624 |
| 304 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 307 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 305 if (!plugin_instance) | 308 if (!plugin_instance) |
| 306 return PP_ERROR_FAILED; | 309 return PP_ERROR_FAILED; |
| 307 if (!plugin_instance->delegate()->Rename( | 310 if (!plugin_instance->delegate()->Rename( |
| 308 GetFileSystemURL(), new_file_ref->GetFileSystemURL(), | 311 GetFileSystemURL(), new_file_ref->GetFileSystemURL(), |
| 309 new FileCallbacks(this, callback))) | 312 base::Bind(&FileCallbacks::DidFinish, |
| 313 base::Owned(new FileCallbacks(this, callback))))) |
| 310 return PP_ERROR_FAILED; | 314 return PP_ERROR_FAILED; |
| 311 return PP_OK_COMPLETIONPENDING; | 315 return PP_OK_COMPLETIONPENDING; |
| 312 } | 316 } |
| 313 | 317 |
| 314 PP_Var PPB_FileRef_Impl::GetAbsolutePath() { | 318 PP_Var PPB_FileRef_Impl::GetAbsolutePath() { |
| 315 if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) | 319 if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) |
| 316 return GetPath(); | 320 return GetPath(); |
| 317 if (!external_path_var_) { | 321 if (!external_path_var_) { |
| 318 external_path_var_ = new StringVar( | 322 external_path_var_ = new StringVar( |
| 319 external_file_system_path_.AsUTF8Unsafe()); | 323 external_file_system_path_.AsUTF8Unsafe()); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 // Non-external file system | 405 // Non-external file system |
| 402 if (!HasValidFileSystem()) | 406 if (!HasValidFileSystem()) |
| 403 return PP_ERROR_NOACCESS; | 407 return PP_ERROR_NOACCESS; |
| 404 | 408 |
| 405 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 409 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 406 PluginDelegate* delegate = | 410 PluginDelegate* delegate = |
| 407 plugin_instance ? plugin_instance->delegate() : NULL; | 411 plugin_instance ? plugin_instance->delegate() : NULL; |
| 408 if (!delegate) | 412 if (!delegate) |
| 409 return PP_ERROR_FAILED; | 413 return PP_ERROR_FAILED; |
| 410 | 414 |
| 415 scoped_ptr<FileCallbacks> callbacks(new FileCallbacks( |
| 416 this, callback, info, |
| 417 delegate->GetFileSystemType(pp_instance(), file_system_))); |
| 411 if (!plugin_instance->delegate()->Query( | 418 if (!plugin_instance->delegate()->Query( |
| 412 GetFileSystemURL(), | 419 GetFileSystemURL(), |
| 413 new FileCallbacks(this, callback, info, | 420 base::Bind(&FileCallbacks::DidReadMetadata, |
| 414 delegate->GetFileSystemType(pp_instance(), | 421 base::Owned(callbacks.release())))) |
| 415 file_system_)))) | |
| 416 return PP_ERROR_FAILED; | 422 return PP_ERROR_FAILED; |
| 417 | 423 |
| 418 } | 424 } |
| 419 return PP_OK_COMPLETIONPENDING; | 425 return PP_OK_COMPLETIONPENDING; |
| 420 } | 426 } |
| 421 | 427 |
| 422 int32_t PPB_FileRef_Impl::ReadDirectoryEntries( | 428 int32_t PPB_FileRef_Impl::ReadDirectoryEntries( |
| 423 const PP_ArrayOutput& output, | 429 const PP_ArrayOutput& output, |
| 424 scoped_refptr<TrackedCallback> callback) { | 430 scoped_refptr<TrackedCallback> callback) { |
| 425 NOTREACHED(); | 431 NOTREACHED(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 437 if (!plugin_instance) | 443 if (!plugin_instance) |
| 438 return PP_ERROR_FAILED; | 444 return PP_ERROR_FAILED; |
| 439 | 445 |
| 440 FileCallbacks::ReadDirectoryEntriesParams params; | 446 FileCallbacks::ReadDirectoryEntriesParams params; |
| 441 params.dir_ref = this; | 447 params.dir_ref = this; |
| 442 params.files = files; | 448 params.files = files; |
| 443 params.file_types = file_types; | 449 params.file_types = file_types; |
| 444 | 450 |
| 445 if (!plugin_instance->delegate()->ReadDirectoryEntries( | 451 if (!plugin_instance->delegate()->ReadDirectoryEntries( |
| 446 GetFileSystemURL(), | 452 GetFileSystemURL(), |
| 447 new FileCallbacks(this, callback, params))) | 453 base::Bind(&FileCallbacks::DidReadDirectory, |
| 454 base::Owned(new FileCallbacks(this, callback, params))))) |
| 448 return PP_ERROR_FAILED; | 455 return PP_ERROR_FAILED; |
| 449 return PP_OK_COMPLETIONPENDING; | 456 return PP_OK_COMPLETIONPENDING; |
| 450 } | 457 } |
| 451 | 458 |
| 452 } // namespace ppapi | 459 } // namespace ppapi |
| 453 } // namespace webkit | 460 } // namespace webkit |
| OLD | NEW |