OLD | NEW |
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 15 matching lines...) Expand all Loading... |
26 | 26 |
27 namespace fileapi { | 27 namespace fileapi { |
28 | 28 |
29 class FileSystemCallbackDispatcher; | 29 class FileSystemCallbackDispatcher; |
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 // This class is self-destructed and an instance automatically gets deleted |
| 37 // when its operation is finished. |
36 class FileSystemOperation { | 38 class FileSystemOperation { |
37 public: | 39 public: |
| 40 // |dispatcher| will be owned by this class. |
38 FileSystemOperation(FileSystemCallbackDispatcher* dispatcher, | 41 FileSystemOperation(FileSystemCallbackDispatcher* dispatcher, |
39 scoped_refptr<base::MessageLoopProxy> proxy); | 42 scoped_refptr<base::MessageLoopProxy> proxy); |
40 virtual ~FileSystemOperation(); | 43 virtual ~FileSystemOperation(); |
41 | 44 |
42 virtual void CreateFile(const FilePath& path, | 45 virtual void CreateFile(const FilePath& path, |
43 bool exclusive); | 46 bool exclusive); |
44 | 47 |
45 virtual void CreateDirectory(const FilePath& path, | 48 virtual void CreateDirectory(const FilePath& path, |
46 bool exclusive, | 49 bool exclusive, |
47 bool recursive); | 50 bool recursive); |
48 | 51 |
49 virtual void Copy(const FilePath& src_path, | 52 virtual void Copy(const FilePath& src_path, |
50 const FilePath& dest_path); | 53 const FilePath& dest_path); |
51 | 54 |
52 virtual void Move(const FilePath& src_path, | 55 virtual void Move(const FilePath& src_path, |
53 const FilePath& dest_path); | 56 const FilePath& dest_path); |
54 | 57 |
55 virtual void DirectoryExists(const FilePath& path); | 58 virtual void DirectoryExists(const FilePath& path); |
56 | 59 |
57 virtual void FileExists(const FilePath& path); | 60 virtual void FileExists(const FilePath& path); |
58 | 61 |
59 virtual void GetMetadata(const FilePath& path); | 62 virtual void GetMetadata(const FilePath& path); |
60 | 63 |
61 virtual void ReadDirectory(const FilePath& path); | 64 virtual void ReadDirectory(const FilePath& path); |
62 | 65 |
63 virtual void Remove(const FilePath& path, bool recursive); | 66 virtual void Remove(const FilePath& path, bool recursive); |
64 | 67 |
65 virtual void Write( | 68 virtual void Write(scoped_refptr<URLRequestContext> url_request_context, |
66 scoped_refptr<URLRequestContext> url_request_context, | 69 const FilePath& path, |
67 const FilePath& path, const GURL& blob_url, int64 offset); | 70 const GURL& blob_url, |
| 71 int64 offset); |
68 | 72 |
69 virtual void Truncate(const FilePath& path, int64 length); | 73 virtual void Truncate(const FilePath& path, int64 length); |
70 | 74 |
71 virtual void TouchFile(const FilePath& path, | 75 virtual void TouchFile(const FilePath& path, |
72 const base::Time& last_access_time, | 76 const base::Time& last_access_time, |
73 const base::Time& last_modified_time); | 77 const base::Time& last_modified_time); |
74 | 78 |
75 // Try to cancel the current operation [we support cancelling write or | 79 // Try to cancel the current operation [we support cancelling write or |
76 // truncate only]. Report failure for the current operation, then tell the | 80 // truncate only]. Report failure for the current operation, then tell the |
77 // passed-in operation to report success. | 81 // passed-in operation to report success. |
78 virtual void Cancel(FileSystemOperation* cancel_operation); | 82 virtual void Cancel(FileSystemOperation* cancel_operation); |
79 | 83 |
80 protected: | 84 protected: |
81 #ifndef NDEBUG | 85 #ifndef NDEBUG |
82 enum OperationType { | 86 enum OperationType { |
83 kOperationNone, | 87 kOperationNone, |
84 kOperationCreateFile, | 88 kOperationCreateFile, |
85 kOperationCreateDirectory, | 89 kOperationCreateDirectory, |
86 kOperationCopy, | 90 kOperationCopy, |
87 kOperationMove, | 91 kOperationMove, |
88 kOperationDirectoryExists, | 92 kOperationDirectoryExists, |
89 kOperationFileExists, | 93 kOperationFileExists, |
90 kOperationGetMetadata, | 94 kOperationGetMetadata, |
91 kOperationReadDirectory, | 95 kOperationReadDirectory, |
92 kOperationRemove, | 96 kOperationRemove, |
93 kOperationWrite, | 97 kOperationWrite, |
94 kOperationTruncate, | 98 kOperationTruncate, |
95 kOperationTouchFile, | 99 kOperationTouchFile, |
96 kOperationCancel, | 100 kOperationCancel, |
97 }; | 101 }; |
98 | 102 |
99 // A flag to make sure we call operation only once per instance. | 103 // A flag to make sure we call operation only once per instance. |
100 OperationType pending_operation_; | 104 OperationType pending_operation_; |
101 #endif | 105 #endif |
102 | 106 |
103 FileSystemCallbackDispatcher* dispatcher() const { return dispatcher_.get(); } | 107 // Returns a destructive dispatcher which deletes the operation instance |
| 108 // after any of its callback methods is called (except for DidWrite with |
| 109 // complete=false cases). |
| 110 FileSystemCallbackDispatcher* destructive_dispatcher() const { |
| 111 return destructive_dispatcher_.get(); |
| 112 } |
| 113 |
| 114 // Returns a non-destructive dispatcher. |
| 115 FileSystemCallbackDispatcher* non_destructive_dispatcher() const; |
104 | 116 |
105 private: | 117 private: |
106 // Callback for CreateFile for |exclusive|=true cases. | 118 // Callback for CreateFile for |exclusive|=true cases. |
107 void DidEnsureFileExistsExclusive(base::PlatformFileError rv, | 119 void DidEnsureFileExistsExclusive(base::PlatformFileError rv, |
108 bool created); | 120 bool created); |
109 | 121 |
110 // Callback for CreateFile for |exclusive|=false cases. | 122 // Callback for CreateFile for |exclusive|=false cases. |
111 void DidEnsureFileExistsNonExclusive(base::PlatformFileError rv, | 123 void DidEnsureFileExistsNonExclusive(base::PlatformFileError rv, |
112 bool created); | 124 bool created); |
113 | 125 |
(...skipping 22 matching lines...) Expand all Loading... |
136 | 148 |
137 // Helper for Write(). | 149 // Helper for Write(). |
138 void OnFileOpenedForWrite( | 150 void OnFileOpenedForWrite( |
139 base::PlatformFileError rv, | 151 base::PlatformFileError rv, |
140 base::PassPlatformFile file, | 152 base::PassPlatformFile file, |
141 bool created); | 153 bool created); |
142 | 154 |
143 // Proxy for calling file_util_proxy methods. | 155 // Proxy for calling file_util_proxy methods. |
144 scoped_refptr<base::MessageLoopProxy> proxy_; | 156 scoped_refptr<base::MessageLoopProxy> proxy_; |
145 | 157 |
146 scoped_ptr<FileSystemCallbackDispatcher> dispatcher_; | 158 scoped_ptr<FileSystemCallbackDispatcher> destructive_dispatcher_; |
147 | 159 |
148 base::ScopedCallbackFactory<FileSystemOperation> callback_factory_; | 160 base::ScopedCallbackFactory<FileSystemOperation> callback_factory_; |
149 | 161 |
150 // These are all used only by Write(). | 162 // These are all used only by Write(). |
151 friend class FileWriterDelegate; | 163 friend class FileWriterDelegate; |
152 scoped_ptr<FileWriterDelegate> file_writer_delegate_; | 164 scoped_ptr<FileWriterDelegate> file_writer_delegate_; |
153 scoped_ptr<URLRequest> blob_request_; | 165 scoped_ptr<URLRequest> blob_request_; |
154 FileSystemOperation* cancel_operation_; | 166 FileSystemOperation* cancel_operation_; |
155 | 167 |
156 DISALLOW_COPY_AND_ASSIGN(FileSystemOperation); | 168 DISALLOW_COPY_AND_ASSIGN(FileSystemOperation); |
157 }; | 169 }; |
158 | 170 |
159 } // namespace fileapi | 171 } // namespace fileapi |
160 | 172 |
161 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ | 173 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ |
OLD | NEW |