Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Side by Side Diff: chrome/browser/chromeos/file_system_provider/operations/read_file.cc

Issue 820673004: json_schema_compiler: Use std::vector<char> for binary values. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simplify_json_schema
Patch Set: Fix merge error. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "base/stl_util.h"
11 #include "chrome/common/extensions/api/file_system_provider.h" 12 #include "chrome/common/extensions/api/file_system_provider.h"
12 #include "chrome/common/extensions/api/file_system_provider_internal.h" 13 #include "chrome/common/extensions/api/file_system_provider_internal.h"
13 14
14 namespace chromeos { 15 namespace chromeos {
15 namespace file_system_provider { 16 namespace file_system_provider {
16 namespace operations { 17 namespace operations {
17 namespace { 18 namespace {
18 19
19 // Convert |value| into |output|. If parsing fails, then returns a negative 20 // Convert |value| into |output|. If parsing fails, then returns a negative
20 // value. Otherwise returns number of bytes written to the buffer. 21 // value. Otherwise returns number of bytes written to the buffer.
21 int CopyRequestValueToBuffer(scoped_ptr<RequestValue> value, 22 int CopyRequestValueToBuffer(scoped_ptr<RequestValue> value,
22 scoped_refptr<net::IOBuffer> buffer, 23 scoped_refptr<net::IOBuffer> buffer,
23 int buffer_offset, 24 int buffer_offset,
24 int buffer_length) { 25 int buffer_length) {
25 using extensions::api::file_system_provider_internal:: 26 using extensions::api::file_system_provider_internal::
26 ReadFileRequestedSuccess::Params; 27 ReadFileRequestedSuccess::Params;
27 28
28 const Params* params = value->read_file_success_params(); 29 const Params* params = value->read_file_success_params();
29 if (!params) 30 if (!params)
30 return -1; 31 return -1;
31 32
32 const size_t chunk_size = params->data.length(); 33 const size_t chunk_size = params->data.size();
33 34
34 // Check for overflows. 35 // Check for overflows.
35 if (chunk_size > static_cast<size_t>(buffer_length) - buffer_offset) 36 if (chunk_size > static_cast<size_t>(buffer_length) - buffer_offset)
36 return -1; 37 return -1;
37 38
38 memcpy(buffer->data() + buffer_offset, params->data.c_str(), chunk_size); 39 memcpy(buffer->data() + buffer_offset, vector_as_array(&params->data),
40 chunk_size);
39 41
40 return chunk_size; 42 return chunk_size;
41 } 43 }
42 44
43 } // namespace 45 } // namespace
44 46
45 ReadFile::ReadFile( 47 ReadFile::ReadFile(
46 extensions::EventRouter* event_router, 48 extensions::EventRouter* event_router,
47 const ProvidedFileSystemInfo& file_system_info, 49 const ProvidedFileSystemInfo& file_system_info,
48 int file_handle, 50 int file_handle,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 void ReadFile::OnError(int /* request_id */, 104 void ReadFile::OnError(int /* request_id */,
103 scoped_ptr<RequestValue> /* result */, 105 scoped_ptr<RequestValue> /* result */,
104 base::File::Error error) { 106 base::File::Error error) {
105 TRACE_EVENT0("file_system_provider", "ReadFile::OnError"); 107 TRACE_EVENT0("file_system_provider", "ReadFile::OnError");
106 callback_.Run(0 /* chunk_length */, false /* has_more */, error); 108 callback_.Run(0 /* chunk_length */, false /* has_more */, error);
107 } 109 }
108 110
109 } // namespace operations 111 } // namespace operations
110 } // namespace file_system_provider 112 } // namespace file_system_provider
111 } // namespace chromeos 113 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698