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 "base/stl_util.h" | |
11 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
12 #include "chrome/common/extensions/api/file_system_provider.h" | 11 #include "chrome/common/extensions/api/file_system_provider.h" |
13 #include "chrome/common/extensions/api/file_system_provider_internal.h" | 12 #include "chrome/common/extensions/api/file_system_provider_internal.h" |
14 | 13 |
15 namespace chromeos { | 14 namespace chromeos { |
16 namespace file_system_provider { | 15 namespace file_system_provider { |
17 namespace operations { | 16 namespace operations { |
18 namespace { | 17 namespace { |
19 | 18 |
20 // Convert |value| into |output|. If parsing fails, then returns a negative | 19 // Convert |value| into |output|. If parsing fails, then returns a negative |
21 // value. Otherwise returns number of bytes written to the buffer. | 20 // value. Otherwise returns number of bytes written to the buffer. |
22 int CopyRequestValueToBuffer(scoped_ptr<RequestValue> value, | 21 int CopyRequestValueToBuffer(scoped_ptr<RequestValue> value, |
23 scoped_refptr<net::IOBuffer> buffer, | 22 scoped_refptr<net::IOBuffer> buffer, |
24 int buffer_offset, | 23 int buffer_offset, |
25 int buffer_length) { | 24 int buffer_length) { |
26 using extensions::api::file_system_provider_internal:: | 25 using extensions::api::file_system_provider_internal:: |
27 ReadFileRequestedSuccess::Params; | 26 ReadFileRequestedSuccess::Params; |
28 | 27 |
29 const Params* params = value->read_file_success_params(); | 28 const Params* params = value->read_file_success_params(); |
30 if (!params) | 29 if (!params) |
31 return -1; | 30 return -1; |
32 | 31 |
33 const size_t chunk_size = params->data.size(); | 32 const size_t chunk_size = params->data.size(); |
34 | 33 |
35 // Check for overflows. | 34 // Check for overflows. |
36 if (chunk_size > static_cast<size_t>(buffer_length) - buffer_offset) | 35 if (chunk_size > static_cast<size_t>(buffer_length) - buffer_offset) |
37 return -1; | 36 return -1; |
38 | 37 |
39 memcpy(buffer->data() + buffer_offset, vector_as_array(¶ms->data), | 38 memcpy(buffer->data() + buffer_offset, params->data.data(), chunk_size); |
40 chunk_size); | |
41 | 39 |
42 return chunk_size; | 40 return chunk_size; |
43 } | 41 } |
44 | 42 |
45 } // namespace | 43 } // namespace |
46 | 44 |
47 ReadFile::ReadFile( | 45 ReadFile::ReadFile( |
48 extensions::EventRouter* event_router, | 46 extensions::EventRouter* event_router, |
49 const ProvidedFileSystemInfo& file_system_info, | 47 const ProvidedFileSystemInfo& file_system_info, |
50 int file_handle, | 48 int file_handle, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 void ReadFile::OnError(int /* request_id */, | 103 void ReadFile::OnError(int /* request_id */, |
106 scoped_ptr<RequestValue> /* result */, | 104 scoped_ptr<RequestValue> /* result */, |
107 base::File::Error error) { | 105 base::File::Error error) { |
108 TRACE_EVENT0("file_system_provider", "ReadFile::OnError"); | 106 TRACE_EVENT0("file_system_provider", "ReadFile::OnError"); |
109 callback_.Run(0 /* chunk_length */, false /* has_more */, error); | 107 callback_.Run(0 /* chunk_length */, false /* has_more */, error); |
110 } | 108 } |
111 | 109 |
112 } // namespace operations | 110 } // namespace operations |
113 } // namespace file_system_provider | 111 } // namespace file_system_provider |
114 } // namespace chromeos | 112 } // namespace chromeos |
OLD | NEW |