| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_FILES_FILE_PROXY_H_ | 5 #ifndef BASE_FILES_FILE_PROXY_H_ |
| 6 #define BASE_FILES_FILE_PROXY_H_ | 6 #define BASE_FILES_FILE_PROXY_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include "base/base_export.h" | 10 #include "base/base_export.h" |
| 9 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
| 10 #include "base/files/file.h" | 12 #include "base/files/file.h" |
| 11 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 14 | 17 |
| 15 namespace tracked_objects { | 18 namespace tracked_objects { |
| 16 class Location; | 19 class Location; |
| 17 }; | 20 }; |
| 18 | 21 |
| 19 namespace base { | 22 namespace base { |
| 20 | 23 |
| 21 class TaskRunner; | 24 class TaskRunner; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 explicit FileProxy(TaskRunner* task_runner); | 60 explicit FileProxy(TaskRunner* task_runner); |
| 58 ~FileProxy(); | 61 ~FileProxy(); |
| 59 | 62 |
| 60 // Creates or opens a file with the given flags. It is invalid to pass a null | 63 // Creates or opens a file with the given flags. It is invalid to pass a null |
| 61 // callback. If File::FLAG_CREATE is set in |file_flags| it always tries to | 64 // callback. If File::FLAG_CREATE is set in |file_flags| it always tries to |
| 62 // create a new file at the given |file_path| and fails if the file already | 65 // create a new file at the given |file_path| and fails if the file already |
| 63 // exists. | 66 // exists. |
| 64 // | 67 // |
| 65 // This returns false if task posting to |task_runner| has failed. | 68 // This returns false if task posting to |task_runner| has failed. |
| 66 bool CreateOrOpen(const FilePath& file_path, | 69 bool CreateOrOpen(const FilePath& file_path, |
| 67 uint32 file_flags, | 70 uint32_t file_flags, |
| 68 const StatusCallback& callback); | 71 const StatusCallback& callback); |
| 69 | 72 |
| 70 // Creates a temporary file for writing. The path and an open file are | 73 // Creates a temporary file for writing. The path and an open file are |
| 71 // returned. It is invalid to pass a null callback. The additional file flags | 74 // returned. It is invalid to pass a null callback. The additional file flags |
| 72 // will be added on top of the default file flags which are: | 75 // will be added on top of the default file flags which are: |
| 73 // File::FLAG_CREATE_ALWAYS | 76 // File::FLAG_CREATE_ALWAYS |
| 74 // File::FLAG_WRITE | 77 // File::FLAG_WRITE |
| 75 // File::FLAG_TEMPORARY. | 78 // File::FLAG_TEMPORARY. |
| 76 // | 79 // |
| 77 // This returns false if task posting to |task_runner| has failed. | 80 // This returns false if task posting to |task_runner| has failed. |
| 78 bool CreateTemporary(uint32 additional_file_flags, | 81 bool CreateTemporary(uint32_t additional_file_flags, |
| 79 const CreateTemporaryCallback& callback); | 82 const CreateTemporaryCallback& callback); |
| 80 | 83 |
| 81 // Returns true if the underlying |file_| is valid. | 84 // Returns true if the underlying |file_| is valid. |
| 82 bool IsValid() const; | 85 bool IsValid() const; |
| 83 | 86 |
| 84 // Returns true if a new file was created (or an old one truncated to zero | 87 // Returns true if a new file was created (or an old one truncated to zero |
| 85 // length to simulate a new file), and false otherwise. | 88 // length to simulate a new file), and false otherwise. |
| 86 bool created() const { return file_.created(); } | 89 bool created() const { return file_.created(); } |
| 87 | 90 |
| 88 // Claims ownership of |file|. It is an error to call this method when | 91 // Claims ownership of |file|. It is an error to call this method when |
| 89 // IsValid() returns true. | 92 // IsValid() returns true. |
| 90 void SetFile(File file); | 93 void SetFile(File file); |
| 91 | 94 |
| 92 File TakeFile(); | 95 File TakeFile(); |
| 93 | 96 |
| 94 PlatformFile GetPlatformFile() const; | 97 PlatformFile GetPlatformFile() const; |
| 95 | 98 |
| 96 // Proxies File::Close. The callback can be null. | 99 // Proxies File::Close. The callback can be null. |
| 97 // This returns false if task posting to |task_runner| has failed. | 100 // This returns false if task posting to |task_runner| has failed. |
| 98 bool Close(const StatusCallback& callback); | 101 bool Close(const StatusCallback& callback); |
| 99 | 102 |
| 100 // Proxies File::GetInfo. The callback can't be null. | 103 // Proxies File::GetInfo. The callback can't be null. |
| 101 // This returns false if task posting to |task_runner| has failed. | 104 // This returns false if task posting to |task_runner| has failed. |
| 102 bool GetInfo(const GetFileInfoCallback& callback); | 105 bool GetInfo(const GetFileInfoCallback& callback); |
| 103 | 106 |
| 104 // Proxies File::Read. The callback can't be null. | 107 // Proxies File::Read. The callback can't be null. |
| 105 // This returns false if |bytes_to_read| is less than zero, or | 108 // This returns false if |bytes_to_read| is less than zero, or |
| 106 // if task posting to |task_runner| has failed. | 109 // if task posting to |task_runner| has failed. |
| 107 bool Read(int64 offset, int bytes_to_read, const ReadCallback& callback); | 110 bool Read(int64_t offset, int bytes_to_read, const ReadCallback& callback); |
| 108 | 111 |
| 109 // Proxies File::Write. The callback can be null. | 112 // Proxies File::Write. The callback can be null. |
| 110 // This returns false if |bytes_to_write| is less than or equal to zero, | 113 // This returns false if |bytes_to_write| is less than or equal to zero, |
| 111 // if |buffer| is NULL, or if task posting to |task_runner| has failed. | 114 // if |buffer| is NULL, or if task posting to |task_runner| has failed. |
| 112 bool Write(int64 offset, | 115 bool Write(int64_t offset, |
| 113 const char* buffer, | 116 const char* buffer, |
| 114 int bytes_to_write, | 117 int bytes_to_write, |
| 115 const WriteCallback& callback); | 118 const WriteCallback& callback); |
| 116 | 119 |
| 117 // Proxies File::SetTimes. The callback can be null. | 120 // Proxies File::SetTimes. The callback can be null. |
| 118 // This returns false if task posting to |task_runner| has failed. | 121 // This returns false if task posting to |task_runner| has failed. |
| 119 bool SetTimes(Time last_access_time, | 122 bool SetTimes(Time last_access_time, |
| 120 Time last_modified_time, | 123 Time last_modified_time, |
| 121 const StatusCallback& callback); | 124 const StatusCallback& callback); |
| 122 | 125 |
| 123 // Proxies File::SetLength. The callback can be null. | 126 // Proxies File::SetLength. The callback can be null. |
| 124 // This returns false if task posting to |task_runner| has failed. | 127 // This returns false if task posting to |task_runner| has failed. |
| 125 bool SetLength(int64 length, const StatusCallback& callback); | 128 bool SetLength(int64_t length, const StatusCallback& callback); |
| 126 | 129 |
| 127 // Proxies File::Flush. The callback can be null. | 130 // Proxies File::Flush. The callback can be null. |
| 128 // This returns false if task posting to |task_runner| has failed. | 131 // This returns false if task posting to |task_runner| has failed. |
| 129 bool Flush(const StatusCallback& callback); | 132 bool Flush(const StatusCallback& callback); |
| 130 | 133 |
| 131 private: | 134 private: |
| 132 friend class FileHelper; | 135 friend class FileHelper; |
| 133 TaskRunner* task_runner() { return task_runner_.get(); } | 136 TaskRunner* task_runner() { return task_runner_.get(); } |
| 134 | 137 |
| 135 scoped_refptr<TaskRunner> task_runner_; | 138 scoped_refptr<TaskRunner> task_runner_; |
| 136 File file_; | 139 File file_; |
| 137 DISALLOW_COPY_AND_ASSIGN(FileProxy); | 140 DISALLOW_COPY_AND_ASSIGN(FileProxy); |
| 138 }; | 141 }; |
| 139 | 142 |
| 140 } // namespace base | 143 } // namespace base |
| 141 | 144 |
| 142 #endif // BASE_FILES_FILE_PROXY_H_ | 145 #endif // BASE_FILES_FILE_PROXY_H_ |
| OLD | NEW |