| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_io_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_file_io_impl.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/file_util_proxy.h" | 9 #include "base/file_util_proxy.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| 11 #include "base/platform_file.h" | 11 #include "base/platform_file.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "ppapi/c/ppb_file_io.h" | 14 #include "ppapi/c/ppb_file_io.h" |
| 15 #include "ppapi/c/trusted/ppb_file_io_trusted.h" | 15 #include "ppapi/c/trusted/ppb_file_io_trusted.h" |
| 16 #include "ppapi/c/pp_completion_callback.h" | 16 #include "ppapi/c/pp_completion_callback.h" |
| 17 #include "ppapi/c/pp_errors.h" | 17 #include "ppapi/c/pp_errors.h" |
| 18 #include "ppapi/thunk/enter.h" | 18 #include "ppapi/thunk/enter.h" |
| 19 #include "ppapi/thunk/ppb_file_ref_api.h" | 19 #include "ppapi/thunk/ppb_file_ref_api.h" |
| 20 #include "webkit/plugins/ppapi/common.h" | 20 #include "webkit/plugins/ppapi/common.h" |
| 21 #include "webkit/plugins/ppapi/file_type_conversions.h" | 21 #include "webkit/plugins/ppapi/file_type_conversions.h" |
| 22 #include "webkit/plugins/ppapi/plugin_module.h" | 22 #include "webkit/plugins/ppapi/plugin_module.h" |
| 23 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 23 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 24 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" | 24 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
| 25 #include "webkit/plugins/ppapi/resource_tracker.h" | 25 #include "webkit/plugins/ppapi/resource_tracker.h" |
| 26 #include "webkit/plugins/ppapi/time_conversion.h" |
| 26 | 27 |
| 27 using ppapi::thunk::EnterResourceNoLock; | 28 using ppapi::thunk::EnterResourceNoLock; |
| 28 using ppapi::thunk::PPB_FileIO_API; | 29 using ppapi::thunk::PPB_FileIO_API; |
| 29 using ppapi::thunk::PPB_FileRef_API; | 30 using ppapi::thunk::PPB_FileRef_API; |
| 30 | 31 |
| 31 namespace webkit { | 32 namespace webkit { |
| 32 namespace ppapi { | 33 namespace ppapi { |
| 33 | 34 |
| 34 PPB_FileIO_Impl::PPB_FileIO_Impl(PluginInstance* instance) | 35 PPB_FileIO_Impl::PPB_FileIO_Impl(PluginInstance* instance) |
| 35 : Resource(instance), | 36 : Resource(instance), |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( | 105 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( |
| 105 instance()->delegate()->GetFileThreadMessageLoopProxy(), file_, | 106 instance()->delegate()->GetFileThreadMessageLoopProxy(), file_, |
| 106 callback_factory_.NewCallback(&PPB_FileIO_Impl::QueryInfoCallback))) | 107 callback_factory_.NewCallback(&PPB_FileIO_Impl::QueryInfoCallback))) |
| 107 return PP_ERROR_FAILED; | 108 return PP_ERROR_FAILED; |
| 108 | 109 |
| 109 RegisterCallback(callback); | 110 RegisterCallback(callback); |
| 110 return PP_OK_COMPLETIONPENDING; | 111 return PP_OK_COMPLETIONPENDING; |
| 111 } | 112 } |
| 112 | 113 |
| 113 int32_t PPB_FileIO_Impl::Touch(PP_Time last_access_time, | 114 int32_t PPB_FileIO_Impl::Touch(PP_Time last_access_time, |
| 114 PP_Time last_modified_time, | 115 PP_Time last_modified_time, |
| 115 PP_CompletionCallback callback) { | 116 PP_CompletionCallback callback) { |
| 116 int32_t rv = CommonCallValidation(true, callback); | 117 int32_t rv = CommonCallValidation(true, callback); |
| 117 if (rv != PP_OK) | 118 if (rv != PP_OK) |
| 118 return rv; | 119 return rv; |
| 119 | 120 |
| 120 if (!base::FileUtilProxy::Touch( | 121 if (!base::FileUtilProxy::Touch( |
| 121 instance()->delegate()->GetFileThreadMessageLoopProxy(), | 122 instance()->delegate()->GetFileThreadMessageLoopProxy(), |
| 122 file_, base::Time::FromDoubleT(last_access_time), | 123 file_, PPTimeToTime(last_access_time), |
| 123 base::Time::FromDoubleT(last_modified_time), | 124 PPTimeToTime(last_modified_time), |
| 124 callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback))) | 125 callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback))) |
| 125 return PP_ERROR_FAILED; | 126 return PP_ERROR_FAILED; |
| 126 | 127 |
| 127 RegisterCallback(callback); | 128 RegisterCallback(callback); |
| 128 return PP_OK_COMPLETIONPENDING; | 129 return PP_OK_COMPLETIONPENDING; |
| 129 } | 130 } |
| 130 | 131 |
| 131 int32_t PPB_FileIO_Impl::Read(int64_t offset, | 132 int32_t PPB_FileIO_Impl::Read(int64_t offset, |
| 132 char* buffer, | 133 char* buffer, |
| 133 int32_t bytes_to_read, | 134 int32_t bytes_to_read, |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 file_ = file; | 279 file_ = file; |
| 279 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); | 280 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); |
| 280 } | 281 } |
| 281 | 282 |
| 282 void PPB_FileIO_Impl::QueryInfoCallback( | 283 void PPB_FileIO_Impl::QueryInfoCallback( |
| 283 base::PlatformFileError error_code, | 284 base::PlatformFileError error_code, |
| 284 const base::PlatformFileInfo& file_info) { | 285 const base::PlatformFileInfo& file_info) { |
| 285 DCHECK(info_); | 286 DCHECK(info_); |
| 286 if (error_code == base::PLATFORM_FILE_OK) { | 287 if (error_code == base::PLATFORM_FILE_OK) { |
| 287 info_->size = file_info.size; | 288 info_->size = file_info.size; |
| 288 info_->creation_time = file_info.creation_time.ToDoubleT(); | 289 info_->creation_time = TimeToPPTime(file_info.creation_time); |
| 289 info_->last_access_time = file_info.last_accessed.ToDoubleT(); | 290 info_->last_access_time = TimeToPPTime(file_info.last_accessed); |
| 290 info_->last_modified_time = file_info.last_modified.ToDoubleT(); | 291 info_->last_modified_time = TimeToPPTime(file_info.last_modified); |
| 291 info_->system_type = file_system_type_; | 292 info_->system_type = file_system_type_; |
| 292 if (file_info.is_directory) | 293 if (file_info.is_directory) |
| 293 info_->type = PP_FILETYPE_DIRECTORY; | 294 info_->type = PP_FILETYPE_DIRECTORY; |
| 294 else | 295 else |
| 295 info_->type = PP_FILETYPE_REGULAR; | 296 info_->type = PP_FILETYPE_REGULAR; |
| 296 } | 297 } |
| 297 info_ = NULL; | 298 info_ = NULL; |
| 298 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); | 299 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); |
| 299 } | 300 } |
| 300 | 301 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 319 void PPB_FileIO_Impl::WriteCallback(base::PlatformFileError error_code, | 320 void PPB_FileIO_Impl::WriteCallback(base::PlatformFileError error_code, |
| 320 int bytes_written) { | 321 int bytes_written) { |
| 321 if (error_code != base::PLATFORM_FILE_OK) | 322 if (error_code != base::PLATFORM_FILE_OK) |
| 322 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); | 323 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); |
| 323 else | 324 else |
| 324 RunPendingCallback(bytes_written); | 325 RunPendingCallback(bytes_written); |
| 325 } | 326 } |
| 326 | 327 |
| 327 } // namespace ppapi | 328 } // namespace ppapi |
| 328 } // namespace webkit | 329 } // namespace webkit |
| OLD | NEW |