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 "ppapi/proxy/file_io_resource.h" | 5 #include "ppapi/proxy/file_io_resource.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/task_runner_util.h" | 8 #include "base/task_runner_util.h" |
9 #include "ipc/ipc_message.h" | 9 #include "ipc/ipc_message.h" |
10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 int32_t FileIOResource::ReadOp::DoWork() { | 71 int32_t FileIOResource::ReadOp::DoWork() { |
72 DCHECK(!buffer_.get()); | 72 DCHECK(!buffer_.get()); |
73 buffer_.reset(new char[bytes_to_read_]); | 73 buffer_.reset(new char[bytes_to_read_]); |
74 return base::ReadPlatformFile( | 74 return base::ReadPlatformFile( |
75 file_handle_->raw_handle(), offset_, buffer_.get(), bytes_to_read_); | 75 file_handle_->raw_handle(), offset_, buffer_.get(), bytes_to_read_); |
76 } | 76 } |
77 | 77 |
78 FileIOResource::FileIOResource(Connection connection, PP_Instance instance) | 78 FileIOResource::FileIOResource(Connection connection, PP_Instance instance) |
79 : PluginResource(connection, instance), | 79 : PluginResource(connection, instance), |
80 file_system_type_(PP_FILESYSTEMTYPE_INVALID) { | 80 file_system_type_(PP_FILESYSTEMTYPE_INVALID) { |
81 SendCreate(RENDERER, PpapiHostMsg_FileIO_Create()); | 81 SendCreate(BROWSER, PpapiHostMsg_FileIO_Create()); |
82 } | 82 } |
83 | 83 |
84 FileIOResource::~FileIOResource() { | 84 FileIOResource::~FileIOResource() { |
85 } | 85 } |
86 | 86 |
87 PPB_FileIO_API* FileIOResource::AsPPB_FileIO_API() { | 87 PPB_FileIO_API* FileIOResource::AsPPB_FileIO_API() { |
88 return this; | 88 return this; |
89 } | 89 } |
90 | 90 |
91 int32_t FileIOResource::Open(PP_Resource file_ref, | 91 int32_t FileIOResource::Open(PP_Resource file_ref, |
(...skipping 16 matching lines...) Expand all Loading... |
108 | 108 |
109 int32_t rv = state_manager_.CheckOperationState( | 109 int32_t rv = state_manager_.CheckOperationState( |
110 FileIOStateManager::OPERATION_EXCLUSIVE, false); | 110 FileIOStateManager::OPERATION_EXCLUSIVE, false); |
111 if (rv != PP_OK) | 111 if (rv != PP_OK) |
112 return rv; | 112 return rv; |
113 | 113 |
114 // Take a reference on the FileRef resource while we're opening the file; we | 114 // Take a reference on the FileRef resource while we're opening the file; we |
115 // don't want the plugin destroying it during the Open operation. | 115 // don't want the plugin destroying it during the Open operation. |
116 file_ref_ = enter.resource(); | 116 file_ref_ = enter.resource(); |
117 | 117 |
118 Call<PpapiPluginMsg_FileIO_OpenReply>(RENDERER, | 118 Call<PpapiPluginMsg_FileIO_OpenReply>(BROWSER, |
119 PpapiHostMsg_FileIO_Open( | 119 PpapiHostMsg_FileIO_Open( |
120 file_ref, | 120 file_ref, |
121 open_flags), | 121 open_flags), |
122 base::Bind(&FileIOResource::OnPluginMsgOpenFileComplete, this, | 122 base::Bind(&FileIOResource::OnPluginMsgOpenFileComplete, this, |
123 callback)); | 123 callback)); |
124 | 124 |
125 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 125 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
126 return PP_OK_COMPLETIONPENDING; | 126 return PP_OK_COMPLETIONPENDING; |
127 } | 127 } |
128 | 128 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 165 } |
166 | 166 |
167 int32_t FileIOResource::Touch(PP_Time last_access_time, | 167 int32_t FileIOResource::Touch(PP_Time last_access_time, |
168 PP_Time last_modified_time, | 168 PP_Time last_modified_time, |
169 scoped_refptr<TrackedCallback> callback) { | 169 scoped_refptr<TrackedCallback> callback) { |
170 int32_t rv = state_manager_.CheckOperationState( | 170 int32_t rv = state_manager_.CheckOperationState( |
171 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 171 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
172 if (rv != PP_OK) | 172 if (rv != PP_OK) |
173 return rv; | 173 return rv; |
174 | 174 |
175 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, | 175 Call<PpapiPluginMsg_FileIO_GeneralReply>(BROWSER, |
176 PpapiHostMsg_FileIO_Touch(last_access_time, last_modified_time), | 176 PpapiHostMsg_FileIO_Touch(last_access_time, last_modified_time), |
177 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, | 177 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, |
178 callback)); | 178 callback)); |
179 | 179 |
180 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 180 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
181 return PP_OK_COMPLETIONPENDING; | 181 return PP_OK_COMPLETIONPENDING; |
182 } | 182 } |
183 | 183 |
184 int32_t FileIOResource::Read(int64_t offset, | 184 int32_t FileIOResource::Read(int64_t offset, |
185 char* buffer, | 185 char* buffer, |
(...skipping 28 matching lines...) Expand all Loading... |
214 int32_t bytes_to_write, | 214 int32_t bytes_to_write, |
215 scoped_refptr<TrackedCallback> callback) { | 215 scoped_refptr<TrackedCallback> callback) { |
216 int32_t rv = state_manager_.CheckOperationState( | 216 int32_t rv = state_manager_.CheckOperationState( |
217 FileIOStateManager::OPERATION_WRITE, true); | 217 FileIOStateManager::OPERATION_WRITE, true); |
218 if (rv != PP_OK) | 218 if (rv != PP_OK) |
219 return rv; | 219 return rv; |
220 | 220 |
221 // TODO(brettw) it would be nice to use a shared memory buffer for large | 221 // TODO(brettw) it would be nice to use a shared memory buffer for large |
222 // writes rather than having to copy to a string (which will involve a number | 222 // writes rather than having to copy to a string (which will involve a number |
223 // of extra copies to serialize over IPC). | 223 // of extra copies to serialize over IPC). |
224 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, | 224 Call<PpapiPluginMsg_FileIO_GeneralReply>(BROWSER, |
225 PpapiHostMsg_FileIO_Write(offset, std::string(buffer, bytes_to_write)), | 225 PpapiHostMsg_FileIO_Write(offset, std::string(buffer, bytes_to_write)), |
226 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, | 226 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, |
227 callback)); | 227 callback)); |
228 | 228 |
229 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_WRITE); | 229 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_WRITE); |
230 return PP_OK_COMPLETIONPENDING; | 230 return PP_OK_COMPLETIONPENDING; |
231 } | 231 } |
232 | 232 |
233 int32_t FileIOResource::SetLength(int64_t length, | 233 int32_t FileIOResource::SetLength(int64_t length, |
234 scoped_refptr<TrackedCallback> callback) { | 234 scoped_refptr<TrackedCallback> callback) { |
235 int32_t rv = state_manager_.CheckOperationState( | 235 int32_t rv = state_manager_.CheckOperationState( |
236 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 236 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
237 if (rv != PP_OK) | 237 if (rv != PP_OK) |
238 return rv; | 238 return rv; |
239 | 239 |
240 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, | 240 Call<PpapiPluginMsg_FileIO_GeneralReply>(BROWSER, |
241 PpapiHostMsg_FileIO_SetLength(length), | 241 PpapiHostMsg_FileIO_SetLength(length), |
242 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, | 242 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, |
243 callback)); | 243 callback)); |
244 | 244 |
245 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 245 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
246 return PP_OK_COMPLETIONPENDING; | 246 return PP_OK_COMPLETIONPENDING; |
247 } | 247 } |
248 | 248 |
249 int32_t FileIOResource::Flush(scoped_refptr<TrackedCallback> callback) { | 249 int32_t FileIOResource::Flush(scoped_refptr<TrackedCallback> callback) { |
250 int32_t rv = state_manager_.CheckOperationState( | 250 int32_t rv = state_manager_.CheckOperationState( |
251 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 251 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
252 if (rv != PP_OK) | 252 if (rv != PP_OK) |
253 return rv; | 253 return rv; |
254 | 254 |
255 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, | 255 Call<PpapiPluginMsg_FileIO_GeneralReply>(BROWSER, |
256 PpapiHostMsg_FileIO_Flush(), | 256 PpapiHostMsg_FileIO_Flush(), |
257 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, | 257 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, |
258 callback)); | 258 callback)); |
259 | 259 |
260 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 260 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
261 return PP_OK_COMPLETIONPENDING; | 261 return PP_OK_COMPLETIONPENDING; |
262 } | 262 } |
263 | 263 |
264 void FileIOResource::Close() { | 264 void FileIOResource::Close() { |
265 if (file_handle_) { | 265 if (file_handle_) { |
266 file_handle_ = NULL; | 266 file_handle_ = NULL; |
267 } | 267 } |
268 Post(RENDERER, PpapiHostMsg_FileIO_Close()); | 268 Post(BROWSER, PpapiHostMsg_FileIO_Close()); |
269 } | 269 } |
270 | 270 |
271 int32_t FileIOResource::RequestOSFileHandle( | 271 int32_t FileIOResource::RequestOSFileHandle( |
272 PP_FileHandle* handle, | 272 PP_FileHandle* handle, |
273 scoped_refptr<TrackedCallback> callback) { | 273 scoped_refptr<TrackedCallback> callback) { |
274 int32_t rv = state_manager_.CheckOperationState( | 274 int32_t rv = state_manager_.CheckOperationState( |
275 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 275 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
276 if (rv != PP_OK) | 276 if (rv != PP_OK) |
277 return rv; | 277 return rv; |
278 | 278 |
279 Call<PpapiPluginMsg_FileIO_RequestOSFileHandleReply>(RENDERER, | 279 Call<PpapiPluginMsg_FileIO_RequestOSFileHandleReply>(BROWSER, |
280 PpapiHostMsg_FileIO_RequestOSFileHandle(), | 280 PpapiHostMsg_FileIO_RequestOSFileHandle(), |
281 base::Bind(&FileIOResource::OnPluginMsgRequestOSFileHandleComplete, this, | 281 base::Bind(&FileIOResource::OnPluginMsgRequestOSFileHandleComplete, this, |
282 callback, handle)); | 282 callback, handle)); |
283 | 283 |
284 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 284 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
285 return PP_OK_COMPLETIONPENDING; | 285 return PP_OK_COMPLETIONPENDING; |
286 } | 286 } |
287 | 287 |
288 FileIOResource::FileHandleHolder::FileHandleHolder(PP_FileHandle file_handle) | 288 FileIOResource::FileHandleHolder::FileHandleHolder(PP_FileHandle file_handle) |
289 : raw_handle_(file_handle) { | 289 : raw_handle_(file_handle) { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); | 431 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); |
432 | 432 |
433 // End this operation now, so the user's callback can execute another FileIO | 433 // End this operation now, so the user's callback can execute another FileIO |
434 // operation, assuming there are no other pending operations. | 434 // operation, assuming there are no other pending operations. |
435 state_manager_.SetOperationFinished(); | 435 state_manager_.SetOperationFinished(); |
436 callback->Run(result); | 436 callback->Run(result); |
437 } | 437 } |
438 | 438 |
439 } // namespace proxy | 439 } // namespace proxy |
440 } // namespace ppapi | 440 } // namespace ppapi |
OLD | NEW |