Chromium Code Reviews| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 bool FakeProvidedFileSystem::GetEntry(const base::FilePath& entry_path, | 66 bool FakeProvidedFileSystem::GetEntry(const base::FilePath& entry_path, |
| 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 ProvidedFileSystemInterface::AbortCallback |
| 77 FakeProvidedFileSystem::RequestUnmount( | |
| 77 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 78 const fileapi::AsyncFileUtil::StatusCallback& callback) { |
| 78 base::MessageLoopProxy::current()->PostTask( | 79 const int task_id = |
| 79 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); | 80 tracker_.PostTask(base::MessageLoopProxy::current(), |
| 81 FROM_HERE, | |
| 82 base::Bind(callback, base::File::FILE_OK)); | |
| 83 return base::Bind( | |
| 84 &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); | |
|
hirono
2014/08/06 08:33:50
How about adding a helper function to call PostTas
mtomasz
2014/08/08 06:29:40
Done.
| |
| 80 } | 85 } |
| 81 | 86 |
| 82 void FakeProvidedFileSystem::GetMetadata( | 87 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::GetMetadata( |
| 83 const base::FilePath& entry_path, | 88 const base::FilePath& entry_path, |
| 84 const ProvidedFileSystemInterface::GetMetadataCallback& callback) { | 89 const ProvidedFileSystemInterface::GetMetadataCallback& callback) { |
| 85 const Entries::const_iterator entry_it = entries_.find(entry_path); | 90 const Entries::const_iterator entry_it = entries_.find(entry_path); |
| 86 | 91 |
| 87 if (entry_it == entries_.end()) { | 92 if (entry_it == entries_.end()) { |
| 88 base::MessageLoopProxy::current()->PostTask( | 93 const int task_id = tracker_.PostTask( |
| 94 base::MessageLoopProxy::current(), | |
| 89 FROM_HERE, | 95 FROM_HERE, |
| 90 base::Bind( | 96 base::Bind( |
| 91 callback, EntryMetadata(), base::File::FILE_ERROR_NOT_FOUND)); | 97 callback, EntryMetadata(), base::File::FILE_ERROR_NOT_FOUND)); |
| 92 return; | 98 return base::Bind(&FakeProvidedFileSystem::Abort, |
| 99 weak_ptr_factory_.GetWeakPtr(), | |
| 100 task_id); | |
| 93 } | 101 } |
| 94 | 102 |
| 95 base::MessageLoopProxy::current()->PostTask( | 103 const int task_id = tracker_.PostTask( |
| 104 base::MessageLoopProxy::current(), | |
| 96 FROM_HERE, | 105 FROM_HERE, |
| 97 base::Bind(callback, entry_it->second.metadata, base::File::FILE_OK)); | 106 base::Bind(callback, entry_it->second.metadata, base::File::FILE_OK)); |
| 107 return base::Bind( | |
| 108 &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); | |
| 98 } | 109 } |
| 99 | 110 |
| 100 void FakeProvidedFileSystem::ReadDirectory( | 111 ProvidedFileSystemInterface::AbortCallback |
| 112 FakeProvidedFileSystem::ReadDirectory( | |
| 101 const base::FilePath& directory_path, | 113 const base::FilePath& directory_path, |
| 102 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) { | 114 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) { |
| 103 fileapi::AsyncFileUtil::EntryList entry_list; | 115 fileapi::AsyncFileUtil::EntryList entry_list; |
| 104 | 116 |
| 105 for (Entries::const_iterator it = entries_.begin(); it != entries_.end(); | 117 for (Entries::const_iterator it = entries_.begin(); it != entries_.end(); |
| 106 ++it) { | 118 ++it) { |
| 107 const base::FilePath file_path = it->first; | 119 const base::FilePath file_path = it->first; |
| 108 if (file_path == directory_path || directory_path.IsParent(file_path)) { | 120 if (file_path == directory_path || directory_path.IsParent(file_path)) { |
| 109 const EntryMetadata& metadata = it->second.metadata; | 121 const EntryMetadata& metadata = it->second.metadata; |
| 110 entry_list.push_back(fileapi::DirectoryEntry( | 122 entry_list.push_back(fileapi::DirectoryEntry( |
| 111 metadata.name, | 123 metadata.name, |
| 112 metadata.is_directory ? fileapi::DirectoryEntry::DIRECTORY | 124 metadata.is_directory ? fileapi::DirectoryEntry::DIRECTORY |
| 113 : fileapi::DirectoryEntry::FILE, | 125 : fileapi::DirectoryEntry::FILE, |
| 114 metadata.size, | 126 metadata.size, |
| 115 metadata.modification_time)); | 127 metadata.modification_time)); |
| 116 } | 128 } |
| 117 } | 129 } |
| 118 | 130 |
| 119 base::MessageLoopProxy::current()->PostTask( | 131 const int task_id = tracker_.PostTask( |
| 132 base::MessageLoopProxy::current(), | |
| 120 FROM_HERE, | 133 FROM_HERE, |
| 121 base::Bind( | 134 base::Bind( |
| 122 callback, base::File::FILE_OK, entry_list, false /* has_more */)); | 135 callback, base::File::FILE_OK, entry_list, false /* has_more */)); |
| 136 return base::Bind( | |
| 137 &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); | |
| 123 } | 138 } |
| 124 | 139 |
| 125 void FakeProvidedFileSystem::OpenFile(const base::FilePath& entry_path, | 140 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::OpenFile( |
| 126 OpenFileMode mode, | 141 const base::FilePath& entry_path, |
| 127 const OpenFileCallback& callback) { | 142 OpenFileMode mode, |
| 143 const OpenFileCallback& callback) { | |
| 128 const Entries::const_iterator entry_it = entries_.find(entry_path); | 144 const Entries::const_iterator entry_it = entries_.find(entry_path); |
| 129 | 145 |
| 130 if (entry_it == entries_.end()) { | 146 if (entry_it == entries_.end()) { |
| 131 base::MessageLoopProxy::current()->PostTask( | 147 const int task_id = tracker_.PostTask( |
| 148 base::MessageLoopProxy::current(), | |
| 132 FROM_HERE, | 149 FROM_HERE, |
| 133 base::Bind( | 150 base::Bind( |
| 134 callback, 0 /* file_handle */, base::File::FILE_ERROR_NOT_FOUND)); | 151 callback, 0 /* file_handle */, base::File::FILE_ERROR_NOT_FOUND)); |
| 135 return; | 152 return base::Bind(&FakeProvidedFileSystem::Abort, |
| 153 weak_ptr_factory_.GetWeakPtr(), | |
| 154 task_id); | |
| 136 } | 155 } |
| 137 | 156 |
| 138 const int file_handle = ++last_file_handle_; | 157 const int file_handle = ++last_file_handle_; |
| 139 opened_files_[file_handle] = entry_path; | 158 opened_files_[file_handle] = entry_path; |
| 140 base::MessageLoopProxy::current()->PostTask( | 159 const int task_id = |
| 141 FROM_HERE, base::Bind(callback, file_handle, base::File::FILE_OK)); | 160 tracker_.PostTask(base::MessageLoopProxy::current(), |
| 161 FROM_HERE, | |
| 162 base::Bind(callback, file_handle, base::File::FILE_OK)); | |
| 163 return base::Bind( | |
| 164 &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); | |
| 142 } | 165 } |
| 143 | 166 |
| 144 void FakeProvidedFileSystem::CloseFile( | 167 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::CloseFile( |
| 145 int file_handle, | 168 int file_handle, |
| 146 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 169 const fileapi::AsyncFileUtil::StatusCallback& callback) { |
| 147 const OpenedFilesMap::iterator opened_file_it = | 170 const OpenedFilesMap::iterator opened_file_it = |
| 148 opened_files_.find(file_handle); | 171 opened_files_.find(file_handle); |
| 149 | 172 |
| 150 if (opened_file_it == opened_files_.end()) { | 173 if (opened_file_it == opened_files_.end()) { |
| 151 base::MessageLoopProxy::current()->PostTask( | 174 const int task_id = tracker_.PostTask( |
| 152 FROM_HERE, base::Bind(callback, base::File::FILE_ERROR_NOT_FOUND)); | 175 base::MessageLoopProxy::current(), |
| 153 return; | 176 FROM_HERE, |
| 177 base::Bind(callback, base::File::FILE_ERROR_NOT_FOUND)); | |
| 178 return base::Bind(&FakeProvidedFileSystem::Abort, | |
| 179 weak_ptr_factory_.GetWeakPtr(), | |
| 180 task_id); | |
| 154 } | 181 } |
| 155 | 182 |
| 156 opened_files_.erase(opened_file_it); | 183 opened_files_.erase(opened_file_it); |
| 157 base::MessageLoopProxy::current()->PostTask( | 184 const int task_id = |
| 158 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); | 185 tracker_.PostTask(base::MessageLoopProxy::current(), |
| 186 FROM_HERE, | |
| 187 base::Bind(callback, base::File::FILE_OK)); | |
| 188 return base::Bind(base::Bind( | |
| 189 &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id)); | |
| 159 } | 190 } |
| 160 | 191 |
| 161 void FakeProvidedFileSystem::ReadFile( | 192 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::ReadFile( |
| 162 int file_handle, | 193 int file_handle, |
| 163 net::IOBuffer* buffer, | 194 net::IOBuffer* buffer, |
| 164 int64 offset, | 195 int64 offset, |
| 165 int length, | 196 int length, |
| 166 const ProvidedFileSystemInterface::ReadChunkReceivedCallback& callback) { | 197 const ProvidedFileSystemInterface::ReadChunkReceivedCallback& callback) { |
| 167 const OpenedFilesMap::iterator opened_file_it = | 198 const OpenedFilesMap::iterator opened_file_it = |
| 168 opened_files_.find(file_handle); | 199 opened_files_.find(file_handle); |
| 169 | 200 |
| 170 if (opened_file_it == opened_files_.end() || | 201 if (opened_file_it == opened_files_.end() || |
| 171 opened_file_it->second.AsUTF8Unsafe() != kFakeFilePath) { | 202 opened_file_it->second.AsUTF8Unsafe() != kFakeFilePath) { |
| 172 base::MessageLoopProxy::current()->PostTask( | 203 const int task_id = |
| 173 FROM_HERE, | 204 tracker_.PostTask(base::MessageLoopProxy::current(), |
| 174 base::Bind(callback, | 205 FROM_HERE, |
| 175 0 /* chunk_length */, | 206 base::Bind(callback, |
| 176 false /* has_more */, | 207 0 /* chunk_length */, |
| 177 base::File::FILE_ERROR_INVALID_OPERATION)); | 208 false /* has_more */, |
| 178 return; | 209 base::File::FILE_ERROR_INVALID_OPERATION)); |
| 210 return base::Bind(&FakeProvidedFileSystem::Abort, | |
| 211 weak_ptr_factory_.GetWeakPtr(), | |
| 212 task_id); | |
| 179 } | 213 } |
| 180 | 214 |
| 181 const Entries::const_iterator entry_it = | 215 const Entries::const_iterator entry_it = |
| 182 entries_.find(opened_file_it->second); | 216 entries_.find(opened_file_it->second); |
| 183 if (entry_it == entries_.end()) { | 217 if (entry_it == entries_.end()) { |
| 184 base::MessageLoopProxy::current()->PostTask( | 218 const int task_id = |
| 185 FROM_HERE, | 219 tracker_.PostTask(base::MessageLoopProxy::current(), |
| 186 base::Bind(callback, | 220 FROM_HERE, |
| 187 0 /* chunk_length */, | 221 base::Bind(callback, |
| 188 false /* has_more */, | 222 0 /* chunk_length */, |
| 189 base::File::FILE_ERROR_INVALID_OPERATION)); | 223 false /* has_more */, |
| 190 return; | 224 base::File::FILE_ERROR_INVALID_OPERATION)); |
| 225 return base::Bind(&FakeProvidedFileSystem::Abort, | |
| 226 weak_ptr_factory_.GetWeakPtr(), | |
| 227 task_id); | |
| 191 } | 228 } |
| 192 | 229 |
| 193 // Send the response byte by byte. | 230 // Send the response byte by byte. |
| 194 int64 current_offset = offset; | 231 int64 current_offset = offset; |
| 195 int current_length = length; | 232 int current_length = length; |
| 196 | 233 |
| 197 // Reading behind EOF is fine, it will just return 0 bytes. | 234 // Reading behind EOF is fine, it will just return 0 bytes. |
| 198 if (current_offset >= entry_it->second.metadata.size || !current_length) { | 235 if (current_offset >= entry_it->second.metadata.size || !current_length) { |
| 199 base::MessageLoopProxy::current()->PostTask( | 236 const int task_id = tracker_.PostTask(base::MessageLoopProxy::current(), |
| 200 FROM_HERE, | 237 FROM_HERE, |
| 201 base::Bind(callback, | 238 base::Bind(callback, |
| 202 0 /* chunk_length */, | 239 0 /* chunk_length */, |
| 203 false /* has_more */, | 240 false /* has_more */, |
| 204 base::File::FILE_OK)); | 241 base::File::FILE_OK)); |
| 242 return base::Bind(&FakeProvidedFileSystem::Abort, | |
| 243 weak_ptr_factory_.GetWeakPtr(), | |
| 244 task_id); | |
| 205 } | 245 } |
| 206 | 246 |
| 207 const FakeEntry& entry = entry_it->second; | 247 const FakeEntry& entry = entry_it->second; |
| 248 std::vector<int> task_ids; | |
| 208 while (current_offset < entry.metadata.size && current_length) { | 249 while (current_offset < entry.metadata.size && current_length) { |
| 209 buffer->data()[current_offset - offset] = entry.contents[current_offset]; | 250 buffer->data()[current_offset - offset] = entry.contents[current_offset]; |
| 210 const bool has_more = | 251 const bool has_more = |
| 211 (current_offset + 1 < entry.metadata.size) && (current_length - 1); | 252 (current_offset + 1 < entry.metadata.size) && (current_length - 1); |
| 212 base::MessageLoopProxy::current()->PostTask( | 253 const int task_id = tracker_.PostTask( |
| 254 base::MessageLoopProxy::current(), | |
| 213 FROM_HERE, | 255 FROM_HERE, |
| 214 base::Bind( | 256 base::Bind( |
| 215 callback, 1 /* chunk_length */, has_more, base::File::FILE_OK)); | 257 callback, 1 /* chunk_length */, has_more, base::File::FILE_OK)); |
| 258 task_ids.push_back(task_id); | |
| 216 current_offset++; | 259 current_offset++; |
| 217 current_length--; | 260 current_length--; |
| 218 } | 261 } |
| 262 | |
| 263 return base::Bind(&FakeProvidedFileSystem::AbortMany, | |
| 264 weak_ptr_factory_.GetWeakPtr(), | |
| 265 task_ids); | |
| 219 } | 266 } |
| 220 | 267 |
| 221 void FakeProvidedFileSystem::CreateDirectory( | 268 ProvidedFileSystemInterface::AbortCallback |
| 269 FakeProvidedFileSystem::CreateDirectory( | |
| 222 const base::FilePath& directory_path, | 270 const base::FilePath& directory_path, |
| 223 bool exclusive, | 271 bool exclusive, |
| 224 bool recursive, | 272 bool recursive, |
| 225 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 273 const fileapi::AsyncFileUtil::StatusCallback& callback) { |
| 226 // TODO(mtomasz): Implement it once needed. | 274 // TODO(mtomasz): Implement it once needed. |
| 227 base::MessageLoopProxy::current()->PostTask( | 275 const int task_id = |
| 228 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); | 276 tracker_.PostTask(base::MessageLoopProxy::current(), |
| 277 FROM_HERE, | |
| 278 base::Bind(callback, base::File::FILE_OK)); | |
| 279 return base::Bind( | |
| 280 &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); | |
| 229 } | 281 } |
| 230 | 282 |
| 231 void FakeProvidedFileSystem::DeleteEntry( | 283 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::DeleteEntry( |
| 232 const base::FilePath& entry_path, | 284 const base::FilePath& entry_path, |
| 233 bool recursive, | 285 bool recursive, |
| 234 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 286 const fileapi::AsyncFileUtil::StatusCallback& callback) { |
| 235 // TODO(mtomasz): Implement it once needed. | 287 // TODO(mtomasz): Implement it once needed. |
| 236 base::MessageLoopProxy::current()->PostTask( | 288 const int task_id = |
| 237 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); | 289 tracker_.PostTask(base::MessageLoopProxy::current(), |
| 290 FROM_HERE, | |
| 291 base::Bind(callback, base::File::FILE_OK)); | |
| 292 return base::Bind( | |
| 293 &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); | |
| 238 } | 294 } |
| 239 | 295 |
| 240 void FakeProvidedFileSystem::CreateFile( | 296 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::CreateFile( |
| 241 const base::FilePath& file_path, | 297 const base::FilePath& file_path, |
| 242 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 298 const fileapi::AsyncFileUtil::StatusCallback& callback) { |
| 243 const base::File::Error result = file_path.AsUTF8Unsafe() != kFakeFilePath | 299 const base::File::Error result = file_path.AsUTF8Unsafe() != kFakeFilePath |
| 244 ? base::File::FILE_ERROR_EXISTS | 300 ? base::File::FILE_ERROR_EXISTS |
| 245 : base::File::FILE_OK; | 301 : base::File::FILE_OK; |
| 246 | 302 |
| 247 base::MessageLoopProxy::current()->PostTask(FROM_HERE, | 303 const int task_id = tracker_.PostTask(base::MessageLoopProxy::current(), |
| 248 base::Bind(callback, result)); | 304 FROM_HERE, |
| 305 base::Bind(callback, result)); | |
| 306 return base::Bind( | |
| 307 &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); | |
| 249 } | 308 } |
| 250 | 309 |
| 251 void FakeProvidedFileSystem::CopyEntry( | 310 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::CopyEntry( |
| 252 const base::FilePath& source_path, | 311 const base::FilePath& source_path, |
| 253 const base::FilePath& target_path, | 312 const base::FilePath& target_path, |
| 254 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 313 const fileapi::AsyncFileUtil::StatusCallback& callback) { |
| 255 base::MessageLoopProxy::current()->PostTask( | 314 // TODO(mtomasz): Implement it once needed. |
| 256 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); | 315 const int task_id = |
| 316 tracker_.PostTask(base::MessageLoopProxy::current(), | |
| 317 FROM_HERE, | |
| 318 base::Bind(callback, base::File::FILE_OK)); | |
| 319 return base::Bind( | |
| 320 &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); | |
| 257 } | 321 } |
| 258 | 322 |
| 259 void FakeProvidedFileSystem::MoveEntry( | 323 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::MoveEntry( |
| 260 const base::FilePath& source_path, | 324 const base::FilePath& source_path, |
| 261 const base::FilePath& target_path, | 325 const base::FilePath& target_path, |
| 262 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 326 const fileapi::AsyncFileUtil::StatusCallback& callback) { |
| 263 base::MessageLoopProxy::current()->PostTask( | 327 // TODO(mtomasz): Implement it once needed. |
| 264 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); | 328 const int task_id = |
| 329 tracker_.PostTask(base::MessageLoopProxy::current(), | |
| 330 FROM_HERE, | |
| 331 base::Bind(callback, base::File::FILE_OK)); | |
| 332 return base::Bind( | |
| 333 &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); | |
| 265 } | 334 } |
| 266 | 335 |
| 267 void FakeProvidedFileSystem::Truncate( | 336 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::Truncate( |
| 268 const base::FilePath& file_path, | 337 const base::FilePath& file_path, |
| 269 int64 length, | 338 int64 length, |
| 270 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 339 const fileapi::AsyncFileUtil::StatusCallback& callback) { |
| 271 base::MessageLoopProxy::current()->PostTask( | 340 // TODO(mtomasz): Implement it once needed. |
| 272 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); | 341 const int task_id = |
| 342 tracker_.PostTask(base::MessageLoopProxy::current(), | |
| 343 FROM_HERE, | |
| 344 base::Bind(callback, base::File::FILE_OK)); | |
| 345 return base::Bind( | |
| 346 &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); | |
| 273 } | 347 } |
| 274 | 348 |
| 275 void FakeProvidedFileSystem::WriteFile( | 349 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::WriteFile( |
| 276 int file_handle, | 350 int file_handle, |
| 277 net::IOBuffer* buffer, | 351 net::IOBuffer* buffer, |
| 278 int64 offset, | 352 int64 offset, |
| 279 int length, | 353 int length, |
| 280 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 354 const fileapi::AsyncFileUtil::StatusCallback& callback) { |
| 281 const OpenedFilesMap::iterator opened_file_it = | 355 const OpenedFilesMap::iterator opened_file_it = |
| 282 opened_files_.find(file_handle); | 356 opened_files_.find(file_handle); |
| 283 | 357 |
| 284 if (opened_file_it == opened_files_.end() || | 358 if (opened_file_it == opened_files_.end() || |
| 285 opened_file_it->second.AsUTF8Unsafe() != kFakeFilePath) { | 359 opened_file_it->second.AsUTF8Unsafe() != kFakeFilePath) { |
| 286 base::MessageLoopProxy::current()->PostTask( | 360 const int task_id = tracker_.PostTask( |
| 361 base::MessageLoopProxy::current(), | |
| 287 FROM_HERE, | 362 FROM_HERE, |
| 288 base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION)); | 363 base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION)); |
| 289 return; | 364 return base::Bind(&FakeProvidedFileSystem::Abort, |
| 365 weak_ptr_factory_.GetWeakPtr(), | |
| 366 task_id); | |
| 290 } | 367 } |
| 291 | 368 |
| 292 const Entries::iterator entry_it = entries_.find(opened_file_it->second); | 369 const Entries::iterator entry_it = entries_.find(opened_file_it->second); |
| 293 if (entry_it == entries_.end()) { | 370 if (entry_it == entries_.end()) { |
| 294 base::MessageLoopProxy::current()->PostTask( | 371 const int task_id = tracker_.PostTask( |
| 372 base::MessageLoopProxy::current(), | |
| 295 FROM_HERE, | 373 FROM_HERE, |
| 296 base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION)); | 374 base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION)); |
| 297 return; | 375 return base::Bind(&FakeProvidedFileSystem::Abort, |
| 376 weak_ptr_factory_.GetWeakPtr(), | |
| 377 task_id); | |
| 298 } | 378 } |
| 299 | 379 |
| 300 FakeEntry* const entry = &entry_it->second; | 380 FakeEntry* const entry = &entry_it->second; |
| 301 if (offset > entry->metadata.size) { | 381 if (offset > entry->metadata.size) { |
| 302 base::MessageLoopProxy::current()->PostTask( | 382 const int task_id = tracker_.PostTask( |
| 383 base::MessageLoopProxy::current(), | |
| 303 FROM_HERE, | 384 FROM_HERE, |
| 304 base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION)); | 385 base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION)); |
| 305 return; | 386 return base::Bind(&FakeProvidedFileSystem::Abort, |
| 387 weak_ptr_factory_.GetWeakPtr(), | |
| 388 task_id); | |
| 306 } | 389 } |
| 307 | 390 |
| 308 // Allocate the string size in advance. | 391 // Allocate the string size in advance. |
| 309 if (offset + length > entry->metadata.size) { | 392 if (offset + length > entry->metadata.size) { |
| 310 entry->metadata.size = offset + length; | 393 entry->metadata.size = offset + length; |
| 311 entry->contents.resize(entry->metadata.size); | 394 entry->contents.resize(entry->metadata.size); |
| 312 } | 395 } |
| 313 | 396 |
| 314 entry->contents.replace(offset, length, buffer->data(), length); | 397 entry->contents.replace(offset, length, buffer->data(), length); |
| 315 | 398 |
| 316 base::MessageLoopProxy::current()->PostTask( | 399 const int task_id = |
| 317 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); | 400 tracker_.PostTask(base::MessageLoopProxy::current(), |
| 401 FROM_HERE, | |
| 402 base::Bind(callback, base::File::FILE_OK)); | |
| 403 return base::Bind( | |
| 404 &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); | |
| 318 } | 405 } |
| 319 | 406 |
| 320 const ProvidedFileSystemInfo& FakeProvidedFileSystem::GetFileSystemInfo() | 407 const ProvidedFileSystemInfo& FakeProvidedFileSystem::GetFileSystemInfo() |
| 321 const { | 408 const { |
| 322 return file_system_info_; | 409 return file_system_info_; |
| 323 } | 410 } |
| 324 | 411 |
| 325 RequestManager* FakeProvidedFileSystem::GetRequestManager() { | 412 RequestManager* FakeProvidedFileSystem::GetRequestManager() { |
| 326 NOTREACHED(); | 413 NOTREACHED(); |
| 327 return NULL; | 414 return NULL; |
| 328 } | 415 } |
| 329 | 416 |
| 330 ProvidedFileSystemInterface* FakeProvidedFileSystem::Create( | 417 ProvidedFileSystemInterface* FakeProvidedFileSystem::Create( |
| 331 Profile* profile, | 418 Profile* profile, |
| 332 const ProvidedFileSystemInfo& file_system_info) { | 419 const ProvidedFileSystemInfo& file_system_info) { |
| 333 return new FakeProvidedFileSystem(file_system_info); | 420 return new FakeProvidedFileSystem(file_system_info); |
| 334 } | 421 } |
| 335 | 422 |
| 336 base::WeakPtr<ProvidedFileSystemInterface> | 423 base::WeakPtr<ProvidedFileSystemInterface> |
| 337 FakeProvidedFileSystem::GetWeakPtr() { | 424 FakeProvidedFileSystem::GetWeakPtr() { |
| 338 return weak_ptr_factory_.GetWeakPtr(); | 425 return weak_ptr_factory_.GetWeakPtr(); |
| 339 } | 426 } |
| 340 | 427 |
| 428 void FakeProvidedFileSystem::Abort( | |
| 429 int task_id, | |
| 430 const fileapi::AsyncFileUtil::StatusCallback& callback) { | |
| 431 tracker_.TryCancel(task_id); | |
| 432 callback.Run(base::File::FILE_OK); | |
| 433 } | |
| 434 | |
| 435 void FakeProvidedFileSystem::AbortMany( | |
| 436 const std::vector<int>& task_ids, | |
| 437 const fileapi::AsyncFileUtil::StatusCallback& callback) { | |
| 438 for (size_t i = 0; i < task_ids.size(); ++i) { | |
| 439 tracker_.TryCancel(task_ids[i]); | |
| 440 } | |
| 441 callback.Run(base::File::FILE_OK); | |
| 442 } | |
| 443 | |
| 341 } // namespace file_system_provider | 444 } // namespace file_system_provider |
| 342 } // namespace chromeos | 445 } // namespace chromeos |
| OLD | NEW |