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 "webkit/browser/fileapi/local_file_util.h" | 5 #include "webkit/browser/fileapi/local_file_util.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file_enumerator.h" |
8 #include "base/files/file_util_proxy.h" | 9 #include "base/files/file_util_proxy.h" |
9 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
10 #include "webkit/browser/fileapi/file_system_context.h" | 11 #include "webkit/browser/fileapi/file_system_context.h" |
11 #include "webkit/browser/fileapi/file_system_operation_context.h" | 12 #include "webkit/browser/fileapi/file_system_operation_context.h" |
12 #include "webkit/browser/fileapi/file_system_url.h" | 13 #include "webkit/browser/fileapi/file_system_url.h" |
13 #include "webkit/browser/fileapi/native_file_util.h" | 14 #include "webkit/browser/fileapi/native_file_util.h" |
14 #include "webkit/common/fileapi/file_system_types.h" | 15 #include "webkit/common/fileapi/file_system_types.h" |
15 #include "webkit/common/fileapi/file_system_util.h" | 16 #include "webkit/common/fileapi/file_system_util.h" |
16 | 17 |
17 namespace fileapi { | 18 namespace fileapi { |
18 | 19 |
19 using base::PlatformFileError; | 20 using base::PlatformFileError; |
20 | 21 |
21 class LocalFileEnumerator : public FileSystemFileUtil::AbstractFileEnumerator { | 22 class LocalFileEnumerator : public FileSystemFileUtil::AbstractFileEnumerator { |
22 public: | 23 public: |
23 LocalFileEnumerator(const base::FilePath& platform_root_path, | 24 LocalFileEnumerator(const base::FilePath& platform_root_path, |
24 const base::FilePath& virtual_root_path, | 25 const base::FilePath& virtual_root_path, |
25 int file_type) | 26 int file_type) |
26 : file_enum_(platform_root_path, false /* recursive */, file_type), | 27 : file_enum_(platform_root_path, false /* recursive */, file_type), |
27 platform_root_path_(platform_root_path), | 28 platform_root_path_(platform_root_path), |
28 virtual_root_path_(virtual_root_path) { | 29 virtual_root_path_(virtual_root_path) { |
29 #if defined(OS_WIN) | |
30 memset(&file_util_info_, 0, sizeof(file_util_info_)); | |
31 #endif // defined(OS_WIN) | |
32 } | 30 } |
33 | 31 |
34 virtual ~LocalFileEnumerator() {} | 32 virtual ~LocalFileEnumerator() {} |
35 | 33 |
36 virtual base::FilePath Next() OVERRIDE; | 34 virtual base::FilePath Next() OVERRIDE; |
37 virtual int64 Size() OVERRIDE; | 35 virtual int64 Size() OVERRIDE; |
38 virtual base::Time LastModifiedTime() OVERRIDE; | 36 virtual base::Time LastModifiedTime() OVERRIDE; |
39 virtual bool IsDirectory() OVERRIDE; | 37 virtual bool IsDirectory() OVERRIDE; |
40 | 38 |
41 private: | 39 private: |
42 file_util::FileEnumerator file_enum_; | 40 base::FileEnumerator file_enum_; |
43 file_util::FileEnumerator::FindInfo file_util_info_; | 41 base::FileEnumerator::FileInfo file_util_info_; |
44 base::FilePath platform_root_path_; | 42 base::FilePath platform_root_path_; |
45 base::FilePath virtual_root_path_; | 43 base::FilePath virtual_root_path_; |
46 }; | 44 }; |
47 | 45 |
48 base::FilePath LocalFileEnumerator::Next() { | 46 base::FilePath LocalFileEnumerator::Next() { |
49 base::FilePath next = file_enum_.Next(); | 47 base::FilePath next = file_enum_.Next(); |
50 // Don't return symlinks. | 48 // Don't return symlinks. |
51 while (!next.empty() && file_util::IsLink(next)) | 49 while (!next.empty() && file_util::IsLink(next)) |
52 next = file_enum_.Next(); | 50 next = file_enum_.Next(); |
53 if (next.empty()) | 51 if (next.empty()) |
54 return next; | 52 return next; |
55 file_enum_.GetFindInfo(&file_util_info_); | 53 file_util_info_ = file_enum_.GetInfo(); |
56 | 54 |
57 base::FilePath path; | 55 base::FilePath path; |
58 platform_root_path_.AppendRelativePath(next, &path); | 56 platform_root_path_.AppendRelativePath(next, &path); |
59 return virtual_root_path_.Append(path); | 57 return virtual_root_path_.Append(path); |
60 } | 58 } |
61 | 59 |
62 int64 LocalFileEnumerator::Size() { | 60 int64 LocalFileEnumerator::Size() { |
63 return file_util::FileEnumerator::GetFilesize(file_util_info_); | 61 return file_util_info_.GetSize(); |
64 } | 62 } |
65 | 63 |
66 base::Time LocalFileEnumerator::LastModifiedTime() { | 64 base::Time LocalFileEnumerator::LastModifiedTime() { |
67 return file_util::FileEnumerator::GetLastModifiedTime(file_util_info_); | 65 return file_util_info_.GetLastModifiedTime(); |
68 } | 66 } |
69 | 67 |
70 bool LocalFileEnumerator::IsDirectory() { | 68 bool LocalFileEnumerator::IsDirectory() { |
71 return file_util::FileEnumerator::IsDirectory(file_util_info_); | 69 return file_util_info_.IsDirectory(); |
72 } | 70 } |
73 | 71 |
74 LocalFileUtil::LocalFileUtil() { | 72 LocalFileUtil::LocalFileUtil() { |
75 } | 73 } |
76 | 74 |
77 LocalFileUtil::~LocalFileUtil() { | 75 LocalFileUtil::~LocalFileUtil() { |
78 } | 76 } |
79 | 77 |
80 PlatformFileError LocalFileUtil::CreateOrOpen( | 78 PlatformFileError LocalFileUtil::CreateOrOpen( |
81 FileSystemOperationContext* context, | 79 FileSystemOperationContext* context, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 FileSystemOperationContext* context, | 142 FileSystemOperationContext* context, |
145 const FileSystemURL& root_url) { | 143 const FileSystemURL& root_url) { |
146 base::FilePath file_path; | 144 base::FilePath file_path; |
147 if (GetLocalFilePath(context, root_url, &file_path) != | 145 if (GetLocalFilePath(context, root_url, &file_path) != |
148 base::PLATFORM_FILE_OK) { | 146 base::PLATFORM_FILE_OK) { |
149 return make_scoped_ptr(new EmptyFileEnumerator) | 147 return make_scoped_ptr(new EmptyFileEnumerator) |
150 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); | 148 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); |
151 } | 149 } |
152 return make_scoped_ptr(new LocalFileEnumerator( | 150 return make_scoped_ptr(new LocalFileEnumerator( |
153 file_path, root_url.path(), | 151 file_path, root_url.path(), |
154 file_util::FileEnumerator::FILES | | 152 base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES)) |
155 file_util::FileEnumerator::DIRECTORIES)) | |
156 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); | 153 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); |
157 } | 154 } |
158 | 155 |
159 PlatformFileError LocalFileUtil::GetLocalFilePath( | 156 PlatformFileError LocalFileUtil::GetLocalFilePath( |
160 FileSystemOperationContext* context, | 157 FileSystemOperationContext* context, |
161 const FileSystemURL& url, | 158 const FileSystemURL& url, |
162 base::FilePath* local_file_path) { | 159 base::FilePath* local_file_path) { |
163 base::FilePath root = context->root_path(); | 160 base::FilePath root = context->root_path(); |
164 if (root.empty()) | 161 if (root.empty()) |
165 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 162 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 base::FilePath* platform_path) { | 248 base::FilePath* platform_path) { |
252 DCHECK(file_info); | 249 DCHECK(file_info); |
253 // We're just returning the local file information. | 250 // We're just returning the local file information. |
254 *error = GetFileInfo(context, url, file_info, platform_path); | 251 *error = GetFileInfo(context, url, file_info, platform_path); |
255 if (*error == base::PLATFORM_FILE_OK && file_info->is_directory) | 252 if (*error == base::PLATFORM_FILE_OK && file_info->is_directory) |
256 *error = base::PLATFORM_FILE_ERROR_NOT_A_FILE; | 253 *error = base::PLATFORM_FILE_ERROR_NOT_A_FILE; |
257 return webkit_blob::ScopedFile(); | 254 return webkit_blob::ScopedFile(); |
258 } | 255 } |
259 | 256 |
260 } // namespace fileapi | 257 } // namespace fileapi |
OLD | NEW |