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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 ProvidedFileSystemInterface::AbortCallback | 76 ProvidedFileSystemInterface::AbortCallback |
77 FakeProvidedFileSystem::RequestUnmount( | 77 FakeProvidedFileSystem::RequestUnmount( |
78 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 78 const storage::AsyncFileUtil::StatusCallback& callback) { |
79 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); | 79 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); |
80 } | 80 } |
81 | 81 |
82 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::GetMetadata( | 82 ProvidedFileSystemInterface::AbortCallback 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 return PostAbortableTask(base::Bind( | 88 return PostAbortableTask(base::Bind( |
89 callback, EntryMetadata(), base::File::FILE_ERROR_NOT_FOUND)); | 89 callback, EntryMetadata(), base::File::FILE_ERROR_NOT_FOUND)); |
90 } | 90 } |
91 | 91 |
92 return PostAbortableTask( | 92 return PostAbortableTask( |
93 base::Bind(callback, entry_it->second.metadata, base::File::FILE_OK)); | 93 base::Bind(callback, entry_it->second.metadata, base::File::FILE_OK)); |
94 } | 94 } |
95 | 95 |
96 ProvidedFileSystemInterface::AbortCallback | 96 ProvidedFileSystemInterface::AbortCallback |
97 FakeProvidedFileSystem::ReadDirectory( | 97 FakeProvidedFileSystem::ReadDirectory( |
98 const base::FilePath& directory_path, | 98 const base::FilePath& directory_path, |
99 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) { | 99 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) { |
100 fileapi::AsyncFileUtil::EntryList entry_list; | 100 storage::AsyncFileUtil::EntryList entry_list; |
101 | 101 |
102 for (Entries::const_iterator it = entries_.begin(); it != entries_.end(); | 102 for (Entries::const_iterator it = entries_.begin(); it != entries_.end(); |
103 ++it) { | 103 ++it) { |
104 const base::FilePath file_path = it->first; | 104 const base::FilePath file_path = it->first; |
105 if (file_path == directory_path || directory_path.IsParent(file_path)) { | 105 if (file_path == directory_path || directory_path.IsParent(file_path)) { |
106 const EntryMetadata& metadata = it->second.metadata; | 106 const EntryMetadata& metadata = it->second.metadata; |
107 entry_list.push_back(fileapi::DirectoryEntry( | 107 entry_list.push_back(storage::DirectoryEntry( |
108 metadata.name, | 108 metadata.name, |
109 metadata.is_directory ? fileapi::DirectoryEntry::DIRECTORY | 109 metadata.is_directory ? storage::DirectoryEntry::DIRECTORY |
110 : fileapi::DirectoryEntry::FILE, | 110 : storage::DirectoryEntry::FILE, |
111 metadata.size, | 111 metadata.size, |
112 metadata.modification_time)); | 112 metadata.modification_time)); |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 return PostAbortableTask(base::Bind( | 116 return PostAbortableTask(base::Bind( |
117 callback, base::File::FILE_OK, entry_list, false /* has_more */)); | 117 callback, base::File::FILE_OK, entry_list, false /* has_more */)); |
118 } | 118 } |
119 | 119 |
120 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::OpenFile( | 120 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::OpenFile( |
121 const base::FilePath& entry_path, | 121 const base::FilePath& entry_path, |
122 OpenFileMode mode, | 122 OpenFileMode mode, |
123 const OpenFileCallback& callback) { | 123 const OpenFileCallback& callback) { |
124 const Entries::const_iterator entry_it = entries_.find(entry_path); | 124 const Entries::const_iterator entry_it = entries_.find(entry_path); |
125 | 125 |
126 if (entry_it == entries_.end()) { | 126 if (entry_it == entries_.end()) { |
127 return PostAbortableTask(base::Bind( | 127 return PostAbortableTask(base::Bind( |
128 callback, 0 /* file_handle */, base::File::FILE_ERROR_NOT_FOUND)); | 128 callback, 0 /* file_handle */, base::File::FILE_ERROR_NOT_FOUND)); |
129 } | 129 } |
130 | 130 |
131 const int file_handle = ++last_file_handle_; | 131 const int file_handle = ++last_file_handle_; |
132 opened_files_[file_handle] = entry_path; | 132 opened_files_[file_handle] = entry_path; |
133 return PostAbortableTask( | 133 return PostAbortableTask( |
134 base::Bind(callback, file_handle, base::File::FILE_OK)); | 134 base::Bind(callback, file_handle, base::File::FILE_OK)); |
135 } | 135 } |
136 | 136 |
137 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::CloseFile( | 137 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::CloseFile( |
138 int file_handle, | 138 int file_handle, |
139 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 139 const storage::AsyncFileUtil::StatusCallback& callback) { |
140 const OpenedFilesMap::iterator opened_file_it = | 140 const OpenedFilesMap::iterator opened_file_it = |
141 opened_files_.find(file_handle); | 141 opened_files_.find(file_handle); |
142 | 142 |
143 if (opened_file_it == opened_files_.end()) { | 143 if (opened_file_it == opened_files_.end()) { |
144 return PostAbortableTask( | 144 return PostAbortableTask( |
145 base::Bind(callback, base::File::FILE_ERROR_NOT_FOUND)); | 145 base::Bind(callback, base::File::FILE_ERROR_NOT_FOUND)); |
146 } | 146 } |
147 | 147 |
148 opened_files_.erase(opened_file_it); | 148 opened_files_.erase(opened_file_it); |
149 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); | 149 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 return base::Bind(&FakeProvidedFileSystem::AbortMany, | 208 return base::Bind(&FakeProvidedFileSystem::AbortMany, |
209 weak_ptr_factory_.GetWeakPtr(), | 209 weak_ptr_factory_.GetWeakPtr(), |
210 task_ids); | 210 task_ids); |
211 } | 211 } |
212 | 212 |
213 ProvidedFileSystemInterface::AbortCallback | 213 ProvidedFileSystemInterface::AbortCallback |
214 FakeProvidedFileSystem::CreateDirectory( | 214 FakeProvidedFileSystem::CreateDirectory( |
215 const base::FilePath& directory_path, | 215 const base::FilePath& directory_path, |
216 bool exclusive, | 216 bool exclusive, |
217 bool recursive, | 217 bool recursive, |
218 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 218 const storage::AsyncFileUtil::StatusCallback& callback) { |
219 // TODO(mtomasz): Implement it once needed. | 219 // TODO(mtomasz): Implement it once needed. |
220 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); | 220 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); |
221 } | 221 } |
222 | 222 |
223 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::DeleteEntry( | 223 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::DeleteEntry( |
224 const base::FilePath& entry_path, | 224 const base::FilePath& entry_path, |
225 bool recursive, | 225 bool recursive, |
226 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 226 const storage::AsyncFileUtil::StatusCallback& callback) { |
227 // TODO(mtomasz): Implement it once needed. | 227 // TODO(mtomasz): Implement it once needed. |
228 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); | 228 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); |
229 } | 229 } |
230 | 230 |
231 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::CreateFile( | 231 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::CreateFile( |
232 const base::FilePath& file_path, | 232 const base::FilePath& file_path, |
233 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 233 const storage::AsyncFileUtil::StatusCallback& callback) { |
234 const base::File::Error result = file_path.AsUTF8Unsafe() != kFakeFilePath | 234 const base::File::Error result = file_path.AsUTF8Unsafe() != kFakeFilePath |
235 ? base::File::FILE_ERROR_EXISTS | 235 ? base::File::FILE_ERROR_EXISTS |
236 : base::File::FILE_OK; | 236 : base::File::FILE_OK; |
237 | 237 |
238 return PostAbortableTask(base::Bind(callback, result)); | 238 return PostAbortableTask(base::Bind(callback, result)); |
239 } | 239 } |
240 | 240 |
241 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::CopyEntry( | 241 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::CopyEntry( |
242 const base::FilePath& source_path, | 242 const base::FilePath& source_path, |
243 const base::FilePath& target_path, | 243 const base::FilePath& target_path, |
244 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 244 const storage::AsyncFileUtil::StatusCallback& callback) { |
245 // TODO(mtomasz): Implement it once needed. | 245 // TODO(mtomasz): Implement it once needed. |
246 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); | 246 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); |
247 } | 247 } |
248 | 248 |
249 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::MoveEntry( | 249 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::MoveEntry( |
250 const base::FilePath& source_path, | 250 const base::FilePath& source_path, |
251 const base::FilePath& target_path, | 251 const base::FilePath& target_path, |
252 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 252 const storage::AsyncFileUtil::StatusCallback& callback) { |
253 // TODO(mtomasz): Implement it once needed. | 253 // TODO(mtomasz): Implement it once needed. |
254 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); | 254 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); |
255 } | 255 } |
256 | 256 |
257 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::Truncate( | 257 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::Truncate( |
258 const base::FilePath& file_path, | 258 const base::FilePath& file_path, |
259 int64 length, | 259 int64 length, |
260 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 260 const storage::AsyncFileUtil::StatusCallback& callback) { |
261 // TODO(mtomasz): Implement it once needed. | 261 // TODO(mtomasz): Implement it once needed. |
262 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); | 262 return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); |
263 } | 263 } |
264 | 264 |
265 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::WriteFile( | 265 ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::WriteFile( |
266 int file_handle, | 266 int file_handle, |
267 net::IOBuffer* buffer, | 267 net::IOBuffer* buffer, |
268 int64 offset, | 268 int64 offset, |
269 int length, | 269 int length, |
270 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 270 const storage::AsyncFileUtil::StatusCallback& callback) { |
271 const OpenedFilesMap::iterator opened_file_it = | 271 const OpenedFilesMap::iterator opened_file_it = |
272 opened_files_.find(file_handle); | 272 opened_files_.find(file_handle); |
273 | 273 |
274 if (opened_file_it == opened_files_.end() || | 274 if (opened_file_it == opened_files_.end() || |
275 opened_file_it->second.AsUTF8Unsafe() != kFakeFilePath) { | 275 opened_file_it->second.AsUTF8Unsafe() != kFakeFilePath) { |
276 return PostAbortableTask( | 276 return PostAbortableTask( |
277 base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION)); | 277 base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION)); |
278 } | 278 } |
279 | 279 |
280 const Entries::iterator entry_it = entries_.find(opened_file_it->second); | 280 const Entries::iterator entry_it = entries_.find(opened_file_it->second); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 ProvidedFileSystemInterface::AbortCallback | 324 ProvidedFileSystemInterface::AbortCallback |
325 FakeProvidedFileSystem::PostAbortableTask(const base::Closure& callback) { | 325 FakeProvidedFileSystem::PostAbortableTask(const base::Closure& callback) { |
326 const int task_id = | 326 const int task_id = |
327 tracker_.PostTask(base::MessageLoopProxy::current(), FROM_HERE, callback); | 327 tracker_.PostTask(base::MessageLoopProxy::current(), FROM_HERE, callback); |
328 return base::Bind( | 328 return base::Bind( |
329 &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); | 329 &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); |
330 } | 330 } |
331 | 331 |
332 void FakeProvidedFileSystem::Abort( | 332 void FakeProvidedFileSystem::Abort( |
333 int task_id, | 333 int task_id, |
334 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 334 const storage::AsyncFileUtil::StatusCallback& callback) { |
335 tracker_.TryCancel(task_id); | 335 tracker_.TryCancel(task_id); |
336 callback.Run(base::File::FILE_OK); | 336 callback.Run(base::File::FILE_OK); |
337 } | 337 } |
338 | 338 |
339 void FakeProvidedFileSystem::AbortMany( | 339 void FakeProvidedFileSystem::AbortMany( |
340 const std::vector<int>& task_ids, | 340 const std::vector<int>& task_ids, |
341 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 341 const storage::AsyncFileUtil::StatusCallback& callback) { |
342 for (size_t i = 0; i < task_ids.size(); ++i) { | 342 for (size_t i = 0; i < task_ids.size(); ++i) { |
343 tracker_.TryCancel(task_ids[i]); | 343 tracker_.TryCancel(task_ids[i]); |
344 } | 344 } |
345 callback.Run(base::File::FILE_OK); | 345 callback.Run(base::File::FILE_OK); |
346 } | 346 } |
347 | 347 |
348 } // namespace file_system_provider | 348 } // namespace file_system_provider |
349 } // namespace chromeos | 349 } // namespace chromeos |
OLD | NEW |