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 does NOT perform automatic proxying to close the underlying file | 28 // This class performs automatic proxying to close the underlying file at |
29 // at destruction, which means that it may potentially close the file in the | 29 // destruction. |
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. | |
33 // | 30 // |
34 // The TaskRunner is in charge of any sequencing of the operations, but a single | 31 // The TaskRunner is in charge of any sequencing of the operations, but a single |
35 // operation can be proxied at a time, regardless of the use of a callback. | 32 // operation can be proxied at a time, regardless of the use of a callback. |
36 // In other words, having a sequence like | 33 // In other words, having a sequence like |
37 // | 34 // |
38 // proxy.Write(...); | 35 // proxy.Write(...); |
39 // delete proxy; | 36 // delete proxy; |
40 // | 37 // |
41 // will keep the file valid during the Write operation but will cause the file | 38 // will keep the file valid during the Write operation but will cause the file |
42 // to be closed in the current thread, when the operation finishes. If Close is | 39 // 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... | |
124 // This returns false if task posting to |task_runner| has failed. | 121 // This returns false if task posting to |task_runner| has failed. |
125 bool SetLength(int64 length, const StatusCallback& callback); | 122 bool SetLength(int64 length, const StatusCallback& callback); |
126 | 123 |
127 // Proxies File::Flush. The callback can be null. | 124 // Proxies File::Flush. The callback can be null. |
128 // This returns false if task posting to |task_runner| has failed. | 125 // This returns false if task posting to |task_runner| has failed. |
129 bool Flush(const StatusCallback& callback); | 126 bool Flush(const StatusCallback& callback); |
130 | 127 |
131 private: | 128 private: |
132 friend class FileHelper; | 129 friend class FileHelper; |
133 void SetFile(File file); | 130 void SetFile(File file); |
131 TaskRunner* task_runner() { return task_runner_.get(); } | |
willchan no longer on Chromium
2014/04/10 20:27:47
I don't really care, but why not just access the t
rvargas (doing something else)
2014/04/10 22:03:51
I think it's a little cleaner if friends' access g
| |
134 | 132 |
135 scoped_refptr<TaskRunner> task_runner_; | 133 scoped_refptr<TaskRunner> task_runner_; |
136 File file_; | 134 File file_; |
137 DISALLOW_COPY_AND_ASSIGN(FileProxy); | 135 DISALLOW_COPY_AND_ASSIGN(FileProxy); |
138 }; | 136 }; |
139 | 137 |
140 } // namespace base | 138 } // namespace base |
141 | 139 |
142 #endif // BASE_FILES_FILE_PROXY_H_ | 140 #endif // BASE_FILES_FILE_PROXY_H_ |
OLD | NEW |