Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: base/file_util_proxy.h

Issue 8231004: Remaining cleanup (base::Bind): Replacing FileUtilProxy calls with new callback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/file_util_proxy.cc » ('j') | base/file_util_proxy.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 BASE_FILE_UTIL_PROXY_H_ 5 #ifndef BASE_FILE_UTIL_PROXY_H_
6 #define BASE_FILE_UTIL_PROXY_H_ 6 #define BASE_FILE_UTIL_PROXY_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base_export.h" 10 #include "base/base_export.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/platform_file.h" 15 #include "base/platform_file.h"
16 #include "base/tracked_objects.h" 16 #include "base/tracked_objects.h"
17 17
18 namespace base { 18 namespace base {
19 19
20 class MessageLoopProxy; 20 class MessageLoopProxy;
21 class Time; 21 class Time;
22 22
23 // This class provides asynchronous access to common file routines. 23 // This class provides asynchronous access to common file routines.
24 class BASE_EXPORT FileUtilProxy { 24 class BASE_EXPORT FileUtilProxy {
25 public: 25 public:
26 // Holds metadata for file or directory entry. Used by ReadDirectoryCallback. 26 // Holds metadata for file or directory entry.
27 struct Entry { 27 struct Entry {
28 FilePath::StringType name; 28 FilePath::StringType name;
29 bool is_directory; 29 bool is_directory;
30 int64 size; 30 int64 size;
31 base::Time last_modified_time; 31 base::Time last_modified_time;
32 }; 32 };
33 33
34 // This callback is used by methods that report only an error code. It is 34 // This callback is used by methods that report only an error code. It is
35 // valid to pass a null callback to any function that takes a StatusCallback, 35 // valid to pass StatusCallback() to any function that takes a StatusCallback,
akalin 2011/10/18 19:05:11 I think "a null callback" is clearer
36 // in which case the operation will complete silently. 36 // in which case the operation will complete silently.
37 typedef base::Callback<void(PlatformFileError /* error code */)> 37 typedef Callback<void(PlatformFileError)> StatusCallback;
38 StatusCallback;
39 38
40 typedef base::Callback<void(PlatformFileError /* error code */, 39 typedef Callback<void(PlatformFileError,
41 PassPlatformFile, 40 PassPlatformFile,
42 bool /* created */)> CreateOrOpenCallback; 41 bool /* created */)> CreateOrOpenCallback;
43 typedef base::Callback<void(PlatformFileError /* error code */, 42 typedef Callback<void(PlatformFileError,
44 PassPlatformFile, 43 PassPlatformFile,
45 FilePath)> CreateTemporaryCallback; 44 FilePath)> CreateTemporaryCallback;
46 typedef base::Callback<void(PlatformFileError /* error code */, 45 typedef Callback<void(PlatformFileError,
47 bool /* created */)> EnsureFileExistsCallback; 46 const PlatformFileInfo&
48 typedef base::Callback<void(PlatformFileError /* error code */, 47 )> GetFileInfoCallback;
49 const PlatformFileInfo& /* file_info */)> 48 typedef Callback<void(PlatformFileError,
50 GetFileInfoCallback; 49 const char* /* data */,
51 typedef base::Callback<void(PlatformFileError /* error code */, 50 int /* bytes read */)> ReadCallback;
52 const std::vector<Entry>&)> ReadDirectoryCallback; 51 typedef Callback<void(PlatformFileError,
53 typedef base::Callback<void(PlatformFileError /* error code */, 52 int /* bytes written */)> WriteCallback;
54 const char* /* data */,
55 int /* bytes read/written */)> ReadCallback;
56 typedef base::Callback<void(PlatformFileError /* error code */,
57 int /* bytes written */)> WriteCallback;
58 53
59 // Creates or opens a file with the given flags. It is invalid to pass a null 54 // Creates or opens a file with the given flags. It is invalid to pass a null
60 // callback. If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to 55 // callback. If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to
61 // create a new file at the given |file_path| and calls back with 56 // create a new file at the given |file_path| and calls back with
62 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists. Takes 57 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists.
63 // ownership of |callback| and will delete it even on failure.
64 static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy, 58 static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy,
65 const FilePath& file_path, 59 const FilePath& file_path,
66 int file_flags, 60 int file_flags,
67 const CreateOrOpenCallback& callback); 61 const CreateOrOpenCallback& callback);
68 62
69 // Creates a temporary file for writing. The path and an open file handle are 63 // Creates a temporary file for writing. The path and an open file handle are
70 // returned. It is invalid to pass a null callback. The additional file flags 64 // returned. It is invalid to pass a null callback. The additional file flags
71 // will be added on top of the default file flags which are: 65 // will be added on top of the default file flags which are:
72 // base::PLATFORM_FILE_CREATE_ALWAYS 66 // base::PLATFORM_FILE_CREATE_ALWAYS
73 // base::PLATFORM_FILE_WRITE 67 // base::PLATFORM_FILE_WRITE
74 // base::PLATFORM_FILE_TEMPORARY. 68 // base::PLATFORM_FILE_TEMPORARY.
75 // Set |additional_file_flags| to 0 for synchronous writes and set to 69 // Set |additional_file_flags| to 0 for synchronous writes and set to
76 // base::PLATFORM_FILE_ASYNC to support asynchronous file operations. 70 // base::PLATFORM_FILE_ASYNC to support asynchronous file operations.
77 static bool CreateTemporary( 71 static bool CreateTemporary(
78 scoped_refptr<MessageLoopProxy> message_loop_proxy, 72 scoped_refptr<MessageLoopProxy> message_loop_proxy,
79 int additional_file_flags, 73 int additional_file_flags,
80 const CreateTemporaryCallback& callback); 74 const CreateTemporaryCallback& callback);
81 75
82 // Close the given file handle. 76 // Close the given file handle.
83 static bool Close(scoped_refptr<MessageLoopProxy> message_loop_proxy, 77 static bool Close(scoped_refptr<MessageLoopProxy> message_loop_proxy,
84 PlatformFile, 78 PlatformFile,
85 const StatusCallback& callback); 79 const StatusCallback& callback);
86 80
87 // Ensures that the given |file_path| exist. This creates a empty new file
88 // at |file_path| if the |file_path| does not exist.
89 // If a new file does not exist and is created at the |file_path|, |created|
90 // of the callback argument is set true and |error code| is set
91 // PLATFORM_FILE_OK. If the file already exists, |created| is set false and
92 // |error code| is set PLATFORM_FILE_OK. If the file hasn't existed but it
93 // couldn't be created for some other reasons, |created| is set false and
94 // |error code| indicates the error.
95 static bool EnsureFileExists(
96 scoped_refptr<MessageLoopProxy> message_loop_proxy,
97 const FilePath& file_path,
98 const EnsureFileExistsCallback& callback);
99
100 // Retrieves the information about a file. It is invalid to pass a null 81 // Retrieves the information about a file. It is invalid to pass a null
101 // callback. 82 // callback.
102 static bool GetFileInfo( 83 static bool GetFileInfo(
103 scoped_refptr<MessageLoopProxy> message_loop_proxy, 84 scoped_refptr<MessageLoopProxy> message_loop_proxy,
104 const FilePath& file_path, 85 const FilePath& file_path,
105 const GetFileInfoCallback& callback); 86 const GetFileInfoCallback& callback);
106 87
107 static bool GetFileInfoFromPlatformFile( 88 static bool GetFileInfoFromPlatformFile(
108 scoped_refptr<MessageLoopProxy> message_loop_proxy, 89 scoped_refptr<MessageLoopProxy> message_loop_proxy,
109 PlatformFile file, 90 PlatformFile file,
110 const GetFileInfoCallback& callback); 91 const GetFileInfoCallback& callback);
111 92
112 static bool ReadDirectory(scoped_refptr<MessageLoopProxy> message_loop_proxy,
113 const FilePath& file_path,
114 const ReadDirectoryCallback& callback);
115
116 // Creates directory at given path. It's an error to create
117 // if |exclusive| is true and dir already exists.
118 static bool CreateDirectory(
119 scoped_refptr<MessageLoopProxy> message_loop_proxy,
120 const FilePath& file_path,
121 bool exclusive,
122 bool recursive,
123 const StatusCallback& callback);
124
125 // Copies a file or a directory from |src_file_path| to |dest_file_path|
126 // Error cases:
127 // If destination file doesn't exist or destination's parent
128 // doesn't exists.
129 // If source dir exists but destination path is an existing file.
130 // If source file exists but destination path is an existing directory.
131 // If source is a parent of destination.
132 // If source doesn't exists.
133 static bool Copy(scoped_refptr<MessageLoopProxy> message_loop_proxy,
134 const FilePath& src_file_path,
135 const FilePath& dest_file_path,
136 const StatusCallback& callback);
137
138 // Moves a file or a directory from src_file_path to dest_file_path.
139 // Error cases are similar to Copy method's error cases.
140 static bool Move(
141 scoped_refptr<MessageLoopProxy> message_loop_proxy,
142 const FilePath& src_file_path,
143 const FilePath& dest_file_path,
144 const StatusCallback& callback);
145
146 // Deletes a file or a directory. 93 // Deletes a file or a directory.
147 // It is an error to delete a non-empty directory with recursive=false. 94 // It is an error to delete a non-empty directory with recursive=false.
148 static bool Delete(scoped_refptr<MessageLoopProxy> message_loop_proxy, 95 static bool Delete(scoped_refptr<MessageLoopProxy> message_loop_proxy,
149 const FilePath& file_path, 96 const FilePath& file_path,
150 bool recursive, 97 bool recursive,
151 const StatusCallback& callback); 98 const StatusCallback& callback);
152 99
153 // Deletes a directory and all of its contents. 100 // Deletes a directory and all of its contents.
154 static bool RecursiveDelete( 101 static bool RecursiveDelete(
155 scoped_refptr<MessageLoopProxy> message_loop_proxy, 102 scoped_refptr<MessageLoopProxy> message_loop_proxy,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 PlatformFile file, 164 PlatformFile file,
218 const StatusCallback& callback); 165 const StatusCallback& callback);
219 166
220 private: 167 private:
221 DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy); 168 DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy);
222 }; 169 };
223 170
224 } // namespace base 171 } // namespace base
225 172
226 #endif // BASE_FILE_UTIL_PROXY_H_ 173 #endif // BASE_FILE_UTIL_PROXY_H_
OLDNEW
« no previous file with comments | « no previous file | base/file_util_proxy.cc » ('j') | base/file_util_proxy.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698