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/fake_provided_file_system .h" | 5 #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system .h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 int length, | 180 int length, |
181 const ProvidedFileSystemInterface::ReadChunkReceivedCallback& callback) { | 181 const ProvidedFileSystemInterface::ReadChunkReceivedCallback& callback) { |
182 const OpenedFilesMap::iterator opened_file_it = | 182 const OpenedFilesMap::iterator opened_file_it = |
183 opened_files_.find(file_handle); | 183 opened_files_.find(file_handle); |
184 if (opened_file_it == opened_files_.end() || | 184 if (opened_file_it == opened_files_.end() || |
185 opened_file_it->second.AsUTF8Unsafe() != kFakeFilePath) { | 185 opened_file_it->second.AsUTF8Unsafe() != kFakeFilePath) { |
186 base::MessageLoopProxy::current()->PostTask( | 186 base::MessageLoopProxy::current()->PostTask( |
187 FROM_HERE, | 187 FROM_HERE, |
188 base::Bind(callback, | 188 base::Bind(callback, |
189 0 /* chunk_length */, | 189 0 /* chunk_length */, |
190 false /* has_next */, | 190 false /* has_more */, |
191 base::File::FILE_ERROR_SECURITY)); | 191 base::File::FILE_ERROR_SECURITY)); |
192 return; | 192 return; |
193 } | 193 } |
194 | 194 |
195 // Send the response byte by byte. | 195 // Send the response byte by byte. |
196 size_t current_offset = static_cast<size_t>(offset); | 196 size_t current_offset = static_cast<size_t>(offset); |
197 size_t current_length = static_cast<size_t>(length); | 197 size_t current_length = static_cast<size_t>(length); |
198 | 198 |
199 // Reading behind EOF, is fine, it will just read 0 bytes. | 199 // Reading behind EOF, is fine, it will just read 0 bytes. |
200 if (current_offset > kFakeFileSize || !current_length) { | 200 if (current_offset > kFakeFileSize || !current_length) { |
kinaba
2014/05/27 07:33:21
Not related to the current change, but,
current_of
mtomasz
2014/05/27 07:48:35
Good catch. I'll fix it with an upcoming CL.
| |
201 base::MessageLoopProxy::current()->PostTask( | 201 base::MessageLoopProxy::current()->PostTask( |
202 FROM_HERE, | 202 FROM_HERE, |
203 base::Bind(callback, | 203 base::Bind(callback, |
204 0 /* chunk_length */, | 204 0 /* chunk_length */, |
205 false /* has_next */, | 205 false /* has_more */, |
206 base::File::FILE_OK)); | 206 base::File::FILE_OK)); |
207 } | 207 } |
208 | 208 |
209 while (current_offset < kFakeFileSize && current_length) { | 209 while (current_offset < kFakeFileSize && current_length) { |
210 buffer->data()[current_offset - offset] = kFakeFileText[current_offset]; | 210 buffer->data()[current_offset - offset] = kFakeFileText[current_offset]; |
211 const bool has_next = | 211 const bool has_more = |
212 (current_offset + 1 < kFakeFileSize) && (current_length - 1); | 212 (current_offset + 1 < kFakeFileSize) && (current_length - 1); |
213 callback.Run(1, has_next, base::File::FILE_OK); | 213 callback.Run(1, has_more, base::File::FILE_OK); |
214 current_offset++; | 214 current_offset++; |
215 current_length--; | 215 current_length--; |
216 } | 216 } |
217 } | 217 } |
218 | 218 |
219 const ProvidedFileSystemInfo& FakeProvidedFileSystem::GetFileSystemInfo() | 219 const ProvidedFileSystemInfo& FakeProvidedFileSystem::GetFileSystemInfo() |
220 const { | 220 const { |
221 return file_system_info_; | 221 return file_system_info_; |
222 } | 222 } |
223 | 223 |
224 RequestManager* FakeProvidedFileSystem::GetRequestManager() { | 224 RequestManager* FakeProvidedFileSystem::GetRequestManager() { |
225 NOTREACHED(); | 225 NOTREACHED(); |
226 return NULL; | 226 return NULL; |
227 } | 227 } |
228 | 228 |
229 ProvidedFileSystemInterface* FakeProvidedFileSystem::Create( | 229 ProvidedFileSystemInterface* FakeProvidedFileSystem::Create( |
230 extensions::EventRouter* event_router, | 230 extensions::EventRouter* event_router, |
231 const ProvidedFileSystemInfo& file_system_info) { | 231 const ProvidedFileSystemInfo& file_system_info) { |
232 return new FakeProvidedFileSystem(file_system_info); | 232 return new FakeProvidedFileSystem(file_system_info); |
233 } | 233 } |
234 | 234 |
235 base::WeakPtr<ProvidedFileSystemInterface> | 235 base::WeakPtr<ProvidedFileSystemInterface> |
236 FakeProvidedFileSystem::GetWeakPtr() { | 236 FakeProvidedFileSystem::GetWeakPtr() { |
237 return weak_ptr_factory_.GetWeakPtr(); | 237 return weak_ptr_factory_.GetWeakPtr(); |
238 } | 238 } |
239 | 239 |
240 } // namespace file_system_provider | 240 } // namespace file_system_provider |
241 } // namespace chromeos | 241 } // namespace chromeos |
OLD | NEW |