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

Side by Side Diff: webkit/browser/fileapi/native_file_util.cc

Issue 19052005: Move PathIsWritable, DirectoryExists, ContentsEqual, and TextContentsEqual to the base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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/browser/fileapi/native_file_util.h" 5 #include "webkit/browser/fileapi/native_file_util.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_enumerator.h" 8 #include "base/files/file_enumerator.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "webkit/browser/fileapi/file_system_operation_context.h" 10 #include "webkit/browser/fileapi/file_system_operation_context.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 return file_util_info_.GetLastModifiedTime(); 72 return file_util_info_.GetLastModifiedTime();
73 } 73 }
74 74
75 bool NativeFileEnumerator::IsDirectory() { 75 bool NativeFileEnumerator::IsDirectory() {
76 return file_util_info_.IsDirectory(); 76 return file_util_info_.IsDirectory();
77 } 77 }
78 78
79 PlatformFileError NativeFileUtil::CreateOrOpen( 79 PlatformFileError NativeFileUtil::CreateOrOpen(
80 const base::FilePath& path, int file_flags, 80 const base::FilePath& path, int file_flags,
81 PlatformFile* file_handle, bool* created) { 81 PlatformFile* file_handle, bool* created) {
82 if (!file_util::DirectoryExists(path.DirName())) { 82 if (!base::DirectoryExists(path.DirName())) {
83 // If its parent does not exist, should return NOT_FOUND error. 83 // If its parent does not exist, should return NOT_FOUND error.
84 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 84 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
85 } 85 }
86 if (file_util::DirectoryExists(path)) 86 if (base::DirectoryExists(path))
87 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; 87 return base::PLATFORM_FILE_ERROR_NOT_A_FILE;
88 PlatformFileError error_code = base::PLATFORM_FILE_OK; 88 PlatformFileError error_code = base::PLATFORM_FILE_OK;
89 *file_handle = base::CreatePlatformFile(path, file_flags, 89 *file_handle = base::CreatePlatformFile(path, file_flags,
90 created, &error_code); 90 created, &error_code);
91 return error_code; 91 return error_code;
92 } 92 }
93 93
94 PlatformFileError NativeFileUtil::Close(PlatformFile file_handle) { 94 PlatformFileError NativeFileUtil::Close(PlatformFile file_handle) {
95 if (!base::ClosePlatformFile(file_handle)) 95 if (!base::ClosePlatformFile(file_handle))
96 return base::PLATFORM_FILE_ERROR_FAILED; 96 return base::PLATFORM_FILE_ERROR_FAILED;
97 return base::PLATFORM_FILE_OK; 97 return base::PLATFORM_FILE_OK;
98 } 98 }
99 99
100 PlatformFileError NativeFileUtil::EnsureFileExists( 100 PlatformFileError NativeFileUtil::EnsureFileExists(
101 const base::FilePath& path, 101 const base::FilePath& path,
102 bool* created) { 102 bool* created) {
103 if (!file_util::DirectoryExists(path.DirName())) 103 if (!base::DirectoryExists(path.DirName()))
104 // If its parent does not exist, should return NOT_FOUND error. 104 // If its parent does not exist, should return NOT_FOUND error.
105 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 105 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
106 PlatformFileError error_code = base::PLATFORM_FILE_OK; 106 PlatformFileError error_code = base::PLATFORM_FILE_OK;
107 // Tries to create the |path| exclusively. This should fail 107 // Tries to create the |path| exclusively. This should fail
108 // with base::PLATFORM_FILE_ERROR_EXISTS if the path already exists. 108 // with base::PLATFORM_FILE_ERROR_EXISTS if the path already exists.
109 PlatformFile handle = base::CreatePlatformFile( 109 PlatformFile handle = base::CreatePlatformFile(
110 path, 110 path,
111 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_READ, 111 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_READ,
112 created, &error_code); 112 created, &error_code);
113 if (error_code == base::PLATFORM_FILE_ERROR_EXISTS) { 113 if (error_code == base::PLATFORM_FILE_ERROR_EXISTS) {
(...skipping 13 matching lines...) Expand all
127 bool recursive) { 127 bool recursive) {
128 // If parent dir of file doesn't exist. 128 // If parent dir of file doesn't exist.
129 if (!recursive && !base::PathExists(path.DirName())) 129 if (!recursive && !base::PathExists(path.DirName()))
130 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 130 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
131 131
132 bool path_exists = base::PathExists(path); 132 bool path_exists = base::PathExists(path);
133 if (exclusive && path_exists) 133 if (exclusive && path_exists)
134 return base::PLATFORM_FILE_ERROR_EXISTS; 134 return base::PLATFORM_FILE_ERROR_EXISTS;
135 135
136 // If file exists at the path. 136 // If file exists at the path.
137 if (path_exists && !file_util::DirectoryExists(path)) 137 if (path_exists && !base::DirectoryExists(path))
138 return base::PLATFORM_FILE_ERROR_EXISTS; 138 return base::PLATFORM_FILE_ERROR_EXISTS;
139 139
140 if (!file_util::CreateDirectory(path)) 140 if (!file_util::CreateDirectory(path))
141 return base::PLATFORM_FILE_ERROR_FAILED; 141 return base::PLATFORM_FILE_ERROR_FAILED;
142 142
143 if (!SetPlatformSpecificDirectoryPermissions(path)) 143 if (!SetPlatformSpecificDirectoryPermissions(path))
144 return base::PLATFORM_FILE_ERROR_FAILED; 144 return base::PLATFORM_FILE_ERROR_FAILED;
145 145
146 return base::PLATFORM_FILE_OK; 146 return base::PLATFORM_FILE_OK;
147 } 147 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 error_code = base::PLATFORM_FILE_ERROR_FAILED; 192 error_code = base::PLATFORM_FILE_ERROR_FAILED;
193 base::ClosePlatformFile(file); 193 base::ClosePlatformFile(file);
194 return error_code; 194 return error_code;
195 } 195 }
196 196
197 bool NativeFileUtil::PathExists(const base::FilePath& path) { 197 bool NativeFileUtil::PathExists(const base::FilePath& path) {
198 return base::PathExists(path); 198 return base::PathExists(path);
199 } 199 }
200 200
201 bool NativeFileUtil::DirectoryExists(const base::FilePath& path) { 201 bool NativeFileUtil::DirectoryExists(const base::FilePath& path) {
202 return file_util::DirectoryExists(path); 202 return base::DirectoryExists(path);
203 } 203 }
204 204
205 PlatformFileError NativeFileUtil::CopyOrMoveFile( 205 PlatformFileError NativeFileUtil::CopyOrMoveFile(
206 const base::FilePath& src_path, 206 const base::FilePath& src_path,
207 const base::FilePath& dest_path, 207 const base::FilePath& dest_path,
208 bool copy) { 208 bool copy) {
209 base::PlatformFileInfo info; 209 base::PlatformFileInfo info;
210 base::PlatformFileError error = NativeFileUtil::GetFileInfo(src_path, &info); 210 base::PlatformFileError error = NativeFileUtil::GetFileInfo(src_path, &info);
211 if (error != base::PLATFORM_FILE_OK) 211 if (error != base::PLATFORM_FILE_OK)
212 return error; 212 return error;
(...skipping 20 matching lines...) Expand all
233 } else { 233 } else {
234 if (base::Move(src_path, dest_path)) 234 if (base::Move(src_path, dest_path))
235 return base::PLATFORM_FILE_OK; 235 return base::PLATFORM_FILE_OK;
236 } 236 }
237 return base::PLATFORM_FILE_ERROR_FAILED; 237 return base::PLATFORM_FILE_ERROR_FAILED;
238 } 238 }
239 239
240 PlatformFileError NativeFileUtil::DeleteFile(const base::FilePath& path) { 240 PlatformFileError NativeFileUtil::DeleteFile(const base::FilePath& path) {
241 if (!base::PathExists(path)) 241 if (!base::PathExists(path))
242 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 242 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
243 if (file_util::DirectoryExists(path)) 243 if (base::DirectoryExists(path))
244 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; 244 return base::PLATFORM_FILE_ERROR_NOT_A_FILE;
245 if (!base::Delete(path, false)) 245 if (!base::Delete(path, false))
246 return base::PLATFORM_FILE_ERROR_FAILED; 246 return base::PLATFORM_FILE_ERROR_FAILED;
247 return base::PLATFORM_FILE_OK; 247 return base::PLATFORM_FILE_OK;
248 } 248 }
249 249
250 PlatformFileError NativeFileUtil::DeleteDirectory(const base::FilePath& path) { 250 PlatformFileError NativeFileUtil::DeleteDirectory(const base::FilePath& path) {
251 if (!base::PathExists(path)) 251 if (!base::PathExists(path))
252 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 252 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
253 if (!file_util::DirectoryExists(path)) 253 if (!base::DirectoryExists(path))
254 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; 254 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY;
255 if (!file_util::IsDirectoryEmpty(path)) 255 if (!file_util::IsDirectoryEmpty(path))
256 return base::PLATFORM_FILE_ERROR_NOT_EMPTY; 256 return base::PLATFORM_FILE_ERROR_NOT_EMPTY;
257 if (!base::Delete(path, false)) 257 if (!base::Delete(path, false))
258 return base::PLATFORM_FILE_ERROR_FAILED; 258 return base::PLATFORM_FILE_ERROR_FAILED;
259 return base::PLATFORM_FILE_OK; 259 return base::PLATFORM_FILE_OK;
260 } 260 }
261 261
262 } // namespace fileapi 262 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/local_file_util_unittest.cc ('k') | webkit/browser/fileapi/native_file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698