| 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" |
| 11 #include "base/file_util_proxy.h" | 11 #include "base/file_util_proxy.h" |
| 12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
| 13 #include "base/platform_file.h" | 13 #include "base/platform_file.h" |
| 14 #include "base/ref_counted.h" | 14 #include "base/ref_counted.h" |
| 15 #include "base/scoped_callback_factory.h" | 15 #include "base/scoped_callback_factory.h" |
| 16 #include "base/scoped_ptr.h" | 16 #include "base/scoped_ptr.h" |
| 17 | 17 |
| 18 class GURL; |
| 19 |
| 18 namespace fileapi { | 20 namespace fileapi { |
| 19 | 21 |
| 20 class FileSystemCallbackDispatcher; | 22 class FileSystemCallbackDispatcher; |
| 21 | 23 |
| 22 // This class is designed to serve one-time file system operation per instance. | 24 // This class is designed to serve one-time file system operation per instance. |
| 23 // Only one method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists, | 25 // Only one method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists, |
| 24 // GetMetadata, ReadDirectory and Remove) may be called during the lifetime of | 26 // GetMetadata, ReadDirectory and Remove) may be called during the lifetime of |
| 25 // this object and it should be called no more than once. | 27 // this object and it should be called no more than once. |
| 26 class FileSystemOperation { | 28 class FileSystemOperation { |
| 27 public: | 29 public: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 48 void DirectoryExists(const FilePath& path); | 50 void DirectoryExists(const FilePath& path); |
| 49 | 51 |
| 50 void FileExists(const FilePath& path); | 52 void FileExists(const FilePath& path); |
| 51 | 53 |
| 52 void GetMetadata(const FilePath& path); | 54 void GetMetadata(const FilePath& path); |
| 53 | 55 |
| 54 void ReadDirectory(const FilePath& path); | 56 void ReadDirectory(const FilePath& path); |
| 55 | 57 |
| 56 void Remove(const FilePath& path); | 58 void Remove(const FilePath& path); |
| 57 | 59 |
| 60 void Write( |
| 61 const FilePath& path, const GURL& blob_url, int64 offset); |
| 62 |
| 63 void Truncate(const FilePath& path, int64 length); |
| 64 |
| 65 // Used to attempt to cancel the current operation. This currently does |
| 66 // nothing for any operation other than Write(). |
| 67 void Cancel(); |
| 68 |
| 58 protected: | 69 protected: |
| 59 // Proxy for calling file_util_proxy methods. | 70 // Proxy for calling file_util_proxy methods. |
| 60 scoped_refptr<base::MessageLoopProxy> proxy_; | 71 scoped_refptr<base::MessageLoopProxy> proxy_; |
| 61 | 72 |
| 62 private: | 73 private: |
| 63 // Callbacks for above methods. | 74 // Callbacks for above methods. |
| 64 void DidCreateFileExclusive( | 75 void DidCreateFileExclusive( |
| 65 base::PlatformFileError rv, base::PassPlatformFile file, bool created); | 76 base::PlatformFileError rv, base::PassPlatformFile file, bool created); |
| 66 | 77 |
| 67 // Returns success even if the file already existed. | 78 // Returns success even if the file already existed. |
| 68 void DidCreateFileNonExclusive( | 79 void DidCreateFileNonExclusive( |
| 69 base::PlatformFileError rv, base::PassPlatformFile file, bool created); | 80 base::PlatformFileError rv, base::PassPlatformFile file, bool created); |
| 70 | 81 |
| 71 // Generic callback that translates platform errors to WebKit error codes. | 82 // Generic callback that translates platform errors to WebKit error codes. |
| 72 void DidFinishFileOperation(base::PlatformFileError rv); | 83 void DidFinishFileOperation(base::PlatformFileError rv); |
| 73 | 84 |
| 74 void DidDirectoryExists(base::PlatformFileError rv, | 85 void DidDirectoryExists(base::PlatformFileError rv, |
| 75 const base::PlatformFileInfo& file_info); | 86 const base::PlatformFileInfo& file_info); |
| 76 | 87 |
| 77 void DidFileExists(base::PlatformFileError rv, | 88 void DidFileExists(base::PlatformFileError rv, |
| 78 const base::PlatformFileInfo& file_info); | 89 const base::PlatformFileInfo& file_info); |
| 79 | 90 |
| 80 void DidGetMetadata(base::PlatformFileError rv, | 91 void DidGetMetadata(base::PlatformFileError rv, |
| 81 const base::PlatformFileInfo& file_info); | 92 const base::PlatformFileInfo& file_info); |
| 82 | 93 |
| 83 void DidReadDirectory( | 94 void DidReadDirectory( |
| 84 base::PlatformFileError rv, | 95 base::PlatformFileError rv, |
| 85 const std::vector<base::file_util_proxy::Entry>& entries); | 96 const std::vector<base::file_util_proxy::Entry>& entries); |
| 86 | 97 |
| 98 void DidWrite( |
| 99 base::PlatformFileError rv, |
| 100 int64 bytes, |
| 101 bool complete); |
| 102 |
| 87 scoped_ptr<FileSystemCallbackDispatcher> dispatcher_; | 103 scoped_ptr<FileSystemCallbackDispatcher> dispatcher_; |
| 88 | 104 |
| 89 base::ScopedCallbackFactory<FileSystemOperation> callback_factory_; | 105 base::ScopedCallbackFactory<FileSystemOperation> callback_factory_; |
| 90 | 106 |
| 91 #ifndef NDEBUG | 107 #ifndef NDEBUG |
| 92 // A flag to make sure we call operation only once per instance. | 108 // A flag to make sure we call operation only once per instance. |
| 93 bool operation_pending_; | 109 bool operation_pending_; |
| 94 #endif | 110 #endif |
| 95 | 111 |
| 96 DISALLOW_COPY_AND_ASSIGN(FileSystemOperation); | 112 DISALLOW_COPY_AND_ASSIGN(FileSystemOperation); |
| 97 }; | 113 }; |
| 98 | 114 |
| 99 } // namespace fileapi | 115 } // namespace fileapi |
| 100 | 116 |
| 101 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ | 117 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ |
| OLD | NEW |