| 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 "ppapi/proxy/file_io_resource.h" | 5 #include "ppapi/proxy/file_io_resource.h" |
| 6 | 6 |
| 7 #include <limits> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
| 9 #include "ipc/ipc_message.h" | 11 #include "ipc/ipc_message.h" |
| 10 #include "ppapi/c/pp_errors.h" | 12 #include "ppapi/c/pp_errors.h" |
| 11 #include "ppapi/proxy/ppapi_messages.h" | 13 #include "ppapi/proxy/ppapi_messages.h" |
| 12 #include "ppapi/shared_impl/array_writer.h" | 14 #include "ppapi/shared_impl/array_writer.h" |
| 13 #include "ppapi/shared_impl/file_ref_create_info.h" | 15 #include "ppapi/shared_impl/file_ref_create_info.h" |
| 14 #include "ppapi/shared_impl/file_system_util.h" | 16 #include "ppapi/shared_impl/file_system_util.h" |
| 15 #include "ppapi/shared_impl/file_type_conversion.h" | 17 #include "ppapi/shared_impl/file_type_conversion.h" |
| 16 #include "ppapi/shared_impl/ppapi_globals.h" | 18 #include "ppapi/shared_impl/ppapi_globals.h" |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_WRITE); | 284 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_WRITE); |
| 283 | 285 |
| 284 if (check_quota_) { | 286 if (check_quota_) { |
| 285 int64_t increase = 0; | 287 int64_t increase = 0; |
| 286 uint64_t max_offset = 0; | 288 uint64_t max_offset = 0; |
| 287 bool append = (open_flags_ & PP_FILEOPENFLAG_APPEND) != 0; | 289 bool append = (open_flags_ & PP_FILEOPENFLAG_APPEND) != 0; |
| 288 if (append) { | 290 if (append) { |
| 289 increase = bytes_to_write; | 291 increase = bytes_to_write; |
| 290 } else { | 292 } else { |
| 291 uint64_t max_offset = offset + bytes_to_write; | 293 uint64_t max_offset = offset + bytes_to_write; |
| 292 if (max_offset > static_cast<uint64_t>(kint64max)) | 294 if (max_offset > |
| 295 static_cast<uint64_t>(std::numeric_limits<int64_t>::max())) { |
| 293 return PP_ERROR_FAILED; // amount calculation would overflow. | 296 return PP_ERROR_FAILED; // amount calculation would overflow. |
| 297 } |
| 294 increase = static_cast<int64_t>(max_offset) - max_written_offset_; | 298 increase = static_cast<int64_t>(max_offset) - max_written_offset_; |
| 295 } | 299 } |
| 296 | 300 |
| 297 if (increase > 0) { | 301 if (increase > 0) { |
| 298 // Request a quota reservation. This makes the Write asynchronous, so we | 302 // Request a quota reservation. This makes the Write asynchronous, so we |
| 299 // must copy the plugin's buffer. | 303 // must copy the plugin's buffer. |
| 300 scoped_ptr<char[]> copy(new char[bytes_to_write]); | 304 scoped_ptr<char[]> copy(new char[bytes_to_write]); |
| 301 memcpy(copy.get(), buffer, bytes_to_write); | 305 memcpy(copy.get(), buffer, bytes_to_write); |
| 302 int64_t result = | 306 int64_t result = |
| 303 file_system_resource_->AsPPB_FileSystem_API()->RequestQuota( | 307 file_system_resource_->AsPPB_FileSystem_API()->RequestQuota( |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); | 713 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); |
| 710 | 714 |
| 711 // End this operation now, so the user's callback can execute another FileIO | 715 // End this operation now, so the user's callback can execute another FileIO |
| 712 // operation, assuming there are no other pending operations. | 716 // operation, assuming there are no other pending operations. |
| 713 state_manager_.SetOperationFinished(); | 717 state_manager_.SetOperationFinished(); |
| 714 callback->Run(result); | 718 callback->Run(result); |
| 715 } | 719 } |
| 716 | 720 |
| 717 } // namespace proxy | 721 } // namespace proxy |
| 718 } // namespace ppapi | 722 } // namespace ppapi |
| OLD | NEW |