Chromium Code Reviews| 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 BASE_FILE_SYSTEM_PROXY_H_ | 5 #ifndef BASE_FILE_UTIL_PROXY_H_ |
| 6 #define BASE_FILE_SYSTEM_PROXY_H_ | 6 #define BASE_FILE_UTIL_PROXY_H_ |
| 7 | |
| 8 #include <vector> | |
| 7 | 9 |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/file_path.h" | |
| 12 #include "base/file_util.h" | |
| 9 #include "base/platform_file.h" | 13 #include "base/platform_file.h" |
| 10 #include "base/ref_counted.h" | 14 #include "base/ref_counted.h" |
| 11 #include "base/tracked_objects.h" | 15 #include "base/tracked_objects.h" |
| 12 | 16 |
| 13 namespace file_util { | 17 namespace file_util { |
| 14 struct FileInfo; | 18 struct FileInfo; |
| 15 } | 19 } |
| 16 | 20 |
| 17 namespace base { | 21 namespace base { |
| 18 | 22 |
| 23 namespace file_util_proxy { | |
|
darin (slow to review)
2010/11/01 17:28:38
introducing the file_util_proxy namespace like thi
Kavita Kanetkar
2010/11/01 19:00:30
Sending a follow-up CL to move this within the Fil
| |
| 24 // Holds metadata for file or directory entry. | |
| 25 struct Entry { | |
| 26 FilePath::StringType name; | |
| 27 bool isDirectory; | |
| 28 }; | |
| 29 } // namespace file_util_proxy | |
| 30 | |
| 19 class MessageLoopProxy; | 31 class MessageLoopProxy; |
| 20 | 32 |
| 21 // This class provides asynchronous access to common file routines. | 33 // This class provides asynchronous access to common file routines. |
| 22 class FileUtilProxy { | 34 class FileUtilProxy { |
| 23 public: | 35 public: |
| 24 // This callback is used by methods that report only an error code. It is | 36 // This callback is used by methods that report only an error code. It is |
| 25 // valid to pass NULL as the callback parameter to any function that takes a | 37 // valid to pass NULL as the callback parameter to any function that takes a |
| 26 // StatusCallback, in which case the operation will complete silently. | 38 // StatusCallback, in which case the operation will complete silently. |
| 27 typedef Callback1<base::PlatformFileError /* error code */ | 39 typedef Callback1<base::PlatformFileError /* error code */ |
| 28 >::Type StatusCallback; | 40 >::Type StatusCallback; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 44 FilePath>::Type CreateTemporaryCallback; | 56 FilePath>::Type CreateTemporaryCallback; |
| 45 static bool CreateTemporary( | 57 static bool CreateTemporary( |
| 46 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 58 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 47 CreateTemporaryCallback* callback); | 59 CreateTemporaryCallback* callback); |
| 48 | 60 |
| 49 // Close the given file handle. | 61 // Close the given file handle. |
| 50 static bool Close(scoped_refptr<MessageLoopProxy> message_loop_proxy, | 62 static bool Close(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 51 base::PlatformFile, | 63 base::PlatformFile, |
| 52 StatusCallback* callback); | 64 StatusCallback* callback); |
| 53 | 65 |
| 54 // Deletes a file or empty directory. | |
| 55 static bool Delete(scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 56 const FilePath& file_path, | |
| 57 StatusCallback* callback); | |
| 58 | |
| 59 // Deletes a directory and all of its contents. | |
| 60 static bool RecursiveDelete( | |
| 61 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 62 const FilePath& file_path, | |
| 63 StatusCallback* callback); | |
| 64 | |
| 65 // Retrieves the information about a file. It is invalid to pass NULL for the | 66 // Retrieves the information about a file. It is invalid to pass NULL for the |
| 66 // callback. | 67 // callback. |
| 67 typedef Callback2<base::PlatformFileError /* error code */, | 68 typedef Callback2<base::PlatformFileError /* error code */, |
| 68 const file_util::FileInfo& /*file_info*/ | 69 const file_util::FileInfo& /*file_info*/ |
| 69 >::Type GetFileInfoCallback; | 70 >::Type GetFileInfoCallback; |
| 70 static bool GetFileInfo( | 71 static bool GetFileInfo( |
| 71 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 72 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 72 const FilePath& file_path, | 73 const FilePath& file_path, |
| 73 GetFileInfoCallback* callback); | 74 GetFileInfoCallback* callback); |
| 74 | 75 |
| 76 typedef Callback2<base::PlatformFileError /* error code */, | |
|
darin (slow to review)
2010/11/01 17:28:38
nit: no need to mention "base::" when you are insi
| |
| 77 const std::vector<base::file_util_proxy::Entry>& | |
| 78 >::Type ReadDirectoryCallback; | |
| 79 static bool ReadDirectory(scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 80 const FilePath& file_path, | |
| 81 ReadDirectoryCallback* callback); | |
| 82 | |
| 83 // Copies a file or a directory from |src_file_path| to |dest_file_path| | |
| 84 // Error cases: | |
| 85 // If destination file doesn't exist or destination's parent | |
| 86 // doesn't exists. | |
| 87 // If source dir exists but destination path is an existing file. | |
| 88 // If source is a parent of destination. | |
| 89 // If source doesn't exists. | |
| 90 static bool Copy(scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 91 const FilePath& src_file_path, | |
| 92 const FilePath& dest_file_path, | |
| 93 StatusCallback* callback); | |
| 94 | |
| 95 // Creates directory at given path. It's an error to create | |
| 96 // if |exclusive| is true and dir already exists. | |
| 97 static bool CreateDirectory( | |
| 98 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 99 const FilePath& file_path, | |
| 100 bool exclusive, | |
| 101 StatusCallback* callback); | |
| 102 | |
| 103 // Deletes a file or empty directory. | |
| 104 static bool Delete(scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 105 const FilePath& file_path, | |
| 106 StatusCallback* callback); | |
| 107 | |
| 108 // Moves a file or a directory from src_file_path to dest_file_path. | |
| 109 // Error cases are similar to Copy method's error cases. | |
| 110 static bool Move( | |
| 111 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 112 const FilePath& src_file_path, | |
| 113 const FilePath& dest_file_path, | |
| 114 StatusCallback* callback); | |
| 115 | |
| 116 // Deletes a directory and all of its contents. | |
| 117 static bool RecursiveDelete( | |
| 118 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 119 const FilePath& file_path, | |
| 120 StatusCallback* callback); | |
| 121 | |
| 75 private: | 122 private: |
| 76 DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy); | 123 DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy); |
| 77 }; | 124 }; |
| 78 | 125 |
| 79 } // namespace base | 126 } // namespace base |
| 80 | 127 |
| 81 #endif // BASE_FILE_SYSTEM_PROXY_H_ | 128 #endif // BASE_FILE_UTIL_PROXY_H_ |
| OLD | NEW |