Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: webkit/fileapi/media/native_media_file_util.cc

Issue 10825042: Implement media path filter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: s/LocalMediaFileUtil/NativeMediaFileUtil/ Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/native_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 while (true) {
32 FilePath next = base_enumerator_->Next();
33 if (next.empty() ||
34 base_enumerator_->IsDirectory() ||
35 filter_->Match(next))
36 return next;
37 }
38 }
39
40 virtual int64 Size() OVERRIDE {
41 return base_enumerator_->Size();
42 }
43
44 virtual base::Time LastModifiedTime() OVERRIDE {
45 return base_enumerator_->LastModifiedTime();
46 }
47
48 virtual bool IsDirectory() OVERRIDE {
49 return base_enumerator_->IsDirectory();
50 }
51
52 private:
53 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> base_enumerator_;
54 MediaPathFilter* filter_;
55 };
56 } // anonymous namespace
57
58 NativeMediaFileUtil::NativeMediaFileUtil() {
59 }
60
61 PlatformFileError NativeMediaFileUtil::CreateOrOpen(
62 FileSystemOperationContext* context,
63 const FileSystemURL& url,
64 int file_flags,
65 PlatformFile* file_handle,
66 bool* created) {
67 // TODO(tzik): Apply context()->mime_path_filter() here when we support write
68 // access.
69 return base::PLATFORM_FILE_ERROR_SECURITY;
70 }
71
72 PlatformFileError NativeMediaFileUtil::EnsureFileExists(
73 FileSystemOperationContext* context,
74 const FileSystemURL& url, bool* created) {
75 // TODO(tzik): Apply context()->mime_path_filter() here when we support write
76 // access.
77 return base::PLATFORM_FILE_ERROR_SECURITY;
78 }
79
80 FileSystemFileUtil::AbstractFileEnumerator*
81 NativeMediaFileUtil::CreateFileEnumerator(
82 FileSystemOperationContext* context,
83 const FileSystemURL& root_url,
84 bool recursive) {
85 AbstractFileEnumerator* base_enumerator =
86 IsolatedFileUtil::CreateFileEnumerator(context, root_url, recursive);
87 return new FilteringFileEnumerator(
88 scoped_ptr<AbstractFileEnumerator>(base_enumerator),
89 context->media_path_filter());
90 }
91
92 PlatformFileError NativeMediaFileUtil::Touch(
93 FileSystemOperationContext* context,
94 const FileSystemURL& url,
95 const base::Time& last_access_time,
96 const base::Time& last_modified_time) {
97 // TODO(tzik): Apply context()->mime_path_filter() here when we support write
98 // access.
99 return base::PLATFORM_FILE_ERROR_SECURITY;
100 }
101
102 PlatformFileError NativeMediaFileUtil::Truncate(
103 FileSystemOperationContext* context,
104 const FileSystemURL& url,
105 int64 length) {
106 // TODO(tzik): Apply context()->mime_path_filter() here when we support write
107 // access.
108 return base::PLATFORM_FILE_ERROR_SECURITY;
109 }
110
111 bool NativeMediaFileUtil::PathExists(
112 FileSystemOperationContext* context,
113 const FileSystemURL& url) {
114 FilePath path;
115 PlatformFileInfo file_info;
116 PlatformFileError error =
117 GetFileInfo(context, url, &file_info, &path);
118 return error == base::PLATFORM_FILE_OK;
119 }
120
121 bool NativeMediaFileUtil::IsDirectoryEmpty(
122 FileSystemOperationContext* context,
123 const FileSystemURL& url) {
124 DCHECK(context);
125 DCHECK(context->media_path_filter());
126
127 scoped_ptr<AbstractFileEnumerator> enumerator(
128 CreateFileEnumerator(context, url, false));
129 FilePath path;
130 while (!(path = enumerator->Next()).empty()) {
131 if (enumerator->IsDirectory() ||
132 context->media_path_filter()->Match(path))
133 return false;
134 }
135 return true;
136 }
137
138 PlatformFileError NativeMediaFileUtil::CopyOrMoveFile(
139 FileSystemOperationContext* context,
140 const FileSystemURL& src_url,
141 const FileSystemURL& dest_url,
142 bool copy) {
143 // TODO(tzik): Apply context()->mime_path_filter() here when we support write
144 // access.
145 return base::PLATFORM_FILE_ERROR_SECURITY;
146 }
147
148 PlatformFileError NativeMediaFileUtil::CopyInForeignFile(
149 FileSystemOperationContext* context,
150 const FilePath& src_file_path,
151 const FileSystemURL& dest_url) {
152 // TODO(tzik): Apply context()->mime_path_filter() here when we support write
153 // access.
154 return base::PLATFORM_FILE_ERROR_SECURITY;
155 }
156
157 PlatformFileError NativeMediaFileUtil::DeleteFile(
158 FileSystemOperationContext* context,
159 const FileSystemURL& url) {
160 return base::PLATFORM_FILE_ERROR_SECURITY;
161 }
162
163 PlatformFileError NativeMediaFileUtil::GetFileInfo(
164 FileSystemOperationContext* context,
165 const FileSystemURL& url,
166 PlatformFileInfo* file_info,
167 FilePath* platform_path) {
168 base::PlatformFileError error =
169 IsolatedFileUtil::GetFileInfo(context, url, file_info, platform_path);
170 if (error != base::PLATFORM_FILE_OK)
171 return error;
172
173 if (file_info->is_directory ||
174 context->media_path_filter()->Match(*platform_path))
175 return base::PLATFORM_FILE_OK;
176 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
177 }
178
179 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698