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

Side by Side Diff: base/file_util_proxy.cc

Issue 3293009: Add recursive flag to file_util_proxy::CreateDirectory (Closed)
Patch Set: rebased Created 10 years, 3 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
« no previous file with comments | « base/file_util_proxy.h ('k') | chrome/browser/file_system/file_system_operation.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "base/file_util_proxy.h" 5 #include "base/file_util_proxy.h"
6 6
7 #include "base/message_loop_proxy.h" 7 #include "base/message_loop_proxy.h"
8 8
9 // TODO(jianli): Move the code from anonymous namespace to base namespace so 9 // TODO(jianli): Move the code from anonymous namespace to base namespace so
10 // that all of the base:: prefixes would be unnecessary. 10 // that all of the base:: prefixes would be unnecessary.
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 private: 313 private:
314 FilePath src_file_path_; 314 FilePath src_file_path_;
315 FilePath dest_file_path_; 315 FilePath dest_file_path_;
316 }; 316 };
317 317
318 class RelayCreateDirectory : public RelayWithStatusCallback { 318 class RelayCreateDirectory : public RelayWithStatusCallback {
319 public: 319 public:
320 RelayCreateDirectory( 320 RelayCreateDirectory(
321 const FilePath& file_path, 321 const FilePath& file_path,
322 bool exclusive, 322 bool exclusive,
323 bool recursive,
323 base::FileUtilProxy::StatusCallback* callback) 324 base::FileUtilProxy::StatusCallback* callback)
324 : RelayWithStatusCallback(callback), 325 : RelayWithStatusCallback(callback),
325 file_path_(file_path), 326 file_path_(file_path),
326 exclusive_(exclusive) { 327 exclusive_(exclusive),
328 recursive_(recursive) {
327 } 329 }
328 330
329 protected: 331 protected:
330 virtual void RunWork() { 332 virtual void RunWork() {
331 bool path_exists = file_util::PathExists(file_path_); 333 bool path_exists = file_util::PathExists(file_path_);
332 // If parent dir of file doesn't exist. 334 // If parent dir of file doesn't exist.
333 if (!file_util::PathExists(file_path_.DirName())) { 335 if (!recursive_ && !file_util::PathExists(file_path_.DirName())) {
334 set_error_code(base::PLATFORM_FILE_ERROR_NOT_FOUND); 336 set_error_code(base::PLATFORM_FILE_ERROR_NOT_FOUND);
335 return; 337 return;
336 } 338 }
337 if (exclusive_ && path_exists) { 339 if (exclusive_ && path_exists) {
338 set_error_code(base::PLATFORM_FILE_ERROR_EXISTS); 340 set_error_code(base::PLATFORM_FILE_ERROR_EXISTS);
339 return; 341 return;
340 } 342 }
341 // If file exists at the path. 343 // If file exists at the path.
342 if (path_exists && !file_util::DirectoryExists(file_path_)) { 344 if (path_exists && !file_util::DirectoryExists(file_path_)) {
343 set_error_code(base::PLATFORM_FILE_ERROR_EXISTS); 345 set_error_code(base::PLATFORM_FILE_ERROR_EXISTS);
344 return; 346 return;
345 } 347 }
346 if (!file_util::CreateDirectory(file_path_)) 348 if (!file_util::CreateDirectory(file_path_))
347 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); 349 set_error_code(base::PLATFORM_FILE_ERROR_FAILED);
348 } 350 }
349 351
350 private: 352 private:
351 FilePath file_path_; 353 FilePath file_path_;
352 bool exclusive_; 354 bool exclusive_;
355 bool recursive_;
353 }; 356 };
354 357
355 class RelayReadDirectory : public MessageLoopRelay { 358 class RelayReadDirectory : public MessageLoopRelay {
356 public: 359 public:
357 RelayReadDirectory(const FilePath& file_path, 360 RelayReadDirectory(const FilePath& file_path,
358 base::FileUtilProxy::ReadDirectoryCallback* callback) 361 base::FileUtilProxy::ReadDirectoryCallback* callback)
359 : callback_(callback), file_path_(file_path) { 362 : callback_(callback), file_path_(file_path) {
360 DCHECK(callback); 363 DCHECK(callback);
361 } 364 }
362 365
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 CreateTemporaryCallback* callback) { 454 CreateTemporaryCallback* callback) {
452 return Start(FROM_HERE, message_loop_proxy, 455 return Start(FROM_HERE, message_loop_proxy,
453 new RelayCreateTemporary(message_loop_proxy, callback)); 456 new RelayCreateTemporary(message_loop_proxy, callback));
454 } 457 }
455 458
456 // static 459 // static
457 bool FileUtilProxy::CreateDirectory( 460 bool FileUtilProxy::CreateDirectory(
458 scoped_refptr<MessageLoopProxy> message_loop_proxy, 461 scoped_refptr<MessageLoopProxy> message_loop_proxy,
459 const FilePath& file_path, 462 const FilePath& file_path,
460 bool exclusive, 463 bool exclusive,
464 bool recursive,
461 StatusCallback* callback) { 465 StatusCallback* callback) {
462 return Start(FROM_HERE, message_loop_proxy, new RelayCreateDirectory( 466 return Start(FROM_HERE, message_loop_proxy, new RelayCreateDirectory(
463 file_path, exclusive, callback)); 467 file_path, exclusive, recursive, callback));
464 } 468 }
465 469
466 // static 470 // static
467 bool FileUtilProxy::Close(scoped_refptr<MessageLoopProxy> message_loop_proxy, 471 bool FileUtilProxy::Close(scoped_refptr<MessageLoopProxy> message_loop_proxy,
468 base::PlatformFile file_handle, 472 base::PlatformFile file_handle,
469 StatusCallback* callback) { 473 StatusCallback* callback) {
470 return Start(FROM_HERE, message_loop_proxy, 474 return Start(FROM_HERE, message_loop_proxy,
471 new RelayClose(file_handle, callback)); 475 new RelayClose(file_handle, callback));
472 } 476 }
473 477
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 // static 523 // static
520 bool FileUtilProxy::RecursiveDelete( 524 bool FileUtilProxy::RecursiveDelete(
521 scoped_refptr<MessageLoopProxy> message_loop_proxy, 525 scoped_refptr<MessageLoopProxy> message_loop_proxy,
522 const FilePath& file_path, 526 const FilePath& file_path,
523 StatusCallback* callback) { 527 StatusCallback* callback) {
524 return Start(FROM_HERE, message_loop_proxy, 528 return Start(FROM_HERE, message_loop_proxy,
525 new RelayDelete(file_path, true, callback)); 529 new RelayDelete(file_path, true, callback));
526 } 530 }
527 531
528 } // namespace base 532 } // namespace base
OLDNEW
« no previous file with comments | « base/file_util_proxy.h ('k') | chrome/browser/file_system/file_system_operation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698