| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/glue/plugins/pepper_file_io.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/dev/ppb_file_io_dev.h" | 14 #include "ppapi/c/dev/ppb_file_io_dev.h" |
| 15 #include "ppapi/c/dev/ppb_file_io_trusted_dev.h" | 15 #include "ppapi/c/dev/ppb_file_io_trusted_dev.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 "webkit/glue/plugins/pepper_common.h" | 18 #include "webkit/plugins/ppapi/common.h" |
| 19 #include "webkit/glue/plugins/pepper_file_ref.h" | 19 #include "webkit/plugins/ppapi/plugin_instance.h" |
| 20 #include "webkit/glue/plugins/pepper_plugin_instance.h" | 20 #include "webkit/plugins/ppapi/plugin_module.h" |
| 21 #include "webkit/glue/plugins/pepper_plugin_module.h" | 21 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
| 22 #include "webkit/glue/plugins/pepper_resource_tracker.h" | 22 #include "webkit/plugins/ppapi/resource_tracker.h" |
| 23 | 23 |
| 24 namespace pepper { | 24 namespace webkit { |
| 25 namespace plugins { |
| 26 namespace ppapi { |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 PP_Resource Create(PP_Module module_id) { | 30 PP_Resource Create(PP_Module module_id) { |
| 29 PluginModule* module = ResourceTracker::Get()->GetModule(module_id); | 31 PluginModule* module = ResourceTracker::Get()->GetModule(module_id); |
| 30 if (!module) | 32 if (!module) |
| 31 return 0; | 33 return 0; |
| 32 | 34 |
| 33 FileIO* file_io = new FileIO(module); | 35 PPB_FileIO_Impl* file_io = new PPB_FileIO_Impl(module); |
| 34 return file_io->GetReference(); | 36 return file_io->GetReference(); |
| 35 } | 37 } |
| 36 | 38 |
| 37 PP_Bool IsFileIO(PP_Resource resource) { | 39 PP_Bool IsFileIO(PP_Resource resource) { |
| 38 return BoolToPPBool(!!Resource::GetAs<FileIO>(resource)); | 40 return BoolToPPBool(!!Resource::GetAs<PPB_FileIO_Impl>(resource)); |
| 39 } | 41 } |
| 40 | 42 |
| 41 int32_t Open(PP_Resource file_io_id, | 43 int32_t Open(PP_Resource file_io_id, |
| 42 PP_Resource file_ref_id, | 44 PP_Resource file_ref_id, |
| 43 int32_t open_flags, | 45 int32_t open_flags, |
| 44 PP_CompletionCallback callback) { | 46 PP_CompletionCallback callback) { |
| 45 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 47 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
| 46 if (!file_io) | 48 if (!file_io) |
| 47 return PP_ERROR_BADRESOURCE; | 49 return PP_ERROR_BADRESOURCE; |
| 48 | 50 |
| 49 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); | 51 scoped_refptr<PPB_FileRef_Impl> file_ref( |
| 52 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
| 50 if (!file_ref) | 53 if (!file_ref) |
| 51 return PP_ERROR_BADRESOURCE; | 54 return PP_ERROR_BADRESOURCE; |
| 52 | 55 |
| 53 return file_io->Open(file_ref, open_flags, callback); | 56 return file_io->Open(file_ref, open_flags, callback); |
| 54 } | 57 } |
| 55 | 58 |
| 56 int32_t Query(PP_Resource file_io_id, | 59 int32_t Query(PP_Resource file_io_id, |
| 57 PP_FileInfo_Dev* info, | 60 PP_FileInfo_Dev* info, |
| 58 PP_CompletionCallback callback) { | 61 PP_CompletionCallback callback) { |
| 59 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 62 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
| 60 if (!file_io) | 63 if (!file_io) |
| 61 return PP_ERROR_BADRESOURCE; | 64 return PP_ERROR_BADRESOURCE; |
| 62 return file_io->Query(info, callback); | 65 return file_io->Query(info, callback); |
| 63 } | 66 } |
| 64 | 67 |
| 65 int32_t Touch(PP_Resource file_io_id, | 68 int32_t Touch(PP_Resource file_io_id, |
| 66 PP_Time last_access_time, | 69 PP_Time last_access_time, |
| 67 PP_Time last_modified_time, | 70 PP_Time last_modified_time, |
| 68 PP_CompletionCallback callback) { | 71 PP_CompletionCallback callback) { |
| 69 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 72 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
| 70 if (!file_io) | 73 if (!file_io) |
| 71 return PP_ERROR_BADRESOURCE; | 74 return PP_ERROR_BADRESOURCE; |
| 72 return file_io->Touch(last_access_time, last_modified_time, callback); | 75 return file_io->Touch(last_access_time, last_modified_time, callback); |
| 73 } | 76 } |
| 74 | 77 |
| 75 int32_t Read(PP_Resource file_io_id, | 78 int32_t Read(PP_Resource file_io_id, |
| 76 int64_t offset, | 79 int64_t offset, |
| 77 char* buffer, | 80 char* buffer, |
| 78 int32_t bytes_to_read, | 81 int32_t bytes_to_read, |
| 79 PP_CompletionCallback callback) { | 82 PP_CompletionCallback callback) { |
| 80 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 83 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
| 81 if (!file_io) | 84 if (!file_io) |
| 82 return PP_ERROR_BADRESOURCE; | 85 return PP_ERROR_BADRESOURCE; |
| 83 return file_io->Read(offset, buffer, bytes_to_read, callback); | 86 return file_io->Read(offset, buffer, bytes_to_read, callback); |
| 84 } | 87 } |
| 85 | 88 |
| 86 int32_t Write(PP_Resource file_io_id, | 89 int32_t Write(PP_Resource file_io_id, |
| 87 int64_t offset, | 90 int64_t offset, |
| 88 const char* buffer, | 91 const char* buffer, |
| 89 int32_t bytes_to_write, | 92 int32_t bytes_to_write, |
| 90 PP_CompletionCallback callback) { | 93 PP_CompletionCallback callback) { |
| 91 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 94 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
| 92 if (!file_io) | 95 if (!file_io) |
| 93 return PP_ERROR_BADRESOURCE; | 96 return PP_ERROR_BADRESOURCE; |
| 94 return file_io->Write(offset, buffer, bytes_to_write, callback); | 97 return file_io->Write(offset, buffer, bytes_to_write, callback); |
| 95 } | 98 } |
| 96 | 99 |
| 97 int32_t SetLength(PP_Resource file_io_id, | 100 int32_t SetLength(PP_Resource file_io_id, |
| 98 int64_t length, | 101 int64_t length, |
| 99 PP_CompletionCallback callback) { | 102 PP_CompletionCallback callback) { |
| 100 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 103 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
| 101 if (!file_io) | 104 if (!file_io) |
| 102 return PP_ERROR_BADRESOURCE; | 105 return PP_ERROR_BADRESOURCE; |
| 103 return file_io->SetLength(length, callback); | 106 return file_io->SetLength(length, callback); |
| 104 } | 107 } |
| 105 | 108 |
| 106 int32_t Flush(PP_Resource file_io_id, | 109 int32_t Flush(PP_Resource file_io_id, |
| 107 PP_CompletionCallback callback) { | 110 PP_CompletionCallback callback) { |
| 108 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 111 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
| 109 if (!file_io) | 112 if (!file_io) |
| 110 return PP_ERROR_BADRESOURCE; | 113 return PP_ERROR_BADRESOURCE; |
| 111 return file_io->Flush(callback); | 114 return file_io->Flush(callback); |
| 112 } | 115 } |
| 113 | 116 |
| 114 void Close(PP_Resource file_io_id) { | 117 void Close(PP_Resource file_io_id) { |
| 115 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 118 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
| 116 if (!file_io) | 119 if (!file_io) |
| 117 return; | 120 return; |
| 118 file_io->Close(); | 121 file_io->Close(); |
| 119 } | 122 } |
| 120 | 123 |
| 121 const PPB_FileIO_Dev ppb_fileio = { | 124 const PPB_FileIO_Dev ppb_fileio = { |
| 122 &Create, | 125 &Create, |
| 123 &IsFileIO, | 126 &IsFileIO, |
| 124 &Open, | 127 &Open, |
| 125 &Query, | 128 &Query, |
| 126 &Touch, | 129 &Touch, |
| 127 &Read, | 130 &Read, |
| 128 &Write, | 131 &Write, |
| 129 &SetLength, | 132 &SetLength, |
| 130 &Flush, | 133 &Flush, |
| 131 &Close | 134 &Close |
| 132 }; | 135 }; |
| 133 | 136 |
| 134 int32_t GetOSFileDescriptor(PP_Resource file_io_id) { | 137 int32_t GetOSFileDescriptor(PP_Resource file_io_id) { |
| 135 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 138 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
| 136 if (!file_io) | 139 if (!file_io) |
| 137 return PP_ERROR_BADRESOURCE; | 140 return PP_ERROR_BADRESOURCE; |
| 138 return file_io->GetOSFileDescriptor(); | 141 return file_io->GetOSFileDescriptor(); |
| 139 } | 142 } |
| 140 | 143 |
| 141 int32_t WillWrite(PP_Resource file_io_id, | 144 int32_t WillWrite(PP_Resource file_io_id, |
| 142 int64_t offset, | 145 int64_t offset, |
| 143 int32_t bytes_to_write, | 146 int32_t bytes_to_write, |
| 144 PP_CompletionCallback callback) { | 147 PP_CompletionCallback callback) { |
| 145 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 148 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
| 146 if (!file_io) | 149 if (!file_io) |
| 147 return PP_ERROR_BADRESOURCE; | 150 return PP_ERROR_BADRESOURCE; |
| 148 return file_io->WillWrite(offset, bytes_to_write, callback); | 151 return file_io->WillWrite(offset, bytes_to_write, callback); |
| 149 } | 152 } |
| 150 | 153 |
| 151 int32_t WillSetLength(PP_Resource file_io_id, | 154 int32_t WillSetLength(PP_Resource file_io_id, |
| 152 int64_t length, | 155 int64_t length, |
| 153 PP_CompletionCallback callback) { | 156 PP_CompletionCallback callback) { |
| 154 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 157 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
| 155 if (!file_io) | 158 if (!file_io) |
| 156 return PP_ERROR_BADRESOURCE; | 159 return PP_ERROR_BADRESOURCE; |
| 157 return file_io->WillSetLength(length, callback); | 160 return file_io->WillSetLength(length, callback); |
| 158 } | 161 } |
| 159 | 162 |
| 160 const PPB_FileIOTrusted_Dev ppb_fileiotrusted = { | 163 const PPB_FileIOTrusted_Dev ppb_fileiotrusted = { |
| 161 &GetOSFileDescriptor, | 164 &GetOSFileDescriptor, |
| 162 &WillWrite, | 165 &WillWrite, |
| 163 &WillSetLength | 166 &WillSetLength |
| 164 }; | 167 }; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 180 case base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY: | 183 case base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY: |
| 181 NOTREACHED(); | 184 NOTREACHED(); |
| 182 return PP_ERROR_FAILED; | 185 return PP_ERROR_FAILED; |
| 183 default: | 186 default: |
| 184 return PP_ERROR_FAILED; | 187 return PP_ERROR_FAILED; |
| 185 } | 188 } |
| 186 } | 189 } |
| 187 | 190 |
| 188 } // namespace | 191 } // namespace |
| 189 | 192 |
| 190 FileIO::FileIO(PluginModule* module) | 193 PPB_FileIO_Impl::PPB_FileIO_Impl(PluginModule* module) |
| 191 : Resource(module), | 194 : Resource(module), |
| 192 delegate_(module->GetSomeInstance()->delegate()), | 195 delegate_(module->GetSomeInstance()->delegate()), |
| 193 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)), | 196 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)), |
| 194 file_(base::kInvalidPlatformFileValue), | 197 file_(base::kInvalidPlatformFileValue), |
| 195 callback_(), | 198 callback_(), |
| 196 info_(NULL) { | 199 info_(NULL) { |
| 197 } | 200 } |
| 198 | 201 |
| 199 FileIO::~FileIO() { | 202 PPB_FileIO_Impl::~PPB_FileIO_Impl() { |
| 200 Close(); | 203 Close(); |
| 201 } | 204 } |
| 202 | 205 |
| 203 // static | 206 // static |
| 204 const PPB_FileIO_Dev* FileIO::GetInterface() { | 207 const PPB_FileIO_Dev* PPB_FileIO_Impl::GetInterface() { |
| 205 return &ppb_fileio; | 208 return &ppb_fileio; |
| 206 } | 209 } |
| 207 | 210 |
| 208 // static | 211 // static |
| 209 const PPB_FileIOTrusted_Dev* FileIO::GetTrustedInterface() { | 212 const PPB_FileIOTrusted_Dev* PPB_FileIO_Impl::GetTrustedInterface() { |
| 210 return &ppb_fileiotrusted; | 213 return &ppb_fileiotrusted; |
| 211 } | 214 } |
| 212 | 215 |
| 213 FileIO* FileIO::AsFileIO() { | 216 PPB_FileIO_Impl* PPB_FileIO_Impl::AsFileIO() { |
| 214 return this; | 217 return this; |
| 215 } | 218 } |
| 216 | 219 |
| 217 int32_t FileIO::Open(FileRef* file_ref, | 220 int32_t PPB_FileIO_Impl::Open(PPB_FileRef_Impl* file_ref, |
| 218 int32_t open_flags, | 221 int32_t open_flags, |
| 219 PP_CompletionCallback callback) { | 222 PP_CompletionCallback callback) { |
| 220 if (file_ != base::kInvalidPlatformFileValue) | 223 if (file_ != base::kInvalidPlatformFileValue) |
| 221 return PP_ERROR_FAILED; | 224 return PP_ERROR_FAILED; |
| 222 | 225 |
| 223 DCHECK(!callback_.func); | 226 DCHECK(!callback_.func); |
| 224 callback_ = callback; | 227 callback_ = callback; |
| 225 | 228 |
| 226 int flags = 0; | 229 int flags = 0; |
| 227 if (open_flags & PP_FILEOPENFLAG_READ) | 230 if (open_flags & PP_FILEOPENFLAG_READ) |
| 228 flags |= base::PLATFORM_FILE_READ; | 231 flags |= base::PLATFORM_FILE_READ; |
| 229 if (open_flags & PP_FILEOPENFLAG_WRITE) { | 232 if (open_flags & PP_FILEOPENFLAG_WRITE) { |
| 230 flags |= base::PLATFORM_FILE_WRITE; | 233 flags |= base::PLATFORM_FILE_WRITE; |
| 231 flags |= base::PLATFORM_FILE_WRITE_ATTRIBUTES; | 234 flags |= base::PLATFORM_FILE_WRITE_ATTRIBUTES; |
| 232 } | 235 } |
| 233 | 236 |
| 234 if (open_flags & PP_FILEOPENFLAG_TRUNCATE) { | 237 if (open_flags & PP_FILEOPENFLAG_TRUNCATE) { |
| 235 DCHECK(open_flags & PP_FILEOPENFLAG_WRITE); | 238 DCHECK(open_flags & PP_FILEOPENFLAG_WRITE); |
| 236 flags |= base::PLATFORM_FILE_TRUNCATE; | 239 flags |= base::PLATFORM_FILE_TRUNCATE; |
| 237 } else if (open_flags & PP_FILEOPENFLAG_CREATE) { | 240 } else if (open_flags & PP_FILEOPENFLAG_CREATE) { |
| 238 if (open_flags & PP_FILEOPENFLAG_EXCLUSIVE) | 241 if (open_flags & PP_FILEOPENFLAG_EXCLUSIVE) |
| 239 flags |= base::PLATFORM_FILE_CREATE; | 242 flags |= base::PLATFORM_FILE_CREATE; |
| 240 else | 243 else |
| 241 flags |= base::PLATFORM_FILE_OPEN_ALWAYS; | 244 flags |= base::PLATFORM_FILE_OPEN_ALWAYS; |
| 242 } else | 245 } else |
| 243 flags |= base::PLATFORM_FILE_OPEN; | 246 flags |= base::PLATFORM_FILE_OPEN; |
| 244 | 247 |
| 245 file_system_type_ = file_ref->GetFileSystemType(); | 248 file_system_type_ = file_ref->GetFileSystemType(); |
| 246 if (!delegate_->AsyncOpenFile( | 249 if (!delegate_->AsyncOpenFile( |
| 247 file_ref->GetSystemPath(), flags, | 250 file_ref->GetSystemPath(), flags, |
| 248 callback_factory_.NewCallback(&FileIO::AsyncOpenFileCallback))) | 251 callback_factory_.NewCallback(&PPB_FileIO_Impl::AsyncOpenFileCallback)
)) |
| 249 return PP_ERROR_FAILED; | 252 return PP_ERROR_FAILED; |
| 250 | 253 |
| 251 return PP_ERROR_WOULDBLOCK; | 254 return PP_ERROR_WOULDBLOCK; |
| 252 } | 255 } |
| 253 | 256 |
| 254 int32_t FileIO::Query(PP_FileInfo_Dev* info, | 257 int32_t PPB_FileIO_Impl::Query(PP_FileInfo_Dev* info, |
| 255 PP_CompletionCallback callback) { | 258 PP_CompletionCallback callback) { |
| 256 if (file_ == base::kInvalidPlatformFileValue) | 259 if (file_ == base::kInvalidPlatformFileValue) |
| 257 return PP_ERROR_FAILED; | 260 return PP_ERROR_FAILED; |
| 258 | 261 |
| 259 DCHECK(!callback_.func); | 262 DCHECK(!callback_.func); |
| 260 callback_ = callback; | 263 callback_ = callback; |
| 261 | 264 |
| 262 DCHECK(!info_); | 265 DCHECK(!info_); |
| 263 DCHECK(info); | 266 DCHECK(info); |
| 264 info_ = info; | 267 info_ = info; |
| 265 | 268 |
| 266 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( | 269 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( |
| 267 delegate_->GetFileThreadMessageLoopProxy(), file_, | 270 delegate_->GetFileThreadMessageLoopProxy(), file_, |
| 268 callback_factory_.NewCallback(&FileIO::QueryInfoCallback))) | 271 callback_factory_.NewCallback(&PPB_FileIO_Impl::QueryInfoCallback))) |
| 269 return PP_ERROR_FAILED; | 272 return PP_ERROR_FAILED; |
| 270 | 273 |
| 271 return PP_ERROR_WOULDBLOCK; | 274 return PP_ERROR_WOULDBLOCK; |
| 272 } | 275 } |
| 273 | 276 |
| 274 int32_t FileIO::Touch(PP_Time last_access_time, | 277 int32_t PPB_FileIO_Impl::Touch(PP_Time last_access_time, |
| 275 PP_Time last_modified_time, | 278 PP_Time last_modified_time, |
| 276 PP_CompletionCallback callback) { | 279 PP_CompletionCallback callback) { |
| 277 if (file_ == base::kInvalidPlatformFileValue) | 280 if (file_ == base::kInvalidPlatformFileValue) |
| 278 return PP_ERROR_FAILED; | 281 return PP_ERROR_FAILED; |
| 279 | 282 |
| 280 DCHECK(!callback_.func); | 283 DCHECK(!callback_.func); |
| 281 callback_ = callback; | 284 callback_ = callback; |
| 282 | 285 |
| 283 if (!base::FileUtilProxy::Touch( | 286 if (!base::FileUtilProxy::Touch( |
| 284 delegate_->GetFileThreadMessageLoopProxy(), | 287 delegate_->GetFileThreadMessageLoopProxy(), |
| 285 file_, base::Time::FromDoubleT(last_access_time), | 288 file_, base::Time::FromDoubleT(last_access_time), |
| 286 base::Time::FromDoubleT(last_modified_time), | 289 base::Time::FromDoubleT(last_modified_time), |
| 287 callback_factory_.NewCallback(&FileIO::StatusCallback))) | 290 callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback))) |
| 288 return PP_ERROR_FAILED; | 291 return PP_ERROR_FAILED; |
| 289 | 292 |
| 290 return PP_ERROR_WOULDBLOCK; | 293 return PP_ERROR_WOULDBLOCK; |
| 291 } | 294 } |
| 292 | 295 |
| 293 int32_t FileIO::Read(int64_t offset, | 296 int32_t PPB_FileIO_Impl::Read(int64_t offset, |
| 294 char* buffer, | 297 char* buffer, |
| 295 int32_t bytes_to_read, | 298 int32_t bytes_to_read, |
| 296 PP_CompletionCallback callback) { | 299 PP_CompletionCallback callback) { |
| 297 if (file_ == base::kInvalidPlatformFileValue) | 300 if (file_ == base::kInvalidPlatformFileValue) |
| 298 return PP_ERROR_FAILED; | 301 return PP_ERROR_FAILED; |
| 299 | 302 |
| 300 DCHECK(!callback_.func); | 303 DCHECK(!callback_.func); |
| 301 callback_ = callback; | 304 callback_ = callback; |
| 302 | 305 |
| 303 if (!base::FileUtilProxy::Read( | 306 if (!base::FileUtilProxy::Read( |
| 304 delegate_->GetFileThreadMessageLoopProxy(), | 307 delegate_->GetFileThreadMessageLoopProxy(), |
| 305 file_, offset, buffer, bytes_to_read, | 308 file_, offset, buffer, bytes_to_read, |
| 306 callback_factory_.NewCallback(&FileIO::ReadWriteCallback))) | 309 callback_factory_.NewCallback(&PPB_FileIO_Impl::ReadWriteCallback))) |
| 307 return PP_ERROR_FAILED; | 310 return PP_ERROR_FAILED; |
| 308 | 311 |
| 309 return PP_ERROR_WOULDBLOCK; | 312 return PP_ERROR_WOULDBLOCK; |
| 310 } | 313 } |
| 311 | 314 |
| 312 int32_t FileIO::Write(int64_t offset, | 315 int32_t PPB_FileIO_Impl::Write(int64_t offset, |
| 313 const char* buffer, | 316 const char* buffer, |
| 314 int32_t bytes_to_write, | 317 int32_t bytes_to_write, |
| 315 PP_CompletionCallback callback) { | 318 PP_CompletionCallback callback) { |
| 316 if (file_ == base::kInvalidPlatformFileValue) | 319 if (file_ == base::kInvalidPlatformFileValue) |
| 317 return PP_ERROR_FAILED; | 320 return PP_ERROR_FAILED; |
| 318 | 321 |
| 319 DCHECK(!callback_.func); | 322 DCHECK(!callback_.func); |
| 320 callback_ = callback; | 323 callback_ = callback; |
| 321 | 324 |
| 322 if (!base::FileUtilProxy::Write( | 325 if (!base::FileUtilProxy::Write( |
| 323 delegate_->GetFileThreadMessageLoopProxy(), | 326 delegate_->GetFileThreadMessageLoopProxy(), |
| 324 file_, offset, buffer, bytes_to_write, | 327 file_, offset, buffer, bytes_to_write, |
| 325 callback_factory_.NewCallback(&FileIO::ReadWriteCallback))) | 328 callback_factory_.NewCallback(&PPB_FileIO_Impl::ReadWriteCallback))) |
| 326 return PP_ERROR_FAILED; | 329 return PP_ERROR_FAILED; |
| 327 | 330 |
| 328 return PP_ERROR_WOULDBLOCK; | 331 return PP_ERROR_WOULDBLOCK; |
| 329 } | 332 } |
| 330 | 333 |
| 331 int32_t FileIO::SetLength(int64_t length, | 334 int32_t PPB_FileIO_Impl::SetLength(int64_t length, |
| 332 PP_CompletionCallback callback) { | 335 PP_CompletionCallback callback) { |
| 333 if (file_ == base::kInvalidPlatformFileValue) | 336 if (file_ == base::kInvalidPlatformFileValue) |
| 334 return PP_ERROR_FAILED; | 337 return PP_ERROR_FAILED; |
| 335 | 338 |
| 336 DCHECK(!callback_.func); | 339 DCHECK(!callback_.func); |
| 337 callback_ = callback; | 340 callback_ = callback; |
| 338 | 341 |
| 339 if (!base::FileUtilProxy::Truncate( | 342 if (!base::FileUtilProxy::Truncate( |
| 340 delegate_->GetFileThreadMessageLoopProxy(), | 343 delegate_->GetFileThreadMessageLoopProxy(), |
| 341 file_, length, | 344 file_, length, |
| 342 callback_factory_.NewCallback(&FileIO::StatusCallback))) | 345 callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback))) |
| 343 return PP_ERROR_FAILED; | 346 return PP_ERROR_FAILED; |
| 344 | 347 |
| 345 return PP_ERROR_WOULDBLOCK; | 348 return PP_ERROR_WOULDBLOCK; |
| 346 } | 349 } |
| 347 | 350 |
| 348 int32_t FileIO::Flush(PP_CompletionCallback callback) { | 351 int32_t PPB_FileIO_Impl::Flush(PP_CompletionCallback callback) { |
| 349 if (file_ == base::kInvalidPlatformFileValue) | 352 if (file_ == base::kInvalidPlatformFileValue) |
| 350 return PP_ERROR_FAILED; | 353 return PP_ERROR_FAILED; |
| 351 | 354 |
| 352 DCHECK(!callback_.func); | 355 DCHECK(!callback_.func); |
| 353 callback_ = callback; | 356 callback_ = callback; |
| 354 | 357 |
| 355 if (!base::FileUtilProxy::Flush( | 358 if (!base::FileUtilProxy::Flush( |
| 356 delegate_->GetFileThreadMessageLoopProxy(), file_, | 359 delegate_->GetFileThreadMessageLoopProxy(), file_, |
| 357 callback_factory_.NewCallback(&FileIO::StatusCallback))) | 360 callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback))) |
| 358 return PP_ERROR_FAILED; | 361 return PP_ERROR_FAILED; |
| 359 | 362 |
| 360 return PP_ERROR_WOULDBLOCK; | 363 return PP_ERROR_WOULDBLOCK; |
| 361 } | 364 } |
| 362 | 365 |
| 363 void FileIO::Close() { | 366 void PPB_FileIO_Impl::Close() { |
| 364 if (file_ != base::kInvalidPlatformFileValue) | 367 if (file_ != base::kInvalidPlatformFileValue) |
| 365 base::FileUtilProxy::Close( | 368 base::FileUtilProxy::Close( |
| 366 delegate_->GetFileThreadMessageLoopProxy(), file_, NULL); | 369 delegate_->GetFileThreadMessageLoopProxy(), file_, NULL); |
| 367 } | 370 } |
| 368 | 371 |
| 369 int32_t FileIO::GetOSFileDescriptor() { | 372 int32_t PPB_FileIO_Impl::GetOSFileDescriptor() { |
| 370 #if defined(OS_POSIX) | 373 #if defined(OS_POSIX) |
| 371 return file_; | 374 return file_; |
| 372 #elif defined(OS_WIN) | 375 #elif defined(OS_WIN) |
| 373 return reinterpret_cast<uintptr_t>(file_); | 376 return reinterpret_cast<uintptr_t>(file_); |
| 374 #else | 377 #else |
| 375 #error "Platform not supported." | 378 #error "Platform not supported." |
| 376 #endif | 379 #endif |
| 377 } | 380 } |
| 378 | 381 |
| 379 int32_t FileIO::WillWrite(int64_t offset, | 382 int32_t PPB_FileIO_Impl::WillWrite(int64_t offset, |
| 380 int32_t bytes_to_write, | 383 int32_t bytes_to_write, |
| 381 PP_CompletionCallback callback) { | 384 PP_CompletionCallback callback) { |
| 382 // TODO(dumi): implement me | 385 // TODO(dumi): implement me |
| 383 return PP_OK; | 386 return PP_OK; |
| 384 } | 387 } |
| 385 | 388 |
| 386 int32_t FileIO::WillSetLength(int64_t length, | 389 int32_t PPB_FileIO_Impl::WillSetLength(int64_t length, |
| 387 PP_CompletionCallback callback) { | 390 PP_CompletionCallback callback) { |
| 388 // TODO(dumi): implement me | 391 // TODO(dumi): implement me |
| 389 return PP_OK; | 392 return PP_OK; |
| 390 } | 393 } |
| 391 | 394 |
| 392 void FileIO::RunPendingCallback(int result) { | 395 void PPB_FileIO_Impl::RunPendingCallback(int result) { |
| 393 if (!callback_.func) | 396 if (!callback_.func) |
| 394 return; | 397 return; |
| 395 | 398 |
| 396 PP_CompletionCallback callback = {0}; | 399 PP_CompletionCallback callback = {0}; |
| 397 std::swap(callback, callback_); | 400 std::swap(callback, callback_); |
| 398 PP_RunCompletionCallback(&callback, result); | 401 PP_RunCompletionCallback(&callback, result); |
| 399 } | 402 } |
| 400 | 403 |
| 401 void FileIO::StatusCallback(base::PlatformFileError error_code) { | 404 void PPB_FileIO_Impl::StatusCallback(base::PlatformFileError error_code) { |
| 402 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); | 405 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); |
| 403 } | 406 } |
| 404 | 407 |
| 405 void FileIO::AsyncOpenFileCallback(base::PlatformFileError error_code, | 408 void PPB_FileIO_Impl::AsyncOpenFileCallback( |
| 406 base::PlatformFile file) { | 409 base::PlatformFileError error_code, |
| 410 base::PlatformFile file) { |
| 407 DCHECK(file_ == base::kInvalidPlatformFileValue); | 411 DCHECK(file_ == base::kInvalidPlatformFileValue); |
| 408 file_ = file; | 412 file_ = file; |
| 409 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); | 413 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); |
| 410 } | 414 } |
| 411 | 415 |
| 412 void FileIO::QueryInfoCallback(base::PlatformFileError error_code, | 416 void PPB_FileIO_Impl::QueryInfoCallback( |
| 413 const base::PlatformFileInfo& file_info) { | 417 base::PlatformFileError error_code, |
| 418 const base::PlatformFileInfo& file_info) { |
| 414 DCHECK(info_); | 419 DCHECK(info_); |
| 415 if (error_code == base::PLATFORM_FILE_OK) { | 420 if (error_code == base::PLATFORM_FILE_OK) { |
| 416 info_->size = file_info.size; | 421 info_->size = file_info.size; |
| 417 info_->creation_time = file_info.creation_time.ToDoubleT(); | 422 info_->creation_time = file_info.creation_time.ToDoubleT(); |
| 418 info_->last_access_time = file_info.last_accessed.ToDoubleT(); | 423 info_->last_access_time = file_info.last_accessed.ToDoubleT(); |
| 419 info_->last_modified_time = file_info.last_modified.ToDoubleT(); | 424 info_->last_modified_time = file_info.last_modified.ToDoubleT(); |
| 420 info_->system_type = file_system_type_; | 425 info_->system_type = file_system_type_; |
| 421 if (file_info.is_directory) | 426 if (file_info.is_directory) |
| 422 info_->type = PP_FILETYPE_DIRECTORY; | 427 info_->type = PP_FILETYPE_DIRECTORY; |
| 423 else | 428 else |
| 424 info_->type = PP_FILETYPE_REGULAR; | 429 info_->type = PP_FILETYPE_REGULAR; |
| 425 } | 430 } |
| 426 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); | 431 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); |
| 427 } | 432 } |
| 428 | 433 |
| 429 void FileIO::ReadWriteCallback(base::PlatformFileError error_code, | 434 void PPB_FileIO_Impl::ReadWriteCallback(base::PlatformFileError error_code, |
| 430 int bytes_read_or_written) { | 435 int bytes_read_or_written) { |
| 431 if (error_code != base::PLATFORM_FILE_OK) | 436 if (error_code != base::PLATFORM_FILE_OK) |
| 432 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); | 437 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); |
| 433 else | 438 else |
| 434 RunPendingCallback(bytes_read_or_written); | 439 RunPendingCallback(bytes_read_or_written); |
| 435 } | 440 } |
| 436 | 441 |
| 437 } // namespace pepper | 442 } // namespace ppapi |
| 443 } // namespace plugins |
| 444 } // namespace webkit |
| 445 |
| OLD | NEW |