| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_FILE_UTIL_PROXY_H_ | 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_ |
| 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_ | 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/file_util_proxy.h" | 12 #include "base/file_util_proxy.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/platform_file.h" | 14 #include "base/platform_file.h" |
| 15 #include "base/tracked_objects.h" | 15 #include "base/tracked_objects.h" |
| 16 | 16 |
| 17 namespace base { | |
| 18 class MessageLoopProxy; | |
| 19 } | |
| 20 | |
| 21 namespace fileapi { | 17 namespace fileapi { |
| 22 | 18 |
| 23 using base::MessageLoopProxy; | |
| 24 using base::PlatformFile; | 19 using base::PlatformFile; |
| 25 using base::PlatformFileError; | 20 using base::PlatformFileError; |
| 26 using base::PlatformFileInfo; | 21 using base::PlatformFileInfo; |
| 27 | 22 |
| 28 class FileSystemFileUtil; | 23 class FileSystemFileUtil; |
| 29 class FileSystemOperationContext; | 24 class FileSystemOperationContext; |
| 30 class FileSystemPath; | 25 class FileSystemPath; |
| 31 | 26 |
| 32 // This class provides asynchronous access to FileSystemFileUtil methods for | 27 // This class provides asynchronous access to FileSystemFileUtil methods for |
| 33 // FileSystem API operations. This also implements cross-FileUtil copy/move | 28 // FileSystem API operations. This also implements cross-FileUtil copy/move |
| 34 // operations on top of FileSystemFileUtil methods. | 29 // operations on top of FileSystemFileUtil methods. |
| 35 class FileSystemFileUtilProxy { | 30 class FileSystemFileUtilProxy { |
| 36 public: | 31 public: |
| 37 // Some of the proxy routines are just wrapping around the FileUtilProxy's | 32 // Some of the proxy routines are just wrapping around the FileUtilProxy's |
| 38 // relay methods, so we use the same types as FileUtilProxy for them. | 33 // relay methods, so we use the same types as FileUtilProxy for them. |
| 39 typedef base::FileUtilProxy::Entry Entry; | 34 typedef base::FileUtilProxy::Entry Entry; |
| 40 typedef base::FileUtilProxy::CreateOrOpenCallback CreateOrOpenCallback; | 35 typedef base::FileUtilProxy::CreateOrOpenCallback CreateOrOpenCallback; |
| 41 | 36 |
| 42 typedef base::Callback<void(PlatformFileError status)> StatusCallback; | 37 typedef base::Callback<void(PlatformFileError status)> StatusCallback; |
| 43 typedef base::Callback<void(PlatformFileError status, | 38 typedef base::Callback<void(PlatformFileError status, |
| 44 bool created)> EnsureFileExistsCallback; | 39 bool created)> EnsureFileExistsCallback; |
| 45 typedef base::Callback<void(PlatformFileError status, | 40 typedef base::Callback<void(PlatformFileError status, |
| 46 const PlatformFileInfo& info, | 41 const PlatformFileInfo& info, |
| 47 const FilePath& platform_path)> | 42 const FilePath& platform_path)> |
| 48 GetFileInfoCallback; | 43 GetFileInfoCallback; |
| 49 typedef base::Callback<void(PlatformFileError, | 44 typedef base::Callback<void(PlatformFileError, |
| 50 const std::vector<Entry>&, | 45 const std::vector<Entry>&, |
| 51 bool has_more)> ReadDirectoryCallback; | 46 bool has_more)> ReadDirectoryCallback; |
| 52 | 47 |
| 53 // Deletes a file or a directory on the given |message_loop_proxy|. | 48 // Deletes a file or a directory on the given context's file_task_runner. |
| 54 // It is an error to delete a non-empty directory with recursive=false. | 49 // It is an error to delete a non-empty directory with recursive=false. |
| 55 static bool Delete( | 50 static bool Delete( |
| 56 MessageLoopProxy* message_loop_proxy, | |
| 57 FileSystemOperationContext* context, | 51 FileSystemOperationContext* context, |
| 58 FileSystemFileUtil* file_util, | 52 FileSystemFileUtil* file_util, |
| 59 const FileSystemPath& path, | 53 const FileSystemPath& path, |
| 60 bool recursive, | 54 bool recursive, |
| 61 const StatusCallback& callback); | 55 const StatusCallback& callback); |
| 62 | 56 |
| 63 // Creates or opens a file with the given flags by calling |file_util|'s | 57 // Creates or opens a file with the given flags by calling |file_util|'s |
| 64 // CreateOrOpen method on the given |message_loop_proxy|. | 58 // CreateOrOpen method on the given context's file_task_runner. |
| 65 static bool CreateOrOpen( | 59 static bool CreateOrOpen( |
| 66 MessageLoopProxy* message_loop_proxy, | |
| 67 FileSystemOperationContext* context, | 60 FileSystemOperationContext* context, |
| 68 FileSystemFileUtil* file_util, | 61 FileSystemFileUtil* file_util, |
| 69 const FileSystemPath& path, | 62 const FileSystemPath& path, |
| 70 int file_flags, | 63 int file_flags, |
| 71 const CreateOrOpenCallback& callback); | 64 const CreateOrOpenCallback& callback); |
| 72 | 65 |
| 73 // Copies a file or a directory from |src_path| to |dest_path| by calling | 66 // Copies a file or a directory from |src_path| to |dest_path| by calling |
| 74 // FileSystemFileUtil's following methods on the given |message_loop_proxy|. | 67 // FileSystemFileUtil's following methods on the given context's |
| 68 // file_task_runner. |
| 75 // - CopyOrMoveFile() for same-filesystem operations | 69 // - CopyOrMoveFile() for same-filesystem operations |
| 76 // - CopyInForeignFile() for (limited) cross-filesystem operations | 70 // - CopyInForeignFile() for (limited) cross-filesystem operations |
| 77 // | 71 // |
| 78 // Error cases: | 72 // Error cases: |
| 79 // If destination's parent doesn't exist. | 73 // If destination's parent doesn't exist. |
| 80 // If source dir exists but destination path is an existing file. | 74 // If source dir exists but destination path is an existing file. |
| 81 // If source file exists but destination path is an existing directory. | 75 // If source file exists but destination path is an existing directory. |
| 82 // If source is a parent of destination. | 76 // If source is a parent of destination. |
| 83 // If source doesn't exist. | 77 // If source doesn't exist. |
| 84 // If source and dest are the same path in the same filesystem. | 78 // If source and dest are the same path in the same filesystem. |
| 85 static bool Copy( | 79 static bool Copy( |
| 86 MessageLoopProxy* message_loop_proxy, | |
| 87 FileSystemOperationContext* context, | 80 FileSystemOperationContext* context, |
| 88 FileSystemFileUtil* src_util, | 81 FileSystemFileUtil* src_util, |
| 89 FileSystemFileUtil* dest_util, | 82 FileSystemFileUtil* dest_util, |
| 90 const FileSystemPath& src_path, | 83 const FileSystemPath& src_path, |
| 91 const FileSystemPath& dest_path, | 84 const FileSystemPath& dest_path, |
| 92 const StatusCallback& callback); | 85 const StatusCallback& callback); |
| 93 | 86 |
| 94 // Moves a file or a directory from |src_path| to |dest_path| by calling | 87 // Moves a file or a directory from |src_path| to |dest_path| by calling |
| 95 // FileSystemFileUtil's following methods on the given |message_loop_proxy|. | 88 // FileSystemFileUtil's following methods on the given context's |
| 89 // file_task_runner. |
| 96 // - CopyOrMoveFile() for same-filesystem operations | 90 // - CopyOrMoveFile() for same-filesystem operations |
| 97 // - CopyInForeignFile() for (limited) cross-filesystem operations | 91 // - CopyInForeignFile() for (limited) cross-filesystem operations |
| 98 // | 92 // |
| 99 // This method returns an error on the same error cases with Copy. | 93 // This method returns an error on the same error cases with Copy. |
| 100 static bool Move( | 94 static bool Move( |
| 101 MessageLoopProxy* message_loop_proxy, | |
| 102 FileSystemOperationContext* context, | 95 FileSystemOperationContext* context, |
| 103 FileSystemFileUtil* src_util, | 96 FileSystemFileUtil* src_util, |
| 104 FileSystemFileUtil* dest_util, | 97 FileSystemFileUtil* dest_util, |
| 105 const FileSystemPath& src_path, | 98 const FileSystemPath& src_path, |
| 106 const FileSystemPath& dest_path, | 99 const FileSystemPath& dest_path, |
| 107 const StatusCallback& callback); | 100 const StatusCallback& callback); |
| 108 | 101 |
| 109 // Ensures that the given |path| exist by calling |file_util|'s | 102 // Ensures that the given |path| exist by calling |file_util|'s |
| 110 // EnsureFileExists method on the given |message_loop_proxy|. | 103 // EnsureFileExists method on the given context's file_task_runner. |
| 111 static bool EnsureFileExists( | 104 static bool EnsureFileExists( |
| 112 MessageLoopProxy* message_loop_proxy, | |
| 113 FileSystemOperationContext* context, | 105 FileSystemOperationContext* context, |
| 114 FileSystemFileUtil* file_util, | 106 FileSystemFileUtil* file_util, |
| 115 const FileSystemPath& path, | 107 const FileSystemPath& path, |
| 116 const EnsureFileExistsCallback& callback); | 108 const EnsureFileExistsCallback& callback); |
| 117 | 109 |
| 118 // Creates directory at a given path by calling |file_util|'s | 110 // Creates directory at a given path by calling |file_util|'s |
| 119 // CreateDirectory method on the given |message_loop_proxy|. | 111 // CreateDirectory method on the given context's file_task_runner. |
| 120 static bool CreateDirectory( | 112 static bool CreateDirectory( |
| 121 MessageLoopProxy* message_loop_proxy, | |
| 122 FileSystemOperationContext* context, | 113 FileSystemOperationContext* context, |
| 123 FileSystemFileUtil* file_util, | 114 FileSystemFileUtil* file_util, |
| 124 const FileSystemPath& path, | 115 const FileSystemPath& path, |
| 125 bool exclusive, | 116 bool exclusive, |
| 126 bool recursive, | 117 bool recursive, |
| 127 const StatusCallback& callback); | 118 const StatusCallback& callback); |
| 128 | 119 |
| 129 // Retrieves the information about a file by calling |file_util|'s | 120 // Retrieves the information about a file by calling |file_util|'s |
| 130 // GetFileInfo method on the given |message_loop_proxy|. | 121 // GetFileInfo method on the given context's file_task_runner. |
| 131 static bool GetFileInfo( | 122 static bool GetFileInfo( |
| 132 MessageLoopProxy* message_loop_proxy, | |
| 133 FileSystemOperationContext* context, | 123 FileSystemOperationContext* context, |
| 134 FileSystemFileUtil* file_util, | 124 FileSystemFileUtil* file_util, |
| 135 const FileSystemPath& path, | 125 const FileSystemPath& path, |
| 136 const GetFileInfoCallback& callback); | 126 const GetFileInfoCallback& callback); |
| 137 | 127 |
| 138 // Reads the filenames in |path| by calling |file_util|'s | 128 // Reads the filenames in |path| by calling |file_util|'s |
| 139 // ReadDirectory method on the given |message_loop_proxy|. | 129 // ReadDirectory method on the given context's file_task_runner. |
| 140 // TODO: this should support returning entries in multiple chunks. | 130 // TODO: this should support returning entries in multiple chunks. |
| 141 static bool ReadDirectory( | 131 static bool ReadDirectory( |
| 142 MessageLoopProxy* message_loop_proxy, | |
| 143 FileSystemOperationContext* context, | 132 FileSystemOperationContext* context, |
| 144 FileSystemFileUtil* file_util, | 133 FileSystemFileUtil* file_util, |
| 145 const FileSystemPath& path, | 134 const FileSystemPath& path, |
| 146 const ReadDirectoryCallback& callback); | 135 const ReadDirectoryCallback& callback); |
| 147 | 136 |
| 148 // Touches a file by calling |file_util|'s Touch method | 137 // Touches a file by calling |file_util|'s Touch method |
| 149 // on the given |message_loop_proxy|. | 138 // on the given context's file_task_runner. |
| 150 static bool Touch( | 139 static bool Touch( |
| 151 MessageLoopProxy* message_loop_proxy, | |
| 152 FileSystemOperationContext* context, | 140 FileSystemOperationContext* context, |
| 153 FileSystemFileUtil* file_util, | 141 FileSystemFileUtil* file_util, |
| 154 const FileSystemPath& path, | 142 const FileSystemPath& path, |
| 155 const base::Time& last_access_time, | 143 const base::Time& last_access_time, |
| 156 const base::Time& last_modified_time, | 144 const base::Time& last_modified_time, |
| 157 const StatusCallback& callback); | 145 const StatusCallback& callback); |
| 158 | 146 |
| 159 // Truncates a file to the given length by calling |file_util|'s | 147 // Truncates a file to the given length by calling |file_util|'s |
| 160 // Truncate method on the given |message_loop_proxy|. | 148 // Truncate method on the given context's file_task_runner. |
| 161 static bool Truncate( | 149 static bool Truncate( |
| 162 MessageLoopProxy* message_loop_proxy, | |
| 163 FileSystemOperationContext* context, | 150 FileSystemOperationContext* context, |
| 164 FileSystemFileUtil* file_util, | 151 FileSystemFileUtil* file_util, |
| 165 const FileSystemPath& path, | 152 const FileSystemPath& path, |
| 166 int64 length, | 153 int64 length, |
| 167 const StatusCallback& callback); | 154 const StatusCallback& callback); |
| 168 | 155 |
| 169 private: | 156 private: |
| 170 DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystemFileUtilProxy); | 157 DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystemFileUtilProxy); |
| 171 }; | 158 }; |
| 172 | 159 |
| 173 } // namespace fileapi | 160 } // namespace fileapi |
| 174 | 161 |
| 175 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_ | 162 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_ |
| OLD | NEW |