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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
14 #include "chrome/common/extensions/api/file_system_provider.h" | 14 #include "chrome/common/extensions/api/file_system_provider.h" |
15 #include "chrome/common/extensions/api/file_system_provider_internal.h" | 15 #include "chrome/common/extensions/api/file_system_provider_internal.h" |
16 | 16 |
17 namespace chromeos { | 17 namespace chromeos { |
18 namespace file_system_provider { | 18 namespace file_system_provider { |
19 namespace operations { | 19 namespace operations { |
20 namespace { | 20 namespace { |
21 | 21 |
22 // Convert |value| into |output|. If parsing fails, then returns a negative | 22 // Convert |value| into |output|. If parsing fails, then returns a negative |
23 // value. Otherwise returns number of bytes written to the buffer. | 23 // value. Otherwise returns number of bytes written to the buffer. |
24 int CopyRequestValueToBuffer(scoped_ptr<RequestValue> value, | 24 int CopyRequestValueToBuffer(std::unique_ptr<RequestValue> value, |
25 scoped_refptr<net::IOBuffer> buffer, | 25 scoped_refptr<net::IOBuffer> buffer, |
26 int buffer_offset, | 26 int buffer_offset, |
27 int buffer_length) { | 27 int buffer_length) { |
28 using extensions::api::file_system_provider_internal:: | 28 using extensions::api::file_system_provider_internal:: |
29 ReadFileRequestedSuccess::Params; | 29 ReadFileRequestedSuccess::Params; |
30 | 30 |
31 const Params* params = value->read_file_success_params(); | 31 const Params* params = value->read_file_success_params(); |
32 if (!params) | 32 if (!params) |
33 return -1; | 33 return -1; |
34 | 34 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 return SendEvent( | 78 return SendEvent( |
79 request_id, | 79 request_id, |
80 extensions::events::FILE_SYSTEM_PROVIDER_ON_READ_FILE_REQUESTED, | 80 extensions::events::FILE_SYSTEM_PROVIDER_ON_READ_FILE_REQUESTED, |
81 extensions::api::file_system_provider::OnReadFileRequested::kEventName, | 81 extensions::api::file_system_provider::OnReadFileRequested::kEventName, |
82 extensions::api::file_system_provider::OnReadFileRequested::Create( | 82 extensions::api::file_system_provider::OnReadFileRequested::Create( |
83 options)); | 83 options)); |
84 } | 84 } |
85 | 85 |
86 void ReadFile::OnSuccess(int /* request_id */, | 86 void ReadFile::OnSuccess(int /* request_id */, |
87 scoped_ptr<RequestValue> result, | 87 std::unique_ptr<RequestValue> result, |
88 bool has_more) { | 88 bool has_more) { |
89 TRACE_EVENT0("file_system_provider", "ReadFile::OnSuccess"); | 89 TRACE_EVENT0("file_system_provider", "ReadFile::OnSuccess"); |
90 const int copy_result = CopyRequestValueToBuffer(std::move(result), buffer_, | 90 const int copy_result = CopyRequestValueToBuffer(std::move(result), buffer_, |
91 current_offset_, length_); | 91 current_offset_, length_); |
92 | 92 |
93 if (copy_result < 0) { | 93 if (copy_result < 0) { |
94 LOG(ERROR) << "Failed to parse a response for the read file operation."; | 94 LOG(ERROR) << "Failed to parse a response for the read file operation."; |
95 callback_.Run( | 95 callback_.Run( |
96 0 /* chunk_length */, false /* has_more */, base::File::FILE_ERROR_IO); | 96 0 /* chunk_length */, false /* has_more */, base::File::FILE_ERROR_IO); |
97 return; | 97 return; |
98 } | 98 } |
99 | 99 |
100 if (copy_result > 0) | 100 if (copy_result > 0) |
101 current_offset_ += copy_result; | 101 current_offset_ += copy_result; |
102 callback_.Run(copy_result, has_more, base::File::FILE_OK); | 102 callback_.Run(copy_result, has_more, base::File::FILE_OK); |
103 } | 103 } |
104 | 104 |
105 void ReadFile::OnError(int /* request_id */, | 105 void ReadFile::OnError(int /* request_id */, |
106 scoped_ptr<RequestValue> /* result */, | 106 std::unique_ptr<RequestValue> /* result */, |
107 base::File::Error error) { | 107 base::File::Error error) { |
108 TRACE_EVENT0("file_system_provider", "ReadFile::OnError"); | 108 TRACE_EVENT0("file_system_provider", "ReadFile::OnError"); |
109 callback_.Run(0 /* chunk_length */, false /* has_more */, error); | 109 callback_.Run(0 /* chunk_length */, false /* has_more */, error); |
110 } | 110 } |
111 | 111 |
112 } // namespace operations | 112 } // namespace operations |
113 } // namespace file_system_provider | 113 } // namespace file_system_provider |
114 } // namespace chromeos | 114 } // namespace chromeos |
OLD | NEW |