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

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

Issue 11960003: Cleanup: Move more recursive operation logic from FileUtilHelper to FileUtil (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 bool NativeMediaFileUtil::IsDirectoryEmpty(
87 FileSystemOperationContext* context,
88 const FileSystemURL& url) {
89 DCHECK(context);
90 DCHECK(context->media_path_filter());
91
92 scoped_ptr<AbstractFileEnumerator> enumerator(
93 CreateFileEnumerator(context, url, false));
94 FilePath path;
95 while (!(path = enumerator->Next()).empty()) {
96 if (enumerator->IsDirectory() ||
97 context->media_path_filter()->Match(path))
98 return false;
99 }
100 return true;
101 }
102
103 PlatformFileError NativeMediaFileUtil::CopyOrMoveFile( 86 PlatformFileError NativeMediaFileUtil::CopyOrMoveFile(
104 FileSystemOperationContext* context, 87 FileSystemOperationContext* context,
105 const FileSystemURL& src_url, 88 const FileSystemURL& src_url,
106 const FileSystemURL& dest_url, 89 const FileSystemURL& dest_url,
107 bool copy) { 90 bool copy) {
108 FilePath src_file_path; 91 FilePath src_file_path;
109 PlatformFileError error = 92 PlatformFileError error =
110 GetFilteredLocalFilePath(context, src_url, &src_file_path); 93 GetFilteredLocalFilePathForExistingFileOrDirectory(
94 context, src_url,
95 base::PLATFORM_FILE_ERROR_NOT_FOUND,
96 &src_file_path);
111 if (error != base::PLATFORM_FILE_OK) 97 if (error != base::PLATFORM_FILE_OK)
112 return error; 98 return error;
99 if (NativeFileUtil::DirectoryExists(src_file_path))
100 return base::PLATFORM_FILE_ERROR_NOT_A_FILE;
113 101
114 FilePath dest_file_path; 102 FilePath dest_file_path;
115 error = GetFilteredLocalFilePath(context, dest_url, &dest_file_path); 103 error = GetLocalFilePath(context, dest_url, &dest_file_path);
116 if (error != base::PLATFORM_FILE_OK) 104 if (error != base::PLATFORM_FILE_OK)
117 return error; 105 return error;
106 PlatformFileInfo file_info;
107 error = NativeFileUtil::GetFileInfo(dest_file_path, &file_info);
108 if (error != base::PLATFORM_FILE_OK &&
109 error != base::PLATFORM_FILE_ERROR_NOT_FOUND)
110 return error;
111 if (error == base::PLATFORM_FILE_OK && file_info.is_directory)
112 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
113 if (!context->media_path_filter()->Match(dest_file_path))
114 return base::PLATFORM_FILE_ERROR_SECURITY;
118 115
119 return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, copy); 116 return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, copy);
120 } 117 }
121 118
122 PlatformFileError NativeMediaFileUtil::CopyInForeignFile( 119 PlatformFileError NativeMediaFileUtil::CopyInForeignFile(
123 FileSystemOperationContext* context, 120 FileSystemOperationContext* context,
124 const FilePath& src_file_path, 121 const FilePath& src_file_path,
125 const FileSystemURL& dest_url) { 122 const FileSystemURL& dest_url) {
126 if (src_file_path.empty()) 123 if (src_file_path.empty())
127 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 124 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 if (!file_info.is_directory && 202 if (!file_info.is_directory &&
206 !context->media_path_filter()->Match(file_path)) { 203 !context->media_path_filter()->Match(file_path)) {
207 return failure_error; 204 return failure_error;
208 } 205 }
209 206
210 *local_file_path = file_path; 207 *local_file_path = file_path;
211 return base::PLATFORM_FILE_OK; 208 return base::PLATFORM_FILE_OK;
212 } 209 }
213 210
214 } // namespace fileapi 211 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698