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