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

Side by Side Diff: webkit/fileapi/file_util_helper.cc

Issue 10855039: Cleanup: Remove FileSystemFileUtil::{Directory,Path}Exists (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test fix 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
« no previous file with comments | « webkit/fileapi/file_util_helper.h ('k') | webkit/fileapi/isolated_file_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/file_util_helper.h" 5 #include "webkit/fileapi/file_util_helper.h"
6 6
7 #include <stack> 7 #include <stack>
8 8
9 #include "webkit/fileapi/file_system_file_util.h" 9 #include "webkit/fileapi/file_system_file_util.h"
10 #include "webkit/fileapi/file_system_operation_context.h" 10 #include "webkit/fileapi/file_system_operation_context.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 src_root_url_.origin() == dest_root_url_.origin() && 98 src_root_url_.origin() == dest_root_url_.origin() &&
99 src_root_url_.type() == dest_root_url_.type(); 99 src_root_url_.type() == dest_root_url_.type();
100 } 100 }
101 101
102 CrossFileUtilHelper::~CrossFileUtilHelper() {} 102 CrossFileUtilHelper::~CrossFileUtilHelper() {}
103 103
104 base::PlatformFileError CrossFileUtilHelper::DoWork() { 104 base::PlatformFileError CrossFileUtilHelper::DoWork() {
105 base::PlatformFileError error = PerformErrorCheckAndPreparation(); 105 base::PlatformFileError error = PerformErrorCheckAndPreparation();
106 if (error != base::PLATFORM_FILE_OK) 106 if (error != base::PLATFORM_FILE_OK)
107 return error; 107 return error;
108 if (src_util_->DirectoryExists(context_, src_root_url_)) 108 if (FileUtilHelper::DirectoryExists(context_, src_util_, src_root_url_))
109 return CopyOrMoveDirectory(src_root_url_, dest_root_url_); 109 return CopyOrMoveDirectory(src_root_url_, dest_root_url_);
110 return CopyOrMoveFile(src_root_url_, dest_root_url_); 110 return CopyOrMoveFile(src_root_url_, dest_root_url_);
111 } 111 }
112 112
113 PlatformFileError CrossFileUtilHelper::PerformErrorCheckAndPreparation() { 113 PlatformFileError CrossFileUtilHelper::PerformErrorCheckAndPreparation() {
114 // Exits earlier if the source path does not exist. 114 // Exits earlier if the source path does not exist.
115 if (!src_util_->PathExists(context_, src_root_url_)) 115 if (!FileUtilHelper::PathExists(context_, src_util_, src_root_url_))
116 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 116 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
117 117
118 // The parent of the |dest_root_url_| does not exist. 118 // The parent of the |dest_root_url_| does not exist.
119 if (!ParentExists(dest_root_url_, dest_util_)) 119 if (!ParentExists(dest_root_url_, dest_util_))
120 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 120 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
121 121
122 // It is an error to try to copy/move an entry into its child. 122 // It is an error to try to copy/move an entry into its child.
123 if (same_file_system_ && src_root_url_.path().IsParent(dest_root_url_.path())) 123 if (same_file_system_ && src_root_url_.path().IsParent(dest_root_url_.path()))
124 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 124 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
125 125
126 // Now it is ok to return if the |dest_root_url_| does not exist. 126 // Now it is ok to return if the |dest_root_url_| does not exist.
127 if (!dest_util_->PathExists(context_, dest_root_url_)) 127 if (!FileUtilHelper::PathExists(context_, dest_util_, dest_root_url_))
128 return base::PLATFORM_FILE_OK; 128 return base::PLATFORM_FILE_OK;
129 129
130 // |src_root_url_| exists and is a directory. 130 // |src_root_url_| exists and is a directory.
131 // |dest_root_url_| exists and is a file. 131 // |dest_root_url_| exists and is a file.
132 bool src_is_directory = src_util_->DirectoryExists(context_, src_root_url_); 132 bool src_is_directory =
133 FileUtilHelper::DirectoryExists(context_, src_util_, src_root_url_);
133 bool dest_is_directory = 134 bool dest_is_directory =
134 dest_util_->DirectoryExists(context_, dest_root_url_); 135 FileUtilHelper::DirectoryExists(context_, dest_util_, dest_root_url_);
135 136
136 // Either one of |src_root_url_| or |dest_root_url_| is directory, 137 // Either one of |src_root_url_| or |dest_root_url_| is directory,
137 // while the other is not. 138 // while the other is not.
138 if (src_is_directory != dest_is_directory) 139 if (src_is_directory != dest_is_directory)
139 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 140 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
140 141
141 // It is an error to copy/move an entry into the same path. 142 // It is an error to copy/move an entry into the same path.
142 if (same_file_system_ && 143 if (same_file_system_ &&
143 src_root_url_.path() == dest_root_url_.path()) 144 src_root_url_.path() == dest_root_url_.path())
144 return base::PLATFORM_FILE_ERROR_EXISTS; 145 return base::PLATFORM_FILE_ERROR_EXISTS;
(...skipping 13 matching lines...) Expand all
158 return base::PLATFORM_FILE_OK; 159 return base::PLATFORM_FILE_OK;
159 } 160 }
160 161
161 bool CrossFileUtilHelper::ParentExists( 162 bool CrossFileUtilHelper::ParentExists(
162 const FileSystemURL& url, FileSystemFileUtil* file_util) { 163 const FileSystemURL& url, FileSystemFileUtil* file_util) {
163 // If path is in the root, path.DirName() will be ".", 164 // If path is in the root, path.DirName() will be ".",
164 // since we use paths with no leading '/'. 165 // since we use paths with no leading '/'.
165 FilePath parent = url.path().DirName(); 166 FilePath parent = url.path().DirName();
166 if (parent == FilePath(FILE_PATH_LITERAL("."))) 167 if (parent == FilePath(FILE_PATH_LITERAL(".")))
167 return true; 168 return true;
168 return file_util->DirectoryExists(context_, url.WithPath(parent)); 169 return FileUtilHelper::DirectoryExists(context_, file_util,
170 url.WithPath(parent));
169 } 171 }
170 172
171 PlatformFileError CrossFileUtilHelper::CopyOrMoveDirectory( 173 PlatformFileError CrossFileUtilHelper::CopyOrMoveDirectory(
172 const FileSystemURL& src_url, 174 const FileSystemURL& src_url,
173 const FileSystemURL& dest_url) { 175 const FileSystemURL& dest_url) {
174 // At this point we must have gone through 176 // At this point we must have gone through
175 // PerformErrorCheckAndPreparationForMoveAndCopy so this must be true. 177 // PerformErrorCheckAndPreparationForMoveAndCopy so this must be true.
176 DCHECK(!same_file_system_ || 178 DCHECK(!same_file_system_ ||
177 !src_url.path().IsParent(dest_url.path())); 179 !src_url.path().IsParent(dest_url.path()));
178 180
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 context_, platform_file_path, dest_url); 280 context_, platform_file_path, dest_url);
279 281
280 if (operation_ == OPERATION_COPY || error != base::PLATFORM_FILE_OK) 282 if (operation_ == OPERATION_COPY || error != base::PLATFORM_FILE_OK)
281 return error; 283 return error;
282 return src_util_->DeleteFile(context_, src_url); 284 return src_util_->DeleteFile(context_, src_url);
283 } 285 }
284 286
285 } // anonymous namespace 287 } // anonymous namespace
286 288
287 // static 289 // static
290 bool FileUtilHelper::PathExists(FileSystemOperationContext* context,
291 FileSystemFileUtil* file_util,
292 const FileSystemURL& url) {
293 base::PlatformFileInfo file_info;
294 FilePath platform_path;
295 PlatformFileError error = file_util->GetFileInfo(
296 context, url, &file_info, &platform_path);
297 return error == base::PLATFORM_FILE_OK;
298 }
299
300 // static
301 bool FileUtilHelper::DirectoryExists(FileSystemOperationContext* context,
302 FileSystemFileUtil* file_util,
303 const FileSystemURL& url) {
304 if (url.path().empty())
305 return true;
306
307 base::PlatformFileInfo file_info;
308 FilePath platform_path;
309 PlatformFileError error = file_util->GetFileInfo(
310 context, url, &file_info, &platform_path);
311 return error == base::PLATFORM_FILE_OK && file_info.is_directory;
312 }
313
314 // static
288 base::PlatformFileError FileUtilHelper::Copy( 315 base::PlatformFileError FileUtilHelper::Copy(
289 FileSystemOperationContext* context, 316 FileSystemOperationContext* context,
290 FileSystemFileUtil* src_file_util, 317 FileSystemFileUtil* src_file_util,
291 FileSystemFileUtil* dest_file_util, 318 FileSystemFileUtil* dest_file_util,
292 const FileSystemURL& src_root_url, 319 const FileSystemURL& src_root_url,
293 const FileSystemURL& dest_root_url) { 320 const FileSystemURL& dest_root_url) {
294 return CrossFileUtilHelper(context, src_file_util, dest_file_util, 321 return CrossFileUtilHelper(context, src_file_util, dest_file_util,
295 src_root_url, dest_root_url, 322 src_root_url, dest_root_url,
296 CrossFileUtilHelper::OPERATION_COPY).DoWork(); 323 CrossFileUtilHelper::OPERATION_COPY).DoWork();
297 } 324 }
298 325
299 // static 326 // static
300 base::PlatformFileError FileUtilHelper::Move( 327 base::PlatformFileError FileUtilHelper::Move(
301 FileSystemOperationContext* context, 328 FileSystemOperationContext* context,
302 FileSystemFileUtil* src_file_util, 329 FileSystemFileUtil* src_file_util,
303 FileSystemFileUtil* dest_file_util, 330 FileSystemFileUtil* dest_file_util,
304 const FileSystemURL& src_root_url, 331 const FileSystemURL& src_root_url,
305 const FileSystemURL& dest_root_url) { 332 const FileSystemURL& dest_root_url) {
306 return CrossFileUtilHelper(context, src_file_util, dest_file_util, 333 return CrossFileUtilHelper(context, src_file_util, dest_file_util,
307 src_root_url, dest_root_url, 334 src_root_url, dest_root_url,
308 CrossFileUtilHelper::OPERATION_MOVE).DoWork(); 335 CrossFileUtilHelper::OPERATION_MOVE).DoWork();
309 } 336 }
310 337
311 // static 338 // static
312 base::PlatformFileError FileUtilHelper::Delete( 339 base::PlatformFileError FileUtilHelper::Delete(
313 FileSystemOperationContext* context, 340 FileSystemOperationContext* context,
314 FileSystemFileUtil* file_util, 341 FileSystemFileUtil* file_util,
315 const FileSystemURL& url, 342 const FileSystemURL& url,
316 bool recursive) { 343 bool recursive) {
317 if (file_util->DirectoryExists(context, url)) { 344 if (DirectoryExists(context, file_util, url)) {
318 if (!recursive) 345 if (!recursive)
319 return file_util->DeleteSingleDirectory(context, url); 346 return file_util->DeleteSingleDirectory(context, url);
320 else 347 else
321 return DeleteDirectoryRecursive(context, file_util, url); 348 return DeleteDirectoryRecursive(context, file_util, url);
322 } else { 349 } else {
323 return file_util->DeleteFile(context, url); 350 return file_util->DeleteFile(context, url);
324 } 351 }
325 } 352 }
326 353
327 // static 354 // static
328 base::PlatformFileError FileUtilHelper::ReadDirectory( 355 base::PlatformFileError FileUtilHelper::ReadDirectory(
329 FileSystemOperationContext* context, 356 FileSystemOperationContext* context,
330 FileSystemFileUtil* file_util, 357 FileSystemFileUtil* file_util,
331 const FileSystemURL& url, 358 const FileSystemURL& url,
332 std::vector<base::FileUtilProxy::Entry>* entries) { 359 std::vector<base::FileUtilProxy::Entry>* entries) {
333 DCHECK(entries); 360 DCHECK(entries);
334 361
335 // TODO(kkanetkar): Implement directory read in multiple chunks. 362 // TODO(kkanetkar): Implement directory read in multiple chunks.
336 if (!file_util->DirectoryExists(context, url)) 363 if (!DirectoryExists(context, file_util, url))
337 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 364 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
338 365
339 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( 366 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum(
340 file_util->CreateFileEnumerator(context, url, false /* recursive */)); 367 file_util->CreateFileEnumerator(context, url, false /* recursive */));
341 368
342 FilePath current; 369 FilePath current;
343 while (!(current = file_enum->Next()).empty()) { 370 while (!(current = file_enum->Next()).empty()) {
344 base::FileUtilProxy::Entry entry; 371 base::FileUtilProxy::Entry entry;
345 entry.is_directory = file_enum->IsDirectory(); 372 entry.is_directory = file_enum->IsDirectory();
346 entry.name = current.BaseName().value(); 373 entry.name = current.BaseName().value();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 context, url.WithPath(directories.top())); 405 context, url.WithPath(directories.top()));
379 if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND && 406 if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND &&
380 error != base::PLATFORM_FILE_OK) 407 error != base::PLATFORM_FILE_OK)
381 return error; 408 return error;
382 directories.pop(); 409 directories.pop();
383 } 410 }
384 return file_util->DeleteSingleDirectory(context, url); 411 return file_util->DeleteSingleDirectory(context, url);
385 } 412 }
386 413
387 } // namespace fileapi 414 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_util_helper.h ('k') | webkit/fileapi/isolated_file_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698