| 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_FILE_UTIL_H_ | 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ |
| 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ | 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/file_util_proxy.h" | 11 #include "base/file_util_proxy.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/singleton.h" | |
| 14 #include "base/platform_file.h" | 13 #include "base/platform_file.h" |
| 15 #include "base/tracked_objects.h" | 14 #include "base/tracked_objects.h" |
| 16 #include "webkit/fileapi/file_system_types.h" | 15 #include "webkit/fileapi/file_system_types.h" |
| 17 | 16 |
| 18 namespace base { | 17 namespace base { |
| 19 struct PlatformFileInfo; | 18 struct PlatformFileInfo; |
| 20 class MessageLoopProxy; | 19 class MessageLoopProxy; |
| 21 class Time; | 20 class Time; |
| 22 } | 21 } |
| 23 | 22 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 40 // DeleteSingleDirectory, Touch, Truncate, PathExists, DirectoryExists, | 39 // DeleteSingleDirectory, Touch, Truncate, PathExists, DirectoryExists, |
| 41 // IsDirectoryEmpty and CreateFileEnumerator. | 40 // IsDirectoryEmpty and CreateFileEnumerator. |
| 42 // | 41 // |
| 43 // The methods below (*2) assume the given paths may not be native ones for the | 42 // The methods below (*2) assume the given paths may not be native ones for the |
| 44 // host platform. The subclasses should not override them. They provide basic | 43 // host platform. The subclasses should not override them. They provide basic |
| 45 // meta logic by using other virtual methods. | 44 // meta logic by using other virtual methods. |
| 46 // (*2) All non-virtual methods: Copy, Move, Delete, DeleteDirectoryRecursive, | 45 // (*2) All non-virtual methods: Copy, Move, Delete, DeleteDirectoryRecursive, |
| 47 // PerformCommonCheckAndPreparationForMoveAndCopy and CopyOrMoveDirectory. | 46 // PerformCommonCheckAndPreparationForMoveAndCopy and CopyOrMoveDirectory. |
| 48 class FileSystemFileUtil { | 47 class FileSystemFileUtil { |
| 49 public: | 48 public: |
| 50 static FileSystemFileUtil* GetInstance(); | 49 FileSystemFileUtil() {} |
| 50 virtual ~FileSystemFileUtil() {} |
| 51 | 51 |
| 52 // Creates or opens a file with the given flags. It is invalid to pass NULL | 52 // Creates or opens a file with the given flags. It is invalid to pass NULL |
| 53 // for the callback. | 53 // for the callback. |
| 54 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create | 54 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create |
| 55 // a new file at the given |file_path| and calls back with | 55 // a new file at the given |file_path| and calls back with |
| 56 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists. | 56 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists. |
| 57 virtual PlatformFileError CreateOrOpen( | 57 virtual PlatformFileError CreateOrOpen( |
| 58 FileSystemOperationContext* context, | 58 FileSystemOperationContext* context, |
| 59 const FilePath& file_path, | 59 const FilePath& file_path, |
| 60 int file_flags, | 60 int file_flags, |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 232 |
| 233 // Returns a pointer to a new instance of AbstractFileEnumerator which is | 233 // Returns a pointer to a new instance of AbstractFileEnumerator which is |
| 234 // implemented for each FileUtil subclass. The instance needs to be freed | 234 // implemented for each FileUtil subclass. The instance needs to be freed |
| 235 // by the caller, and its lifetime should not extend past when the current | 235 // by the caller, and its lifetime should not extend past when the current |
| 236 // call returns to the main FILE message loop. | 236 // call returns to the main FILE message loop. |
| 237 virtual AbstractFileEnumerator* CreateFileEnumerator( | 237 virtual AbstractFileEnumerator* CreateFileEnumerator( |
| 238 FileSystemOperationContext* unused, | 238 FileSystemOperationContext* unused, |
| 239 const FilePath& root_path); | 239 const FilePath& root_path); |
| 240 | 240 |
| 241 protected: | 241 protected: |
| 242 FileSystemFileUtil() { } | |
| 243 virtual ~FileSystemFileUtil() { } | |
| 244 | |
| 245 // Deletes a directory and all entries under the directory. | 242 // Deletes a directory and all entries under the directory. |
| 246 // | 243 // |
| 247 // This method is called from Delete. It internally calls two following | 244 // This method is called from Delete. It internally calls two following |
| 248 // virtual methods, | 245 // virtual methods, |
| 249 // - (virtual) DeleteFile to delete files, and | 246 // - (virtual) DeleteFile to delete files, and |
| 250 // - (virtual) DeleteSingleDirectory to delete empty directories after all | 247 // - (virtual) DeleteSingleDirectory to delete empty directories after all |
| 251 // the files are deleted. | 248 // the files are deleted. |
| 252 PlatformFileError DeleteDirectoryRecursive( | 249 PlatformFileError DeleteDirectoryRecursive( |
| 253 FileSystemOperationContext* context, | 250 FileSystemOperationContext* context, |
| 254 const FilePath& file_path); | 251 const FilePath& file_path); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 274 // Determines whether a simple same-filesystem move or copy can be done. If | 271 // Determines whether a simple same-filesystem move or copy can be done. If |
| 275 // so, it delegates to CopyOrMoveFile. Otherwise it looks up the true | 272 // so, it delegates to CopyOrMoveFile. Otherwise it looks up the true |
| 276 // platform path of the source file, delegates to CopyInForeignFile, and [for | 273 // platform path of the source file, delegates to CopyInForeignFile, and [for |
| 277 // move] calls DeleteFile on the source file. | 274 // move] calls DeleteFile on the source file. |
| 278 PlatformFileError CopyOrMoveFileHelper( | 275 PlatformFileError CopyOrMoveFileHelper( |
| 279 FileSystemOperationContext* context, | 276 FileSystemOperationContext* context, |
| 280 const FilePath& src_file_path, | 277 const FilePath& src_file_path, |
| 281 const FilePath& dest_file_path, | 278 const FilePath& dest_file_path, |
| 282 bool copy); | 279 bool copy); |
| 283 | 280 |
| 284 friend struct DefaultSingletonTraits<FileSystemFileUtil>; | |
| 285 DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtil); | 281 DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtil); |
| 286 }; | 282 }; |
| 287 | 283 |
| 288 } // namespace fileapi | 284 } // namespace fileapi |
| 289 | 285 |
| 290 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ | 286 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ |
| OLD | NEW |