| 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 "base/base_export.h" | 8 #include "base/base_export.h" |
| 9 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 | 14 |
| 15 namespace tracked_objects { | 15 namespace tracked_objects { |
| 16 class Location; | 16 class Location; |
| 17 }; | 17 }; |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 | 20 |
| 21 class TaskRunner; | 21 class TaskRunner; |
| 22 class Time; | 22 class Time; |
| 23 | 23 |
| 24 // This class provides asynchronous access to a File. All methods follow the | 24 // This class provides asynchronous access to a File. All methods follow the |
| 25 // same rules of the equivalent File method, as they are implemented by bouncing | 25 // same rules of the equivalent File method, as they are implemented by bouncing |
| 26 // the operation to File using a TaskRunner. | 26 // the operation to File using a TaskRunner. |
| 27 // | 27 // |
| 28 // This class performs automatic proxying to close the underlying file at | 28 // This class does NOT perform automatic proxying to close the underlying file |
| 29 // destruction. | 29 // at destruction, which means that it may potentially close the file in the |
| 30 // wrong thread (the current thread). If that is not appropriate, the caller |
| 31 // must ensure that Close() is called, so that the operation happens on the |
| 32 // desired thread. |
| 30 // | 33 // |
| 31 // The TaskRunner is in charge of any sequencing of the operations, but a single | 34 // The TaskRunner is in charge of any sequencing of the operations, but a single |
| 32 // operation can be proxied at a time, regardless of the use of a callback. | 35 // operation can be proxied at a time, regardless of the use of a callback. |
| 33 // In other words, having a sequence like | 36 // In other words, having a sequence like |
| 34 // | 37 // |
| 35 // proxy.Write(...); | 38 // proxy.Write(...); |
| 36 // delete proxy; | 39 // delete proxy; |
| 37 // | 40 // |
| 38 // will keep the file valid during the Write operation but will cause the file | 41 // will keep the file valid during the Write operation but will cause the file |
| 39 // to be closed in the current thread, when the operation finishes. If Close is | 42 // to be closed in the current thread, when the operation finishes. If Close is |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // This returns false if task posting to |task_runner| has failed. | 124 // This returns false if task posting to |task_runner| has failed. |
| 122 bool SetLength(int64 length, const StatusCallback& callback); | 125 bool SetLength(int64 length, const StatusCallback& callback); |
| 123 | 126 |
| 124 // Proxies File::Flush. The callback can be null. | 127 // Proxies File::Flush. The callback can be null. |
| 125 // This returns false if task posting to |task_runner| has failed. | 128 // This returns false if task posting to |task_runner| has failed. |
| 126 bool Flush(const StatusCallback& callback); | 129 bool Flush(const StatusCallback& callback); |
| 127 | 130 |
| 128 private: | 131 private: |
| 129 friend class FileHelper; | 132 friend class FileHelper; |
| 130 void SetFile(File file); | 133 void SetFile(File file); |
| 131 TaskRunner* task_runner() { return task_runner_.get(); } | |
| 132 | 134 |
| 133 scoped_refptr<TaskRunner> task_runner_; | 135 scoped_refptr<TaskRunner> task_runner_; |
| 134 File file_; | 136 File file_; |
| 135 DISALLOW_COPY_AND_ASSIGN(FileProxy); | 137 DISALLOW_COPY_AND_ASSIGN(FileProxy); |
| 136 }; | 138 }; |
| 137 | 139 |
| 138 } // namespace base | 140 } // namespace base |
| 139 | 141 |
| 140 #endif // BASE_FILES_FILE_PROXY_H_ | 142 #endif // BASE_FILES_FILE_PROXY_H_ |
| OLD | NEW |