| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/file_util_proxy.h" | 10 #include "base/file_util_proxy.h" |
| 11 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
| 12 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "ppapi/c/ppb_file_io.h" | 15 #include "ppapi/c/ppb_file_io.h" |
| 16 #include "ppapi/c/trusted/ppb_file_io_trusted.h" | 16 #include "ppapi/c/trusted/ppb_file_io_trusted.h" |
| 17 #include "ppapi/c/pp_completion_callback.h" | 17 #include "ppapi/c/pp_completion_callback.h" |
| 18 #include "ppapi/c/pp_errors.h" | 18 #include "ppapi/c/pp_errors.h" |
| 19 #include "ppapi/shared_impl/file_type_conversion.h" | 19 #include "ppapi/shared_impl/file_type_conversion.h" |
| 20 #include "ppapi/shared_impl/time_conversion.h" | 20 #include "ppapi/shared_impl/time_conversion.h" |
| 21 #include "ppapi/thunk/enter.h" | 21 #include "ppapi/thunk/enter.h" |
| 22 #include "ppapi/thunk/ppb_file_ref_api.h" | 22 #include "ppapi/thunk/ppb_file_ref_api.h" |
| 23 #include "webkit/plugins/ppapi/common.h" | 23 #include "webkit/plugins/ppapi/common.h" |
| 24 #include "webkit/plugins/ppapi/plugin_module.h" | 24 #include "webkit/plugins/ppapi/plugin_module.h" |
| 25 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 25 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 26 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" | 26 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
| 27 #include "webkit/plugins/ppapi/quota_file_io.h" | 27 #include "webkit/plugins/ppapi/quota_file_io.h" |
| 28 #include "webkit/plugins/ppapi/resource_helper.h" | 28 #include "webkit/plugins/ppapi/resource_helper.h" |
| 29 | 29 |
| 30 using ppapi::ApiCallbackType; |
| 30 using ppapi::PPTimeToTime; | 31 using ppapi::PPTimeToTime; |
| 31 using ppapi::TimeToPPTime; | 32 using ppapi::TimeToPPTime; |
| 32 using ppapi::thunk::PPB_FileRef_API; | 33 using ppapi::thunk::PPB_FileRef_API; |
| 33 | 34 |
| 34 namespace webkit { | 35 namespace webkit { |
| 35 namespace ppapi { | 36 namespace ppapi { |
| 36 | 37 |
| 37 PPB_FileIO_Impl::PPB_FileIO_Impl(PP_Instance instance) | 38 PPB_FileIO_Impl::PPB_FileIO_Impl(PP_Instance instance) |
| 38 : ::ppapi::PPB_FileIO_Shared(instance), | 39 : ::ppapi::PPB_FileIO_Shared(instance), |
| 39 file_(base::kInvalidPlatformFileValue), | 40 file_(base::kInvalidPlatformFileValue), |
| 40 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 41 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 41 } | 42 } |
| 42 | 43 |
| 43 PPB_FileIO_Impl::~PPB_FileIO_Impl() { | 44 PPB_FileIO_Impl::~PPB_FileIO_Impl() { |
| 44 Close(); | 45 Close(); |
| 45 } | 46 } |
| 46 | 47 |
| 47 int32_t PPB_FileIO_Impl::OpenValidated(PP_Resource file_ref_resource, | 48 int32_t PPB_FileIO_Impl::OpenValidated(PP_Resource file_ref_resource, |
| 48 PPB_FileRef_API* file_ref_api, | 49 PPB_FileRef_API* file_ref_api, |
| 49 int32_t open_flags, | 50 int32_t open_flags, |
| 50 PP_CompletionCallback callback) { | 51 ApiCallbackType callback) { |
| 51 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(file_ref_api); | 52 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(file_ref_api); |
| 52 | 53 |
| 53 int flags = 0; | 54 int flags = 0; |
| 54 if (!::ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags, &flags)) | 55 if (!::ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags, &flags)) |
| 55 return PP_ERROR_BADARGUMENT; | 56 return PP_ERROR_BADARGUMENT; |
| 56 | 57 |
| 57 PluginDelegate* plugin_delegate = GetPluginDelegate(); | 58 PluginDelegate* plugin_delegate = GetPluginDelegate(); |
| 58 if (!plugin_delegate) | 59 if (!plugin_delegate) |
| 59 return PP_ERROR_BADARGUMENT; | 60 return PP_ERROR_BADARGUMENT; |
| 60 | 61 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 73 base::Bind(&PPB_FileIO_Impl::ExecutePlatformOpenFileCallback, | 74 base::Bind(&PPB_FileIO_Impl::ExecutePlatformOpenFileCallback, |
| 74 weak_factory_.GetWeakPtr()))) | 75 weak_factory_.GetWeakPtr()))) |
| 75 return PP_ERROR_FAILED; | 76 return PP_ERROR_FAILED; |
| 76 } | 77 } |
| 77 | 78 |
| 78 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); | 79 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); |
| 79 return PP_OK_COMPLETIONPENDING; | 80 return PP_OK_COMPLETIONPENDING; |
| 80 } | 81 } |
| 81 | 82 |
| 82 int32_t PPB_FileIO_Impl::QueryValidated(PP_FileInfo* info, | 83 int32_t PPB_FileIO_Impl::QueryValidated(PP_FileInfo* info, |
| 83 PP_CompletionCallback callback) { | 84 ApiCallbackType callback) { |
| 84 PluginDelegate* plugin_delegate = GetPluginDelegate(); | 85 PluginDelegate* plugin_delegate = GetPluginDelegate(); |
| 85 if (!plugin_delegate) | 86 if (!plugin_delegate) |
| 86 return PP_ERROR_FAILED; | 87 return PP_ERROR_FAILED; |
| 87 | 88 |
| 88 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( | 89 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( |
| 89 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, | 90 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, |
| 90 base::Bind(&PPB_FileIO_Impl::ExecutePlatformQueryCallback, | 91 base::Bind(&PPB_FileIO_Impl::ExecutePlatformQueryCallback, |
| 91 weak_factory_.GetWeakPtr()))) | 92 weak_factory_.GetWeakPtr()))) |
| 92 return PP_ERROR_FAILED; | 93 return PP_ERROR_FAILED; |
| 93 | 94 |
| 94 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, info); | 95 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, info); |
| 95 return PP_OK_COMPLETIONPENDING; | 96 return PP_OK_COMPLETIONPENDING; |
| 96 } | 97 } |
| 97 | 98 |
| 98 int32_t PPB_FileIO_Impl::TouchValidated(PP_Time last_access_time, | 99 int32_t PPB_FileIO_Impl::TouchValidated(PP_Time last_access_time, |
| 99 PP_Time last_modified_time, | 100 PP_Time last_modified_time, |
| 100 PP_CompletionCallback callback) { | 101 ApiCallbackType callback) { |
| 101 PluginDelegate* plugin_delegate = GetPluginDelegate(); | 102 PluginDelegate* plugin_delegate = GetPluginDelegate(); |
| 102 if (!plugin_delegate) | 103 if (!plugin_delegate) |
| 103 return PP_ERROR_FAILED; | 104 return PP_ERROR_FAILED; |
| 104 | 105 |
| 105 if (!base::FileUtilProxy::Touch( | 106 if (!base::FileUtilProxy::Touch( |
| 106 plugin_delegate->GetFileThreadMessageLoopProxy(), | 107 plugin_delegate->GetFileThreadMessageLoopProxy(), |
| 107 file_, PPTimeToTime(last_access_time), | 108 file_, PPTimeToTime(last_access_time), |
| 108 PPTimeToTime(last_modified_time), | 109 PPTimeToTime(last_modified_time), |
| 109 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback, | 110 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback, |
| 110 weak_factory_.GetWeakPtr()))) | 111 weak_factory_.GetWeakPtr()))) |
| 111 return PP_ERROR_FAILED; | 112 return PP_ERROR_FAILED; |
| 112 | 113 |
| 113 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); | 114 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); |
| 114 return PP_OK_COMPLETIONPENDING; | 115 return PP_OK_COMPLETIONPENDING; |
| 115 } | 116 } |
| 116 | 117 |
| 117 int32_t PPB_FileIO_Impl::ReadValidated(int64_t offset, | 118 int32_t PPB_FileIO_Impl::ReadValidated(int64_t offset, |
| 118 char* buffer, | 119 char* buffer, |
| 119 int32_t bytes_to_read, | 120 int32_t bytes_to_read, |
| 120 PP_CompletionCallback callback) { | 121 ApiCallbackType callback) { |
| 121 PluginDelegate* plugin_delegate = GetPluginDelegate(); | 122 PluginDelegate* plugin_delegate = GetPluginDelegate(); |
| 122 if (!plugin_delegate) | 123 if (!plugin_delegate) |
| 123 return PP_ERROR_FAILED; | 124 return PP_ERROR_FAILED; |
| 124 | 125 |
| 125 if (!base::FileUtilProxy::Read( | 126 if (!base::FileUtilProxy::Read( |
| 126 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, offset, | 127 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, offset, |
| 127 bytes_to_read, | 128 bytes_to_read, |
| 128 base::Bind(&PPB_FileIO_Impl::ExecutePlatformReadCallback, | 129 base::Bind(&PPB_FileIO_Impl::ExecutePlatformReadCallback, |
| 129 weak_factory_.GetWeakPtr()))) | 130 weak_factory_.GetWeakPtr()))) |
| 130 return PP_ERROR_FAILED; | 131 return PP_ERROR_FAILED; |
| 131 | 132 |
| 132 RegisterCallback(OPERATION_READ, callback, buffer, NULL); | 133 RegisterCallback(OPERATION_READ, callback, buffer, NULL); |
| 133 return PP_OK_COMPLETIONPENDING; | 134 return PP_OK_COMPLETIONPENDING; |
| 134 } | 135 } |
| 135 | 136 |
| 136 int32_t PPB_FileIO_Impl::WriteValidated(int64_t offset, | 137 int32_t PPB_FileIO_Impl::WriteValidated(int64_t offset, |
| 137 const char* buffer, | 138 const char* buffer, |
| 138 int32_t bytes_to_write, | 139 int32_t bytes_to_write, |
| 139 PP_CompletionCallback callback) { | 140 ApiCallbackType callback) { |
| 140 PluginDelegate* plugin_delegate = GetPluginDelegate(); | 141 PluginDelegate* plugin_delegate = GetPluginDelegate(); |
| 141 if (!plugin_delegate) | 142 if (!plugin_delegate) |
| 142 return PP_ERROR_FAILED; | 143 return PP_ERROR_FAILED; |
| 143 | 144 |
| 144 if (quota_file_io_.get()) { | 145 if (quota_file_io_.get()) { |
| 145 if (!quota_file_io_->Write( | 146 if (!quota_file_io_->Write( |
| 146 offset, buffer, bytes_to_write, | 147 offset, buffer, bytes_to_write, |
| 147 base::Bind(&PPB_FileIO_Impl::ExecutePlatformWriteCallback, | 148 base::Bind(&PPB_FileIO_Impl::ExecutePlatformWriteCallback, |
| 148 weak_factory_.GetWeakPtr()))) | 149 weak_factory_.GetWeakPtr()))) |
| 149 return PP_ERROR_FAILED; | 150 return PP_ERROR_FAILED; |
| 150 } else { | 151 } else { |
| 151 if (!base::FileUtilProxy::Write( | 152 if (!base::FileUtilProxy::Write( |
| 152 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, offset, | 153 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, offset, |
| 153 buffer, bytes_to_write, | 154 buffer, bytes_to_write, |
| 154 base::Bind(&PPB_FileIO_Impl::ExecutePlatformWriteCallback, | 155 base::Bind(&PPB_FileIO_Impl::ExecutePlatformWriteCallback, |
| 155 weak_factory_.GetWeakPtr()))) | 156 weak_factory_.GetWeakPtr()))) |
| 156 return PP_ERROR_FAILED; | 157 return PP_ERROR_FAILED; |
| 157 } | 158 } |
| 158 | 159 |
| 159 RegisterCallback(OPERATION_WRITE, callback, NULL, NULL); | 160 RegisterCallback(OPERATION_WRITE, callback, NULL, NULL); |
| 160 return PP_OK_COMPLETIONPENDING; | 161 return PP_OK_COMPLETIONPENDING; |
| 161 } | 162 } |
| 162 | 163 |
| 163 int32_t PPB_FileIO_Impl::SetLengthValidated(int64_t length, | 164 int32_t PPB_FileIO_Impl::SetLengthValidated(int64_t length, |
| 164 PP_CompletionCallback callback) { | 165 ApiCallbackType callback) { |
| 165 PluginDelegate* plugin_delegate = GetPluginDelegate(); | 166 PluginDelegate* plugin_delegate = GetPluginDelegate(); |
| 166 if (!plugin_delegate) | 167 if (!plugin_delegate) |
| 167 return PP_ERROR_FAILED; | 168 return PP_ERROR_FAILED; |
| 168 | 169 |
| 169 if (quota_file_io_.get()) { | 170 if (quota_file_io_.get()) { |
| 170 if (!quota_file_io_->SetLength( | 171 if (!quota_file_io_->SetLength( |
| 171 length, | 172 length, |
| 172 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback, | 173 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback, |
| 173 weak_factory_.GetWeakPtr()))) | 174 weak_factory_.GetWeakPtr()))) |
| 174 return PP_ERROR_FAILED; | 175 return PP_ERROR_FAILED; |
| 175 } else { | 176 } else { |
| 176 if (!base::FileUtilProxy::Truncate( | 177 if (!base::FileUtilProxy::Truncate( |
| 177 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, length, | 178 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, length, |
| 178 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback, | 179 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback, |
| 179 weak_factory_.GetWeakPtr()))) | 180 weak_factory_.GetWeakPtr()))) |
| 180 return PP_ERROR_FAILED; | 181 return PP_ERROR_FAILED; |
| 181 } | 182 } |
| 182 | 183 |
| 183 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); | 184 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); |
| 184 return PP_OK_COMPLETIONPENDING; | 185 return PP_OK_COMPLETIONPENDING; |
| 185 } | 186 } |
| 186 | 187 |
| 187 int32_t PPB_FileIO_Impl::FlushValidated(PP_CompletionCallback callback) { | 188 int32_t PPB_FileIO_Impl::FlushValidated(ApiCallbackType callback) { |
| 188 PluginDelegate* plugin_delegate = GetPluginDelegate(); | 189 PluginDelegate* plugin_delegate = GetPluginDelegate(); |
| 189 if (!plugin_delegate) | 190 if (!plugin_delegate) |
| 190 return PP_ERROR_FAILED; | 191 return PP_ERROR_FAILED; |
| 191 | 192 |
| 192 if (!base::FileUtilProxy::Flush( | 193 if (!base::FileUtilProxy::Flush( |
| 193 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, | 194 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, |
| 194 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback, | 195 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback, |
| 195 weak_factory_.GetWeakPtr()))) | 196 weak_factory_.GetWeakPtr()))) |
| 196 return PP_ERROR_FAILED; | 197 return PP_ERROR_FAILED; |
| 197 | 198 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 215 return file_; | 216 return file_; |
| 216 #elif defined(OS_WIN) | 217 #elif defined(OS_WIN) |
| 217 return reinterpret_cast<uintptr_t>(file_); | 218 return reinterpret_cast<uintptr_t>(file_); |
| 218 #else | 219 #else |
| 219 #error "Platform not supported." | 220 #error "Platform not supported." |
| 220 #endif | 221 #endif |
| 221 } | 222 } |
| 222 | 223 |
| 223 int32_t PPB_FileIO_Impl::WillWrite(int64_t offset, | 224 int32_t PPB_FileIO_Impl::WillWrite(int64_t offset, |
| 224 int32_t bytes_to_write, | 225 int32_t bytes_to_write, |
| 225 PP_CompletionCallback callback) { | 226 ApiCallbackType callback) { |
| 226 int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE, callback); | 227 int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE); |
| 227 if (rv != PP_OK) | 228 if (rv != PP_OK) |
| 228 return rv; | 229 return rv; |
| 229 | 230 |
| 230 if (!quota_file_io_.get()) | 231 if (!quota_file_io_.get()) |
| 231 return PP_OK; | 232 return PP_OK; |
| 232 | 233 |
| 233 if (!quota_file_io_->WillWrite( | 234 if (!quota_file_io_->WillWrite( |
| 234 offset, bytes_to_write, | 235 offset, bytes_to_write, |
| 235 base::Bind(&PPB_FileIO_Impl::ExecutePlatformWillWriteCallback, | 236 base::Bind(&PPB_FileIO_Impl::ExecutePlatformWillWriteCallback, |
| 236 weak_factory_.GetWeakPtr()))) | 237 weak_factory_.GetWeakPtr()))) |
| 237 return PP_ERROR_FAILED; | 238 return PP_ERROR_FAILED; |
| 238 | 239 |
| 239 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); | 240 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); |
| 240 return PP_OK_COMPLETIONPENDING; | 241 return PP_OK_COMPLETIONPENDING; |
| 241 } | 242 } |
| 242 | 243 |
| 243 int32_t PPB_FileIO_Impl::WillSetLength(int64_t length, | 244 int32_t PPB_FileIO_Impl::WillSetLength(int64_t length, |
| 244 PP_CompletionCallback callback) { | 245 ApiCallbackType callback) { |
| 245 int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE, callback); | 246 int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE); |
| 246 if (rv != PP_OK) | 247 if (rv != PP_OK) |
| 247 return rv; | 248 return rv; |
| 248 | 249 |
| 249 if (!quota_file_io_.get()) | 250 if (!quota_file_io_.get()) |
| 250 return PP_OK; | 251 return PP_OK; |
| 251 | 252 |
| 252 if (!quota_file_io_->WillSetLength( | 253 if (!quota_file_io_->WillSetLength( |
| 253 length, | 254 length, |
| 254 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback, | 255 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback, |
| 255 weak_factory_.GetWeakPtr()))) | 256 weak_factory_.GetWeakPtr()))) |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 if (error_code != base::PLATFORM_FILE_OK) { | 331 if (error_code != base::PLATFORM_FILE_OK) { |
| 331 RunAndRemoveFirstPendingCallback( | 332 RunAndRemoveFirstPendingCallback( |
| 332 ::ppapi::PlatformFileErrorToPepperError(error_code)); | 333 ::ppapi::PlatformFileErrorToPepperError(error_code)); |
| 333 } else { | 334 } else { |
| 334 RunAndRemoveFirstPendingCallback(bytes_written); | 335 RunAndRemoveFirstPendingCallback(bytes_written); |
| 335 } | 336 } |
| 336 } | 337 } |
| 337 | 338 |
| 338 } // namespace ppapi | 339 } // namespace ppapi |
| 339 } // namespace webkit | 340 } // namespace webkit |
| OLD | NEW |