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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 int length, | 191 int length, |
192 const ProvidedFileSystemInterface::ReadChunkReceivedCallback& callback) { | 192 const ProvidedFileSystemInterface::ReadChunkReceivedCallback& callback) { |
193 const OpenedFilesMap::iterator opened_file_it = | 193 const OpenedFilesMap::iterator opened_file_it = |
194 opened_files_.find(file_handle); | 194 opened_files_.find(file_handle); |
195 if (opened_file_it == opened_files_.end() || | 195 if (opened_file_it == opened_files_.end() || |
196 opened_file_it->second.AsUTF8Unsafe() != kFakeFilePath) { | 196 opened_file_it->second.AsUTF8Unsafe() != kFakeFilePath) { |
197 base::MessageLoopProxy::current()->PostTask( | 197 base::MessageLoopProxy::current()->PostTask( |
198 FROM_HERE, | 198 FROM_HERE, |
199 base::Bind(callback, | 199 base::Bind(callback, |
200 0 /* chunk_length */, | 200 0 /* chunk_length */, |
201 false /* has_next */, | 201 false /* has_more */, |
202 base::File::FILE_ERROR_INVALID_OPERATION)); | 202 base::File::FILE_ERROR_INVALID_OPERATION)); |
203 return; | 203 return; |
204 } | 204 } |
205 | 205 |
206 // Send the response byte by byte. | 206 // Send the response byte by byte. |
207 size_t current_offset = static_cast<size_t>(offset); | 207 size_t current_offset = static_cast<size_t>(offset); |
208 size_t current_length = static_cast<size_t>(length); | 208 size_t current_length = static_cast<size_t>(length); |
209 | 209 |
210 // Reading behind EOF is fine, it will just return 0 bytes. | 210 // Reading behind EOF is fine, it will just return 0 bytes. |
211 if (current_offset >= kFakeFileSize || !current_length) { | 211 if (current_offset >= kFakeFileSize || !current_length) { |
212 base::MessageLoopProxy::current()->PostTask( | 212 base::MessageLoopProxy::current()->PostTask( |
213 FROM_HERE, | 213 FROM_HERE, |
214 base::Bind(callback, | 214 base::Bind(callback, |
215 0 /* chunk_length */, | 215 0 /* chunk_length */, |
216 false /* has_next */, | 216 false /* has_more */, |
217 base::File::FILE_OK)); | 217 base::File::FILE_OK)); |
218 } | 218 } |
219 | 219 |
220 while (current_offset < kFakeFileSize && current_length) { | 220 while (current_offset < kFakeFileSize && current_length) { |
221 buffer->data()[current_offset - offset] = kFakeFileText[current_offset]; | 221 buffer->data()[current_offset - offset] = kFakeFileText[current_offset]; |
222 const bool has_next = | 222 const bool has_more = |
223 (current_offset + 1 < kFakeFileSize) && (current_length - 1); | 223 (current_offset + 1 < kFakeFileSize) && (current_length - 1); |
224 base::MessageLoopProxy::current()->PostTask( | 224 base::MessageLoopProxy::current()->PostTask( |
225 FROM_HERE, | 225 FROM_HERE, |
226 base::Bind( | 226 base::Bind( |
227 callback, 1 /* chunk_length */, has_next, base::File::FILE_OK)); | 227 callback, 1 /* chunk_length */, has_more, base::File::FILE_OK)); |
228 current_offset++; | 228 current_offset++; |
229 current_length--; | 229 current_length--; |
230 } | 230 } |
231 } | 231 } |
232 | 232 |
233 const ProvidedFileSystemInfo& FakeProvidedFileSystem::GetFileSystemInfo() | 233 const ProvidedFileSystemInfo& FakeProvidedFileSystem::GetFileSystemInfo() |
234 const { | 234 const { |
235 return file_system_info_; | 235 return file_system_info_; |
236 } | 236 } |
237 | 237 |
238 RequestManager* FakeProvidedFileSystem::GetRequestManager() { | 238 RequestManager* FakeProvidedFileSystem::GetRequestManager() { |
239 NOTREACHED(); | 239 NOTREACHED(); |
240 return NULL; | 240 return NULL; |
241 } | 241 } |
242 | 242 |
243 ProvidedFileSystemInterface* FakeProvidedFileSystem::Create( | 243 ProvidedFileSystemInterface* FakeProvidedFileSystem::Create( |
244 extensions::EventRouter* event_router, | 244 extensions::EventRouter* event_router, |
245 const ProvidedFileSystemInfo& file_system_info) { | 245 const ProvidedFileSystemInfo& file_system_info) { |
246 return new FakeProvidedFileSystem(file_system_info); | 246 return new FakeProvidedFileSystem(file_system_info); |
247 } | 247 } |
248 | 248 |
249 base::WeakPtr<ProvidedFileSystemInterface> | 249 base::WeakPtr<ProvidedFileSystemInterface> |
250 FakeProvidedFileSystem::GetWeakPtr() { | 250 FakeProvidedFileSystem::GetWeakPtr() { |
251 return weak_ptr_factory_.GetWeakPtr(); | 251 return weak_ptr_factory_.GetWeakPtr(); |
252 } | 252 } |
253 | 253 |
254 } // namespace file_system_provider | 254 } // namespace file_system_provider |
255 } // namespace chromeos | 255 } // namespace chromeos |
OLD | NEW |