| 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 <stddef.h> |
| 8 |
| 7 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
| 8 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
| 9 | 11 |
| 10 namespace chromeos { | 12 namespace chromeos { |
| 11 namespace file_system_provider { | 13 namespace file_system_provider { |
| 12 namespace { | 14 namespace { |
| 13 | 15 |
| 14 const char kFakeFileName[] = "hello.txt"; | 16 const char kFakeFileName[] = "hello.txt"; |
| 15 const char kFakeFileText[] = | 17 const char kFakeFileText[] = |
| 16 "This is a testing file. Lorem ipsum dolor sit amet est."; | 18 "This is a testing file. Lorem ipsum dolor sit amet est."; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 46 DCHECK(base::Time::FromString(kFakeFileModificationTime, &modification_time)); | 48 DCHECK(base::Time::FromString(kFakeFileModificationTime, &modification_time)); |
| 47 AddEntry(base::FilePath(kFakeFilePath), false, kFakeFileName, kFakeFileSize, | 49 AddEntry(base::FilePath(kFakeFilePath), false, kFakeFileName, kFakeFileSize, |
| 48 modification_time, kFakeFileMimeType, kFakeFileText); | 50 modification_time, kFakeFileMimeType, kFakeFileText); |
| 49 } | 51 } |
| 50 | 52 |
| 51 FakeProvidedFileSystem::~FakeProvidedFileSystem() {} | 53 FakeProvidedFileSystem::~FakeProvidedFileSystem() {} |
| 52 | 54 |
| 53 void FakeProvidedFileSystem::AddEntry(const base::FilePath& entry_path, | 55 void FakeProvidedFileSystem::AddEntry(const base::FilePath& entry_path, |
| 54 bool is_directory, | 56 bool is_directory, |
| 55 const std::string& name, | 57 const std::string& name, |
| 56 int64 size, | 58 int64_t size, |
| 57 base::Time modification_time, | 59 base::Time modification_time, |
| 58 std::string mime_type, | 60 std::string mime_type, |
| 59 std::string contents) { | 61 std::string contents) { |
| 60 DCHECK(entries_.find(entry_path) == entries_.end()); | 62 DCHECK(entries_.find(entry_path) == entries_.end()); |
| 61 scoped_ptr<EntryMetadata> metadata(new EntryMetadata); | 63 scoped_ptr<EntryMetadata> metadata(new EntryMetadata); |
| 62 | 64 |
| 63 metadata->is_directory.reset(new bool(is_directory)); | 65 metadata->is_directory.reset(new bool(is_directory)); |
| 64 metadata->name.reset(new std::string(name)); | 66 metadata->name.reset(new std::string(name)); |
| 65 metadata->size.reset(new int64(size)); | 67 metadata->size.reset(new int64_t(size)); |
| 66 metadata->modification_time.reset(new base::Time(modification_time)); | 68 metadata->modification_time.reset(new base::Time(modification_time)); |
| 67 metadata->mime_type.reset(new std::string(mime_type)); | 69 metadata->mime_type.reset(new std::string(mime_type)); |
| 68 | 70 |
| 69 entries_[entry_path] = | 71 entries_[entry_path] = |
| 70 make_linked_ptr(new FakeEntry(metadata.Pass(), contents)); | 72 make_linked_ptr(new FakeEntry(metadata.Pass(), contents)); |
| 71 } | 73 } |
| 72 | 74 |
| 73 const FakeEntry* FakeProvidedFileSystem::GetEntry( | 75 const FakeEntry* FakeProvidedFileSystem::GetEntry( |
| 74 const base::FilePath& entry_path) const { | 76 const base::FilePath& entry_path) const { |
| 75 const Entries::const_iterator entry_it = entries_.find(entry_path); | 77 const Entries::const_iterator entry_it = entries_.find(entry_path); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 98 } | 100 } |
| 99 | 101 |
| 100 scoped_ptr<EntryMetadata> metadata(new EntryMetadata); | 102 scoped_ptr<EntryMetadata> metadata(new EntryMetadata); |
| 101 if (fields & ProvidedFileSystemInterface::METADATA_FIELD_IS_DIRECTORY) { | 103 if (fields & ProvidedFileSystemInterface::METADATA_FIELD_IS_DIRECTORY) { |
| 102 metadata->is_directory.reset( | 104 metadata->is_directory.reset( |
| 103 new bool(*entry_it->second->metadata->is_directory)); | 105 new bool(*entry_it->second->metadata->is_directory)); |
| 104 } | 106 } |
| 105 if (fields & ProvidedFileSystemInterface::METADATA_FIELD_NAME) | 107 if (fields & ProvidedFileSystemInterface::METADATA_FIELD_NAME) |
| 106 metadata->name.reset(new std::string(*entry_it->second->metadata->name)); | 108 metadata->name.reset(new std::string(*entry_it->second->metadata->name)); |
| 107 if (fields & ProvidedFileSystemInterface::METADATA_FIELD_SIZE) | 109 if (fields & ProvidedFileSystemInterface::METADATA_FIELD_SIZE) |
| 108 metadata->size.reset(new int64(*entry_it->second->metadata->size)); | 110 metadata->size.reset(new int64_t(*entry_it->second->metadata->size)); |
| 109 if (fields & ProvidedFileSystemInterface::METADATA_FIELD_MODIFICATION_TIME) { | 111 if (fields & ProvidedFileSystemInterface::METADATA_FIELD_MODIFICATION_TIME) { |
| 110 metadata->modification_time.reset( | 112 metadata->modification_time.reset( |
| 111 new base::Time(*entry_it->second->metadata->modification_time)); | 113 new base::Time(*entry_it->second->metadata->modification_time)); |
| 112 } | 114 } |
| 113 if (fields & ProvidedFileSystemInterface::METADATA_FIELD_MIME_TYPE && | 115 if (fields & ProvidedFileSystemInterface::METADATA_FIELD_MIME_TYPE && |
| 114 entry_it->second->metadata->mime_type.get()) { | 116 entry_it->second->metadata->mime_type.get()) { |
| 115 metadata->mime_type.reset( | 117 metadata->mime_type.reset( |
| 116 new std::string(*entry_it->second->metadata->mime_type)); | 118 new std::string(*entry_it->second->metadata->mime_type)); |
| 117 } | 119 } |
| 118 if (fields & ProvidedFileSystemInterface::METADATA_FIELD_THUMBNAIL && | 120 if (fields & ProvidedFileSystemInterface::METADATA_FIELD_THUMBNAIL && |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 base::Bind(callback, base::File::FILE_ERROR_NOT_FOUND)); | 191 base::Bind(callback, base::File::FILE_ERROR_NOT_FOUND)); |
| 190 } | 192 } |
| 191 | 193 |
| 192 opened_files_.erase(opened_file_it); | 194 opened_files_.erase(opened_file_it); |
| 193 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); | 195 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); |
| 194 } | 196 } |
| 195 | 197 |
| 196 AbortCallback FakeProvidedFileSystem::ReadFile( | 198 AbortCallback FakeProvidedFileSystem::ReadFile( |
| 197 int file_handle, | 199 int file_handle, |
| 198 net::IOBuffer* buffer, | 200 net::IOBuffer* buffer, |
| 199 int64 offset, | 201 int64_t offset, |
| 200 int length, | 202 int length, |
| 201 const ProvidedFileSystemInterface::ReadChunkReceivedCallback& callback) { | 203 const ProvidedFileSystemInterface::ReadChunkReceivedCallback& callback) { |
| 202 const auto opened_file_it = opened_files_.find(file_handle); | 204 const auto opened_file_it = opened_files_.find(file_handle); |
| 203 | 205 |
| 204 if (opened_file_it == opened_files_.end() || | 206 if (opened_file_it == opened_files_.end() || |
| 205 opened_file_it->second.file_path.AsUTF8Unsafe() != kFakeFilePath) { | 207 opened_file_it->second.file_path.AsUTF8Unsafe() != kFakeFilePath) { |
| 206 return PostAbortableTask( | 208 return PostAbortableTask( |
| 207 base::Bind(callback, | 209 base::Bind(callback, |
| 208 0 /* chunk_length */, | 210 0 /* chunk_length */, |
| 209 false /* has_more */, | 211 false /* has_more */, |
| 210 base::File::FILE_ERROR_INVALID_OPERATION)); | 212 base::File::FILE_ERROR_INVALID_OPERATION)); |
| 211 } | 213 } |
| 212 | 214 |
| 213 const Entries::const_iterator entry_it = | 215 const Entries::const_iterator entry_it = |
| 214 entries_.find(opened_file_it->second.file_path); | 216 entries_.find(opened_file_it->second.file_path); |
| 215 if (entry_it == entries_.end()) { | 217 if (entry_it == entries_.end()) { |
| 216 return PostAbortableTask( | 218 return PostAbortableTask( |
| 217 base::Bind(callback, | 219 base::Bind(callback, |
| 218 0 /* chunk_length */, | 220 0 /* chunk_length */, |
| 219 false /* has_more */, | 221 false /* has_more */, |
| 220 base::File::FILE_ERROR_INVALID_OPERATION)); | 222 base::File::FILE_ERROR_INVALID_OPERATION)); |
| 221 } | 223 } |
| 222 | 224 |
| 223 // Send the response byte by byte. | 225 // Send the response byte by byte. |
| 224 int64 current_offset = offset; | 226 int64_t current_offset = offset; |
| 225 int current_length = length; | 227 int current_length = length; |
| 226 | 228 |
| 227 // Reading behind EOF is fine, it will just return 0 bytes. | 229 // Reading behind EOF is fine, it will just return 0 bytes. |
| 228 if (current_offset >= *entry_it->second->metadata->size || !current_length) { | 230 if (current_offset >= *entry_it->second->metadata->size || !current_length) { |
| 229 return PostAbortableTask(base::Bind(callback, | 231 return PostAbortableTask(base::Bind(callback, |
| 230 0 /* chunk_length */, | 232 0 /* chunk_length */, |
| 231 false /* has_more */, | 233 false /* has_more */, |
| 232 base::File::FILE_OK)); | 234 base::File::FILE_OK)); |
| 233 } | 235 } |
| 234 | 236 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 AbortCallback FakeProvidedFileSystem::MoveEntry( | 291 AbortCallback FakeProvidedFileSystem::MoveEntry( |
| 290 const base::FilePath& source_path, | 292 const base::FilePath& source_path, |
| 291 const base::FilePath& target_path, | 293 const base::FilePath& target_path, |
| 292 const storage::AsyncFileUtil::StatusCallback& callback) { | 294 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 293 // TODO(mtomasz): Implement it once needed. | 295 // TODO(mtomasz): Implement it once needed. |
| 294 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); | 296 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); |
| 295 } | 297 } |
| 296 | 298 |
| 297 AbortCallback FakeProvidedFileSystem::Truncate( | 299 AbortCallback FakeProvidedFileSystem::Truncate( |
| 298 const base::FilePath& file_path, | 300 const base::FilePath& file_path, |
| 299 int64 length, | 301 int64_t length, |
| 300 const storage::AsyncFileUtil::StatusCallback& callback) { | 302 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 301 // TODO(mtomasz): Implement it once needed. | 303 // TODO(mtomasz): Implement it once needed. |
| 302 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); | 304 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); |
| 303 } | 305 } |
| 304 | 306 |
| 305 AbortCallback FakeProvidedFileSystem::WriteFile( | 307 AbortCallback FakeProvidedFileSystem::WriteFile( |
| 306 int file_handle, | 308 int file_handle, |
| 307 net::IOBuffer* buffer, | 309 net::IOBuffer* buffer, |
| 308 int64 offset, | 310 int64_t offset, |
| 309 int length, | 311 int length, |
| 310 const storage::AsyncFileUtil::StatusCallback& callback) { | 312 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 311 const auto opened_file_it = opened_files_.find(file_handle); | 313 const auto opened_file_it = opened_files_.find(file_handle); |
| 312 | 314 |
| 313 if (opened_file_it == opened_files_.end() || | 315 if (opened_file_it == opened_files_.end() || |
| 314 opened_file_it->second.file_path.AsUTF8Unsafe() != kFakeFilePath) { | 316 opened_file_it->second.file_path.AsUTF8Unsafe() != kFakeFilePath) { |
| 315 return PostAbortableTask( | 317 return PostAbortableTask( |
| 316 base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION)); | 318 base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION)); |
| 317 } | 319 } |
| 318 | 320 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 } | 433 } |
| 432 | 434 |
| 433 void FakeProvidedFileSystem::AbortMany(const std::vector<int>& task_ids) { | 435 void FakeProvidedFileSystem::AbortMany(const std::vector<int>& task_ids) { |
| 434 for (size_t i = 0; i < task_ids.size(); ++i) { | 436 for (size_t i = 0; i < task_ids.size(); ++i) { |
| 435 tracker_.TryCancel(task_ids[i]); | 437 tracker_.TryCancel(task_ids[i]); |
| 436 } | 438 } |
| 437 } | 439 } |
| 438 | 440 |
| 439 } // namespace file_system_provider | 441 } // namespace file_system_provider |
| 440 } // namespace chromeos | 442 } // namespace chromeos |
| OLD | NEW |