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

Unified Diff: webkit/fileapi/file_util_helper.cc

Issue 9564047: Add FileUtileHelper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: s/DeletePath/Delete/g Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/fileapi/file_util_helper.h ('k') | webkit/fileapi/obfuscated_file_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/fileapi/file_util_helper.cc
diff --git a/webkit/fileapi/file_util_helper.cc b/webkit/fileapi/file_util_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..46163ea6559788049120e563d37fb60703adee1c
--- /dev/null
+++ b/webkit/fileapi/file_util_helper.cc
@@ -0,0 +1,62 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/fileapi/file_util_helper.h"
+
+#include "webkit/fileapi/file_system_file_util.h"
+#include "webkit/fileapi/file_system_operation_context.h"
+#include "webkit/fileapi/file_system_path.h"
+
+using base::PlatformFileError;
+
+namespace fileapi {
+
+base::PlatformFileError FileUtilHelper::Delete(
+ FileSystemOperationContext* context,
+ FileSystemFileUtil* file_util,
+ const FileSystemPath& path,
+ bool recursive) {
+ if (file_util->DirectoryExists(context, path)) {
+ if (!recursive)
+ return file_util->DeleteSingleDirectory(context, path);
+ else
+ return DeleteDirectoryRecursive(context, file_util, path);
+ } else {
+ return file_util->DeleteFile(context, path);
+ }
+}
+
+base::PlatformFileError FileUtilHelper::DeleteDirectoryRecursive(
+ FileSystemOperationContext* context,
+ FileSystemFileUtil* file_util,
+ const FileSystemPath& path) {
+
+ scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum(
+ file_util->CreateFileEnumerator(context, path));
+ FilePath file_path_each;
+ std::stack<FilePath> directories;
+ while (!(file_path_each = file_enum->Next()).empty()) {
+ if (file_enum->IsDirectory()) {
+ directories.push(file_path_each);
+ } else {
+ PlatformFileError error = file_util->DeleteFile(
+ context, path.WithInternalPath(file_path_each));
+ if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND &&
+ error != base::PLATFORM_FILE_OK)
+ return error;
+ }
+ }
+
+ while (!directories.empty()) {
+ PlatformFileError error = file_util->DeleteSingleDirectory(
+ context, path.WithInternalPath(directories.top()));
+ if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND &&
+ error != base::PLATFORM_FILE_OK)
+ return error;
+ directories.pop();
+ }
+ return file_util->DeleteSingleDirectory(context, path);
+}
+
+} // namespace fileapi
« no previous file with comments | « webkit/fileapi/file_util_helper.h ('k') | webkit/fileapi/obfuscated_file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698