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

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

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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
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 "webkit/fileapi/file_system_operation_context.h" 7 #include "webkit/fileapi/file_system_operation_context.h"
8 #include "webkit/fileapi/media/media_path_filter.h" 8 #include "webkit/fileapi/media/media_path_filter.h"
9 #include "webkit/fileapi/media/filtering_file_enumerator.h" 9 #include "webkit/fileapi/media/filtering_file_enumerator.h"
10 #include "webkit/fileapi/native_file_util.h" 10 #include "webkit/fileapi/native_file_util.h"
(...skipping 13 matching lines...) Expand all
24 int file_flags, 24 int file_flags,
25 PlatformFile* file_handle, 25 PlatformFile* file_handle,
26 bool* created) { 26 bool* created) {
27 // Only called by NaCl, which should not have access to media file systems. 27 // Only called by NaCl, which should not have access to media file systems.
28 return base::PLATFORM_FILE_ERROR_SECURITY; 28 return base::PLATFORM_FILE_ERROR_SECURITY;
29 } 29 }
30 30
31 PlatformFileError NativeMediaFileUtil::EnsureFileExists( 31 PlatformFileError NativeMediaFileUtil::EnsureFileExists(
32 FileSystemOperationContext* context, 32 FileSystemOperationContext* context,
33 const FileSystemURL& url, bool* created) { 33 const FileSystemURL& url, bool* created) {
34 FilePath file_path; 34 base::FilePath file_path;
35 PlatformFileError error = GetFilteredLocalFilePath(context, url, &file_path); 35 PlatformFileError error = GetFilteredLocalFilePath(context, url, &file_path);
36 if (error != base::PLATFORM_FILE_OK) 36 if (error != base::PLATFORM_FILE_OK)
37 return error; 37 return error;
38 return NativeFileUtil::EnsureFileExists(file_path, created); 38 return NativeFileUtil::EnsureFileExists(file_path, created);
39 } 39 }
40 40
41 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> 41 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator>
42 NativeMediaFileUtil::CreateFileEnumerator( 42 NativeMediaFileUtil::CreateFileEnumerator(
43 FileSystemOperationContext* context, 43 FileSystemOperationContext* context,
44 const FileSystemURL& root_url, 44 const FileSystemURL& root_url,
45 bool recursive) { 45 bool recursive) {
46 DCHECK(context); 46 DCHECK(context);
47 return make_scoped_ptr(new FilteringFileEnumerator( 47 return make_scoped_ptr(new FilteringFileEnumerator(
48 IsolatedFileUtil::CreateFileEnumerator(context, root_url, recursive), 48 IsolatedFileUtil::CreateFileEnumerator(context, root_url, recursive),
49 context->media_path_filter())) 49 context->media_path_filter()))
50 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); 50 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>();
51 } 51 }
52 52
53 PlatformFileError NativeMediaFileUtil::Touch( 53 PlatformFileError NativeMediaFileUtil::Touch(
54 FileSystemOperationContext* context, 54 FileSystemOperationContext* context,
55 const FileSystemURL& url, 55 const FileSystemURL& url,
56 const base::Time& last_access_time, 56 const base::Time& last_access_time,
57 const base::Time& last_modified_time) { 57 const base::Time& last_modified_time) {
58 FilePath file_path; 58 base::FilePath file_path;
59 PlatformFileError error = GetFilteredLocalFilePathForExistingFileOrDirectory( 59 PlatformFileError error = GetFilteredLocalFilePathForExistingFileOrDirectory(
60 context, 60 context,
61 url, 61 url,
62 // Touch fails for non-existent paths and filtered paths. 62 // Touch fails for non-existent paths and filtered paths.
63 base::PLATFORM_FILE_ERROR_FAILED, 63 base::PLATFORM_FILE_ERROR_FAILED,
64 &file_path); 64 &file_path);
65 if (error != base::PLATFORM_FILE_OK) 65 if (error != base::PLATFORM_FILE_OK)
66 return error; 66 return error;
67 return NativeFileUtil::Touch(file_path, last_access_time, last_modified_time); 67 return NativeFileUtil::Touch(file_path, last_access_time, last_modified_time);
68 } 68 }
69 69
70 PlatformFileError NativeMediaFileUtil::Truncate( 70 PlatformFileError NativeMediaFileUtil::Truncate(
71 FileSystemOperationContext* context, 71 FileSystemOperationContext* context,
72 const FileSystemURL& url, 72 const FileSystemURL& url,
73 int64 length) { 73 int64 length) {
74 FilePath file_path; 74 base::FilePath file_path;
75 PlatformFileError error = GetFilteredLocalFilePathForExistingFileOrDirectory( 75 PlatformFileError error = GetFilteredLocalFilePathForExistingFileOrDirectory(
76 context, 76 context,
77 url, 77 url,
78 // Cannot truncate paths that do not exist, or are filtered. 78 // Cannot truncate paths that do not exist, or are filtered.
79 base::PLATFORM_FILE_ERROR_NOT_FOUND, 79 base::PLATFORM_FILE_ERROR_NOT_FOUND,
80 &file_path); 80 &file_path);
81 if (error != base::PLATFORM_FILE_OK) 81 if (error != base::PLATFORM_FILE_OK)
82 return error; 82 return error;
83 return NativeFileUtil::Truncate(file_path, length); 83 return NativeFileUtil::Truncate(file_path, length);
84 } 84 }
85 85
86 PlatformFileError NativeMediaFileUtil::CopyOrMoveFile( 86 PlatformFileError NativeMediaFileUtil::CopyOrMoveFile(
87 FileSystemOperationContext* context, 87 FileSystemOperationContext* context,
88 const FileSystemURL& src_url, 88 const FileSystemURL& src_url,
89 const FileSystemURL& dest_url, 89 const FileSystemURL& dest_url,
90 bool copy) { 90 bool copy) {
91 FilePath src_file_path; 91 base::FilePath src_file_path;
92 PlatformFileError error = 92 PlatformFileError error =
93 GetFilteredLocalFilePathForExistingFileOrDirectory( 93 GetFilteredLocalFilePathForExistingFileOrDirectory(
94 context, src_url, 94 context, src_url,
95 base::PLATFORM_FILE_ERROR_NOT_FOUND, 95 base::PLATFORM_FILE_ERROR_NOT_FOUND,
96 &src_file_path); 96 &src_file_path);
97 if (error != base::PLATFORM_FILE_OK) 97 if (error != base::PLATFORM_FILE_OK)
98 return error; 98 return error;
99 if (NativeFileUtil::DirectoryExists(src_file_path)) 99 if (NativeFileUtil::DirectoryExists(src_file_path))
100 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; 100 return base::PLATFORM_FILE_ERROR_NOT_A_FILE;
101 101
102 FilePath dest_file_path; 102 base::FilePath dest_file_path;
103 error = GetLocalFilePath(context, dest_url, &dest_file_path); 103 error = GetLocalFilePath(context, dest_url, &dest_file_path);
104 if (error != base::PLATFORM_FILE_OK) 104 if (error != base::PLATFORM_FILE_OK)
105 return error; 105 return error;
106 PlatformFileInfo file_info; 106 PlatformFileInfo file_info;
107 error = NativeFileUtil::GetFileInfo(dest_file_path, &file_info); 107 error = NativeFileUtil::GetFileInfo(dest_file_path, &file_info);
108 if (error != base::PLATFORM_FILE_OK && 108 if (error != base::PLATFORM_FILE_OK &&
109 error != base::PLATFORM_FILE_ERROR_NOT_FOUND) 109 error != base::PLATFORM_FILE_ERROR_NOT_FOUND)
110 return error; 110 return error;
111 if (error == base::PLATFORM_FILE_OK && file_info.is_directory) 111 if (error == base::PLATFORM_FILE_OK && file_info.is_directory)
112 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 112 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
113 if (!context->media_path_filter()->Match(dest_file_path)) 113 if (!context->media_path_filter()->Match(dest_file_path))
114 return base::PLATFORM_FILE_ERROR_SECURITY; 114 return base::PLATFORM_FILE_ERROR_SECURITY;
115 115
116 return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, copy); 116 return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, copy);
117 } 117 }
118 118
119 PlatformFileError NativeMediaFileUtil::CopyInForeignFile( 119 PlatformFileError NativeMediaFileUtil::CopyInForeignFile(
120 FileSystemOperationContext* context, 120 FileSystemOperationContext* context,
121 const FilePath& src_file_path, 121 const base::FilePath& src_file_path,
122 const FileSystemURL& dest_url) { 122 const FileSystemURL& dest_url) {
123 if (src_file_path.empty()) 123 if (src_file_path.empty())
124 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 124 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
125 125
126 FilePath dest_file_path; 126 base::FilePath dest_file_path;
127 PlatformFileError error = 127 PlatformFileError error =
128 GetFilteredLocalFilePath(context, dest_url, &dest_file_path); 128 GetFilteredLocalFilePath(context, dest_url, &dest_file_path);
129 if (error != base::PLATFORM_FILE_OK) 129 if (error != base::PLATFORM_FILE_OK)
130 return error; 130 return error;
131 return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, true); 131 return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, true);
132 } 132 }
133 133
134 PlatformFileError NativeMediaFileUtil::DeleteFile( 134 PlatformFileError NativeMediaFileUtil::DeleteFile(
135 FileSystemOperationContext* context, 135 FileSystemOperationContext* context,
136 const FileSystemURL& url) { 136 const FileSystemURL& url) {
137 FilePath file_path; 137 base::FilePath file_path;
138 PlatformFileError error = GetLocalFilePath(context, url, &file_path); 138 PlatformFileError error = GetLocalFilePath(context, url, &file_path);
139 if (error != base::PLATFORM_FILE_OK) 139 if (error != base::PLATFORM_FILE_OK)
140 return error; 140 return error;
141 PlatformFileInfo file_info; 141 PlatformFileInfo file_info;
142 error = NativeFileUtil::GetFileInfo(file_path, &file_info); 142 error = NativeFileUtil::GetFileInfo(file_path, &file_info);
143 if (error != base::PLATFORM_FILE_OK) 143 if (error != base::PLATFORM_FILE_OK)
144 return error; 144 return error;
145 if (file_info.is_directory) 145 if (file_info.is_directory)
146 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; 146 return base::PLATFORM_FILE_ERROR_NOT_A_FILE;
147 if (!context->media_path_filter()->Match(file_path)) 147 if (!context->media_path_filter()->Match(file_path))
148 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 148 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
149 return NativeFileUtil::DeleteFile(file_path); 149 return NativeFileUtil::DeleteFile(file_path);
150 } 150 }
151 151
152 PlatformFileError NativeMediaFileUtil::GetFileInfo( 152 PlatformFileError NativeMediaFileUtil::GetFileInfo(
153 FileSystemOperationContext* context, 153 FileSystemOperationContext* context,
154 const FileSystemURL& url, 154 const FileSystemURL& url,
155 PlatformFileInfo* file_info, 155 PlatformFileInfo* file_info,
156 FilePath* platform_path) { 156 base::FilePath* platform_path) {
157 DCHECK(context); 157 DCHECK(context);
158 DCHECK(context->media_path_filter()); 158 DCHECK(context->media_path_filter());
159 DCHECK(file_info); 159 DCHECK(file_info);
160 DCHECK(platform_path); 160 DCHECK(platform_path);
161 161
162 base::PlatformFileError error = 162 base::PlatformFileError error =
163 IsolatedFileUtil::GetFileInfo(context, url, file_info, platform_path); 163 IsolatedFileUtil::GetFileInfo(context, url, file_info, platform_path);
164 if (error != base::PLATFORM_FILE_OK) 164 if (error != base::PLATFORM_FILE_OK)
165 return error; 165 return error;
166 166
167 if (file_info->is_directory || 167 if (file_info->is_directory ||
168 context->media_path_filter()->Match(*platform_path)) { 168 context->media_path_filter()->Match(*platform_path)) {
169 return base::PLATFORM_FILE_OK; 169 return base::PLATFORM_FILE_OK;
170 } 170 }
171 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 171 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
172 } 172 }
173 173
174 PlatformFileError NativeMediaFileUtil::GetFilteredLocalFilePath( 174 PlatformFileError NativeMediaFileUtil::GetFilteredLocalFilePath(
175 FileSystemOperationContext* context, 175 FileSystemOperationContext* context,
176 const FileSystemURL& file_system_url, 176 const FileSystemURL& file_system_url,
177 FilePath* local_file_path) { 177 base::FilePath* local_file_path) {
178 FilePath file_path; 178 base::FilePath file_path;
179 PlatformFileError error = 179 PlatformFileError error =
180 IsolatedFileUtil::GetLocalFilePath(context, file_system_url, &file_path); 180 IsolatedFileUtil::GetLocalFilePath(context, file_system_url, &file_path);
181 if (error != base::PLATFORM_FILE_OK) 181 if (error != base::PLATFORM_FILE_OK)
182 return error; 182 return error;
183 if (!context->media_path_filter()->Match(file_path)) 183 if (!context->media_path_filter()->Match(file_path))
184 return base::PLATFORM_FILE_ERROR_SECURITY; 184 return base::PLATFORM_FILE_ERROR_SECURITY;
185 185
186 *local_file_path = file_path; 186 *local_file_path = file_path;
187 return base::PLATFORM_FILE_OK; 187 return base::PLATFORM_FILE_OK;
188 } 188 }
189 189
190 PlatformFileError 190 PlatformFileError
191 NativeMediaFileUtil::GetFilteredLocalFilePathForExistingFileOrDirectory( 191 NativeMediaFileUtil::GetFilteredLocalFilePathForExistingFileOrDirectory(
192 FileSystemOperationContext* context, 192 FileSystemOperationContext* context,
193 const FileSystemURL& file_system_url, 193 const FileSystemURL& file_system_url,
194 PlatformFileError failure_error, 194 PlatformFileError failure_error,
195 FilePath* local_file_path) { 195 base::FilePath* local_file_path) {
196 FilePath file_path; 196 base::FilePath file_path;
197 PlatformFileError error = 197 PlatformFileError error =
198 GetLocalFilePath(context, file_system_url, &file_path); 198 GetLocalFilePath(context, file_system_url, &file_path);
199 if (error != base::PLATFORM_FILE_OK) 199 if (error != base::PLATFORM_FILE_OK)
200 return error; 200 return error;
201 201
202 if (!file_util::PathExists(file_path)) 202 if (!file_util::PathExists(file_path))
203 return failure_error; 203 return failure_error;
204 PlatformFileInfo file_info; 204 PlatformFileInfo file_info;
205 if (!file_util::GetFileInfo(file_path, &file_info)) 205 if (!file_util::GetFileInfo(file_path, &file_info))
206 return base::PLATFORM_FILE_ERROR_FAILED; 206 return base::PLATFORM_FILE_ERROR_FAILED;
207 207
208 if (!file_info.is_directory && 208 if (!file_info.is_directory &&
209 !context->media_path_filter()->Match(file_path)) { 209 !context->media_path_filter()->Match(file_path)) {
210 return failure_error; 210 return failure_error;
211 } 211 }
212 212
213 *local_file_path = file_path; 213 *local_file_path = file_path;
214 return base::PLATFORM_FILE_OK; 214 return base::PLATFORM_FILE_OK;
215 } 215 }
216 216
217 } // namespace fileapi 217 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/media/native_media_file_util.h ('k') | webkit/fileapi/media/native_media_file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698