OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "webkit/fileapi/media/local_media_file_util.h" | |
6 | |
7 #include "net/base/mime_util.h" | |
8 #include "webkit/fileapi/file_system_operation_context.h" | |
9 #include "webkit/fileapi/media/media_path_filter.h" | |
10 | |
11 using base::PlatformFileError; | |
12 using base::PlatformFileInfo; | |
13 | |
14 namespace fileapi { | |
15 | |
16 class MediaPathFilter; | |
17 | |
18 namespace { | |
19 | |
20 class FilteringFileEnumerator | |
21 : public FileSystemFileUtil::AbstractFileEnumerator { | |
22 public: | |
23 FilteringFileEnumerator( | |
24 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> base_enumerator, | |
25 MediaPathFilter* filter) | |
26 : base_enumerator_(base_enumerator.Pass()), | |
27 filter_(filter) { | |
28 } | |
29 | |
30 virtual FilePath Next() OVERRIDE { | |
31 { | |
32 FilePath next = base_enumerator_->Next(); | |
33 if (next.empty() || | |
34 base_enumerator_->IsDirectory() || | |
35 filter_->Match(next)) | |
36 return next; | |
37 } | |
kinuko
2012/07/26 20:21:56
Why is this in a separate blocK?
tzik
2012/07/27 17:18:56
I think, this block makes Next() call tail recursi
kinuko
2012/07/28 01:23:35
Ah oh ok :) clever.
| |
38 return Next(); | |
kinuko
2012/07/26 20:21:56
Can we make this non-recursive?
tzik
2012/07/27 17:18:56
Done.
| |
39 } | |
40 | |
41 virtual int64 Size() OVERRIDE { | |
42 return base_enumerator_->Size(); | |
43 } | |
44 | |
45 virtual base::Time LastModifiedTime() OVERRIDE { | |
46 return base_enumerator_->LastModifiedTime(); | |
47 } | |
48 | |
49 virtual bool IsDirectory() OVERRIDE { | |
50 return base_enumerator_->IsDirectory(); | |
51 } | |
52 | |
53 private: | |
54 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> base_enumerator_; | |
55 MediaPathFilter* filter_; | |
56 }; | |
57 } // anonymous namespace | |
kinuko
2012/07/28 01:23:35
nit: please add empty line between line 56 and 57.
tzik
2012/07/30 23:32:36
Done.
| |
58 | |
59 LocalMediaFileUtil::LocalMediaFileUtil() { | |
60 } | |
61 | |
62 | |
kinuko
2012/07/26 20:21:56
nit: please remove extra empty line.
tzik
2012/07/27 17:18:56
Done.
| |
63 PlatformFileError LocalMediaFileUtil::CreateOrOpen( | |
64 FileSystemOperationContext* context, | |
65 const FileSystemURL& url, | |
66 int file_flags, | |
67 PlatformFile* file_handle, | |
68 bool* created) { | |
69 return base::PLATFORM_FILE_ERROR_SECURITY; | |
70 } | |
71 | |
72 PlatformFileError LocalMediaFileUtil::EnsureFileExists( | |
73 FileSystemOperationContext* context, | |
74 const FileSystemURL& url, bool* created) { | |
75 return base::PLATFORM_FILE_ERROR_SECURITY; | |
kinuko
2012/07/26 20:21:56
Is this FileUtil also trying to explicitly disable
tzik
2012/07/27 17:18:56
Yes, for now. We need some special handling to sup
| |
76 } | |
77 | |
78 FileSystemFileUtil::AbstractFileEnumerator* | |
79 LocalMediaFileUtil::CreateFileEnumerator( | |
80 FileSystemOperationContext* context, | |
81 const FileSystemURL& root_url, | |
82 bool recursive) { | |
83 AbstractFileEnumerator* base_enumerator = | |
84 IsolatedFileUtil::CreateFileEnumerator(context, root_url, recursive); | |
85 return new FilteringFileEnumerator( | |
86 scoped_ptr<AbstractFileEnumerator>(base_enumerator), | |
87 context->media_path_filter()); | |
88 } | |
89 | |
90 PlatformFileError LocalMediaFileUtil::Touch( | |
91 FileSystemOperationContext* context, | |
92 const FileSystemURL& url, | |
93 const base::Time& last_access_time, | |
94 const base::Time& last_modified_time) { | |
95 return base::PLATFORM_FILE_ERROR_SECURITY; | |
96 } | |
97 | |
98 PlatformFileError LocalMediaFileUtil::Truncate( | |
99 FileSystemOperationContext* context, | |
100 const FileSystemURL& url, | |
101 int64 length) { | |
102 return base::PLATFORM_FILE_ERROR_SECURITY; | |
103 } | |
104 | |
105 bool LocalMediaFileUtil::PathExists( | |
106 FileSystemOperationContext* context, | |
107 const FileSystemURL& url) { | |
108 FilePath path; | |
109 PlatformFileInfo file_info; | |
110 PlatformFileError error = | |
111 GetFileInfo(context, url, &file_info, &path); | |
112 return error == base::PLATFORM_FILE_OK; | |
113 } | |
114 | |
115 bool LocalMediaFileUtil::IsDirectoryEmpty( | |
116 FileSystemOperationContext* context, | |
117 const FileSystemURL& url) { | |
118 DCHECK(context); | |
119 DCHECK(context->media_path_filter()); | |
120 | |
121 scoped_ptr<AbstractFileEnumerator> enumerator( | |
122 CreateFileEnumerator(context, url, false)); | |
123 FilePath path; | |
124 while (!(path = enumerator->Next()).empty()) { | |
125 if (enumerator->IsDirectory() || | |
126 context->media_path_filter()->Match(path)) | |
127 return false; | |
128 } | |
129 return true; | |
130 } | |
131 | |
132 PlatformFileError LocalMediaFileUtil::CopyOrMoveFile( | |
133 FileSystemOperationContext* context, | |
134 const FileSystemURL& src_url, | |
135 const FileSystemURL& dest_url, | |
136 bool copy) { | |
137 return base::PLATFORM_FILE_ERROR_SECURITY; | |
138 } | |
139 | |
140 PlatformFileError LocalMediaFileUtil::CopyInForeignFile( | |
141 FileSystemOperationContext* context, | |
142 const FilePath& src_file_path, | |
143 const FileSystemURL& dest_url) { | |
144 return base::PLATFORM_FILE_ERROR_SECURITY; | |
145 } | |
146 | |
147 PlatformFileError LocalMediaFileUtil::DeleteFile( | |
148 FileSystemOperationContext* context, | |
149 const FileSystemURL& url) { | |
150 return base::PLATFORM_FILE_ERROR_SECURITY; | |
151 } | |
152 | |
153 scoped_refptr<webkit_blob::ShareableFileReference> | |
154 LocalMediaFileUtil::CreateSnapshotFile( | |
155 FileSystemOperationContext* context, | |
156 const FileSystemURL& url, | |
157 base::PlatformFileError* result, | |
158 base::PlatformFileInfo* file_info, | |
159 FilePath* platform_path) { | |
160 *result = base::PLATFORM_FILE_ERROR_SECURITY; | |
kinuko
2012/07/26 20:21:56
Why does this just return error?
tzik
2012/07/27 17:18:56
Ah, it's an error. We shouldn't block this. Remove
| |
161 return NULL; | |
162 } | |
163 | |
164 PlatformFileError LocalMediaFileUtil::GetFileInfo( | |
165 FileSystemOperationContext* context, | |
166 const FileSystemURL& url, | |
167 PlatformFileInfo* file_info, | |
168 FilePath* platform_path) { | |
169 base::PlatformFileError error = | |
170 IsolatedFileUtil::GetFileInfo(context, url, file_info, platform_path); | |
171 if (error != base::PLATFORM_FILE_OK) | |
172 return error; | |
173 | |
174 if (file_info->is_directory || | |
175 context->media_path_filter()->Match(*platform_path)) | |
176 return base::PLATFORM_FILE_OK; | |
177 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
178 } | |
179 | |
180 } // namespace fileapi | |
OLD | NEW |