OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/memory/weak_ptr.h" | 6 #include "base/memory/weak_ptr.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "webkit/chromeos/fileapi/memory_file_util.h" | 8 #include "webkit/chromeos/fileapi/memory_file_util.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 base::WeakPtrFactory<MemoryFileUtilAsyncFileStream> weak_ptr_factory_; | 127 base::WeakPtrFactory<MemoryFileUtilAsyncFileStream> weak_ptr_factory_; |
128 }; | 128 }; |
129 | 129 |
130 MemoryFileUtil::FileEntry::FileEntry() | 130 MemoryFileUtil::FileEntry::FileEntry() |
131 : is_directory(false) { | 131 : is_directory(false) { |
132 } | 132 } |
133 | 133 |
134 MemoryFileUtil::FileEntry::~FileEntry() { | 134 MemoryFileUtil::FileEntry::~FileEntry() { |
135 } | 135 } |
136 | 136 |
137 MemoryFileUtil::MemoryFileUtil(const FilePath& root_path) | 137 MemoryFileUtil::MemoryFileUtil(const base::FilePath& root_path) |
138 : read_directory_buffer_size_(kDefaultReadDirectoryBufferSize) { | 138 : read_directory_buffer_size_(kDefaultReadDirectoryBufferSize) { |
139 FileEntry root; | 139 FileEntry root; |
140 root.is_directory = true; | 140 root.is_directory = true; |
141 root.last_modified = base::Time::Now(); | 141 root.last_modified = base::Time::Now(); |
142 | 142 |
143 files_[root_path] = root; | 143 files_[root_path] = root; |
144 } | 144 } |
145 | 145 |
146 MemoryFileUtil::~MemoryFileUtil() { | 146 MemoryFileUtil::~MemoryFileUtil() { |
147 } | 147 } |
(...skipping 24 matching lines...) Expand all Loading... |
172 // - OpenVerifiedFile OR Create | 172 // - OpenVerifiedFile OR Create |
173 // DidCreateOrTruncateForOpen | 173 // DidCreateOrTruncateForOpen |
174 // OpenVerifiedFile | 174 // OpenVerifiedFile |
175 // | 175 // |
176 // PLATFORM_FILE_OPEN_TRUNCATED: | 176 // PLATFORM_FILE_OPEN_TRUNCATED: |
177 // - Truncate | 177 // - Truncate |
178 // - DidCreateOrTruncateForOpen | 178 // - DidCreateOrTruncateForOpen |
179 // - OpenVerifiedFile | 179 // - OpenVerifiedFile |
180 // | 180 // |
181 void MemoryFileUtil::Open( | 181 void MemoryFileUtil::Open( |
182 const FilePath& file_path, | 182 const base::FilePath& file_path, |
183 int flags, | 183 int flags, |
184 const OpenCallback& callback) { | 184 const OpenCallback& callback) { |
185 int create_flag = flags & (base::PLATFORM_FILE_OPEN | | 185 int create_flag = flags & (base::PLATFORM_FILE_OPEN | |
186 base::PLATFORM_FILE_CREATE | | 186 base::PLATFORM_FILE_CREATE | |
187 base::PLATFORM_FILE_OPEN_ALWAYS | | 187 base::PLATFORM_FILE_OPEN_ALWAYS | |
188 base::PLATFORM_FILE_CREATE_ALWAYS | | 188 base::PLATFORM_FILE_CREATE_ALWAYS | |
189 base::PLATFORM_FILE_OPEN_TRUNCATED); | 189 base::PLATFORM_FILE_OPEN_TRUNCATED); |
190 switch (create_flag) { | 190 switch (create_flag) { |
191 case base::PLATFORM_FILE_OPEN: | 191 case base::PLATFORM_FILE_OPEN: |
192 case base::PLATFORM_FILE_OPEN_ALWAYS: | 192 case base::PLATFORM_FILE_OPEN_ALWAYS: |
(...skipping 30 matching lines...) Expand all Loading... |
223 default: | 223 default: |
224 MessageLoop::current()->PostTask( | 224 MessageLoop::current()->PostTask( |
225 FROM_HERE, | 225 FROM_HERE, |
226 base::Bind(callback, | 226 base::Bind(callback, |
227 base::PLATFORM_FILE_ERROR_INVALID_OPERATION, | 227 base::PLATFORM_FILE_ERROR_INVALID_OPERATION, |
228 static_cast<AsyncFileStream*>(NULL))); | 228 static_cast<AsyncFileStream*>(NULL))); |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
232 void MemoryFileUtil::GetFileInfo( | 232 void MemoryFileUtil::GetFileInfo( |
233 const FilePath& file_path, | 233 const base::FilePath& file_path, |
234 const GetFileInfoCallback& callback) { | 234 const GetFileInfoCallback& callback) { |
235 MessageLoop::current()->PostTask( | 235 MessageLoop::current()->PostTask( |
236 FROM_HERE, | 236 FROM_HERE, |
237 base::Bind(&MemoryFileUtil::DoGetFileInfo, base::Unretained(this), | 237 base::Bind(&MemoryFileUtil::DoGetFileInfo, base::Unretained(this), |
238 file_path.StripTrailingSeparators(), callback)); | 238 file_path.StripTrailingSeparators(), callback)); |
239 } | 239 } |
240 | 240 |
241 void MemoryFileUtil::Create( | 241 void MemoryFileUtil::Create( |
242 const FilePath& file_path, | 242 const base::FilePath& file_path, |
243 const StatusCallback& callback) { | 243 const StatusCallback& callback) { |
244 MessageLoop::current()->PostTask( | 244 MessageLoop::current()->PostTask( |
245 FROM_HERE, | 245 FROM_HERE, |
246 base::Bind(&MemoryFileUtil::DoCreate, base::Unretained(this), | 246 base::Bind(&MemoryFileUtil::DoCreate, base::Unretained(this), |
247 file_path.StripTrailingSeparators(), false, callback)); | 247 file_path.StripTrailingSeparators(), false, callback)); |
248 } | 248 } |
249 | 249 |
250 void MemoryFileUtil::Truncate( | 250 void MemoryFileUtil::Truncate( |
251 const FilePath& file_path, | 251 const base::FilePath& file_path, |
252 int64 length, | 252 int64 length, |
253 const StatusCallback& callback) { | 253 const StatusCallback& callback) { |
254 MessageLoop::current()->PostTask( | 254 MessageLoop::current()->PostTask( |
255 FROM_HERE, | 255 FROM_HERE, |
256 base::Bind(&MemoryFileUtil::DoTruncate, base::Unretained(this), | 256 base::Bind(&MemoryFileUtil::DoTruncate, base::Unretained(this), |
257 file_path.StripTrailingSeparators(), length, callback)); | 257 file_path.StripTrailingSeparators(), length, callback)); |
258 } | 258 } |
259 | 259 |
260 void MemoryFileUtil::Touch( | 260 void MemoryFileUtil::Touch( |
261 const FilePath& file_path, | 261 const base::FilePath& file_path, |
262 const base::Time& last_access_time, | 262 const base::Time& last_access_time, |
263 const base::Time& last_modified_time, | 263 const base::Time& last_modified_time, |
264 const StatusCallback& callback) { | 264 const StatusCallback& callback) { |
265 MessageLoop::current()->PostTask( | 265 MessageLoop::current()->PostTask( |
266 FROM_HERE, | 266 FROM_HERE, |
267 base::Bind(&MemoryFileUtil::DoTouch, base::Unretained(this), | 267 base::Bind(&MemoryFileUtil::DoTouch, base::Unretained(this), |
268 file_path.StripTrailingSeparators(), | 268 file_path.StripTrailingSeparators(), |
269 last_modified_time, callback)); | 269 last_modified_time, callback)); |
270 } | 270 } |
271 | 271 |
272 void MemoryFileUtil::Remove( | 272 void MemoryFileUtil::Remove( |
273 const FilePath& file_path, | 273 const base::FilePath& file_path, |
274 bool recursive, | 274 bool recursive, |
275 const StatusCallback& callback) { | 275 const StatusCallback& callback) { |
276 if (recursive) { | 276 if (recursive) { |
277 MessageLoop::current()->PostTask( | 277 MessageLoop::current()->PostTask( |
278 FROM_HERE, | 278 FROM_HERE, |
279 base::Bind(&MemoryFileUtil::DoRemoveRecursive, | 279 base::Bind(&MemoryFileUtil::DoRemoveRecursive, |
280 base::Unretained(this), file_path.StripTrailingSeparators(), | 280 base::Unretained(this), file_path.StripTrailingSeparators(), |
281 callback)); | 281 callback)); |
282 } else { | 282 } else { |
283 MessageLoop::current()->PostTask( | 283 MessageLoop::current()->PostTask( |
284 FROM_HERE, | 284 FROM_HERE, |
285 base::Bind(&MemoryFileUtil::DoRemoveSingleFile, | 285 base::Bind(&MemoryFileUtil::DoRemoveSingleFile, |
286 base::Unretained(this), file_path.StripTrailingSeparators(), | 286 base::Unretained(this), file_path.StripTrailingSeparators(), |
287 callback)); | 287 callback)); |
288 } | 288 } |
289 } | 289 } |
290 | 290 |
291 void MemoryFileUtil::CreateDirectory( | 291 void MemoryFileUtil::CreateDirectory( |
292 const FilePath& dir_path, | 292 const base::FilePath& dir_path, |
293 const StatusCallback& callback) { | 293 const StatusCallback& callback) { |
294 MessageLoop::current()->PostTask( | 294 MessageLoop::current()->PostTask( |
295 FROM_HERE, | 295 FROM_HERE, |
296 base::Bind(&MemoryFileUtil::DoCreate, | 296 base::Bind(&MemoryFileUtil::DoCreate, |
297 base::Unretained(this), dir_path.StripTrailingSeparators(), | 297 base::Unretained(this), dir_path.StripTrailingSeparators(), |
298 true, callback)); | 298 true, callback)); |
299 } | 299 } |
300 | 300 |
301 void MemoryFileUtil::ReadDirectory( | 301 void MemoryFileUtil::ReadDirectory( |
302 const FilePath& dir_path, | 302 const base::FilePath& dir_path, |
303 const ReadDirectoryCallback& callback) { | 303 const ReadDirectoryCallback& callback) { |
304 MessageLoop::current()->PostTask( | 304 MessageLoop::current()->PostTask( |
305 FROM_HERE, | 305 FROM_HERE, |
306 base::Bind(&MemoryFileUtil::DoReadDirectory, | 306 base::Bind(&MemoryFileUtil::DoReadDirectory, |
307 base::Unretained(this), dir_path.StripTrailingSeparators(), | 307 base::Unretained(this), dir_path.StripTrailingSeparators(), |
308 FilePath(), callback)); | 308 base::FilePath(), callback)); |
309 } | 309 } |
310 | 310 |
311 void MemoryFileUtil::DoGetFileInfo(const FilePath& file_path, | 311 void MemoryFileUtil::DoGetFileInfo(const base::FilePath& file_path, |
312 const GetFileInfoCallback& callback) { | 312 const GetFileInfoCallback& callback) { |
313 base::PlatformFileInfo file_info; | 313 base::PlatformFileInfo file_info; |
314 | 314 |
315 FileIterator file_it = files_.find(file_path); | 315 FileIterator file_it = files_.find(file_path); |
316 | 316 |
317 if (file_it == files_.end()) { | 317 if (file_it == files_.end()) { |
318 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, file_info); | 318 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, file_info); |
319 return; | 319 return; |
320 } | 320 } |
321 const FileEntry& file_entry = file_it->second; | 321 const FileEntry& file_entry = file_it->second; |
322 | 322 |
323 file_info.size = file_entry.contents.size(); | 323 file_info.size = file_entry.contents.size(); |
324 file_info.is_directory = file_entry.is_directory; | 324 file_info.is_directory = file_entry.is_directory; |
325 file_info.is_symbolic_link = false; | 325 file_info.is_symbolic_link = false; |
326 | 326 |
327 // In this file system implementation we store only one datetime. Many | 327 // In this file system implementation we store only one datetime. Many |
328 // popular file systems do the same. | 328 // popular file systems do the same. |
329 file_info.last_modified = file_entry.last_modified; | 329 file_info.last_modified = file_entry.last_modified; |
330 file_info.last_accessed = file_entry.last_modified; | 330 file_info.last_accessed = file_entry.last_modified; |
331 file_info.creation_time = file_entry.last_modified; | 331 file_info.creation_time = file_entry.last_modified; |
332 | 332 |
333 callback.Run(base::PLATFORM_FILE_OK, file_info); | 333 callback.Run(base::PLATFORM_FILE_OK, file_info); |
334 } | 334 } |
335 | 335 |
336 void MemoryFileUtil::DoCreate( | 336 void MemoryFileUtil::DoCreate( |
337 const FilePath& file_path, | 337 const base::FilePath& file_path, |
338 bool is_directory, | 338 bool is_directory, |
339 const StatusCallback& callback) { | 339 const StatusCallback& callback) { |
340 if (FileExists(file_path)) { | 340 if (FileExists(file_path)) { |
341 callback.Run(base::PLATFORM_FILE_ERROR_EXISTS); | 341 callback.Run(base::PLATFORM_FILE_ERROR_EXISTS); |
342 return; | 342 return; |
343 } | 343 } |
344 | 344 |
345 if (!IsDirectory(file_path.DirName())) { | 345 if (!IsDirectory(file_path.DirName())) { |
346 callback.Run(base::PLATFORM_FILE_ERROR_FAILED); | 346 callback.Run(base::PLATFORM_FILE_ERROR_FAILED); |
347 return; | 347 return; |
348 } | 348 } |
349 | 349 |
350 FileEntry file; | 350 FileEntry file; |
351 file.is_directory = is_directory; | 351 file.is_directory = is_directory; |
352 file.last_modified = base::Time::Now(); | 352 file.last_modified = base::Time::Now(); |
353 | 353 |
354 files_[file_path] = file; | 354 files_[file_path] = file; |
355 callback.Run(base::PLATFORM_FILE_OK); | 355 callback.Run(base::PLATFORM_FILE_OK); |
356 } | 356 } |
357 | 357 |
358 void MemoryFileUtil::DoTruncate( | 358 void MemoryFileUtil::DoTruncate( |
359 const FilePath& file_path, | 359 const base::FilePath& file_path, |
360 int64 length, | 360 int64 length, |
361 const StatusCallback& callback) { | 361 const StatusCallback& callback) { |
362 FileIterator file_it = files_.find(file_path); | 362 FileIterator file_it = files_.find(file_path); |
363 if (file_it == files_.end()) { | 363 if (file_it == files_.end()) { |
364 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); | 364 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
365 return; | 365 return; |
366 } | 366 } |
367 | 367 |
368 FileEntry& file = file_it->second; | 368 FileEntry& file = file_it->second; |
369 | 369 |
370 // Fill the extended part with 0 if |length| is larger than the original | 370 // Fill the extended part with 0 if |length| is larger than the original |
371 // contents size. | 371 // contents size. |
372 file.contents.resize(length, 0); | 372 file.contents.resize(length, 0); |
373 callback.Run(base::PLATFORM_FILE_OK); | 373 callback.Run(base::PLATFORM_FILE_OK); |
374 } | 374 } |
375 | 375 |
376 void MemoryFileUtil::DoTouch( | 376 void MemoryFileUtil::DoTouch( |
377 const FilePath& file_path, | 377 const base::FilePath& file_path, |
378 const base::Time& last_modified_time, | 378 const base::Time& last_modified_time, |
379 const StatusCallback& callback) { | 379 const StatusCallback& callback) { |
380 FileIterator file_it = files_.find(file_path); | 380 FileIterator file_it = files_.find(file_path); |
381 if (file_it == files_.end()) { | 381 if (file_it == files_.end()) { |
382 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); | 382 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
383 return; | 383 return; |
384 } | 384 } |
385 | 385 |
386 FileEntry& file = file_it->second; | 386 FileEntry& file = file_it->second; |
387 | 387 |
388 file.last_modified = last_modified_time; | 388 file.last_modified = last_modified_time; |
389 callback.Run(base::PLATFORM_FILE_OK); | 389 callback.Run(base::PLATFORM_FILE_OK); |
390 } | 390 } |
391 | 391 |
392 void MemoryFileUtil::DoRemoveSingleFile( | 392 void MemoryFileUtil::DoRemoveSingleFile( |
393 const FilePath& file_path, | 393 const base::FilePath& file_path, |
394 const StatusCallback& callback) { | 394 const StatusCallback& callback) { |
395 FileIterator file_it = files_.find(file_path); | 395 FileIterator file_it = files_.find(file_path); |
396 if (file_it == files_.end()) { | 396 if (file_it == files_.end()) { |
397 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); | 397 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
398 return; | 398 return; |
399 } | 399 } |
400 | 400 |
401 FileEntry& file = file_it->second; | 401 FileEntry& file = file_it->second; |
402 if (file.is_directory) { | 402 if (file.is_directory) { |
403 // Check if the directory is empty. This can be done by checking if | 403 // Check if the directory is empty. This can be done by checking if |
404 // the next file is present under the directory. Note that |files_| is | 404 // the next file is present under the directory. Note that |files_| is |
405 // a map hence the file names are sorted by names. | 405 // a map hence the file names are sorted by names. |
406 FileIterator tmp_it = file_it; | 406 FileIterator tmp_it = file_it; |
407 ++tmp_it; | 407 ++tmp_it; |
408 if (tmp_it != files_.end() && file_path.IsParent(tmp_it->first)) { | 408 if (tmp_it != files_.end() && file_path.IsParent(tmp_it->first)) { |
409 callback.Run(base::PLATFORM_FILE_ERROR_NOT_A_FILE); | 409 callback.Run(base::PLATFORM_FILE_ERROR_NOT_A_FILE); |
410 return; | 410 return; |
411 } | 411 } |
412 } | 412 } |
413 | 413 |
414 files_.erase(file_it); | 414 files_.erase(file_it); |
415 callback.Run(base::PLATFORM_FILE_OK); | 415 callback.Run(base::PLATFORM_FILE_OK); |
416 } | 416 } |
417 | 417 |
418 void MemoryFileUtil::DoRemoveRecursive( | 418 void MemoryFileUtil::DoRemoveRecursive( |
419 const FilePath& file_path, | 419 const base::FilePath& file_path, |
420 const StatusCallback& callback) { | 420 const StatusCallback& callback) { |
421 FileIterator file_it = files_.find(file_path); | 421 FileIterator file_it = files_.find(file_path); |
422 if (file_it == files_.end()) { | 422 if (file_it == files_.end()) { |
423 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); | 423 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
424 return; | 424 return; |
425 } | 425 } |
426 | 426 |
427 FileEntry& file = file_it->second; | 427 FileEntry& file = file_it->second; |
428 if (!file.is_directory) { | 428 if (!file.is_directory) { |
429 files_.erase(file_it); | 429 files_.erase(file_it); |
430 callback.Run(base::PLATFORM_FILE_OK); | 430 callback.Run(base::PLATFORM_FILE_OK); |
431 return; | 431 return; |
432 } | 432 } |
433 | 433 |
434 // Remove the directory itself. | 434 // Remove the directory itself. |
435 files_.erase(file_it++); | 435 files_.erase(file_it++); |
436 // Remove files under the directory. | 436 // Remove files under the directory. |
437 while (file_it != files_.end()) { | 437 while (file_it != files_.end()) { |
438 if (file_path.IsParent(file_it->first)) { | 438 if (file_path.IsParent(file_it->first)) { |
439 files_.erase(file_it++); | 439 files_.erase(file_it++); |
440 } else { | 440 } else { |
441 break; | 441 break; |
442 } | 442 } |
443 } | 443 } |
444 callback.Run(base::PLATFORM_FILE_OK); | 444 callback.Run(base::PLATFORM_FILE_OK); |
445 } | 445 } |
446 | 446 |
447 void MemoryFileUtil::DoReadDirectory( | 447 void MemoryFileUtil::DoReadDirectory( |
448 const FilePath& dir_path, | 448 const base::FilePath& dir_path, |
449 const FilePath& in_from, | 449 const base::FilePath& in_from, |
450 const ReadDirectoryCallback& callback) { | 450 const ReadDirectoryCallback& callback) { |
451 FilePath from = in_from; | 451 base::FilePath from = in_from; |
452 read_directory_buffer_.clear(); | 452 read_directory_buffer_.clear(); |
453 | 453 |
454 if (!FileExists(dir_path)) { | 454 if (!FileExists(dir_path)) { |
455 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 455 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
456 read_directory_buffer_, true); | 456 read_directory_buffer_, true); |
457 return; | 457 return; |
458 } | 458 } |
459 | 459 |
460 if (!IsDirectory(dir_path)) { | 460 if (!IsDirectory(dir_path)) { |
461 callback.Run(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, | 461 callback.Run(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 if (!completed) { | 503 if (!completed) { |
504 MessageLoop::current()->PostTask( | 504 MessageLoop::current()->PostTask( |
505 FROM_HERE, | 505 FROM_HERE, |
506 base::Bind(&MemoryFileUtil::DoReadDirectory, | 506 base::Bind(&MemoryFileUtil::DoReadDirectory, |
507 base::Unretained(this), dir_path, | 507 base::Unretained(this), dir_path, |
508 from, callback)); | 508 from, callback)); |
509 } | 509 } |
510 } | 510 } |
511 | 511 |
512 void MemoryFileUtil::OpenVerifiedFile( | 512 void MemoryFileUtil::OpenVerifiedFile( |
513 const FilePath& file_path, | 513 const base::FilePath& file_path, |
514 int flags, | 514 int flags, |
515 const OpenCallback& callback) { | 515 const OpenCallback& callback) { |
516 FileIterator file_it = files_.find(file_path); | 516 FileIterator file_it = files_.find(file_path); |
517 // The existence of the file is guranteed here. | 517 // The existence of the file is guranteed here. |
518 DCHECK(file_it != files_.end()); | 518 DCHECK(file_it != files_.end()); |
519 | 519 |
520 FileEntry* file_entry = &file_it->second; | 520 FileEntry* file_entry = &file_it->second; |
521 callback.Run(base::PLATFORM_FILE_OK, | 521 callback.Run(base::PLATFORM_FILE_OK, |
522 new MemoryFileUtilAsyncFileStream(file_entry, flags)); | 522 new MemoryFileUtilAsyncFileStream(file_entry, flags)); |
523 } | 523 } |
524 | 524 |
525 void MemoryFileUtil::DidGetFileInfoForOpen( | 525 void MemoryFileUtil::DidGetFileInfoForOpen( |
526 const FilePath& file_path, | 526 const base::FilePath& file_path, |
527 int flags, | 527 int flags, |
528 const OpenCallback& callback, | 528 const OpenCallback& callback, |
529 PlatformFileError get_info_result, | 529 PlatformFileError get_info_result, |
530 const base::PlatformFileInfo& file_info) { | 530 const base::PlatformFileInfo& file_info) { |
531 if (get_info_result == base::PLATFORM_FILE_OK && file_info.is_directory) { | 531 if (get_info_result == base::PLATFORM_FILE_OK && file_info.is_directory) { |
532 callback.Run(base::PLATFORM_FILE_ERROR_NOT_A_FILE, NULL); | 532 callback.Run(base::PLATFORM_FILE_ERROR_NOT_A_FILE, NULL); |
533 return; | 533 return; |
534 } | 534 } |
535 | 535 |
536 if (get_info_result == base::PLATFORM_FILE_OK) { | 536 if (get_info_result == base::PLATFORM_FILE_OK) { |
537 OpenVerifiedFile(file_path, flags, callback); | 537 OpenVerifiedFile(file_path, flags, callback); |
538 return; | 538 return; |
539 } | 539 } |
540 | 540 |
541 if (get_info_result == base::PLATFORM_FILE_ERROR_NOT_FOUND && | 541 if (get_info_result == base::PLATFORM_FILE_ERROR_NOT_FOUND && |
542 flags & base::PLATFORM_FILE_CREATE_ALWAYS) { | 542 flags & base::PLATFORM_FILE_CREATE_ALWAYS) { |
543 Create(file_path, | 543 Create(file_path, |
544 base::Bind(&MemoryFileUtil::DidCreateOrTruncateForOpen, | 544 base::Bind(&MemoryFileUtil::DidCreateOrTruncateForOpen, |
545 base::Unretained(this), file_path, flags, 0, callback)); | 545 base::Unretained(this), file_path, flags, 0, callback)); |
546 return; | 546 return; |
547 } | 547 } |
548 | 548 |
549 callback.Run(get_info_result, NULL); | 549 callback.Run(get_info_result, NULL); |
550 } | 550 } |
551 | 551 |
552 void MemoryFileUtil::OpenTruncatedFileOrCreate( | 552 void MemoryFileUtil::OpenTruncatedFileOrCreate( |
553 const FilePath& file_path, | 553 const base::FilePath& file_path, |
554 int flags, | 554 int flags, |
555 const OpenCallback& callback, | 555 const OpenCallback& callback, |
556 PlatformFileError result) { | 556 PlatformFileError result) { |
557 if (result == base::PLATFORM_FILE_OK) { | 557 if (result == base::PLATFORM_FILE_OK) { |
558 OpenVerifiedFile(file_path, flags, callback); | 558 OpenVerifiedFile(file_path, flags, callback); |
559 return; | 559 return; |
560 } | 560 } |
561 | 561 |
562 if (result == base::PLATFORM_FILE_ERROR_NOT_FOUND) { | 562 if (result == base::PLATFORM_FILE_ERROR_NOT_FOUND) { |
563 Create( | 563 Create( |
564 file_path, | 564 file_path, |
565 base::Bind(&MemoryFileUtil::DidCreateOrTruncateForOpen, | 565 base::Bind(&MemoryFileUtil::DidCreateOrTruncateForOpen, |
566 base::Unretained(this), file_path, flags, 0, callback)); | 566 base::Unretained(this), file_path, flags, 0, callback)); |
567 return; | 567 return; |
568 } | 568 } |
569 | 569 |
570 callback.Run(result, NULL); | 570 callback.Run(result, NULL); |
571 } | 571 } |
572 | 572 |
573 void MemoryFileUtil::DidCreateOrTruncateForOpen( | 573 void MemoryFileUtil::DidCreateOrTruncateForOpen( |
574 const FilePath& file_path, | 574 const base::FilePath& file_path, |
575 int flags, | 575 int flags, |
576 int64 size, | 576 int64 size, |
577 const OpenCallback& callback, | 577 const OpenCallback& callback, |
578 PlatformFileError result) { | 578 PlatformFileError result) { |
579 if (result != base::PLATFORM_FILE_OK) { | 579 if (result != base::PLATFORM_FILE_OK) { |
580 callback.Run(result, NULL); | 580 callback.Run(result, NULL); |
581 return; | 581 return; |
582 } | 582 } |
583 | 583 |
584 OpenVerifiedFile(file_path, flags, callback); | 584 OpenVerifiedFile(file_path, flags, callback); |
585 } | 585 } |
586 | 586 |
587 } // namespace fileapi | 587 } // namespace fileapi |
OLD | NEW |