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

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

Issue 4054003: FileSystem code cleanup 2nd cut - introduce SandboxedFileSystemOperation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 10 years, 1 month 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
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 19 matching lines...) Expand all
30 class FileWriterDelegate; 30 class FileWriterDelegate;
31 31
32 // This class is designed to serve one-time file system operation per instance. 32 // This class is designed to serve one-time file system operation per instance.
33 // Only one method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists, 33 // Only one method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists,
34 // GetMetadata, ReadDirectory and Remove) may be called during the lifetime of 34 // GetMetadata, ReadDirectory and Remove) may be called during the lifetime of
35 // this object and it should be called no more than once. 35 // this object and it should be called no more than once.
36 class FileSystemOperation { 36 class FileSystemOperation {
37 public: 37 public:
38 FileSystemOperation(FileSystemCallbackDispatcher* dispatcher, 38 FileSystemOperation(FileSystemCallbackDispatcher* dispatcher,
39 scoped_refptr<base::MessageLoopProxy> proxy); 39 scoped_refptr<base::MessageLoopProxy> proxy);
40 ~FileSystemOperation(); 40 virtual ~FileSystemOperation();
41 41
42 void CreateFile(const FilePath& path, 42 virtual void CreateFile(const FilePath& path,
43 bool exclusive); 43 bool exclusive);
44 44
45 void CreateDirectory(const FilePath& path, 45 virtual void CreateDirectory(const FilePath& path,
46 bool exclusive, 46 bool exclusive,
47 bool recursive); 47 bool recursive);
48 48
49 void Copy(const FilePath& src_path, 49 virtual void Copy(const FilePath& src_path,
50 const FilePath& dest_path); 50 const FilePath& dest_path);
51 51
52 void Move(const FilePath& src_path, 52 virtual void Move(const FilePath& src_path,
53 const FilePath& dest_path); 53 const FilePath& dest_path);
54 54
55 void DirectoryExists(const FilePath& path); 55 virtual void DirectoryExists(const FilePath& path);
56 56
57 void FileExists(const FilePath& path); 57 virtual void FileExists(const FilePath& path);
58 58
59 void GetMetadata(const FilePath& path); 59 virtual void GetMetadata(const FilePath& path);
60 60
61 void ReadDirectory(const FilePath& path); 61 virtual void ReadDirectory(const FilePath& path);
62 62
63 void Remove(const FilePath& path, bool recursive); 63 virtual void Remove(const FilePath& path, bool recursive);
64 64
65 void Write( 65 virtual void Write(
66 scoped_refptr<URLRequestContext> url_request_context, 66 scoped_refptr<URLRequestContext> url_request_context,
67 const FilePath& path, const GURL& blob_url, int64 offset); 67 const FilePath& path, const GURL& blob_url, int64 offset);
68 68
69 void Truncate(const FilePath& path, int64 length); 69 virtual void Truncate(const FilePath& path, int64 length);
70 70
71 void TouchFile(const FilePath& path, 71 virtual void TouchFile(const FilePath& path,
72 const base::Time& last_access_time, 72 const base::Time& last_access_time,
73 const base::Time& last_modified_time); 73 const base::Time& last_modified_time);
74 74
75 // Try to cancel the current operation [we support cancelling write or 75 // Try to cancel the current operation [we support cancelling write or
76 // truncate only]. Report failure for the current operation, then tell the 76 // truncate only]. Report failure for the current operation, then tell the
77 // passed-in operation to report success. 77 // passed-in operation to report success.
78 void Cancel(FileSystemOperation* cancel_operation); 78 virtual void Cancel(FileSystemOperation* cancel_operation);
79 79
80 protected: 80 protected:
81 // Proxy for calling file_util_proxy methods. 81 #ifndef NDEBUG
82 scoped_refptr<base::MessageLoopProxy> proxy_; 82 enum OperationType {
83 kOperationNone,
84 kOperationCreateFile,
85 kOperationCreateDirectory,
86 kOperationCopy,
87 kOperationMove,
88 kOperationDirectoryExists,
89 kOperationFileExists,
90 kOperationGetMetadata,
91 kOperationReadDirectory,
92 kOperationRemove,
93 kOperationWrite,
94 kOperationTruncate,
95 kOperationTouchFile,
96 kOperationCancel,
97 };
98
99 // A flag to make sure we call operation only once per instance.
100 OperationType pending_operation_;
101 #endif
102
103 FileSystemCallbackDispatcher* dispatcher() const { return dispatcher_.get(); }
83 104
84 private: 105 private:
85 // Callback for CreateFile for |exclusive|=true cases. 106 // Callback for CreateFile for |exclusive|=true cases.
86 void DidEnsureFileExistsExclusive(base::PlatformFileError rv, 107 void DidEnsureFileExistsExclusive(base::PlatformFileError rv,
87 bool created); 108 bool created);
88 109
89 // Callback for CreateFile for |exclusive|=false cases. 110 // Callback for CreateFile for |exclusive|=false cases.
90 void DidEnsureFileExistsNonExclusive(base::PlatformFileError rv, 111 void DidEnsureFileExistsNonExclusive(base::PlatformFileError rv,
91 bool created); 112 bool created);
92 113
(...skipping 19 matching lines...) Expand all
112 bool complete); 133 bool complete);
113 134
114 void DidTouchFile(base::PlatformFileError rv); 135 void DidTouchFile(base::PlatformFileError rv);
115 136
116 // Helper for Write(). 137 // Helper for Write().
117 void OnFileOpenedForWrite( 138 void OnFileOpenedForWrite(
118 base::PlatformFileError rv, 139 base::PlatformFileError rv,
119 base::PassPlatformFile file, 140 base::PassPlatformFile file,
120 bool created); 141 bool created);
121 142
143 // Proxy for calling file_util_proxy methods.
144 scoped_refptr<base::MessageLoopProxy> proxy_;
145
122 scoped_ptr<FileSystemCallbackDispatcher> dispatcher_; 146 scoped_ptr<FileSystemCallbackDispatcher> dispatcher_;
147
123 base::ScopedCallbackFactory<FileSystemOperation> callback_factory_; 148 base::ScopedCallbackFactory<FileSystemOperation> callback_factory_;
124 149
125 // These are all used only by Write(). 150 // These are all used only by Write().
126 friend class FileWriterDelegate; 151 friend class FileWriterDelegate;
127 scoped_ptr<FileWriterDelegate> file_writer_delegate_; 152 scoped_ptr<FileWriterDelegate> file_writer_delegate_;
128 scoped_ptr<URLRequest> blob_request_; 153 scoped_ptr<URLRequest> blob_request_;
129 FileSystemOperation* cancel_operation_; 154 FileSystemOperation* cancel_operation_;
130 155
131 #ifndef NDEBUG
132 enum OperationType {
133 kOperationNone,
134 kOperationCreateFile,
135 kOperationCreateDirectory,
136 kOperationCopy,
137 kOperationMove,
138 kOperationDirectoryExists,
139 kOperationFileExists,
140 kOperationGetMetadata,
141 kOperationReadDirectory,
142 kOperationRemove,
143 kOperationWrite,
144 kOperationTruncate,
145 kOperationTouchFile,
146 kOperationCancel,
147 };
148
149 // A flag to make sure we call operation only once per instance.
150 OperationType pending_operation_;
151 #endif
152
153 DISALLOW_COPY_AND_ASSIGN(FileSystemOperation); 156 DISALLOW_COPY_AND_ASSIGN(FileSystemOperation);
154 }; 157 };
155 158
156 } // namespace fileapi 159 } // namespace fileapi
157 160
158 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ 161 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_
OLDNEW
« no previous file with comments | « chrome/browser/file_system/file_system_dispatcher_host.cc ('k') | webkit/fileapi/sandboxed_file_system_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698