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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 int32_t FileIOResource::ReadOp::DoWork() { | 72 int32_t FileIOResource::ReadOp::DoWork() { |
73 DCHECK(!buffer_.get()); | 73 DCHECK(!buffer_.get()); |
74 buffer_.reset(new char[bytes_to_read_]); | 74 buffer_.reset(new char[bytes_to_read_]); |
75 return base::ReadPlatformFile( | 75 return base::ReadPlatformFile( |
76 file_handle_->raw_handle(), offset_, buffer_.get(), bytes_to_read_); | 76 file_handle_->raw_handle(), offset_, buffer_.get(), bytes_to_read_); |
77 } | 77 } |
78 | 78 |
79 FileIOResource::FileIOResource(Connection connection, PP_Instance instance) | 79 FileIOResource::FileIOResource(Connection connection, PP_Instance instance) |
80 : PluginResource(connection, instance), | 80 : PluginResource(connection, instance), |
81 file_system_type_(PP_FILESYSTEMTYPE_INVALID) { | 81 file_system_type_(PP_FILESYSTEMTYPE_INVALID) { |
82 SendCreate(RENDERER, PpapiHostMsg_FileIO_Create()); | 82 SendCreate(BROWSER, PpapiHostMsg_FileIO_Create()); |
83 } | 83 } |
84 | 84 |
85 FileIOResource::~FileIOResource() { | 85 FileIOResource::~FileIOResource() { |
86 } | 86 } |
87 | 87 |
88 PPB_FileIO_API* FileIOResource::AsPPB_FileIO_API() { | 88 PPB_FileIO_API* FileIOResource::AsPPB_FileIO_API() { |
89 return this; | 89 return this; |
90 } | 90 } |
91 | 91 |
92 int32_t FileIOResource::Open(PP_Resource file_ref, | 92 int32_t FileIOResource::Open(PP_Resource file_ref, |
(...skipping 13 matching lines...) Expand all Loading... |
106 | 106 |
107 int32_t rv = state_manager_.CheckOperationState( | 107 int32_t rv = state_manager_.CheckOperationState( |
108 FileIOStateManager::OPERATION_EXCLUSIVE, false); | 108 FileIOStateManager::OPERATION_EXCLUSIVE, false); |
109 if (rv != PP_OK) | 109 if (rv != PP_OK) |
110 return rv; | 110 return rv; |
111 | 111 |
112 // Take a reference on the FileRef resource while we're opening the file; we | 112 // Take a reference on the FileRef resource while we're opening the file; we |
113 // don't want the plugin destroying it during the Open operation. | 113 // don't want the plugin destroying it during the Open operation. |
114 file_ref_ = enter.resource(); | 114 file_ref_ = enter.resource(); |
115 | 115 |
116 Call<PpapiPluginMsg_FileIO_OpenReply>(RENDERER, | 116 Call<PpapiPluginMsg_FileIO_OpenReply>(BROWSER, |
117 PpapiHostMsg_FileIO_Open( | 117 PpapiHostMsg_FileIO_Open( |
118 file_ref, | 118 file_ref, |
119 open_flags), | 119 open_flags), |
120 base::Bind(&FileIOResource::OnPluginMsgOpenFileComplete, this, | 120 base::Bind(&FileIOResource::OnPluginMsgOpenFileComplete, this, |
121 callback)); | 121 callback)); |
122 | 122 |
123 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 123 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
124 return PP_OK_COMPLETIONPENDING; | 124 return PP_OK_COMPLETIONPENDING; |
125 } | 125 } |
126 | 126 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } | 175 } |
176 | 176 |
177 int32_t FileIOResource::Touch(PP_Time last_access_time, | 177 int32_t FileIOResource::Touch(PP_Time last_access_time, |
178 PP_Time last_modified_time, | 178 PP_Time last_modified_time, |
179 scoped_refptr<TrackedCallback> callback) { | 179 scoped_refptr<TrackedCallback> callback) { |
180 int32_t rv = state_manager_.CheckOperationState( | 180 int32_t rv = state_manager_.CheckOperationState( |
181 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 181 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
182 if (rv != PP_OK) | 182 if (rv != PP_OK) |
183 return rv; | 183 return rv; |
184 | 184 |
185 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, | 185 Call<PpapiPluginMsg_FileIO_GeneralReply>(BROWSER, |
186 PpapiHostMsg_FileIO_Touch(last_access_time, last_modified_time), | 186 PpapiHostMsg_FileIO_Touch(last_access_time, last_modified_time), |
187 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, | 187 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, |
188 callback)); | 188 callback)); |
189 | 189 |
190 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 190 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
191 return PP_OK_COMPLETIONPENDING; | 191 return PP_OK_COMPLETIONPENDING; |
192 } | 192 } |
193 | 193 |
194 int32_t FileIOResource::Read(int64_t offset, | 194 int32_t FileIOResource::Read(int64_t offset, |
195 char* buffer, | 195 char* buffer, |
(...skipping 28 matching lines...) Expand all Loading... |
224 int32_t bytes_to_write, | 224 int32_t bytes_to_write, |
225 scoped_refptr<TrackedCallback> callback) { | 225 scoped_refptr<TrackedCallback> callback) { |
226 int32_t rv = state_manager_.CheckOperationState( | 226 int32_t rv = state_manager_.CheckOperationState( |
227 FileIOStateManager::OPERATION_WRITE, true); | 227 FileIOStateManager::OPERATION_WRITE, true); |
228 if (rv != PP_OK) | 228 if (rv != PP_OK) |
229 return rv; | 229 return rv; |
230 | 230 |
231 // TODO(brettw) it would be nice to use a shared memory buffer for large | 231 // TODO(brettw) it would be nice to use a shared memory buffer for large |
232 // writes rather than having to copy to a string (which will involve a number | 232 // writes rather than having to copy to a string (which will involve a number |
233 // of extra copies to serialize over IPC). | 233 // of extra copies to serialize over IPC). |
234 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, | 234 Call<PpapiPluginMsg_FileIO_GeneralReply>(BROWSER, |
235 PpapiHostMsg_FileIO_Write(offset, std::string(buffer, bytes_to_write)), | 235 PpapiHostMsg_FileIO_Write(offset, std::string(buffer, bytes_to_write)), |
236 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, | 236 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, |
237 callback)); | 237 callback)); |
238 | 238 |
239 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_WRITE); | 239 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_WRITE); |
240 return PP_OK_COMPLETIONPENDING; | 240 return PP_OK_COMPLETIONPENDING; |
241 } | 241 } |
242 | 242 |
243 int32_t FileIOResource::SetLength(int64_t length, | 243 int32_t FileIOResource::SetLength(int64_t length, |
244 scoped_refptr<TrackedCallback> callback) { | 244 scoped_refptr<TrackedCallback> callback) { |
245 int32_t rv = state_manager_.CheckOperationState( | 245 int32_t rv = state_manager_.CheckOperationState( |
246 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 246 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
247 if (rv != PP_OK) | 247 if (rv != PP_OK) |
248 return rv; | 248 return rv; |
249 | 249 |
250 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, | 250 Call<PpapiPluginMsg_FileIO_GeneralReply>(BROWSER, |
251 PpapiHostMsg_FileIO_SetLength(length), | 251 PpapiHostMsg_FileIO_SetLength(length), |
252 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, | 252 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, |
253 callback)); | 253 callback)); |
254 | 254 |
255 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 255 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
256 return PP_OK_COMPLETIONPENDING; | 256 return PP_OK_COMPLETIONPENDING; |
257 } | 257 } |
258 | 258 |
259 int32_t FileIOResource::Flush(scoped_refptr<TrackedCallback> callback) { | 259 int32_t FileIOResource::Flush(scoped_refptr<TrackedCallback> callback) { |
260 int32_t rv = state_manager_.CheckOperationState( | 260 int32_t rv = state_manager_.CheckOperationState( |
261 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 261 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
262 if (rv != PP_OK) | 262 if (rv != PP_OK) |
263 return rv; | 263 return rv; |
264 | 264 |
265 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, | 265 Call<PpapiPluginMsg_FileIO_GeneralReply>(BROWSER, |
266 PpapiHostMsg_FileIO_Flush(), | 266 PpapiHostMsg_FileIO_Flush(), |
267 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, | 267 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, |
268 callback)); | 268 callback)); |
269 | 269 |
270 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 270 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
271 return PP_OK_COMPLETIONPENDING; | 271 return PP_OK_COMPLETIONPENDING; |
272 } | 272 } |
273 | 273 |
274 void FileIOResource::Close() { | 274 void FileIOResource::Close() { |
275 if (file_handle_) { | 275 if (file_handle_) { |
276 file_handle_ = NULL; | 276 file_handle_ = NULL; |
277 } | 277 } |
278 Post(RENDERER, PpapiHostMsg_FileIO_Close()); | 278 Post(BROWSER, PpapiHostMsg_FileIO_Close()); |
279 } | 279 } |
280 | 280 |
281 int32_t FileIOResource::RequestOSFileHandle( | 281 int32_t FileIOResource::RequestOSFileHandle( |
282 PP_FileHandle* handle, | 282 PP_FileHandle* handle, |
283 scoped_refptr<TrackedCallback> callback) { | 283 scoped_refptr<TrackedCallback> callback) { |
284 int32_t rv = state_manager_.CheckOperationState( | 284 int32_t rv = state_manager_.CheckOperationState( |
285 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 285 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
286 if (rv != PP_OK) | 286 if (rv != PP_OK) |
287 return rv; | 287 return rv; |
288 | 288 |
289 Call<PpapiPluginMsg_FileIO_RequestOSFileHandleReply>(RENDERER, | 289 Call<PpapiPluginMsg_FileIO_RequestOSFileHandleReply>(BROWSER, |
290 PpapiHostMsg_FileIO_RequestOSFileHandle(), | 290 PpapiHostMsg_FileIO_RequestOSFileHandle(), |
291 base::Bind(&FileIOResource::OnPluginMsgRequestOSFileHandleComplete, this, | 291 base::Bind(&FileIOResource::OnPluginMsgRequestOSFileHandleComplete, this, |
292 callback, handle)); | 292 callback, handle)); |
293 | 293 |
294 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 294 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
295 return PP_OK_COMPLETIONPENDING; | 295 return PP_OK_COMPLETIONPENDING; |
296 } | 296 } |
297 | 297 |
298 FileIOResource::FileHandleHolder::FileHandleHolder(PP_FileHandle file_handle) | 298 FileIOResource::FileHandleHolder::FileHandleHolder(PP_FileHandle file_handle) |
299 : raw_handle_(file_handle) { | 299 : raw_handle_(file_handle) { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); | 450 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); |
451 | 451 |
452 // End this operation now, so the user's callback can execute another FileIO | 452 // End this operation now, so the user's callback can execute another FileIO |
453 // operation, assuming there are no other pending operations. | 453 // operation, assuming there are no other pending operations. |
454 state_manager_.SetOperationFinished(); | 454 state_manager_.SetOperationFinished(); |
455 callback->Run(result); | 455 callback->Run(result); |
456 } | 456 } |
457 | 457 |
458 } // namespace proxy | 458 } // namespace proxy |
459 } // namespace ppapi | 459 } // namespace ppapi |
OLD | NEW |