| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| 11 #include "base/file_util_proxy.h" | 11 #include "base/file_util_proxy.h" |
| 12 #include "base/gtest_prod_util.h" |
| 12 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
| 13 #include "base/platform_file.h" | 14 #include "base/platform_file.h" |
| 14 #include "base/ref_counted.h" | 15 #include "base/ref_counted.h" |
| 15 #include "base/scoped_callback_factory.h" | 16 #include "base/scoped_callback_factory.h" |
| 16 #include "base/scoped_ptr.h" | 17 #include "base/scoped_ptr.h" |
| 17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 18 #include "webkit/fileapi/file_system_types.h" | 19 #include "webkit/fileapi/file_system_types.h" |
| 19 #include "webkit/fileapi/file_system_operation_context.h" | 20 #include "webkit/fileapi/file_system_operation_context.h" |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 22 class Time; | 23 class Time; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace net { | 26 namespace net { |
| 26 class URLRequest; | 27 class URLRequest; |
| 27 class URLRequestContext; | 28 class URLRequestContext; |
| 28 } // namespace net | 29 } // namespace net |
| 29 | 30 |
| 30 class GURL; | 31 class GURL; |
| 31 | 32 |
| 32 namespace fileapi { | 33 namespace fileapi { |
| 33 | 34 |
| 34 class FileSystemCallbackDispatcher; | 35 class FileSystemCallbackDispatcher; |
| 35 class FileSystemContext; | 36 class FileSystemContext; |
| 36 class FileWriterDelegate; | 37 class FileWriterDelegate; |
| 38 class FileSystemOperationTest; |
| 37 | 39 |
| 38 // This class is designed to serve one-time file system operation per instance. | 40 // This class is designed to serve one-time file system operation per instance. |
| 39 // Only one method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists, | 41 // Only one method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists, |
| 40 // GetMetadata, ReadDirectory and Remove) may be called during the lifetime of | 42 // GetMetadata, ReadDirectory and Remove) may be called during the lifetime of |
| 41 // this object and it should be called no more than once. | 43 // this object and it should be called no more than once. |
| 42 // This class is self-destructed and an instance automatically gets deleted | 44 // This class is self-destructed and an instance automatically gets deleted |
| 43 // when its operation is finished. | 45 // when its operation is finished. |
| 44 class FileSystemOperation { | 46 class FileSystemOperation { |
| 45 public: | 47 public: |
| 46 // |dispatcher| will be owned by this class. | 48 // |dispatcher| will be owned by this class. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 74 void TouchFile(const FilePath& path, | 76 void TouchFile(const FilePath& path, |
| 75 const base::Time& last_access_time, | 77 const base::Time& last_access_time, |
| 76 const base::Time& last_modified_time); | 78 const base::Time& last_modified_time); |
| 77 | 79 |
| 78 // Try to cancel the current operation [we support cancelling write or | 80 // Try to cancel the current operation [we support cancelling write or |
| 79 // truncate only]. Report failure for the current operation, then tell the | 81 // truncate only]. Report failure for the current operation, then tell the |
| 80 // passed-in operation to report success. | 82 // passed-in operation to report success. |
| 81 void Cancel(FileSystemOperation* cancel_operation); | 83 void Cancel(FileSystemOperation* cancel_operation); |
| 82 | 84 |
| 83 private: | 85 private: |
| 86 FileSystemContext* file_system_context() const { |
| 87 return file_system_operation_context_.file_system_context(); |
| 88 } |
| 89 |
| 90 FileSystemOperationContext* file_system_operation_context() { |
| 91 return &file_system_operation_context_; |
| 92 } |
| 93 friend class FileSystemOperationTest; |
| 94 |
| 84 // A callback used for OpenFileSystem. | 95 // A callback used for OpenFileSystem. |
| 85 void DidGetRootPath(bool success, | 96 void DidGetRootPath(bool success, |
| 86 const FilePath& path, | 97 const FilePath& path, |
| 87 const std::string& name); | 98 const std::string& name); |
| 88 | 99 |
| 89 // Callback for CreateFile for |exclusive|=true cases. | 100 // Callback for CreateFile for |exclusive|=true cases. |
| 90 void DidEnsureFileExistsExclusive(base::PlatformFileError rv, | 101 void DidEnsureFileExistsExclusive(base::PlatformFileError rv, |
| 91 bool created); | 102 bool created); |
| 92 | 103 |
| 93 // Callback for CreateFile for |exclusive|=false cases. | 104 // Callback for CreateFile for |exclusive|=false cases. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 111 int64 bytes, | 122 int64 bytes, |
| 112 bool complete); | 123 bool complete); |
| 113 void DidTouchFile(base::PlatformFileError rv); | 124 void DidTouchFile(base::PlatformFileError rv); |
| 114 | 125 |
| 115 // Helper for Write(). | 126 // Helper for Write(). |
| 116 void OnFileOpenedForWrite( | 127 void OnFileOpenedForWrite( |
| 117 base::PlatformFileError rv, | 128 base::PlatformFileError rv, |
| 118 base::PassPlatformFile file, | 129 base::PassPlatformFile file, |
| 119 bool created); | 130 bool created); |
| 120 | 131 |
| 121 // Checks the validity of a given |path| for reading. | 132 // Checks the validity of a given |path| for reading, and cracks the path into |
| 133 // root URL and virtual path components. |
| 122 // Returns true if the given |path| is a valid FileSystem path. | 134 // Returns true if the given |path| is a valid FileSystem path. |
| 123 // Otherwise it calls dispatcher's DidFail method with | 135 // Otherwise it calls dispatcher's DidFail method with |
| 124 // PLATFORM_FILE_ERROR_SECURITY and returns false. | 136 // PLATFORM_FILE_ERROR_SECURITY and returns false. |
| 125 // (Note: this doesn't delete this when it calls DidFail and returns false; | 137 // (Note: this doesn't delete this when it calls DidFail and returns false; |
| 126 // it's the caller's responsibility.) | 138 // it's the caller's responsibility.) |
| 127 bool VerifyFileSystemPathForRead(const FilePath& path); | 139 bool VerifyFileSystemPathForRead(const FilePath& path, |
| 140 GURL* root_url, |
| 141 FileSystemType* type, |
| 142 FilePath* virtual_path); |
| 128 | 143 |
| 129 // Checks the validity of a given |path| for writing. | 144 // Checks the validity of a given |path| for writing, and cracks the path into |
| 145 // root URL and virtual path components. |
| 130 // Returns true if the given |path| is a valid FileSystem path, and | 146 // Returns true if the given |path| is a valid FileSystem path, and |
| 131 // its origin embedded in the path has the right to write. | 147 // its origin embedded in the path has the right to write. |
| 132 // Otherwise it fires dispatcher's DidFail method with | 148 // Otherwise it fires dispatcher's DidFail method with |
| 133 // PLATFORM_FILE_ERROR_SECURITY if the path is not valid for writing, | 149 // PLATFORM_FILE_ERROR_SECURITY if the path is not valid for writing, |
| 134 // or with PLATFORM_FILE_ERROR_NO_SPACE if the origin is not allowed to | 150 // or with PLATFORM_FILE_ERROR_NO_SPACE if the origin is not allowed to |
| 135 // write to the storage. | 151 // write to the storage. |
| 136 // In either case it returns false after firing DidFail. | 152 // In either case it returns false after firing DidFail. |
| 137 // If |create| flag is true this also checks if the |path| contains | 153 // If |create| flag is true this also checks if the |path| contains |
| 138 // any restricted names and chars. If it does, the call fires dispatcher's | 154 // any restricted names and chars. If it does, the call fires dispatcher's |
| 139 // DidFail with PLATFORM_FILE_ERROR_SECURITY and returns false. | 155 // DidFail with PLATFORM_FILE_ERROR_SECURITY and returns false. |
| 140 // (Note: this doesn't delete this when it calls DidFail and returns false; | 156 // (Note: this doesn't delete this when it calls DidFail and returns false; |
| 141 // it's the caller's responsibility.) | 157 // it's the caller's responsibility.) |
| 142 bool VerifyFileSystemPathForWrite(const FilePath& path, | 158 bool VerifyFileSystemPathForWrite(const FilePath& path, |
| 143 bool create); | 159 bool create, |
| 160 GURL* root_url, |
| 161 FileSystemType* type, |
| 162 FilePath* virtual_path); |
| 144 | 163 |
| 145 #ifndef NDEBUG | 164 #ifndef NDEBUG |
| 146 enum OperationType { | 165 enum OperationType { |
| 147 kOperationNone, | 166 kOperationNone, |
| 148 kOperationOpenFileSystem, | 167 kOperationOpenFileSystem, |
| 149 kOperationCreateFile, | 168 kOperationCreateFile, |
| 150 kOperationCreateDirectory, | 169 kOperationCreateDirectory, |
| 151 kOperationCopy, | 170 kOperationCopy, |
| 152 kOperationMove, | 171 kOperationMove, |
| 153 kOperationDirectoryExists, | 172 kOperationDirectoryExists, |
| 154 kOperationFileExists, | 173 kOperationFileExists, |
| 155 kOperationGetMetadata, | 174 kOperationGetMetadata, |
| 156 kOperationReadDirectory, | 175 kOperationReadDirectory, |
| 157 kOperationRemove, | 176 kOperationRemove, |
| 158 kOperationWrite, | 177 kOperationWrite, |
| 159 kOperationTruncate, | 178 kOperationTruncate, |
| 160 kOperationTouchFile, | 179 kOperationTouchFile, |
| 161 kOperationCancel, | 180 kOperationCancel, |
| 162 }; | 181 }; |
| 163 | 182 |
| 164 // A flag to make sure we call operation only once per instance. | 183 // A flag to make sure we call operation only once per instance. |
| 165 OperationType pending_operation_; | 184 OperationType pending_operation_; |
| 166 #endif | 185 #endif |
| 167 | 186 |
| 168 // Proxy for calling file_util_proxy methods. | 187 // Proxy for calling file_util_proxy methods. |
| 169 scoped_refptr<base::MessageLoopProxy> proxy_; | 188 scoped_refptr<base::MessageLoopProxy> proxy_; |
| 170 | 189 |
| 171 scoped_ptr<FileSystemCallbackDispatcher> dispatcher_; | 190 scoped_ptr<FileSystemCallbackDispatcher> dispatcher_; |
| 172 | 191 |
| 173 scoped_refptr<FileSystemContext> file_system_context_; | |
| 174 FileSystemOperationContext file_system_operation_context_; | 192 FileSystemOperationContext file_system_operation_context_; |
| 175 | 193 |
| 176 base::ScopedCallbackFactory<FileSystemOperation> callback_factory_; | 194 base::ScopedCallbackFactory<FileSystemOperation> callback_factory_; |
| 177 | 195 |
| 178 // These are all used only by Write(). | 196 // These are all used only by Write(). |
| 179 friend class FileWriterDelegate; | 197 friend class FileWriterDelegate; |
| 180 scoped_ptr<FileWriterDelegate> file_writer_delegate_; | 198 scoped_ptr<FileWriterDelegate> file_writer_delegate_; |
| 181 scoped_ptr<net::URLRequest> blob_request_; | 199 scoped_ptr<net::URLRequest> blob_request_; |
| 182 scoped_ptr<FileSystemOperation> cancel_operation_; | 200 scoped_ptr<FileSystemOperation> cancel_operation_; |
| 183 | 201 |
| 184 DISALLOW_COPY_AND_ASSIGN(FileSystemOperation); | 202 DISALLOW_COPY_AND_ASSIGN(FileSystemOperation); |
| 185 }; | 203 }; |
| 186 | 204 |
| 187 } // namespace fileapi | 205 } // namespace fileapi |
| 188 | 206 |
| 189 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ | 207 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ |
| OLD | NEW |