| 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" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 int32_t rv = CommonCallValidation(true, callback); | 269 int32_t rv = CommonCallValidation(true, callback); |
| 270 if (rv != PP_OK) | 270 if (rv != PP_OK) |
| 271 return rv; | 271 return rv; |
| 272 | 272 |
| 273 if (!info) | 273 if (!info) |
| 274 return PP_ERROR_BADARGUMENT; | 274 return PP_ERROR_BADARGUMENT; |
| 275 | 275 |
| 276 DCHECK(!info_); // If |info_|, a callback should be pending (caught above). | 276 DCHECK(!info_); // If |info_|, a callback should be pending (caught above). |
| 277 info_ = info; | 277 info_ = info; |
| 278 | 278 |
| 279 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( | 279 if (!base::FileUtilProxy::GetInstance()->GetFileInfoFromPlatformFile( |
| 280 instance()->delegate()->GetFileThreadMessageLoopProxy(), file_, | 280 instance()->delegate()->GetFileThreadMessageLoopProxy(), file_, |
| 281 callback_factory_.NewCallback(&PPB_FileIO_Impl::QueryInfoCallback))) | 281 callback_factory_.NewCallback(&PPB_FileIO_Impl::QueryInfoCallback))) |
| 282 return PP_ERROR_FAILED; | 282 return PP_ERROR_FAILED; |
| 283 | 283 |
| 284 RegisterCallback(callback); | 284 RegisterCallback(callback); |
| 285 return PP_ERROR_WOULDBLOCK; | 285 return PP_ERROR_WOULDBLOCK; |
| 286 } | 286 } |
| 287 | 287 |
| 288 int32_t PPB_FileIO_Impl::Touch(PP_Time last_access_time, | 288 int32_t PPB_FileIO_Impl::Touch(PP_Time last_access_time, |
| 289 PP_Time last_modified_time, | 289 PP_Time last_modified_time, |
| 290 PP_CompletionCallback callback) { | 290 PP_CompletionCallback callback) { |
| 291 int32_t rv = CommonCallValidation(true, callback); | 291 int32_t rv = CommonCallValidation(true, callback); |
| 292 if (rv != PP_OK) | 292 if (rv != PP_OK) |
| 293 return rv; | 293 return rv; |
| 294 | 294 |
| 295 if (!base::FileUtilProxy::Touch( | 295 if (!base::FileUtilProxy::GetInstance()->Touch( |
| 296 instance()->delegate()->GetFileThreadMessageLoopProxy(), | 296 instance()->delegate()->GetFileThreadMessageLoopProxy(), |
| 297 file_, base::Time::FromDoubleT(last_access_time), | 297 file_, base::Time::FromDoubleT(last_access_time), |
| 298 base::Time::FromDoubleT(last_modified_time), | 298 base::Time::FromDoubleT(last_modified_time), |
| 299 callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback))) | 299 callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback))) |
| 300 return PP_ERROR_FAILED; | 300 return PP_ERROR_FAILED; |
| 301 | 301 |
| 302 RegisterCallback(callback); | 302 RegisterCallback(callback); |
| 303 return PP_ERROR_WOULDBLOCK; | 303 return PP_ERROR_WOULDBLOCK; |
| 304 } | 304 } |
| 305 | 305 |
| 306 int32_t PPB_FileIO_Impl::Read(int64_t offset, | 306 int32_t PPB_FileIO_Impl::Read(int64_t offset, |
| 307 char* buffer, | 307 char* buffer, |
| 308 int32_t bytes_to_read, | 308 int32_t bytes_to_read, |
| 309 PP_CompletionCallback callback) { | 309 PP_CompletionCallback callback) { |
| 310 int32_t rv = CommonCallValidation(true, callback); | 310 int32_t rv = CommonCallValidation(true, callback); |
| 311 if (rv != PP_OK) | 311 if (rv != PP_OK) |
| 312 return rv; | 312 return rv; |
| 313 | 313 |
| 314 if (!base::FileUtilProxy::Read( | 314 if (!base::FileUtilProxy::GetInstance()->Read( |
| 315 instance()->delegate()->GetFileThreadMessageLoopProxy(), | 315 instance()->delegate()->GetFileThreadMessageLoopProxy(), |
| 316 file_, offset, buffer, bytes_to_read, | 316 file_, offset, buffer, bytes_to_read, |
| 317 callback_factory_.NewCallback(&PPB_FileIO_Impl::ReadWriteCallback))) | 317 callback_factory_.NewCallback(&PPB_FileIO_Impl::ReadWriteCallback))) |
| 318 return PP_ERROR_FAILED; | 318 return PP_ERROR_FAILED; |
| 319 | 319 |
| 320 RegisterCallback(callback); | 320 RegisterCallback(callback); |
| 321 return PP_ERROR_WOULDBLOCK; | 321 return PP_ERROR_WOULDBLOCK; |
| 322 } | 322 } |
| 323 | 323 |
| 324 int32_t PPB_FileIO_Impl::Write(int64_t offset, | 324 int32_t PPB_FileIO_Impl::Write(int64_t offset, |
| 325 const char* buffer, | 325 const char* buffer, |
| 326 int32_t bytes_to_write, | 326 int32_t bytes_to_write, |
| 327 PP_CompletionCallback callback) { | 327 PP_CompletionCallback callback) { |
| 328 int32_t rv = CommonCallValidation(true, callback); | 328 int32_t rv = CommonCallValidation(true, callback); |
| 329 if (rv != PP_OK) | 329 if (rv != PP_OK) |
| 330 return rv; | 330 return rv; |
| 331 | 331 |
| 332 if (!base::FileUtilProxy::Write( | 332 if (!base::FileUtilProxy::GetInstance()->Write( |
| 333 instance()->delegate()->GetFileThreadMessageLoopProxy(), | 333 instance()->delegate()->GetFileThreadMessageLoopProxy(), |
| 334 file_, offset, buffer, bytes_to_write, | 334 file_, offset, buffer, bytes_to_write, |
| 335 callback_factory_.NewCallback(&PPB_FileIO_Impl::ReadWriteCallback))) | 335 callback_factory_.NewCallback(&PPB_FileIO_Impl::ReadWriteCallback))) |
| 336 return PP_ERROR_FAILED; | 336 return PP_ERROR_FAILED; |
| 337 | 337 |
| 338 RegisterCallback(callback); | 338 RegisterCallback(callback); |
| 339 return PP_ERROR_WOULDBLOCK; | 339 return PP_ERROR_WOULDBLOCK; |
| 340 } | 340 } |
| 341 | 341 |
| 342 int32_t PPB_FileIO_Impl::SetLength(int64_t length, | 342 int32_t PPB_FileIO_Impl::SetLength(int64_t length, |
| 343 PP_CompletionCallback callback) { | 343 PP_CompletionCallback callback) { |
| 344 int32_t rv = CommonCallValidation(true, callback); | 344 int32_t rv = CommonCallValidation(true, callback); |
| 345 if (rv != PP_OK) | 345 if (rv != PP_OK) |
| 346 return rv; | 346 return rv; |
| 347 | 347 |
| 348 if (!base::FileUtilProxy::Truncate( | 348 if (!base::FileUtilProxy::GetInstance()->Truncate( |
| 349 instance()->delegate()->GetFileThreadMessageLoopProxy(), | 349 instance()->delegate()->GetFileThreadMessageLoopProxy(), |
| 350 file_, length, | 350 file_, length, |
| 351 callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback))) | 351 callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback))) |
| 352 return PP_ERROR_FAILED; | 352 return PP_ERROR_FAILED; |
| 353 | 353 |
| 354 RegisterCallback(callback); | 354 RegisterCallback(callback); |
| 355 return PP_ERROR_WOULDBLOCK; | 355 return PP_ERROR_WOULDBLOCK; |
| 356 } | 356 } |
| 357 | 357 |
| 358 int32_t PPB_FileIO_Impl::Flush(PP_CompletionCallback callback) { | 358 int32_t PPB_FileIO_Impl::Flush(PP_CompletionCallback callback) { |
| 359 int32_t rv = CommonCallValidation(true, callback); | 359 int32_t rv = CommonCallValidation(true, callback); |
| 360 if (rv != PP_OK) | 360 if (rv != PP_OK) |
| 361 return rv; | 361 return rv; |
| 362 | 362 |
| 363 if (!base::FileUtilProxy::Flush( | 363 if (!base::FileUtilProxy::GetInstance()->Flush( |
| 364 instance()->delegate()->GetFileThreadMessageLoopProxy(), file_, | 364 instance()->delegate()->GetFileThreadMessageLoopProxy(), file_, |
| 365 callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback))) | 365 callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback))) |
| 366 return PP_ERROR_FAILED; | 366 return PP_ERROR_FAILED; |
| 367 | 367 |
| 368 RegisterCallback(callback); | 368 RegisterCallback(callback); |
| 369 return PP_ERROR_WOULDBLOCK; | 369 return PP_ERROR_WOULDBLOCK; |
| 370 } | 370 } |
| 371 | 371 |
| 372 void PPB_FileIO_Impl::Close() { | 372 void PPB_FileIO_Impl::Close() { |
| 373 if (file_ != base::kInvalidPlatformFileValue) { | 373 if (file_ != base::kInvalidPlatformFileValue) { |
| 374 base::FileUtilProxy::Close( | 374 base::FileUtilProxy::GetInstance()->Close( |
| 375 instance()->delegate()->GetFileThreadMessageLoopProxy(), file_, NULL); | 375 instance()->delegate()->GetFileThreadMessageLoopProxy(), file_, NULL); |
| 376 file_ = base::kInvalidPlatformFileValue; | 376 file_ = base::kInvalidPlatformFileValue; |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 | 379 |
| 380 int32_t PPB_FileIO_Impl::GetOSFileDescriptor() { | 380 int32_t PPB_FileIO_Impl::GetOSFileDescriptor() { |
| 381 #if defined(OS_POSIX) | 381 #if defined(OS_POSIX) |
| 382 return file_; | 382 return file_; |
| 383 #elif defined(OS_WIN) | 383 #elif defined(OS_WIN) |
| 384 return reinterpret_cast<uintptr_t>(file_); | 384 return reinterpret_cast<uintptr_t>(file_); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 void PPB_FileIO_Impl::ReadWriteCallback(base::PlatformFileError error_code, | 472 void PPB_FileIO_Impl::ReadWriteCallback(base::PlatformFileError error_code, |
| 473 int bytes_read_or_written) { | 473 int bytes_read_or_written) { |
| 474 if (error_code != base::PLATFORM_FILE_OK) | 474 if (error_code != base::PLATFORM_FILE_OK) |
| 475 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); | 475 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); |
| 476 else | 476 else |
| 477 RunPendingCallback(bytes_read_or_written); | 477 RunPendingCallback(bytes_read_or_written); |
| 478 } | 478 } |
| 479 | 479 |
| 480 } // namespace ppapi | 480 } // namespace ppapi |
| 481 } // namespace webkit | 481 } // namespace webkit |
| OLD | NEW |