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

Side by Side Diff: base/files/file_proxy.cc

Issue 180243015: Base: Introduce a new version of FileUtilProxy that works with File. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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
OLDNEW
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 #include "base/files/file_util_proxy.h" 5 #include "base/files/file_proxy.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/message_loop/message_loop_proxy.h" 12 #include "base/message_loop/message_loop_proxy.h"
13 #include "base/task_runner.h" 13 #include "base/task_runner.h"
14 #include "base/task_runner_util.h" 14 #include "base/task_runner_util.h"
15 15
16 namespace base { 16 namespace base {
17 17
18 class FileHelper {
19 public:
20 FileHelper(FileProxy* proxy, File file)
21 : file_(file.Pass()),
22 proxy_(AsWeakPtr(proxy)),
23 error_(File::FILE_ERROR_FAILED) {
24 }
25
26 void PassFile() {
27 if (proxy_)
28 proxy_->SetFile(file_.Pass());
29 }
30
31 protected:
32 File file_;
33 WeakPtr<FileProxy> proxy_;
34 File::Error error_;
35
36 private:
37 DISALLOW_COPY_AND_ASSIGN(FileHelper);
38 };
39
18 namespace { 40 namespace {
19 41
20 void CallWithTranslatedParameter(const FileUtilProxy::StatusCallback& callback, 42 class GenericFileHelper : public FileHelper {
21 bool value) {
22 DCHECK(!callback.is_null());
23 callback.Run(value ? File::FILE_OK : File::FILE_ERROR_FAILED);
24 }
25
26 // Helper classes or routines for individual methods.
27 class CreateOrOpenHelper {
28 public: 43 public:
29 CreateOrOpenHelper(TaskRunner* task_runner, 44 GenericFileHelper(FileProxy* proxy, File file)
30 const FileUtilProxy::CloseTask& close_task) 45 : FileHelper(proxy, file.Pass()) {
31 : task_runner_(task_runner),
32 close_task_(close_task),
33 file_handle_(kInvalidPlatformFileValue),
34 created_(false),
35 error_(File::FILE_OK) {}
36
37 ~CreateOrOpenHelper() {
38 if (file_handle_ != kInvalidPlatformFileValue) {
39 task_runner_->PostTask(
40 FROM_HERE,
41 base::Bind(base::IgnoreResult(close_task_), file_handle_));
42 }
43 } 46 }
44 47
45 void RunWork(const FileUtilProxy::CreateOrOpenTask& task) { 48 void Close() {
46 error_ = task.Run(&file_handle_, &created_); 49 file_.Close();
50 error_ = File::FILE_OK;
47 } 51 }
48 52
49 void Reply(const FileUtilProxy::CreateOrOpenCallback& callback) { 53 void SetTimes(Time last_access_time, Time last_modified_time) {
50 DCHECK(!callback.is_null()); 54 bool rv = file_.SetTimes(last_access_time, last_modified_time);
51 callback.Run(error_, PassPlatformFile(&file_handle_), created_); 55 error_ = rv ? File::FILE_OK : File::FILE_ERROR_FAILED;
56 }
57
58 void SetLength(int64 length) {
59 if (file_.SetLength(length))
60 error_ = File::FILE_OK;
61 }
62
63 void Flush() {
64 if (file_.Flush())
65 error_ = File::FILE_OK;
66 }
67
68 void Reply(const FileProxy::StatusCallback& callback) {
69 PassFile();
70 if (!callback.is_null())
71 callback.Run(error_);
52 } 72 }
53 73
54 private: 74 private:
55 scoped_refptr<TaskRunner> task_runner_; 75 DISALLOW_COPY_AND_ASSIGN(GenericFileHelper);
56 FileUtilProxy::CloseTask close_task_; 76 };
57 PlatformFile file_handle_; 77
58 bool created_; 78 class CreateOrOpenHelper : public FileHelper {
59 File::Error error_; 79 public:
80 CreateOrOpenHelper(FileProxy* proxy, File file)
81 : FileHelper(proxy, file.Pass()) {
82 }
83
84 void RunWork(const FilePath& file_path, int file_flags) {
85 file_.Initialize(file_path, file_flags);
86 error_ = file_.IsValid() ? File::FILE_OK : file_.error_details();
87 }
88
89 void Reply(const FileProxy::StatusCallback& callback) {
90 DCHECK(!callback.is_null());
91 PassFile();
92 callback.Run(error_);
93 }
94
95 private:
60 DISALLOW_COPY_AND_ASSIGN(CreateOrOpenHelper); 96 DISALLOW_COPY_AND_ASSIGN(CreateOrOpenHelper);
61 }; 97 };
62 98
63 class CreateTemporaryHelper { 99 class CreateTemporaryHelper : public FileHelper {
64 public: 100 public:
65 explicit CreateTemporaryHelper(TaskRunner* task_runner) 101 CreateTemporaryHelper(FileProxy* proxy, File file)
66 : task_runner_(task_runner), 102 : FileHelper(proxy, file.Pass()) {
67 file_handle_(kInvalidPlatformFileValue),
68 error_(File::FILE_OK) {}
69
70 ~CreateTemporaryHelper() {
71 if (file_handle_ != kInvalidPlatformFileValue) {
72 FileUtilProxy::Close(
73 task_runner_.get(), file_handle_, FileUtilProxy::StatusCallback());
74 }
75 } 103 }
76 104
77 void RunWork(int additional_file_flags) { 105 void RunWork(uint32 additional_file_flags) {
78 // TODO(darin): file_util should have a variant of CreateTemporaryFile 106 // TODO(darin): file_util should have a variant of CreateTemporaryFile
79 // that returns a FilePath and a PlatformFile. 107 // that returns a FilePath and a File.
80 base::CreateTemporaryFile(&file_path_); 108 CreateTemporaryFile(&file_path_);
81 109
82 int file_flags = 110 uint32 file_flags = File::FLAG_WRITE |
83 PLATFORM_FILE_WRITE | 111 File::FLAG_TEMPORARY |
84 PLATFORM_FILE_TEMPORARY | 112 File::FLAG_CREATE_ALWAYS |
85 PLATFORM_FILE_CREATE_ALWAYS | 113 additional_file_flags;
86 additional_file_flags;
87 114
88 error_ = File::FILE_OK; 115 file_.Initialize(file_path_, file_flags);
89 // TODO(rvargas): Convert this code to use File. 116 error_ = file_.IsValid() ? File::FILE_OK : file_.error_details();
90 file_handle_ =
91 CreatePlatformFile(file_path_, file_flags, NULL,
92 reinterpret_cast<PlatformFileError*>(&error_));
93 } 117 }
94 118
95 void Reply(const FileUtilProxy::CreateTemporaryCallback& callback) { 119 void Reply(const FileProxy::CreateTemporaryCallback& callback) {
96 DCHECK(!callback.is_null()); 120 DCHECK(!callback.is_null());
97 callback.Run(error_, PassPlatformFile(&file_handle_), file_path_); 121 PassFile();
122 callback.Run(error_, file_path_);
98 } 123 }
99 124
100 private: 125 private:
101 scoped_refptr<TaskRunner> task_runner_;
102 PlatformFile file_handle_;
103 FilePath file_path_; 126 FilePath file_path_;
104 File::Error error_;
105 DISALLOW_COPY_AND_ASSIGN(CreateTemporaryHelper); 127 DISALLOW_COPY_AND_ASSIGN(CreateTemporaryHelper);
106 }; 128 };
107 129
108 class GetFileInfoHelper { 130 class GetInfoHelper : public FileHelper {
109 public: 131 public:
110 GetFileInfoHelper() 132 GetInfoHelper(FileProxy* proxy, File file)
111 : error_(File::FILE_OK) {} 133 : FileHelper(proxy, file.Pass()) {
112
113 void RunWorkForFilePath(const FilePath& file_path) {
114 if (!PathExists(file_path)) {
115 error_ = File::FILE_ERROR_NOT_FOUND;
116 return;
117 }
118 // TODO(rvargas): switch this file to base::File.
119 if (!GetFileInfo(file_path, reinterpret_cast<File::Info*>(&file_info_)))
120 error_ = File::FILE_ERROR_FAILED;
121 } 134 }
122 135
123 void RunWorkForPlatformFile(PlatformFile file) { 136 void RunWork() {
124 if (!GetPlatformFileInfo( 137 if (file_.GetInfo(&file_info_))
125 file, reinterpret_cast<PlatformFileInfo*>(&file_info_))) { 138 error_ = File::FILE_OK;
126 error_ = File::FILE_ERROR_FAILED;
127 }
128 } 139 }
129 140
130 void Reply(const FileUtilProxy::GetFileInfoCallback& callback) { 141 void Reply(const FileProxy::GetFileInfoCallback& callback) {
131 if (!callback.is_null()) { 142 PassFile();
132 callback.Run(error_, file_info_); 143 DCHECK(!callback.is_null());
133 } 144 callback.Run(error_, file_info_);
134 } 145 }
135 146
136 private: 147 private:
137 File::Error error_;
138 File::Info file_info_; 148 File::Info file_info_;
139 DISALLOW_COPY_AND_ASSIGN(GetFileInfoHelper); 149 DISALLOW_COPY_AND_ASSIGN(GetInfoHelper);
140 }; 150 };
141 151
142 class ReadHelper { 152 class ReadHelper : public FileHelper {
143 public: 153 public:
144 explicit ReadHelper(int bytes_to_read) 154 ReadHelper(FileProxy* proxy, File file, int bytes_to_read)
145 : buffer_(new char[bytes_to_read]), 155 : FileHelper(proxy, file.Pass()),
156 buffer_(new char[bytes_to_read]),
146 bytes_to_read_(bytes_to_read), 157 bytes_to_read_(bytes_to_read),
147 bytes_read_(0) {} 158 bytes_read_(0) {
148
149 void RunWork(PlatformFile file, int64 offset) {
150 bytes_read_ = ReadPlatformFile(file, offset, buffer_.get(), bytes_to_read_);
151 } 159 }
152 160
153 void Reply(const FileUtilProxy::ReadCallback& callback) { 161 void RunWork(int64 offset) {
154 if (!callback.is_null()) { 162 bytes_read_ = file_.Read(offset, buffer_.get(), bytes_to_read_);
155 File::Error error = 163 error_ = (bytes_read_ < 0) ? File::FILE_ERROR_FAILED : File::FILE_OK;
156 (bytes_read_ < 0) ? File::FILE_ERROR_FAILED : File::FILE_OK; 164 }
157 callback.Run(error, buffer_.get(), bytes_read_); 165
158 } 166 void Reply(const FileProxy::ReadCallback& callback) {
167 PassFile();
168 DCHECK(!callback.is_null());
169 callback.Run(error_, buffer_.get(), bytes_read_);
159 } 170 }
160 171
161 private: 172 private:
162 scoped_ptr<char[]> buffer_; 173 scoped_ptr<char[]> buffer_;
163 int bytes_to_read_; 174 int bytes_to_read_;
164 int bytes_read_; 175 int bytes_read_;
165 DISALLOW_COPY_AND_ASSIGN(ReadHelper); 176 DISALLOW_COPY_AND_ASSIGN(ReadHelper);
166 }; 177 };
167 178
168 class WriteHelper { 179 class WriteHelper : public FileHelper {
169 public: 180 public:
170 WriteHelper(const char* buffer, int bytes_to_write) 181 WriteHelper(FileProxy* proxy,
171 : buffer_(new char[bytes_to_write]), 182 File file,
183 const char* buffer, int bytes_to_write)
184 : FileHelper(proxy, file.Pass()),
185 buffer_(new char[bytes_to_write]),
172 bytes_to_write_(bytes_to_write), 186 bytes_to_write_(bytes_to_write),
173 bytes_written_(0) { 187 bytes_written_(0) {
174 memcpy(buffer_.get(), buffer, bytes_to_write); 188 memcpy(buffer_.get(), buffer, bytes_to_write);
175 } 189 }
176 190
177 void RunWork(PlatformFile file, int64 offset) { 191 void RunWork(int64 offset) {
178 bytes_written_ = WritePlatformFile(file, offset, buffer_.get(), 192 bytes_written_ = file_.Write(offset, buffer_.get(), bytes_to_write_);
179 bytes_to_write_); 193 error_ = (bytes_written_ < 0) ? File::FILE_ERROR_FAILED : File::FILE_OK;
180 } 194 }
181 195
182 void Reply(const FileUtilProxy::WriteCallback& callback) { 196 void Reply(const FileProxy::WriteCallback& callback) {
183 if (!callback.is_null()) { 197 PassFile();
184 File::Error error = 198 if (!callback.is_null())
185 (bytes_written_ < 0) ? File::FILE_ERROR_FAILED : File::FILE_OK; 199 callback.Run(error_, bytes_written_);
186 callback.Run(error, bytes_written_);
187 }
188 } 200 }
189 201
190 private: 202 private:
191 scoped_ptr<char[]> buffer_; 203 scoped_ptr<char[]> buffer_;
192 int bytes_to_write_; 204 int bytes_to_write_;
193 int bytes_written_; 205 int bytes_written_;
194 DISALLOW_COPY_AND_ASSIGN(WriteHelper); 206 DISALLOW_COPY_AND_ASSIGN(WriteHelper);
195 }; 207 };
196 208
197 File::Error CreateOrOpenAdapter( 209 } // namespace
198 const FilePath& file_path, int file_flags, 210
199 PlatformFile* file_handle, bool* created) { 211 FileProxy::FileProxy() : task_runner_(NULL) {
200 DCHECK(file_handle);
201 DCHECK(created);
202 if (!DirectoryExists(file_path.DirName())) {
203 // If its parent does not exist, should return NOT_FOUND error.
204 return File::FILE_ERROR_NOT_FOUND;
205 }
206 File::Error error = File::FILE_OK;
207 *file_handle =
208 CreatePlatformFile(file_path, file_flags, created,
209 reinterpret_cast<PlatformFileError*>(&error));
210 return error;
211 } 212 }
212 213
213 File::Error CloseAdapter(PlatformFile file_handle) { 214 FileProxy::FileProxy(TaskRunner* task_runner) : task_runner_(task_runner) {
214 if (!ClosePlatformFile(file_handle)) {
215 return File::FILE_ERROR_FAILED;
216 }
217 return File::FILE_OK;
218 } 215 }
219 216
220 File::Error DeleteAdapter(const FilePath& file_path, bool recursive) { 217 FileProxy::~FileProxy() {
kinuko 2014/03/03 05:58:58 This may lead to close a file on non-blocking thre
rvargas (doing something else) 2014/03/03 20:38:34 Correct. I think that would be an error that would
kinuko 2014/03/04 04:07:45 Ok... not performing Close automatically in dtor a
rvargas (doing something else) 2014/03/04 23:53:53 I added a comment to the class description.
221 if (!PathExists(file_path)) {
222 return File::FILE_ERROR_NOT_FOUND;
223 }
224 if (!base::DeleteFile(file_path, recursive)) {
225 if (!recursive && !base::IsDirectoryEmpty(file_path)) {
226 return File::FILE_ERROR_NOT_EMPTY;
227 }
228 return File::FILE_ERROR_FAILED;
229 }
230 return File::FILE_OK;
231 } 218 }
232 219
233 } // namespace 220 bool FileProxy::CreateOrOpen(const FilePath& file_path,
234 221 uint32 file_flags,
235 // static 222 const StatusCallback& callback) {
236 bool FileUtilProxy::CreateOrOpen( 223 CreateOrOpenHelper* helper = new CreateOrOpenHelper(this, File());
237 TaskRunner* task_runner, 224 return task_runner_->PostTaskAndReply(
238 const FilePath& file_path, int file_flags, 225 FROM_HERE,
239 const CreateOrOpenCallback& callback) { 226 Bind(&CreateOrOpenHelper::RunWork, Unretained(helper), file_path,
240 return RelayCreateOrOpen( 227 file_flags),
241 task_runner, 228 Bind(&CreateOrOpenHelper::Reply, Owned(helper), callback));
242 base::Bind(&CreateOrOpenAdapter, file_path, file_flags),
243 base::Bind(&CloseAdapter),
244 callback);
245 } 229 }
246 230
247 // static 231 bool FileProxy::CreateTemporary(uint32 additional_file_flags,
248 bool FileUtilProxy::CreateTemporary( 232 const CreateTemporaryCallback& callback) {
249 TaskRunner* task_runner, 233 CreateTemporaryHelper* helper = new CreateTemporaryHelper(this, File());
250 int additional_file_flags, 234 return task_runner_->PostTaskAndReply(
251 const CreateTemporaryCallback& callback) {
252 CreateTemporaryHelper* helper = new CreateTemporaryHelper(task_runner);
253 return task_runner->PostTaskAndReply(
254 FROM_HERE, 235 FROM_HERE,
255 Bind(&CreateTemporaryHelper::RunWork, Unretained(helper), 236 Bind(&CreateTemporaryHelper::RunWork, Unretained(helper),
256 additional_file_flags), 237 additional_file_flags),
257 Bind(&CreateTemporaryHelper::Reply, Owned(helper), callback)); 238 Bind(&CreateTemporaryHelper::Reply, Owned(helper), callback));
258 } 239 }
259 240
260 // static 241 bool FileProxy::IsValid() const {
261 bool FileUtilProxy::Close( 242 return file_.IsValid();
262 TaskRunner* task_runner,
263 base::PlatformFile file_handle,
264 const StatusCallback& callback) {
265 return RelayClose(
266 task_runner,
267 base::Bind(&CloseAdapter),
268 file_handle, callback);
269 } 243 }
270 244
271 // Retrieves the information about a file. It is invalid to pass NULL for the 245 File FileProxy::TakeFile() {
272 // callback. 246 return file_.Pass();
273 bool FileUtilProxy::GetFileInfo(
274 TaskRunner* task_runner,
275 const FilePath& file_path,
276 const GetFileInfoCallback& callback) {
277 GetFileInfoHelper* helper = new GetFileInfoHelper;
278 return task_runner->PostTaskAndReply(
279 FROM_HERE,
280 Bind(&GetFileInfoHelper::RunWorkForFilePath,
281 Unretained(helper), file_path),
282 Bind(&GetFileInfoHelper::Reply, Owned(helper), callback));
283 } 247 }
284 248
285 // static 249 bool FileProxy::Close(const StatusCallback& callback) {
286 bool FileUtilProxy::GetFileInfoFromPlatformFile( 250 GenericFileHelper* helper = new GenericFileHelper(this, file_.Pass());
287 TaskRunner* task_runner, 251 return task_runner_->PostTaskAndReply(
288 PlatformFile file,
289 const GetFileInfoCallback& callback) {
290 GetFileInfoHelper* helper = new GetFileInfoHelper;
291 return task_runner->PostTaskAndReply(
292 FROM_HERE, 252 FROM_HERE,
293 Bind(&GetFileInfoHelper::RunWorkForPlatformFile, 253 Bind(&GenericFileHelper::Close, Unretained(helper)),
294 Unretained(helper), file), 254 Bind(&GenericFileHelper::Reply, Owned(helper), callback));
295 Bind(&GetFileInfoHelper::Reply, Owned(helper), callback));
296 } 255 }
297 256
298 // static 257 bool FileProxy::GetInfo(const GetFileInfoCallback& callback) {
299 bool FileUtilProxy::DeleteFile(TaskRunner* task_runner, 258 GetInfoHelper* helper = new GetInfoHelper(this, file_.Pass());
300 const FilePath& file_path, 259 return task_runner_->PostTaskAndReply(
301 bool recursive, 260 FROM_HERE,
302 const StatusCallback& callback) { 261 Bind(&GetInfoHelper::RunWork, Unretained(helper)),
303 return base::PostTaskAndReplyWithResult( 262 Bind(&GetInfoHelper::Reply, Owned(helper), callback));
304 task_runner, FROM_HERE,
305 Bind(&DeleteAdapter, file_path, recursive),
306 callback);
307 } 263 }
308 264
309 // static 265 bool FileProxy::Read(int64 offset,
310 bool FileUtilProxy::Read( 266 int bytes_to_read,
311 TaskRunner* task_runner, 267 const ReadCallback& callback) {
312 PlatformFile file, 268 if (bytes_to_read < 0)
313 int64 offset,
314 int bytes_to_read,
315 const ReadCallback& callback) {
316 if (bytes_to_read < 0) {
317 return false; 269 return false;
318 } 270
319 ReadHelper* helper = new ReadHelper(bytes_to_read); 271 ReadHelper* helper = new ReadHelper(this, file_.Pass(), bytes_to_read);
320 return task_runner->PostTaskAndReply( 272 return task_runner_->PostTaskAndReply(
321 FROM_HERE, 273 FROM_HERE,
322 Bind(&ReadHelper::RunWork, Unretained(helper), file, offset), 274 Bind(&ReadHelper::RunWork, Unretained(helper), offset),
323 Bind(&ReadHelper::Reply, Owned(helper), callback)); 275 Bind(&ReadHelper::Reply, Owned(helper), callback));
324 } 276 }
325 277
326 // static 278 bool FileProxy::Write(int64 offset,
327 bool FileUtilProxy::Write( 279 const char* buffer,
328 TaskRunner* task_runner, 280 int bytes_to_write,
329 PlatformFile file, 281 const WriteCallback& callback) {
330 int64 offset, 282 if (bytes_to_write <= 0 || buffer == NULL)
331 const char* buffer,
332 int bytes_to_write,
333 const WriteCallback& callback) {
334 if (bytes_to_write <= 0 || buffer == NULL) {
335 return false; 283 return false;
336 } 284
337 WriteHelper* helper = new WriteHelper(buffer, bytes_to_write); 285 WriteHelper* helper =
338 return task_runner->PostTaskAndReply( 286 new WriteHelper(this, file_.Pass(), buffer, bytes_to_write);
287 return task_runner_->PostTaskAndReply(
339 FROM_HERE, 288 FROM_HERE,
340 Bind(&WriteHelper::RunWork, Unretained(helper), file, offset), 289 Bind(&WriteHelper::RunWork, Unretained(helper), offset),
341 Bind(&WriteHelper::Reply, Owned(helper), callback)); 290 Bind(&WriteHelper::Reply, Owned(helper), callback));
342 } 291 }
343 292
344 // static 293 bool FileProxy::SetTimes(Time last_access_time,
345 bool FileUtilProxy::Touch( 294 Time last_modified_time,
346 TaskRunner* task_runner, 295 const StatusCallback& callback) {
347 PlatformFile file, 296 GenericFileHelper* helper = new GenericFileHelper(this, file_.Pass());
348 const Time& last_access_time, 297 return task_runner_->PostTaskAndReply(
349 const Time& last_modified_time,
350 const StatusCallback& callback) {
351 return base::PostTaskAndReplyWithResult(
352 task_runner,
353 FROM_HERE, 298 FROM_HERE,
354 Bind(&TouchPlatformFile, file, 299 Bind(&GenericFileHelper::SetTimes, Unretained(helper), last_access_time,
355 last_access_time, last_modified_time), 300 last_modified_time),
356 Bind(&CallWithTranslatedParameter, callback)); 301 Bind(&GenericFileHelper::Reply, Owned(helper), callback));
357 } 302 }
358 303
359 // static 304 bool FileProxy::SetLength(int64 length, const StatusCallback& callback) {
360 bool FileUtilProxy::Touch( 305 GenericFileHelper* helper = new GenericFileHelper(this, file_.Pass());
361 TaskRunner* task_runner, 306 return task_runner_->PostTaskAndReply(
362 const FilePath& file_path,
363 const Time& last_access_time,
364 const Time& last_modified_time,
365 const StatusCallback& callback) {
366 return base::PostTaskAndReplyWithResult(
367 task_runner,
368 FROM_HERE, 307 FROM_HERE,
369 Bind(&TouchFile, file_path, last_access_time, last_modified_time), 308 Bind(&GenericFileHelper::SetLength, Unretained(helper), length),
370 Bind(&CallWithTranslatedParameter, callback)); 309 Bind(&GenericFileHelper::Reply, Owned(helper), callback));
371 } 310 }
372 311
373 // static 312 bool FileProxy::Flush(const StatusCallback& callback) {
374 bool FileUtilProxy::Truncate( 313 GenericFileHelper* helper = new GenericFileHelper(this, file_.Pass());
375 TaskRunner* task_runner, 314 return task_runner_->PostTaskAndReply(
376 PlatformFile file,
377 int64 length,
378 const StatusCallback& callback) {
379 return base::PostTaskAndReplyWithResult(
380 task_runner,
381 FROM_HERE, 315 FROM_HERE,
382 Bind(&TruncatePlatformFile, file, length), 316 Bind(&GenericFileHelper::Flush, Unretained(helper)),
383 Bind(&CallWithTranslatedParameter, callback)); 317 Bind(&GenericFileHelper::Reply, Owned(helper), callback));
384 } 318 }
385 319
386 // static 320 void FileProxy::SetFile(File file) {
387 bool FileUtilProxy::Flush( 321 DCHECK(!file_.IsValid());
388 TaskRunner* task_runner, 322 file_ = file.Pass();
389 PlatformFile file,
390 const StatusCallback& callback) {
391 return base::PostTaskAndReplyWithResult(
392 task_runner,
393 FROM_HERE,
394 Bind(&FlushPlatformFile, file),
395 Bind(&CallWithTranslatedParameter, callback));
396 }
397
398 // static
399 bool FileUtilProxy::RelayCreateOrOpen(
400 TaskRunner* task_runner,
401 const CreateOrOpenTask& open_task,
402 const CloseTask& close_task,
403 const CreateOrOpenCallback& callback) {
404 CreateOrOpenHelper* helper = new CreateOrOpenHelper(
405 task_runner, close_task);
406 return task_runner->PostTaskAndReply(
407 FROM_HERE,
408 Bind(&CreateOrOpenHelper::RunWork, Unretained(helper), open_task),
409 Bind(&CreateOrOpenHelper::Reply, Owned(helper), callback));
410 }
411
412 // static
413 bool FileUtilProxy::RelayClose(
414 TaskRunner* task_runner,
415 const CloseTask& close_task,
416 PlatformFile file_handle,
417 const StatusCallback& callback) {
418 return base::PostTaskAndReplyWithResult(
419 task_runner, FROM_HERE, Bind(close_task, file_handle), callback);
420 } 323 }
421 324
422 } // namespace base 325 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698