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

Side by Side Diff: ppapi/proxy/file_io_resource.h

Issue 304513007: Remove PlatformFile from ppapi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « ppapi/nacl_irt/ppapi_dispatcher.h ('k') | ppapi/proxy/file_io_resource.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) 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 #ifndef PPAPI_PROXY_FILE_IO_RESOURCE_H_ 5 #ifndef PPAPI_PROXY_FILE_IO_RESOURCE_H_
6 #define PPAPI_PROXY_FILE_IO_RESOURCE_H_ 6 #define PPAPI_PROXY_FILE_IO_RESOURCE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/files/file.h" 10 #include "base/files/file.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 virtual int64_t GetAppendModeWriteAmount() const OVERRIDE; 62 virtual int64_t GetAppendModeWriteAmount() const OVERRIDE;
63 virtual void SetMaxWrittenOffset(int64_t max_written_offset) OVERRIDE; 63 virtual void SetMaxWrittenOffset(int64_t max_written_offset) OVERRIDE;
64 virtual void SetAppendModeWriteAmount( 64 virtual void SetAppendModeWriteAmount(
65 int64_t append_mode_write_amount) OVERRIDE; 65 int64_t append_mode_write_amount) OVERRIDE;
66 virtual int32_t Flush(scoped_refptr<TrackedCallback> callback) OVERRIDE; 66 virtual int32_t Flush(scoped_refptr<TrackedCallback> callback) OVERRIDE;
67 virtual void Close() OVERRIDE; 67 virtual void Close() OVERRIDE;
68 virtual int32_t RequestOSFileHandle( 68 virtual int32_t RequestOSFileHandle(
69 PP_FileHandle* handle, 69 PP_FileHandle* handle,
70 scoped_refptr<TrackedCallback> callback) OVERRIDE; 70 scoped_refptr<TrackedCallback> callback) OVERRIDE;
71 71
72 // FileHandleHolder is used to guarantee that file operations will have a 72 // FileHolder is used to guarantee that file operations will have a valid FD
73 // valid FD to operate on, even if they're in a different thread. 73 // to operate on, even if they're in a different thread.
74 // If instead we just passed the raw FD, the FD could be closed before the 74 // If instead we just passed the raw FD, the FD could be closed before the
75 // file operation has a chance to run. It could interact with an invalid FD, 75 // file operation has a chance to run. It could interact with an invalid FD,
76 // or worse, the FD value could be reused if another file is opened quickly 76 // or worse, the FD value could be reused if another file is opened quickly
77 // (POSIX is required to provide the lowest available value when opening a 77 // (POSIX is required to provide the lowest available value when opening a
78 // file). This could result in strange problems such as writing data to the 78 // file). This could result in strange problems such as writing data to the
79 // wrong file. 79 // wrong file.
80 // 80 //
81 // Operations that run on a background thread should hold one of these to 81 // Operations that run on a background thread should hold one of these to
82 // ensure they have a valid file descriptor. The file handle is only closed 82 // ensure they have a valid file descriptor. The file handle is only closed
83 // when the last reference to the FileHandleHolder is removed, so we are 83 // when the last reference to the FileHolder is removed, so we are guaranteed
84 // guaranteed to operate on the correct file descriptor. It *is* still 84 // to operate on the correct file descriptor. It *is* still possible that the
85 // possible that the FileIOResource will be destroyed and "Abort" callbacks 85 // FileIOResource will be destroyed and "Abort" callbacks just before the
86 // just before the operation does its task (e.g., Reading). In that case, we 86 // operation does its task (e.g., Reading). In that case, we might for example
87 // might for example Read from a file even though the FileIO has been 87 // Read from a file even though the FileIO has been destroyed and the plugin's
88 // destroyed and the plugin's callback got a PP_ERROR_ABORTED result. In the 88 // callback got a PP_ERROR_ABORTED result. In the case of a write, we could
89 // case of a write, we could write some data to the file despite the plugin 89 // write some data to the file despite the plugin receiving a
90 // receiving a PP_ERROR_ABORTED instead of a successful result. 90 // PP_ERROR_ABORTED instead of a successful result.
91 class FileHandleHolder : public base::RefCountedThreadSafe<FileHandleHolder> { 91 class FileHolder : public base::RefCountedThreadSafe<FileHolder> {
92 public: 92 public:
93 explicit FileHandleHolder(PP_FileHandle file_handle_); 93 explicit FileHolder(PP_FileHandle file_handle);
94 PP_FileHandle raw_handle() { 94 base::File* file() {
95 return raw_handle_; 95 return &file_;
96 } 96 }
97 static bool IsValid( 97 static bool IsValid(
98 const scoped_refptr<FileIOResource::FileHandleHolder>& handle); 98 const scoped_refptr<FileIOResource::FileHolder>& handle);
99 private: 99 private:
100 friend class base::RefCountedThreadSafe<FileHandleHolder>; 100 friend class base::RefCountedThreadSafe<FileHolder>;
101 ~FileHandleHolder(); 101 ~FileHolder();
102 PP_FileHandle raw_handle_; 102 base::File file_;
103 }; 103 };
104 scoped_refptr<FileHandleHolder> file_handle() { 104
105 return file_handle_; 105 scoped_refptr<FileHolder> file_holder() {
106 return file_holder_;
106 } 107 }
107 108
108 private: 109 private:
109 // Class to perform file query operations across multiple threads. 110 // Class to perform file query operations across multiple threads.
110 class QueryOp : public base::RefCountedThreadSafe<QueryOp> { 111 class QueryOp : public base::RefCountedThreadSafe<QueryOp> {
111 public: 112 public:
112 explicit QueryOp(scoped_refptr<FileHandleHolder> file_handle); 113 explicit QueryOp(scoped_refptr<FileHolder> file_holder);
113 114
114 // Queries the file. Called on the file thread (non-blocking) or the plugin 115 // Queries the file. Called on the file thread (non-blocking) or the plugin
115 // thread (blocking). This should not be called when we hold the proxy lock. 116 // thread (blocking). This should not be called when we hold the proxy lock.
116 int32_t DoWork(); 117 int32_t DoWork();
117 118
118 const base::File::Info& file_info() const { return file_info_; } 119 const base::File::Info& file_info() const { return file_info_; }
119 120
120 private: 121 private:
121 friend class base::RefCountedThreadSafe<QueryOp>; 122 friend class base::RefCountedThreadSafe<QueryOp>;
122 ~QueryOp(); 123 ~QueryOp();
123 124
124 scoped_refptr<FileHandleHolder> file_handle_; 125 scoped_refptr<FileHolder> file_holder_;
125 base::File::Info file_info_; 126 base::File::Info file_info_;
126 }; 127 };
127 128
128 // Class to perform file read operations across multiple threads. 129 // Class to perform file read operations across multiple threads.
129 class ReadOp : public base::RefCountedThreadSafe<ReadOp> { 130 class ReadOp : public base::RefCountedThreadSafe<ReadOp> {
130 public: 131 public:
131 ReadOp(scoped_refptr<FileHandleHolder> file_handle, 132 ReadOp(scoped_refptr<FileHolder> file_holder,
132 int64_t offset, 133 int64_t offset,
133 int32_t bytes_to_read); 134 int32_t bytes_to_read);
134 135
135 // Reads the file. Called on the file thread (non-blocking) or the plugin 136 // Reads the file. Called on the file thread (non-blocking) or the plugin
136 // thread (blocking). This should not be called when we hold the proxy lock. 137 // thread (blocking). This should not be called when we hold the proxy lock.
137 int32_t DoWork(); 138 int32_t DoWork();
138 139
139 char* buffer() const { return buffer_.get(); } 140 char* buffer() const { return buffer_.get(); }
140 141
141 private: 142 private:
142 friend class base::RefCountedThreadSafe<ReadOp>; 143 friend class base::RefCountedThreadSafe<ReadOp>;
143 ~ReadOp(); 144 ~ReadOp();
144 145
145 scoped_refptr<FileHandleHolder> file_handle_; 146 scoped_refptr<FileHolder> file_holder_;
146 int64_t offset_; 147 int64_t offset_;
147 int32_t bytes_to_read_; 148 int32_t bytes_to_read_;
148 scoped_ptr<char[]> buffer_; 149 scoped_ptr<char[]> buffer_;
149 }; 150 };
150 151
151 // Class to perform file write operations across multiple threads. 152 // Class to perform file write operations across multiple threads.
152 class WriteOp : public base::RefCountedThreadSafe<WriteOp> { 153 class WriteOp : public base::RefCountedThreadSafe<WriteOp> {
153 public: 154 public:
154 WriteOp(scoped_refptr<FileHandleHolder> file_handle, 155 WriteOp(scoped_refptr<FileHolder> file_holder,
155 int64_t offset, 156 int64_t offset,
156 scoped_ptr<char[]> buffer, 157 scoped_ptr<char[]> buffer,
157 int32_t bytes_to_write, 158 int32_t bytes_to_write,
158 bool append); 159 bool append);
159 160
160 // Writes the file. Called on the file thread (non-blocking) or the plugin 161 // Writes the file. Called on the file thread (non-blocking) or the plugin
161 // thread (blocking). This should not be called when we hold the proxy lock. 162 // thread (blocking). This should not be called when we hold the proxy lock.
162 int32_t DoWork(); 163 int32_t DoWork();
163 164
164 private: 165 private:
165 friend class base::RefCountedThreadSafe<WriteOp>; 166 friend class base::RefCountedThreadSafe<WriteOp>;
166 ~WriteOp(); 167 ~WriteOp();
167 168
168 scoped_refptr<FileHandleHolder> file_handle_; 169 scoped_refptr<FileHolder> file_holder_;
169 int64_t offset_; 170 int64_t offset_;
170 scoped_ptr<char[]> buffer_; 171 scoped_ptr<char[]> buffer_;
171 int32_t bytes_to_write_; 172 int32_t bytes_to_write_;
172 bool append_; 173 bool append_;
173 }; 174 };
174 175
175 void OnRequestWriteQuotaComplete(int64_t offset, 176 void OnRequestWriteQuotaComplete(int64_t offset,
176 scoped_ptr<char[]> buffer, 177 scoped_ptr<char[]> buffer,
177 int32_t bytes_to_write, 178 int32_t bytes_to_write,
178 scoped_refptr<TrackedCallback> callback, 179 scoped_refptr<TrackedCallback> callback,
(...skipping 27 matching lines...) Expand all
206 const ResourceMessageReplyParams& params); 207 const ResourceMessageReplyParams& params);
207 void OnPluginMsgOpenFileComplete(scoped_refptr<TrackedCallback> callback, 208 void OnPluginMsgOpenFileComplete(scoped_refptr<TrackedCallback> callback,
208 const ResourceMessageReplyParams& params, 209 const ResourceMessageReplyParams& params,
209 PP_Resource quota_file_system, 210 PP_Resource quota_file_system,
210 int64_t max_written_offset); 211 int64_t max_written_offset);
211 void OnPluginMsgRequestOSFileHandleComplete( 212 void OnPluginMsgRequestOSFileHandleComplete(
212 scoped_refptr<TrackedCallback> callback, 213 scoped_refptr<TrackedCallback> callback,
213 PP_FileHandle* output_handle, 214 PP_FileHandle* output_handle,
214 const ResourceMessageReplyParams& params); 215 const ResourceMessageReplyParams& params);
215 216
216 scoped_refptr<FileHandleHolder> file_handle_; 217 scoped_refptr<FileHolder> file_holder_;
217 PP_FileSystemType file_system_type_; 218 PP_FileSystemType file_system_type_;
218 scoped_refptr<Resource> file_system_resource_; 219 scoped_refptr<Resource> file_system_resource_;
219 FileIOStateManager state_manager_; 220 FileIOStateManager state_manager_;
220 221
221 scoped_refptr<Resource> file_ref_; 222 scoped_refptr<Resource> file_ref_;
222 223
223 int32_t open_flags_; 224 int32_t open_flags_;
224 int64_t max_written_offset_; 225 int64_t max_written_offset_;
225 int64_t append_mode_write_amount_; 226 int64_t append_mode_write_amount_;
226 bool check_quota_; 227 bool check_quota_;
227 bool called_close_; 228 bool called_close_;
228 229
229 DISALLOW_COPY_AND_ASSIGN(FileIOResource); 230 DISALLOW_COPY_AND_ASSIGN(FileIOResource);
230 }; 231 };
231 232
232 } // namespace proxy 233 } // namespace proxy
233 } // namespace ppapi 234 } // namespace ppapi
234 235
235 #endif // PPAPI_PROXY_FILE_IO_RESOURCE_H_ 236 #endif // PPAPI_PROXY_FILE_IO_RESOURCE_H_
OLDNEW
« no previous file with comments | « ppapi/nacl_irt/ppapi_dispatcher.h ('k') | ppapi/proxy/file_io_resource.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698