| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/file_system_provider/operations/read_file.h" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/read_file.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "chrome/common/extensions/api/file_system_provider.h" | 10 #include "chrome/common/extensions/api/file_system_provider.h" |
| 11 #include "chrome/common/extensions/api/file_system_provider_internal.h" | 11 #include "chrome/common/extensions/api/file_system_provider_internal.h" |
| 12 | 12 |
| 13 namespace chromeos { | 13 namespace chromeos { |
| 14 namespace file_system_provider { | 14 namespace file_system_provider { |
| 15 namespace operations { | 15 namespace operations { |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // Convert |value| into |output|. If parsing fails, then returns a negative | 18 // Convert |value| into |output|. If parsing fails, then returns a negative |
| 19 // value. Otherwise returns number of bytes written to the buffer. | 19 // value. Otherwise returns number of bytes written to the buffer. |
| 20 int CopyRequestValueToBuffer(scoped_ptr<RequestValue> value, | 20 int CopyRequestValueToBuffer(scoped_ptr<RequestValue> value, |
| 21 net::IOBuffer* buffer, | 21 scoped_refptr<net::IOBuffer> buffer, |
| 22 int buffer_offset, | 22 int buffer_offset, |
| 23 int buffer_length) { | 23 int buffer_length) { |
| 24 using extensions::api::file_system_provider_internal:: | 24 using extensions::api::file_system_provider_internal:: |
| 25 ReadFileRequestedSuccess::Params; | 25 ReadFileRequestedSuccess::Params; |
| 26 | 26 |
| 27 const Params* params = value->read_file_success_params(); | 27 const Params* params = value->read_file_success_params(); |
| 28 if (!params) | 28 if (!params) |
| 29 return -1; | 29 return -1; |
| 30 | 30 |
| 31 const size_t chunk_size = params->data.length(); | 31 const size_t chunk_size = params->data.length(); |
| 32 | 32 |
| 33 // Check for overflows. | 33 // Check for overflows. |
| 34 if (chunk_size > static_cast<size_t>(buffer_length) - buffer_offset) | 34 if (chunk_size > static_cast<size_t>(buffer_length) - buffer_offset) |
| 35 return -1; | 35 return -1; |
| 36 | 36 |
| 37 memcpy(buffer->data() + buffer_offset, params->data.c_str(), chunk_size); | 37 memcpy(buffer->data() + buffer_offset, params->data.c_str(), chunk_size); |
| 38 | 38 |
| 39 return chunk_size; | 39 return chunk_size; |
| 40 } | 40 } |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 ReadFile::ReadFile( | 44 ReadFile::ReadFile( |
| 45 extensions::EventRouter* event_router, | 45 extensions::EventRouter* event_router, |
| 46 const ProvidedFileSystemInfo& file_system_info, | 46 const ProvidedFileSystemInfo& file_system_info, |
| 47 int file_handle, | 47 int file_handle, |
| 48 net::IOBuffer* buffer, | 48 scoped_refptr<net::IOBuffer> buffer, |
| 49 int64 offset, | 49 int64 offset, |
| 50 int length, | 50 int length, |
| 51 const ProvidedFileSystemInterface::ReadChunkReceivedCallback& callback) | 51 const ProvidedFileSystemInterface::ReadChunkReceivedCallback& callback) |
| 52 : Operation(event_router, file_system_info), | 52 : Operation(event_router, file_system_info), |
| 53 file_handle_(file_handle), | 53 file_handle_(file_handle), |
| 54 buffer_(buffer), | 54 buffer_(buffer), |
| 55 offset_(offset), | 55 offset_(offset), |
| 56 length_(length), | 56 length_(length), |
| 57 current_offset_(0), | 57 current_offset_(0), |
| 58 callback_(callback) { | 58 callback_(callback) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 84 callback_.Run(copy_result, has_next, base::File::FILE_OK); | 84 callback_.Run(copy_result, has_next, base::File::FILE_OK); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void ReadFile::OnError(int /* request_id */, base::File::Error error) { | 87 void ReadFile::OnError(int /* request_id */, base::File::Error error) { |
| 88 callback_.Run(0 /* chunk_length */, false /* has_next */, error); | 88 callback_.Run(0 /* chunk_length */, false /* has_next */, error); |
| 89 } | 89 } |
| 90 | 90 |
| 91 } // namespace operations | 91 } // namespace operations |
| 92 } // namespace file_system_provider | 92 } // namespace file_system_provider |
| 93 } // namespace chromeos | 93 } // namespace chromeos |
| OLD | NEW |