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

Unified Diff: webkit/fileapi/file_util_delete_helper.cc

Issue 9564047: Add FileUtileHelper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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_delete_helper.h ('k') | webkit/fileapi/webkit_fileapi.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/fileapi/file_util_delete_helper.cc
diff --git a/webkit/fileapi/file_util_delete_helper.cc b/webkit/fileapi/file_util_delete_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0750146ff871a0f42ebe73018801bbb88ca702e6
--- /dev/null
+++ b/webkit/fileapi/file_util_delete_helper.cc
@@ -0,0 +1,68 @@
+// 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_delete_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 {
+
+FileUtilDeleteHelper::FileUtilDeleteHelper(
+ FileSystemOperationContext* context,
+ FileSystemFileUtil* file_util)
+ : context_(context),
+ file_util_(file_util) {
+}
+
+FileUtilDeleteHelper::~FileUtilDeleteHelper() {
+}
+
+base::PlatformFileError FileUtilDeleteHelper::DoWork(const FileSystemPath& path,
+ bool recursive) {
+ if (file_util_->DirectoryExists(context_, path)) {
+ if (!recursive)
+ return file_util_->DeleteSingleDirectory(context_, path);
+ else
+ return DeleteDirectoryRecursive(path);
+ } else {
+ return file_util_->DeleteFile(context_, path);
+ }
+}
+
+PlatformFileError FileUtilDeleteHelper::DeleteDirectoryRecursive(
+ 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)
+ return base::PLATFORM_FILE_ERROR_FAILED;
kinuko 2012/03/02 05:25:16 It makes me wonder we should just let it go here..
tzik 2012/03/02 19:09:09 Seems right. No test require it.
+ else if (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)
+ return base::PLATFORM_FILE_ERROR_FAILED;
+ else if (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_delete_helper.h ('k') | webkit/fileapi/webkit_fileapi.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698