| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/fileapi/file_system_file_util.h" | 5 #include "webkit/fileapi/file_system_file_util.h" |
| 6 | 6 |
| 7 #include <stack> | 7 #include <stack> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util_proxy.h" | 10 #include "base/file_util_proxy.h" |
| 11 #include "base/logging.h" | |
| 12 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 13 #include "webkit/fileapi/file_system_operation_context.h" | 12 #include "webkit/fileapi/file_system_operation_context.h" |
| 14 | 13 |
| 15 namespace fileapi { | 14 namespace fileapi { |
| 16 | 15 |
| 17 namespace { | 16 namespace { |
| 18 | 17 |
| 19 // This assumes that the root exists. | 18 // This assumes that the root exists. |
| 20 bool ParentExists(FileSystemOperationContext* context, | 19 bool ParentExists(FileSystemOperationContext* context, |
| 21 FileSystemFileUtil* file_util, const FilePath& file_path) { | 20 FileSystemFileUtil* file_util, const FilePath& file_path) { |
| 22 // If file_path is in the root, file_path.DirName() will be ".", | 21 // If file_path is in the root, file_path.DirName() will be ".", |
| 23 // since we use paths with no leading '/'. | 22 // since we use paths with no leading '/'. |
| 24 FilePath parent = file_path.DirName(); | 23 FilePath parent = file_path.DirName(); |
| 25 if (parent == FilePath(FILE_PATH_LITERAL("."))) | 24 if (parent == FilePath(FILE_PATH_LITERAL("."))) |
| 26 return true; | 25 return true; |
| 27 return file_util->DirectoryExists(context, parent); | 26 return file_util->DirectoryExists(context, parent); |
| 28 } | 27 } |
| 29 | 28 |
| 30 } // namespace | 29 } // namespace |
| 31 | 30 |
| 32 // static | |
| 33 FileSystemFileUtil* FileSystemFileUtil::GetInstance() { | |
| 34 return Singleton<FileSystemFileUtil>::get(); | |
| 35 } | |
| 36 | |
| 37 PlatformFileError FileSystemFileUtil::CreateOrOpen( | 31 PlatformFileError FileSystemFileUtil::CreateOrOpen( |
| 38 FileSystemOperationContext* unused, | 32 FileSystemOperationContext* unused, |
| 39 const FilePath& file_path, int file_flags, | 33 const FilePath& file_path, int file_flags, |
| 40 PlatformFile* file_handle, bool* created) { | 34 PlatformFile* file_handle, bool* created) { |
| 41 if (!file_util::DirectoryExists(file_path.DirName())) { | 35 if (!file_util::DirectoryExists(file_path.DirName())) { |
| 42 // If its parent does not exist, should return NOT_FOUND error. | 36 // If its parent does not exist, should return NOT_FOUND error. |
| 43 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 37 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 44 } | 38 } |
| 45 PlatformFileError error_code = base::PLATFORM_FILE_OK; | 39 PlatformFileError error_code = base::PLATFORM_FILE_OK; |
| 46 *file_handle = base::CreatePlatformFile(file_path, file_flags, | 40 *file_handle = base::CreatePlatformFile(file_path, file_flags, |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 FileSystemFileUtil::CreateFileEnumerator( | 548 FileSystemFileUtil::CreateFileEnumerator( |
| 555 FileSystemOperationContext* unused, | 549 FileSystemOperationContext* unused, |
| 556 const FilePath& root_path) { | 550 const FilePath& root_path) { |
| 557 return new FileSystemFileEnumerator( | 551 return new FileSystemFileEnumerator( |
| 558 root_path, true, static_cast<file_util::FileEnumerator::FILE_TYPE>( | 552 root_path, true, static_cast<file_util::FileEnumerator::FILE_TYPE>( |
| 559 file_util::FileEnumerator::FILES | | 553 file_util::FileEnumerator::FILES | |
| 560 file_util::FileEnumerator::DIRECTORIES)); | 554 file_util::FileEnumerator::DIRECTORIES)); |
| 561 } | 555 } |
| 562 | 556 |
| 563 } // namespace fileapi | 557 } // namespace fileapi |
| OLD | NEW |