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/fileapi/media/native_media_file_util.h" | 5 #include "webkit/fileapi/media/native_media_file_util.h" |
6 | 6 |
7 #include "net/base/mime_util.h" | 7 #include "net/base/mime_util.h" |
8 #include "webkit/fileapi/file_system_operation_context.h" | 8 #include "webkit/fileapi/file_system_operation_context.h" |
9 #include "webkit/fileapi/media/media_path_filter.h" | 9 #include "webkit/fileapi/media/media_path_filter.h" |
10 #include "webkit/fileapi/media/filtering_file_enumerator.h" | |
10 | 11 |
11 using base::PlatformFileError; | 12 using base::PlatformFileError; |
12 using base::PlatformFileInfo; | 13 using base::PlatformFileInfo; |
13 | 14 |
14 namespace fileapi { | 15 namespace fileapi { |
15 | 16 |
16 class MediaPathFilter; | 17 class MediaPathFilter; |
17 | 18 |
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 DCHECK(base_enumerator_.get()); | |
29 DCHECK(filter); | |
30 } | |
31 | |
32 virtual FilePath Next() OVERRIDE { | |
33 while (true) { | |
34 FilePath next = base_enumerator_->Next(); | |
35 if (next.empty() || | |
36 base_enumerator_->IsDirectory() || | |
37 filter_->Match(next)) | |
38 return next; | |
39 } | |
40 } | |
41 | |
42 virtual int64 Size() OVERRIDE { | |
43 return base_enumerator_->Size(); | |
44 } | |
45 | |
46 virtual base::Time LastModifiedTime() OVERRIDE { | |
47 return base_enumerator_->LastModifiedTime(); | |
48 } | |
49 | |
50 virtual bool IsDirectory() OVERRIDE { | |
51 return base_enumerator_->IsDirectory(); | |
52 } | |
53 | |
54 private: | |
55 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> base_enumerator_; | |
56 MediaPathFilter* filter_; | |
57 }; | |
58 | |
59 } // namespace | |
60 | |
61 NativeMediaFileUtil::NativeMediaFileUtil() { | 19 NativeMediaFileUtil::NativeMediaFileUtil() { |
62 } | 20 } |
63 | 21 |
64 PlatformFileError NativeMediaFileUtil::CreateOrOpen( | 22 PlatformFileError NativeMediaFileUtil::CreateOrOpen( |
65 FileSystemOperationContext* context, | 23 FileSystemOperationContext* context, |
66 const FileSystemURL& url, | 24 const FileSystemURL& url, |
67 int file_flags, | 25 int file_flags, |
68 PlatformFile* file_handle, | 26 PlatformFile* file_handle, |
69 bool* created) { | 27 bool* created) { |
70 // TODO(tzik): Apply context()->mime_path_filter() here when we support write | 28 // TODO(tzik): Apply context()->media_path_filter() here when we support write |
71 // access. | 29 // access. |
kinuko
2012/08/06 18:32:05
Having these repeated TODOs only in native_media_f
| |
72 return base::PLATFORM_FILE_ERROR_SECURITY; | 30 return base::PLATFORM_FILE_ERROR_SECURITY; |
73 } | 31 } |
74 | 32 |
75 PlatformFileError NativeMediaFileUtil::EnsureFileExists( | 33 PlatformFileError NativeMediaFileUtil::EnsureFileExists( |
76 FileSystemOperationContext* context, | 34 FileSystemOperationContext* context, |
77 const FileSystemURL& url, bool* created) { | 35 const FileSystemURL& url, bool* created) { |
78 // TODO(tzik): Apply context()->mime_path_filter() here when we support write | 36 // TODO(tzik): Apply context()->media_path_filter() here when we support write |
79 // access. | 37 // access. |
80 return base::PLATFORM_FILE_ERROR_SECURITY; | 38 return base::PLATFORM_FILE_ERROR_SECURITY; |
81 } | 39 } |
82 | 40 |
83 FileSystemFileUtil::AbstractFileEnumerator* | 41 FileSystemFileUtil::AbstractFileEnumerator* |
84 NativeMediaFileUtil::CreateFileEnumerator( | 42 NativeMediaFileUtil::CreateFileEnumerator( |
85 FileSystemOperationContext* context, | 43 FileSystemOperationContext* context, |
86 const FileSystemURL& root_url, | 44 const FileSystemURL& root_url, |
87 bool recursive) { | 45 bool recursive) { |
88 DCHECK(context); | 46 DCHECK(context); |
89 | 47 |
90 AbstractFileEnumerator* base_enumerator = | 48 AbstractFileEnumerator* base_enumerator = |
91 IsolatedFileUtil::CreateFileEnumerator(context, root_url, recursive); | 49 IsolatedFileUtil::CreateFileEnumerator(context, root_url, recursive); |
92 return new FilteringFileEnumerator( | 50 return new FilteringFileEnumerator( |
93 scoped_ptr<AbstractFileEnumerator>(base_enumerator), | 51 scoped_ptr<AbstractFileEnumerator>(base_enumerator), |
94 context->media_path_filter()); | 52 context->media_path_filter()); |
95 } | 53 } |
96 | 54 |
97 PlatformFileError NativeMediaFileUtil::Touch( | 55 PlatformFileError NativeMediaFileUtil::Touch( |
98 FileSystemOperationContext* context, | 56 FileSystemOperationContext* context, |
99 const FileSystemURL& url, | 57 const FileSystemURL& url, |
100 const base::Time& last_access_time, | 58 const base::Time& last_access_time, |
101 const base::Time& last_modified_time) { | 59 const base::Time& last_modified_time) { |
102 // TODO(tzik): Apply context()->mime_path_filter() here when we support write | 60 // TODO(tzik): Apply context()->media_path_filter() here when we support write |
103 // access. | 61 // access. |
104 return base::PLATFORM_FILE_ERROR_SECURITY; | 62 return base::PLATFORM_FILE_ERROR_SECURITY; |
105 } | 63 } |
106 | 64 |
107 PlatformFileError NativeMediaFileUtil::Truncate( | 65 PlatformFileError NativeMediaFileUtil::Truncate( |
108 FileSystemOperationContext* context, | 66 FileSystemOperationContext* context, |
109 const FileSystemURL& url, | 67 const FileSystemURL& url, |
110 int64 length) { | 68 int64 length) { |
111 // TODO(tzik): Apply context()->mime_path_filter() here when we support write | 69 // TODO(tzik): Apply context()->media_path_filter() here when we support write |
112 // access. | 70 // access. |
113 return base::PLATFORM_FILE_ERROR_SECURITY; | 71 return base::PLATFORM_FILE_ERROR_SECURITY; |
114 } | 72 } |
115 | 73 |
116 bool NativeMediaFileUtil::PathExists( | 74 bool NativeMediaFileUtil::PathExists( |
117 FileSystemOperationContext* context, | 75 FileSystemOperationContext* context, |
118 const FileSystemURL& url) { | 76 const FileSystemURL& url) { |
119 DCHECK(context); | 77 DCHECK(context); |
120 | 78 |
121 FilePath path; | 79 FilePath path; |
(...skipping 18 matching lines...) Expand all Loading... | |
140 return false; | 98 return false; |
141 } | 99 } |
142 return true; | 100 return true; |
143 } | 101 } |
144 | 102 |
145 PlatformFileError NativeMediaFileUtil::CopyOrMoveFile( | 103 PlatformFileError NativeMediaFileUtil::CopyOrMoveFile( |
146 FileSystemOperationContext* context, | 104 FileSystemOperationContext* context, |
147 const FileSystemURL& src_url, | 105 const FileSystemURL& src_url, |
148 const FileSystemURL& dest_url, | 106 const FileSystemURL& dest_url, |
149 bool copy) { | 107 bool copy) { |
150 // TODO(tzik): Apply context()->mime_path_filter() here when we support write | 108 // TODO(tzik): Apply context()->media_path_filter() here when we support write |
151 // access. | 109 // access. |
152 return base::PLATFORM_FILE_ERROR_SECURITY; | 110 return base::PLATFORM_FILE_ERROR_SECURITY; |
153 } | 111 } |
154 | 112 |
155 PlatformFileError NativeMediaFileUtil::CopyInForeignFile( | 113 PlatformFileError NativeMediaFileUtil::CopyInForeignFile( |
156 FileSystemOperationContext* context, | 114 FileSystemOperationContext* context, |
157 const FilePath& src_file_path, | 115 const FilePath& src_file_path, |
158 const FileSystemURL& dest_url) { | 116 const FileSystemURL& dest_url) { |
159 // TODO(tzik): Apply context()->mime_path_filter() here when we support write | 117 // TODO(tzik): Apply context()->media_path_filter() here when we support write |
160 // access. | 118 // access. |
161 return base::PLATFORM_FILE_ERROR_SECURITY; | 119 return base::PLATFORM_FILE_ERROR_SECURITY; |
162 } | 120 } |
163 | 121 |
164 PlatformFileError NativeMediaFileUtil::DeleteFile( | 122 PlatformFileError NativeMediaFileUtil::DeleteFile( |
165 FileSystemOperationContext* context, | 123 FileSystemOperationContext* context, |
166 const FileSystemURL& url) { | 124 const FileSystemURL& url) { |
167 return base::PLATFORM_FILE_ERROR_SECURITY; | 125 return base::PLATFORM_FILE_ERROR_SECURITY; |
168 } | 126 } |
169 | 127 |
(...skipping 12 matching lines...) Expand all Loading... | |
182 if (error != base::PLATFORM_FILE_OK) | 140 if (error != base::PLATFORM_FILE_OK) |
183 return error; | 141 return error; |
184 | 142 |
185 if (file_info->is_directory || | 143 if (file_info->is_directory || |
186 context->media_path_filter()->Match(*platform_path)) | 144 context->media_path_filter()->Match(*platform_path)) |
187 return base::PLATFORM_FILE_OK; | 145 return base::PLATFORM_FILE_OK; |
188 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 146 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
189 } | 147 } |
190 | 148 |
191 } // namespace fileapi | 149 } // namespace fileapi |
OLD | NEW |