OLD | NEW |
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_util_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/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 callback.Run(error_, file_info_); | 41 callback.Run(error_, file_info_); |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 private: | 45 private: |
46 File::Error error_; | 46 File::Error error_; |
47 File::Info file_info_; | 47 File::Info file_info_; |
48 DISALLOW_COPY_AND_ASSIGN(GetFileInfoHelper); | 48 DISALLOW_COPY_AND_ASSIGN(GetFileInfoHelper); |
49 }; | 49 }; |
50 | 50 |
51 File::Error DeleteAdapter(const FilePath& file_path, bool recursive) { | |
52 if (!PathExists(file_path)) { | |
53 return File::FILE_ERROR_NOT_FOUND; | |
54 } | |
55 if (!base::DeleteFile(file_path, recursive)) { | |
56 if (!recursive && !base::IsDirectoryEmpty(file_path)) { | |
57 return File::FILE_ERROR_NOT_EMPTY; | |
58 } | |
59 return File::FILE_ERROR_FAILED; | |
60 } | |
61 return File::FILE_OK; | |
62 } | |
63 | |
64 } // namespace | 51 } // namespace |
65 | 52 |
66 // Retrieves the information about a file. It is invalid to pass NULL for the | 53 // Retrieves the information about a file. It is invalid to pass NULL for the |
67 // callback. | 54 // callback. |
68 bool FileUtilProxy::GetFileInfo( | 55 bool FileUtilProxy::GetFileInfo( |
69 TaskRunner* task_runner, | 56 TaskRunner* task_runner, |
70 const FilePath& file_path, | 57 const FilePath& file_path, |
71 const GetFileInfoCallback& callback) { | 58 const GetFileInfoCallback& callback) { |
72 GetFileInfoHelper* helper = new GetFileInfoHelper; | 59 GetFileInfoHelper* helper = new GetFileInfoHelper; |
73 return task_runner->PostTaskAndReply( | 60 return task_runner->PostTaskAndReply( |
74 FROM_HERE, | 61 FROM_HERE, |
75 Bind(&GetFileInfoHelper::RunWorkForFilePath, | 62 Bind(&GetFileInfoHelper::RunWorkForFilePath, |
76 Unretained(helper), file_path), | 63 Unretained(helper), file_path), |
77 Bind(&GetFileInfoHelper::Reply, Owned(helper), callback)); | 64 Bind(&GetFileInfoHelper::Reply, Owned(helper), callback)); |
78 } | 65 } |
79 | 66 |
80 // static | 67 // static |
81 bool FileUtilProxy::DeleteFile(TaskRunner* task_runner, | |
82 const FilePath& file_path, | |
83 bool recursive, | |
84 const StatusCallback& callback) { | |
85 return base::PostTaskAndReplyWithResult( | |
86 task_runner, FROM_HERE, | |
87 Bind(&DeleteAdapter, file_path, recursive), | |
88 callback); | |
89 } | |
90 | |
91 // static | |
92 bool FileUtilProxy::Touch( | 68 bool FileUtilProxy::Touch( |
93 TaskRunner* task_runner, | 69 TaskRunner* task_runner, |
94 const FilePath& file_path, | 70 const FilePath& file_path, |
95 const Time& last_access_time, | 71 const Time& last_access_time, |
96 const Time& last_modified_time, | 72 const Time& last_modified_time, |
97 const StatusCallback& callback) { | 73 const StatusCallback& callback) { |
98 return base::PostTaskAndReplyWithResult( | 74 return base::PostTaskAndReplyWithResult( |
99 task_runner, | 75 task_runner, |
100 FROM_HERE, | 76 FROM_HERE, |
101 Bind(&TouchFile, file_path, last_access_time, last_modified_time), | 77 Bind(&TouchFile, file_path, last_access_time, last_modified_time), |
102 Bind(&CallWithTranslatedParameter, callback)); | 78 Bind(&CallWithTranslatedParameter, callback)); |
103 } | 79 } |
104 | 80 |
105 } // namespace base | 81 } // namespace base |
OLD | NEW |