| 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 "base/files/file.h" | 7 #include "base/files/file.h" |
| 8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
| 9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
| 10 | 10 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 FakeEntry* fake_entry) const { | 67 FakeEntry* fake_entry) const { |
| 68 const Entries::const_iterator entry_it = entries_.find(entry_path); | 68 const Entries::const_iterator entry_it = entries_.find(entry_path); |
| 69 if (entry_it == entries_.end()) | 69 if (entry_it == entries_.end()) |
| 70 return false; | 70 return false; |
| 71 | 71 |
| 72 *fake_entry = entry_it->second; | 72 *fake_entry = entry_it->second; |
| 73 return true; | 73 return true; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void FakeProvidedFileSystem::RequestUnmount( | 76 void FakeProvidedFileSystem::RequestUnmount( |
| 77 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 77 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 78 base::MessageLoopProxy::current()->PostTask( | 78 base::MessageLoopProxy::current()->PostTask( |
| 79 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); | 79 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void FakeProvidedFileSystem::GetMetadata( | 82 void FakeProvidedFileSystem::GetMetadata( |
| 83 const base::FilePath& entry_path, | 83 const base::FilePath& entry_path, |
| 84 const ProvidedFileSystemInterface::GetMetadataCallback& callback) { | 84 const ProvidedFileSystemInterface::GetMetadataCallback& callback) { |
| 85 const Entries::const_iterator entry_it = entries_.find(entry_path); | 85 const Entries::const_iterator entry_it = entries_.find(entry_path); |
| 86 | 86 |
| 87 if (entry_it == entries_.end()) { | 87 if (entry_it == entries_.end()) { |
| 88 base::MessageLoopProxy::current()->PostTask( | 88 base::MessageLoopProxy::current()->PostTask( |
| 89 FROM_HERE, | 89 FROM_HERE, |
| 90 base::Bind( | 90 base::Bind( |
| 91 callback, EntryMetadata(), base::File::FILE_ERROR_NOT_FOUND)); | 91 callback, EntryMetadata(), base::File::FILE_ERROR_NOT_FOUND)); |
| 92 return; | 92 return; |
| 93 } | 93 } |
| 94 | 94 |
| 95 base::MessageLoopProxy::current()->PostTask( | 95 base::MessageLoopProxy::current()->PostTask( |
| 96 FROM_HERE, | 96 FROM_HERE, |
| 97 base::Bind(callback, entry_it->second.metadata, base::File::FILE_OK)); | 97 base::Bind(callback, entry_it->second.metadata, base::File::FILE_OK)); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void FakeProvidedFileSystem::ReadDirectory( | 100 void FakeProvidedFileSystem::ReadDirectory( |
| 101 const base::FilePath& directory_path, | 101 const base::FilePath& directory_path, |
| 102 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) { | 102 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) { |
| 103 fileapi::AsyncFileUtil::EntryList entry_list; | 103 storage::AsyncFileUtil::EntryList entry_list; |
| 104 | 104 |
| 105 for (Entries::const_iterator it = entries_.begin(); it != entries_.end(); | 105 for (Entries::const_iterator it = entries_.begin(); it != entries_.end(); |
| 106 ++it) { | 106 ++it) { |
| 107 const base::FilePath file_path = it->first; | 107 const base::FilePath file_path = it->first; |
| 108 if (file_path == directory_path || directory_path.IsParent(file_path)) { | 108 if (file_path == directory_path || directory_path.IsParent(file_path)) { |
| 109 const EntryMetadata& metadata = it->second.metadata; | 109 const EntryMetadata& metadata = it->second.metadata; |
| 110 entry_list.push_back(fileapi::DirectoryEntry( | 110 entry_list.push_back(storage::DirectoryEntry( |
| 111 metadata.name, | 111 metadata.name, |
| 112 metadata.is_directory ? fileapi::DirectoryEntry::DIRECTORY | 112 metadata.is_directory ? storage::DirectoryEntry::DIRECTORY |
| 113 : fileapi::DirectoryEntry::FILE, | 113 : storage::DirectoryEntry::FILE, |
| 114 metadata.size, | 114 metadata.size, |
| 115 metadata.modification_time)); | 115 metadata.modification_time)); |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 | 118 |
| 119 base::MessageLoopProxy::current()->PostTask( | 119 base::MessageLoopProxy::current()->PostTask( |
| 120 FROM_HERE, | 120 FROM_HERE, |
| 121 base::Bind( | 121 base::Bind( |
| 122 callback, base::File::FILE_OK, entry_list, false /* has_more */)); | 122 callback, base::File::FILE_OK, entry_list, false /* has_more */)); |
| 123 } | 123 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 136 } | 136 } |
| 137 | 137 |
| 138 const int file_handle = ++last_file_handle_; | 138 const int file_handle = ++last_file_handle_; |
| 139 opened_files_[file_handle] = entry_path; | 139 opened_files_[file_handle] = entry_path; |
| 140 base::MessageLoopProxy::current()->PostTask( | 140 base::MessageLoopProxy::current()->PostTask( |
| 141 FROM_HERE, base::Bind(callback, file_handle, base::File::FILE_OK)); | 141 FROM_HERE, base::Bind(callback, file_handle, base::File::FILE_OK)); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void FakeProvidedFileSystem::CloseFile( | 144 void FakeProvidedFileSystem::CloseFile( |
| 145 int file_handle, | 145 int file_handle, |
| 146 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 146 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 147 const OpenedFilesMap::iterator opened_file_it = | 147 const OpenedFilesMap::iterator opened_file_it = |
| 148 opened_files_.find(file_handle); | 148 opened_files_.find(file_handle); |
| 149 | 149 |
| 150 if (opened_file_it == opened_files_.end()) { | 150 if (opened_file_it == opened_files_.end()) { |
| 151 base::MessageLoopProxy::current()->PostTask( | 151 base::MessageLoopProxy::current()->PostTask( |
| 152 FROM_HERE, base::Bind(callback, base::File::FILE_ERROR_NOT_FOUND)); | 152 FROM_HERE, base::Bind(callback, base::File::FILE_ERROR_NOT_FOUND)); |
| 153 return; | 153 return; |
| 154 } | 154 } |
| 155 | 155 |
| 156 opened_files_.erase(opened_file_it); | 156 opened_files_.erase(opened_file_it); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 callback, 1 /* chunk_length */, has_more, base::File::FILE_OK)); | 215 callback, 1 /* chunk_length */, has_more, base::File::FILE_OK)); |
| 216 current_offset++; | 216 current_offset++; |
| 217 current_length--; | 217 current_length--; |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 | 220 |
| 221 void FakeProvidedFileSystem::CreateDirectory( | 221 void FakeProvidedFileSystem::CreateDirectory( |
| 222 const base::FilePath& directory_path, | 222 const base::FilePath& directory_path, |
| 223 bool exclusive, | 223 bool exclusive, |
| 224 bool recursive, | 224 bool recursive, |
| 225 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 225 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 226 // TODO(mtomasz): Implement it once needed. | 226 // TODO(mtomasz): Implement it once needed. |
| 227 base::MessageLoopProxy::current()->PostTask( | 227 base::MessageLoopProxy::current()->PostTask( |
| 228 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); | 228 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void FakeProvidedFileSystem::DeleteEntry( | 231 void FakeProvidedFileSystem::DeleteEntry( |
| 232 const base::FilePath& entry_path, | 232 const base::FilePath& entry_path, |
| 233 bool recursive, | 233 bool recursive, |
| 234 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 234 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 235 // TODO(mtomasz): Implement it once needed. | 235 // TODO(mtomasz): Implement it once needed. |
| 236 base::MessageLoopProxy::current()->PostTask( | 236 base::MessageLoopProxy::current()->PostTask( |
| 237 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); | 237 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void FakeProvidedFileSystem::CreateFile( | 240 void FakeProvidedFileSystem::CreateFile( |
| 241 const base::FilePath& file_path, | 241 const base::FilePath& file_path, |
| 242 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 242 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 243 const base::File::Error result = file_path.AsUTF8Unsafe() != kFakeFilePath | 243 const base::File::Error result = file_path.AsUTF8Unsafe() != kFakeFilePath |
| 244 ? base::File::FILE_ERROR_EXISTS | 244 ? base::File::FILE_ERROR_EXISTS |
| 245 : base::File::FILE_OK; | 245 : base::File::FILE_OK; |
| 246 | 246 |
| 247 base::MessageLoopProxy::current()->PostTask(FROM_HERE, | 247 base::MessageLoopProxy::current()->PostTask(FROM_HERE, |
| 248 base::Bind(callback, result)); | 248 base::Bind(callback, result)); |
| 249 } | 249 } |
| 250 | 250 |
| 251 void FakeProvidedFileSystem::CopyEntry( | 251 void FakeProvidedFileSystem::CopyEntry( |
| 252 const base::FilePath& source_path, | 252 const base::FilePath& source_path, |
| 253 const base::FilePath& target_path, | 253 const base::FilePath& target_path, |
| 254 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 254 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 255 base::MessageLoopProxy::current()->PostTask( | 255 base::MessageLoopProxy::current()->PostTask( |
| 256 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); | 256 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void FakeProvidedFileSystem::MoveEntry( | 259 void FakeProvidedFileSystem::MoveEntry( |
| 260 const base::FilePath& source_path, | 260 const base::FilePath& source_path, |
| 261 const base::FilePath& target_path, | 261 const base::FilePath& target_path, |
| 262 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 262 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 263 base::MessageLoopProxy::current()->PostTask( | 263 base::MessageLoopProxy::current()->PostTask( |
| 264 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); | 264 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); |
| 265 } | 265 } |
| 266 | 266 |
| 267 void FakeProvidedFileSystem::Truncate( | 267 void FakeProvidedFileSystem::Truncate( |
| 268 const base::FilePath& file_path, | 268 const base::FilePath& file_path, |
| 269 int64 length, | 269 int64 length, |
| 270 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 270 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 271 base::MessageLoopProxy::current()->PostTask( | 271 base::MessageLoopProxy::current()->PostTask( |
| 272 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); | 272 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); |
| 273 } | 273 } |
| 274 | 274 |
| 275 void FakeProvidedFileSystem::WriteFile( | 275 void FakeProvidedFileSystem::WriteFile( |
| 276 int file_handle, | 276 int file_handle, |
| 277 net::IOBuffer* buffer, | 277 net::IOBuffer* buffer, |
| 278 int64 offset, | 278 int64 offset, |
| 279 int length, | 279 int length, |
| 280 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 280 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 281 const OpenedFilesMap::iterator opened_file_it = | 281 const OpenedFilesMap::iterator opened_file_it = |
| 282 opened_files_.find(file_handle); | 282 opened_files_.find(file_handle); |
| 283 | 283 |
| 284 if (opened_file_it == opened_files_.end() || | 284 if (opened_file_it == opened_files_.end() || |
| 285 opened_file_it->second.AsUTF8Unsafe() != kFakeFilePath) { | 285 opened_file_it->second.AsUTF8Unsafe() != kFakeFilePath) { |
| 286 base::MessageLoopProxy::current()->PostTask( | 286 base::MessageLoopProxy::current()->PostTask( |
| 287 FROM_HERE, | 287 FROM_HERE, |
| 288 base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION)); | 288 base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION)); |
| 289 return; | 289 return; |
| 290 } | 290 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 return new FakeProvidedFileSystem(file_system_info); | 333 return new FakeProvidedFileSystem(file_system_info); |
| 334 } | 334 } |
| 335 | 335 |
| 336 base::WeakPtr<ProvidedFileSystemInterface> | 336 base::WeakPtr<ProvidedFileSystemInterface> |
| 337 FakeProvidedFileSystem::GetWeakPtr() { | 337 FakeProvidedFileSystem::GetWeakPtr() { |
| 338 return weak_ptr_factory_.GetWeakPtr(); | 338 return weak_ptr_factory_.GetWeakPtr(); |
| 339 } | 339 } |
| 340 | 340 |
| 341 } // namespace file_system_provider | 341 } // namespace file_system_provider |
| 342 } // namespace chromeos | 342 } // namespace chromeos |
| OLD | NEW |