summaryrefslogtreecommitdiffstats
path: root/webkit/browser/fileapi/recursive_operation_delegate.h
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-21 08:26:36 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-21 08:26:36 +0000
commit20c2df688030ad6ef485df9a5da4e889b2e477c4 (patch)
tree8a940a5c26090972b058778d8486c6461e842f1f /webkit/browser/fileapi/recursive_operation_delegate.h
parent03393a9a5d76c7009ee996083c727bcdc47c74aa (diff)
downloadchromium_src-20c2df688030ad6ef485df9a5da4e889b2e477c4.zip
chromium_src-20c2df688030ad6ef485df9a5da4e889b2e477c4.tar.gz
chromium_src-20c2df688030ad6ef485df9a5da4e889b2e477c4.tar.bz2
Move browser-specific FileAPI code from webkit/fileapi to webkit/browser/fileapi
This moves following files from webkit/fileapi to webkit/browser/fileapi: - copy_or_move_file_validator* - cross_operation_delegate* - file_system_quota_client* - recursive_operation_delegate* BUG=239710 TBR=tzik@chromium.org Review URL: https://codereview.chromium.org/15535006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201258 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/browser/fileapi/recursive_operation_delegate.h')
-rw-r--r--webkit/browser/fileapi/recursive_operation_delegate.h103
1 files changed, 103 insertions, 0 deletions
diff --git a/webkit/browser/fileapi/recursive_operation_delegate.h b/webkit/browser/fileapi/recursive_operation_delegate.h
new file mode 100644
index 0000000..23e0735
--- /dev/null
+++ b/webkit/browser/fileapi/recursive_operation_delegate.h
@@ -0,0 +1,103 @@
+// Copyright (c) 2013 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.
+
+#ifndef WEBKIT_BROWSER_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_
+#define WEBKIT_BROWSER_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_
+
+#include <queue>
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/memory/weak_ptr.h"
+#include "webkit/fileapi/file_system_operation.h"
+#include "webkit/fileapi/file_system_url.h"
+
+namespace fileapi {
+
+class FileSystemContext;
+
+// A base class for recursive operation delegates.
+// This also provides some convenient default implementations for subclasses
+// like StartRecursiveOperation() and NewNestedOperation().
+//
+// In short, each subclass should override ProcessFile and ProcessDirectory
+// to process a directory or a file. To start the recursive operation it
+// should also call StartRecursiveOperation.
+//
+// Each subclass can call NewNestedOperation to create a new file system
+// operation to perform a sub-operations, e.g. can call RemoveFile for
+// recursive Remove.
+class RecursiveOperationDelegate
+ : public base::SupportsWeakPtr<RecursiveOperationDelegate> {
+ public:
+ typedef FileSystemOperation::StatusCallback StatusCallback;
+ typedef FileSystemOperation::FileEntryList FileEntryList;
+
+ RecursiveOperationDelegate(FileSystemContext* file_system_context,
+ LocalFileSystemOperation* operation);
+ virtual ~RecursiveOperationDelegate();
+
+ // This is called when the consumer of this instance starts a non-recursive
+ // operation.
+ virtual void Run() = 0;
+
+ // This is called when the consumer of this instance starts a recursive
+ // operation.
+ virtual void RunRecursively() = 0;
+
+ // This is called each time a file is found while recursively
+ // performing an operation.
+ virtual void ProcessFile(const FileSystemURL& url,
+ const StatusCallback& callback) = 0;
+
+ // This is called each time a directory is found while recursively
+ // performing an operation.
+ virtual void ProcessDirectory(const FileSystemURL& url,
+ const StatusCallback& callback) = 0;
+
+ protected:
+ // Starts to process files/directories recursively from the given |root|.
+ // This will call ProcessFile and ProcessDirectory on each directory or file.
+ // If the given |root| is a file this simply calls ProcessFile and exits.
+ //
+ // |callback| is fired with base::PLATFORM_FILE_OK when every file/directory
+ // under |root| is processed, or fired earlier when any suboperation fails.
+ void StartRecursiveOperation(const FileSystemURL& root,
+ const StatusCallback& callback);
+
+ // Returns new nested sub-operation.
+ LocalFileSystemOperation* NewNestedOperation();
+
+ FileSystemContext* file_system_context() { return file_system_context_; }
+ const FileSystemContext* file_system_context() const {
+ return file_system_context_;
+ }
+
+ private:
+ void ProcessNextDirectory();
+ void ProcessPendingFiles();
+ void DidProcessFile(base::PlatformFileError error);
+ void DidProcessDirectory(const FileSystemURL& url,
+ base::PlatformFileError error);
+ void DidReadDirectory(
+ const FileSystemURL& parent,
+ base::PlatformFileError error,
+ const FileEntryList& entries,
+ bool has_more);
+ void DidTryProcessFile(base::PlatformFileError previous_error,
+ base::PlatformFileError error);
+
+ FileSystemContext* file_system_context_;
+ LocalFileSystemOperation* operation_;
+ StatusCallback callback_;
+ std::queue<FileSystemURL> pending_directories_;
+ std::queue<FileSystemURL> pending_files_;
+ int inflight_operations_;
+
+ DISALLOW_COPY_AND_ASSIGN(RecursiveOperationDelegate);
+};
+
+} // namespace fileapi
+
+#endif // WEBKIT_BROWSER_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_