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

Side by Side Diff: webkit/fileapi/recursive_operation_delegate.h

Issue 12051010: (For-try) Divide recursive Copy/Move into multiple async tasks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test fix Created 7 years, 11 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
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef WEBKIT_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_
6 #define WEBKIT_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_
7
8 #include <queue>
9
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/weak_ptr.h"
13 #include "webkit/fileapi/file_system_operation.h"
14 #include "webkit/fileapi/file_system_url.h"
15
16 namespace fileapi {
17
18 class FileSystemContext;
19 class LocalFileSystemOperation;
20
21 // A base class for recursive operation delegates.
22 // This also provides some convenient default implementations for subclasses
23 // like StartRecursiveOperation() and NewOperation().
24 //
25 // In short, each subclass should override ProcessFile and ProcessDirectory
26 // to process a directory or a file. To start the recursive operation it
27 // should also call StartRecursiveOperation.
28 //
29 // Each subclass can call NewOperation to create a new file system operation
30 // to perform a sub-operations, e.g. can call RemoveFile for recursive Remove.
31 class RecursiveOperationDelegate
32 : public base::SupportsWeakPtr<RecursiveOperationDelegate> {
33 public:
34 typedef FileSystemOperation::StatusCallback StatusCallback;
35 typedef FileSystemOperation::FileEntryList FileEntryList;
36
37 RecursiveOperationDelegate(LocalFileSystemOperation* original_operation);
38 virtual ~RecursiveOperationDelegate();
39
40 // This is called when the consumer of this instance starts a non-recursive
41 // operation.
42 virtual void Run() = 0;
43
44 // This is called when the consumer of this instance starts a recursive
45 // operation.
46 virtual void RunRecursively() = 0;
47
48 // This is called each time a file is found while recursively
49 // performing an operation.
50 virtual void ProcessFile(const FileSystemURL& url,
51 const StatusCallback& callback) = 0;
52
53 // This is called each time a directory is found while recursively
54 // performing an operation.
55 virtual void ProcessDirectory(const FileSystemURL& url,
56 const StatusCallback& callback) = 0;
57
58 protected:
59 // Starts to process files/directories recursively from the given |root|.
60 // This will call ProcessFile and ProcessDirectory on each directory or file.
61 // If the given |root| is a file this simply calls ProcessFile and exits.
62 //
63 // |callback| is fired with base::PLATFORM_FILE_OK when every file/directory
64 // under |root| is processed, or fired earlier when any suboperation fails.
65 void StartRecursiveOperation(const FileSystemURL& root,
66 const StatusCallback& callback);
67
68 // Returns new sub-operation for a given |url|.
69 // This may return NULL if any error has happened.
70 // If non-null |error| is given it is set to the error code.
71 LocalFileSystemOperation* NewOperation(const FileSystemURL& url,
72 base::PlatformFileError* error);
73
74 FileSystemContext* file_system_context();
75
76 private:
77 void ProcessNextDirectory(base::PlatformFileError error);
78 void DidProcessFile(base::PlatformFileError error);
79 void DidProcessDirectory(const FileSystemURL& url,
80 base::PlatformFileError error);
81 void DidReadDirectory(
82 const FileSystemURL& parent,
83 base::PlatformFileError error,
84 const FileEntryList& entries,
85 bool has_more);
86 void DidTryProcessFile(base::PlatformFileError previous_error,
87 base::PlatformFileError error);
88
89 LocalFileSystemOperation* original_operation_;
90 StatusCallback callback_;
91 std::queue<FileSystemURL> pending_directories_;
92 int inflight_operations_;
93
94 DISALLOW_COPY_AND_ASSIGN(RecursiveOperationDelegate);
95 };
96
97 } // namespace fileapi
98
99 #endif // WEBKIT_FILEAPI_RECURSIVE_OPERATION_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698