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 "ipc/ipc_message.h" | 8 #include "ipc/ipc_message.h" |
9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
10 #include "ppapi/proxy/ppapi_messages.h" | 10 #include "ppapi/proxy/ppapi_messages.h" |
11 #include "ppapi/shared_impl/array_writer.h" | 11 #include "ppapi/shared_impl/array_writer.h" |
| 12 #include "ppapi/shared_impl/file_type_conversion.h" |
12 #include "ppapi/shared_impl/ppapi_globals.h" | 13 #include "ppapi/shared_impl/ppapi_globals.h" |
| 14 #include "ppapi/shared_impl/proxy_lock.h" |
13 #include "ppapi/shared_impl/resource_tracker.h" | 15 #include "ppapi/shared_impl/resource_tracker.h" |
14 #include "ppapi/thunk/enter.h" | 16 #include "ppapi/thunk/enter.h" |
15 #include "ppapi/thunk/ppb_file_ref_api.h" | 17 #include "ppapi/thunk/ppb_file_ref_api.h" |
16 | 18 |
17 using ppapi::thunk::EnterResourceNoLock; | 19 using ppapi::thunk::EnterResourceNoLock; |
18 using ppapi::thunk::PPB_FileIO_API; | 20 using ppapi::thunk::PPB_FileIO_API; |
19 using ppapi::thunk::PPB_FileRef_API; | 21 using ppapi::thunk::PPB_FileRef_API; |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 // An adapter to let Read() share the same implementation with ReadToArray(). | 25 // An adapter to let Read() share the same implementation with ReadToArray(). |
24 void* DummyGetDataBuffer(void* user_data, uint32_t count, uint32_t size) { | 26 void* DummyGetDataBuffer(void* user_data, uint32_t count, uint32_t size) { |
25 return user_data; | 27 return user_data; |
26 } | 28 } |
27 | 29 |
| 30 // File thread task to close the file handle. |
| 31 void DoClose(base::PlatformFile file) { |
| 32 base::ClosePlatformFile(file); |
| 33 } |
| 34 |
28 } // namespace | 35 } // namespace |
29 | 36 |
30 namespace ppapi { | 37 namespace ppapi { |
31 namespace proxy { | 38 namespace proxy { |
32 | 39 |
33 FileIOResource::FileIOResource(Connection connection, PP_Instance instance) | 40 FileIOResource::FileIOResource(Connection connection, PP_Instance instance) |
34 : PluginResource(connection, instance) { | 41 : PluginResource(connection, instance), |
| 42 file_handle_(base::kInvalidPlatformFileValue), |
| 43 file_system_type_(PP_FILESYSTEMTYPE_INVALID) { |
35 SendCreate(RENDERER, PpapiHostMsg_FileIO_Create()); | 44 SendCreate(RENDERER, PpapiHostMsg_FileIO_Create()); |
36 } | 45 } |
37 | 46 |
38 FileIOResource::~FileIOResource() { | 47 FileIOResource::~FileIOResource() { |
| 48 CloseFileHandle(); |
39 } | 49 } |
40 | 50 |
41 PPB_FileIO_API* FileIOResource::AsPPB_FileIO_API() { | 51 PPB_FileIO_API* FileIOResource::AsPPB_FileIO_API() { |
42 return this; | 52 return this; |
43 } | 53 } |
44 | 54 |
45 int32_t FileIOResource::Open(PP_Resource file_ref, | 55 int32_t FileIOResource::Open(PP_Resource file_ref, |
46 int32_t open_flags, | 56 int32_t open_flags, |
47 scoped_refptr<TrackedCallback> callback) { | 57 scoped_refptr<TrackedCallback> callback) { |
48 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, true); | 58 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, true); |
49 if (enter.failed()) | 59 if (enter.failed()) |
50 return PP_ERROR_BADRESOURCE; | 60 return PP_ERROR_BADRESOURCE; |
51 | 61 |
| 62 PPB_FileRef_API* file_ref_api = enter.object(); |
| 63 PP_FileSystemType type = file_ref_api->GetFileSystemType(); |
| 64 if (type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && |
| 65 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY && |
| 66 type != PP_FILESYSTEMTYPE_EXTERNAL && |
| 67 type != PP_FILESYSTEMTYPE_ISOLATED) { |
| 68 NOTREACHED(); |
| 69 return PP_ERROR_FAILED; |
| 70 } |
| 71 file_system_type_ = type; |
| 72 |
52 int32_t rv = state_manager_.CheckOperationState( | 73 int32_t rv = state_manager_.CheckOperationState( |
53 FileIOStateManager::OPERATION_EXCLUSIVE, false); | 74 FileIOStateManager::OPERATION_EXCLUSIVE, false); |
54 if (rv != PP_OK) | 75 if (rv != PP_OK) |
55 return rv; | 76 return rv; |
56 | 77 |
57 Call<PpapiPluginMsg_FileIO_OpenReply>(RENDERER, | 78 Call<PpapiPluginMsg_FileIO_OpenReply>(RENDERER, |
58 PpapiHostMsg_FileIO_Open( | 79 PpapiHostMsg_FileIO_Open( |
59 enter.resource()->host_resource().host_resource(), | 80 enter.resource()->host_resource().host_resource(), |
60 open_flags), | 81 open_flags), |
61 base::Bind(&FileIOResource::OnPluginMsgOpenFileComplete, this, | 82 base::Bind(&FileIOResource::OnPluginMsgOpenFileComplete, this, |
62 callback)); | 83 callback)); |
63 | 84 |
64 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 85 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
65 return PP_OK_COMPLETIONPENDING; | 86 return PP_OK_COMPLETIONPENDING; |
66 } | 87 } |
67 | 88 |
68 int32_t FileIOResource::Query(PP_FileInfo* info, | 89 int32_t FileIOResource::Query(PP_FileInfo* info, |
69 scoped_refptr<TrackedCallback> callback) { | 90 scoped_refptr<TrackedCallback> callback) { |
70 int32_t rv = state_manager_.CheckOperationState( | 91 int32_t rv = state_manager_.CheckOperationState( |
71 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 92 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
72 if (rv != PP_OK) | 93 if (rv != PP_OK) |
73 return rv; | 94 return rv; |
74 | 95 |
| 96 if (callback->is_blocking() && |
| 97 file_handle_ != base::kInvalidPlatformFileValue) { |
| 98 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
| 99 int32_t result = PP_ERROR_FAILED; |
| 100 base::PlatformFileInfo file_info; |
| 101 // Release the proxy lock while making a potentially blocking file call. |
| 102 { |
| 103 ProxyAutoUnlock unlock; |
| 104 result = base::GetPlatformFileInfo(file_handle_, &file_info) ? |
| 105 PP_OK : PP_ERROR_FAILED; |
| 106 } |
| 107 if ((result == PP_OK) && TrackedCallback::IsPending(callback)) { |
| 108 ppapi::PlatformFileInfoToPepperFileInfo(file_info, file_system_type_, |
| 109 info); |
| 110 } |
| 111 |
| 112 state_manager_.SetOperationFinished(); |
| 113 return result; |
| 114 } |
| 115 |
75 Call<PpapiPluginMsg_FileIO_QueryReply>(RENDERER, | 116 Call<PpapiPluginMsg_FileIO_QueryReply>(RENDERER, |
76 PpapiHostMsg_FileIO_Query(), | 117 PpapiHostMsg_FileIO_Query(), |
77 base::Bind(&FileIOResource::OnPluginMsgQueryComplete, this, | 118 base::Bind(&FileIOResource::OnPluginMsgQueryComplete, this, |
78 callback, info)); | 119 callback, info)); |
79 | 120 |
80 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 121 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
81 return PP_OK_COMPLETIONPENDING; | 122 return PP_OK_COMPLETIONPENDING; |
82 } | 123 } |
83 | 124 |
84 int32_t FileIOResource::Touch(PP_Time last_access_time, | 125 int32_t FileIOResource::Touch(PP_Time last_access_time, |
(...skipping 18 matching lines...) Expand all Loading... |
103 int32_t bytes_to_read, | 144 int32_t bytes_to_read, |
104 scoped_refptr<TrackedCallback> callback) { | 145 scoped_refptr<TrackedCallback> callback) { |
105 int32_t rv = state_manager_.CheckOperationState( | 146 int32_t rv = state_manager_.CheckOperationState( |
106 FileIOStateManager::OPERATION_READ, true); | 147 FileIOStateManager::OPERATION_READ, true); |
107 if (rv != PP_OK) | 148 if (rv != PP_OK) |
108 return rv; | 149 return rv; |
109 | 150 |
110 PP_ArrayOutput output_adapter; | 151 PP_ArrayOutput output_adapter; |
111 output_adapter.GetDataBuffer = &DummyGetDataBuffer; | 152 output_adapter.GetDataBuffer = &DummyGetDataBuffer; |
112 output_adapter.user_data = buffer; | 153 output_adapter.user_data = buffer; |
113 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_READ); | |
114 return ReadValidated(offset, bytes_to_read, output_adapter, callback); | 154 return ReadValidated(offset, bytes_to_read, output_adapter, callback); |
115 } | 155 } |
116 | 156 |
117 int32_t FileIOResource::ReadToArray(int64_t offset, | 157 int32_t FileIOResource::ReadToArray(int64_t offset, |
118 int32_t max_read_length, | 158 int32_t max_read_length, |
119 PP_ArrayOutput* array_output, | 159 PP_ArrayOutput* array_output, |
120 scoped_refptr<TrackedCallback> callback) { | 160 scoped_refptr<TrackedCallback> callback) { |
121 DCHECK(array_output); | 161 DCHECK(array_output); |
122 int32_t rv = state_manager_.CheckOperationState( | 162 int32_t rv = state_manager_.CheckOperationState( |
123 FileIOStateManager::OPERATION_READ, true); | 163 FileIOStateManager::OPERATION_READ, true); |
124 if (rv != PP_OK) | 164 if (rv != PP_OK) |
125 return rv; | 165 return rv; |
126 | 166 |
127 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_READ); | |
128 return ReadValidated(offset, max_read_length, *array_output, callback); | 167 return ReadValidated(offset, max_read_length, *array_output, callback); |
129 } | 168 } |
130 | 169 |
131 int32_t FileIOResource::Write(int64_t offset, | 170 int32_t FileIOResource::Write(int64_t offset, |
132 const char* buffer, | 171 const char* buffer, |
133 int32_t bytes_to_write, | 172 int32_t bytes_to_write, |
134 scoped_refptr<TrackedCallback> callback) { | 173 scoped_refptr<TrackedCallback> callback) { |
135 int32_t rv = state_manager_.CheckOperationState( | 174 int32_t rv = state_manager_.CheckOperationState( |
136 FileIOStateManager::OPERATION_WRITE, true); | 175 FileIOStateManager::OPERATION_WRITE, true); |
137 if (rv != PP_OK) | 176 if (rv != PP_OK) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, | 213 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, |
175 PpapiHostMsg_FileIO_Flush(), | 214 PpapiHostMsg_FileIO_Flush(), |
176 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, | 215 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, |
177 callback)); | 216 callback)); |
178 | 217 |
179 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 218 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
180 return PP_OK_COMPLETIONPENDING; | 219 return PP_OK_COMPLETIONPENDING; |
181 } | 220 } |
182 | 221 |
183 void FileIOResource::Close() { | 222 void FileIOResource::Close() { |
| 223 CloseFileHandle(); |
184 Post(RENDERER, PpapiHostMsg_FileIO_Close()); | 224 Post(RENDERER, PpapiHostMsg_FileIO_Close()); |
185 } | 225 } |
186 | 226 |
187 int32_t FileIOResource::GetOSFileDescriptor() { | 227 int32_t FileIOResource::GetOSFileDescriptor() { |
188 int32_t file_descriptor; | 228 int32_t file_descriptor; |
189 // Only available when running in process. | 229 // Only available when running in process. |
190 SyncCall<PpapiPluginMsg_FileIO_GetOSFileDescriptorReply>( | 230 SyncCall<PpapiPluginMsg_FileIO_GetOSFileDescriptorReply>( |
191 RENDERER, PpapiHostMsg_FileIO_GetOSFileDescriptor(), &file_descriptor); | 231 RENDERER, PpapiHostMsg_FileIO_GetOSFileDescriptor(), &file_descriptor); |
192 return file_descriptor; | 232 return file_descriptor; |
193 } | 233 } |
194 | 234 |
| 235 int32_t FileIOResource::RequestOSFileHandle( |
| 236 PP_FileHandle* handle, |
| 237 scoped_refptr<TrackedCallback> callback) { |
| 238 int32_t rv = state_manager_.CheckOperationState( |
| 239 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
| 240 if (rv != PP_OK) |
| 241 return rv; |
| 242 |
| 243 Call<PpapiPluginMsg_FileIO_RequestOSFileHandleReply>(RENDERER, |
| 244 PpapiHostMsg_FileIO_RequestOSFileHandle(), |
| 245 base::Bind(&FileIOResource::OnPluginMsgRequestOSFileHandleComplete, this, |
| 246 callback, handle)); |
| 247 |
| 248 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
| 249 return PP_OK_COMPLETIONPENDING; |
| 250 } |
| 251 |
195 int32_t FileIOResource::WillWrite(int64_t offset, | 252 int32_t FileIOResource::WillWrite(int64_t offset, |
196 int32_t bytes_to_write, | 253 int32_t bytes_to_write, |
197 scoped_refptr<TrackedCallback> callback) { | 254 scoped_refptr<TrackedCallback> callback) { |
198 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, | 255 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, |
199 PpapiHostMsg_FileIO_WillWrite(offset, bytes_to_write), | 256 PpapiHostMsg_FileIO_WillWrite(offset, bytes_to_write), |
200 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, | 257 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, callback)); |
201 callback)); | 258 |
202 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 259 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
203 return PP_OK_COMPLETIONPENDING; | 260 return PP_OK_COMPLETIONPENDING; |
204 } | 261 } |
205 | 262 |
206 int32_t FileIOResource::WillSetLength(int64_t length, | 263 int32_t FileIOResource::WillSetLength(int64_t length, |
207 scoped_refptr<TrackedCallback> callback) { | 264 scoped_refptr<TrackedCallback> callback) { |
208 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, | 265 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, |
209 PpapiHostMsg_FileIO_WillSetLength(length), | 266 PpapiHostMsg_FileIO_WillSetLength(length), |
210 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, | 267 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, callback)); |
211 callback)); | 268 |
212 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 269 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
213 return PP_OK_COMPLETIONPENDING; | 270 return PP_OK_COMPLETIONPENDING; |
214 } | 271 } |
215 | 272 |
216 int32_t FileIOResource::ReadValidated(int64_t offset, | 273 int32_t FileIOResource::ReadValidated(int64_t offset, |
217 int32_t bytes_to_read, | 274 int32_t bytes_to_read, |
218 const PP_ArrayOutput& array_output, | 275 const PP_ArrayOutput& array_output, |
219 scoped_refptr<TrackedCallback> callback) { | 276 scoped_refptr<TrackedCallback> callback) { |
| 277 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_READ); |
| 278 |
| 279 if (callback->is_blocking() && |
| 280 file_handle_ != base::kInvalidPlatformFileValue) { |
| 281 int32_t result = PP_ERROR_FAILED; |
| 282 if (bytes_to_read >= 0) { |
| 283 // We need a buffer (and therefore we must copy) since we don't know until |
| 284 // reacquire the lock whether to write data to the plugin's buffer. |
| 285 scoped_ptr<char[]> buffer; |
| 286 // Release the proxy lock while making a potentially blocking file call. |
| 287 { |
| 288 ProxyAutoUnlock unlock; |
| 289 buffer.reset(new char[bytes_to_read]); |
| 290 int32_t bytes_read = base::ReadPlatformFile( |
| 291 file_handle_, offset, buffer.get(), bytes_to_read); |
| 292 result = (bytes_read < 0) ? PP_ERROR_FAILED : bytes_read; |
| 293 } |
| 294 if ((result >= 0) && TrackedCallback::IsPending(callback)) { |
| 295 ArrayWriter output; |
| 296 output.set_pp_array_output(array_output); |
| 297 if (output.is_valid()) |
| 298 output.StoreArray(buffer.get(), result); |
| 299 else |
| 300 result = PP_ERROR_FAILED; |
| 301 } |
| 302 } |
| 303 |
| 304 state_manager_.SetOperationFinished(); |
| 305 return result; |
| 306 } |
| 307 |
220 Call<PpapiPluginMsg_FileIO_ReadReply>(RENDERER, | 308 Call<PpapiPluginMsg_FileIO_ReadReply>(RENDERER, |
221 PpapiHostMsg_FileIO_Read(offset, bytes_to_read), | 309 PpapiHostMsg_FileIO_Read(offset, bytes_to_read), |
222 base::Bind(&FileIOResource::OnPluginMsgReadComplete, this, | 310 base::Bind(&FileIOResource::OnPluginMsgReadComplete, this, |
223 callback, array_output)); | 311 callback, array_output)); |
224 return PP_OK_COMPLETIONPENDING; | 312 return PP_OK_COMPLETIONPENDING; |
225 } | 313 } |
226 | 314 |
227 int32_t FileIOResource::RequestOSFileHandle( | 315 void FileIOResource::CloseFileHandle() { |
228 PP_FileHandle* handle, | 316 if (file_handle_ != base::kInvalidPlatformFileValue) { |
229 scoped_refptr<TrackedCallback> callback) { | 317 // Close our local fd on the file thread. |
230 int32_t rv = state_manager_.CheckOperationState( | 318 base::TaskRunner* file_task_runner = |
231 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 319 PpapiGlobals::Get()->GetFileTaskRunner(pp_instance()); |
232 if (rv != PP_OK) | 320 file_task_runner->PostTask(FROM_HERE, |
233 return rv; | 321 base::Bind(&DoClose, file_handle_)); |
234 | 322 |
235 Call<PpapiPluginMsg_FileIO_RequestOSFileHandleReply>(RENDERER, | 323 file_handle_ = base::kInvalidPlatformFileValue; |
236 PpapiHostMsg_FileIO_RequestOSFileHandle(), | 324 } |
237 base::Bind(&FileIOResource::OnPluginMsgRequestOSFileHandleComplete, this, | |
238 callback, handle)); | |
239 | |
240 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | |
241 return PP_OK_COMPLETIONPENDING; | |
242 } | 325 } |
243 | 326 |
244 void FileIOResource::OnPluginMsgGeneralComplete( | 327 void FileIOResource::OnPluginMsgGeneralComplete( |
245 scoped_refptr<TrackedCallback> callback, | 328 scoped_refptr<TrackedCallback> callback, |
246 const ResourceMessageReplyParams& params) { | 329 const ResourceMessageReplyParams& params) { |
247 DCHECK(state_manager_.get_pending_operation() == | 330 DCHECK(state_manager_.get_pending_operation() == |
248 FileIOStateManager::OPERATION_EXCLUSIVE || | 331 FileIOStateManager::OPERATION_EXCLUSIVE || |
249 state_manager_.get_pending_operation() == | 332 state_manager_.get_pending_operation() == |
250 FileIOStateManager::OPERATION_WRITE); | 333 FileIOStateManager::OPERATION_WRITE); |
251 // End the operation now. The callback may perform another file operation. | 334 // End this operation now, so the user's callback can execute another FileIO |
| 335 // operation, assuming there are no other pending operations. |
252 state_manager_.SetOperationFinished(); | 336 state_manager_.SetOperationFinished(); |
253 callback->Run(params.result()); | 337 callback->Run(params.result()); |
254 } | 338 } |
255 | 339 |
256 void FileIOResource::OnPluginMsgOpenFileComplete( | 340 void FileIOResource::OnPluginMsgOpenFileComplete( |
257 scoped_refptr<TrackedCallback> callback, | 341 scoped_refptr<TrackedCallback> callback, |
258 const ResourceMessageReplyParams& params) { | 342 const ResourceMessageReplyParams& params) { |
259 DCHECK(state_manager_.get_pending_operation() == | 343 DCHECK(state_manager_.get_pending_operation() == |
260 FileIOStateManager::OPERATION_EXCLUSIVE); | 344 FileIOStateManager::OPERATION_EXCLUSIVE); |
261 if (params.result() == PP_OK) | 345 if (params.result() == PP_OK) |
262 state_manager_.SetOpenSucceed(); | 346 state_manager_.SetOpenSucceed(); |
263 // End the operation now. The callback may perform another file operation. | 347 |
| 348 int32_t result = params.result(); |
| 349 IPC::PlatformFileForTransit transit_file; |
| 350 if ((result == PP_OK) && params.TakeFileHandleAtIndex(0, &transit_file)) |
| 351 file_handle_ = IPC::PlatformFileForTransitToPlatformFile(transit_file); |
| 352 // End this operation now, so the user's callback can execute another FileIO |
| 353 // operation, assuming there are no other pending operations. |
264 state_manager_.SetOperationFinished(); | 354 state_manager_.SetOperationFinished(); |
265 callback->Run(params.result()); | 355 callback->Run(result); |
266 } | 356 } |
267 | 357 |
268 void FileIOResource::OnPluginMsgQueryComplete( | 358 void FileIOResource::OnPluginMsgQueryComplete( |
269 scoped_refptr<TrackedCallback> callback, | 359 scoped_refptr<TrackedCallback> callback, |
270 PP_FileInfo* output_info, | 360 PP_FileInfo* output_info, |
271 const ResourceMessageReplyParams& params, | 361 const ResourceMessageReplyParams& params, |
272 const PP_FileInfo& info) { | 362 const PP_FileInfo& info) { |
273 DCHECK(state_manager_.get_pending_operation() == | 363 DCHECK(state_manager_.get_pending_operation() == |
274 FileIOStateManager::OPERATION_EXCLUSIVE); | 364 FileIOStateManager::OPERATION_EXCLUSIVE); |
275 *output_info = info; | 365 *output_info = info; |
276 // End the operation now. The callback may perform another file operation. | 366 // End this operation now, so the user's callback can execute another FileIO |
| 367 // operation, assuming there are no other pending operations. |
277 state_manager_.SetOperationFinished(); | 368 state_manager_.SetOperationFinished(); |
278 callback->Run(params.result()); | 369 callback->Run(params.result()); |
279 } | 370 } |
280 | 371 |
281 void FileIOResource::OnPluginMsgReadComplete( | 372 void FileIOResource::OnPluginMsgReadComplete( |
282 scoped_refptr<TrackedCallback> callback, | 373 scoped_refptr<TrackedCallback> callback, |
283 PP_ArrayOutput array_output, | 374 PP_ArrayOutput array_output, |
284 const ResourceMessageReplyParams& params, | 375 const ResourceMessageReplyParams& params, |
285 const std::string& data) { | 376 const std::string& data) { |
286 DCHECK(state_manager_.get_pending_operation() == | 377 DCHECK(state_manager_.get_pending_operation() == |
287 FileIOStateManager::OPERATION_READ); | 378 FileIOStateManager::OPERATION_READ); |
288 | 379 |
289 // The result code should contain the data size if it's positive. | 380 // The result code should contain the data size if it's positive. |
290 int32_t result = params.result(); | 381 int32_t result = params.result(); |
291 DCHECK((result < 0 && data.size() == 0) || | 382 DCHECK((result < 0 && data.size() == 0) || |
292 result == static_cast<int32_t>(data.size())); | 383 result == static_cast<int32_t>(data.size())); |
293 | 384 |
294 ArrayWriter output; | 385 ArrayWriter output; |
295 output.set_pp_array_output(array_output); | 386 output.set_pp_array_output(array_output); |
296 if (output.is_valid()) | 387 if (output.is_valid()) |
297 output.StoreArray(data.data(), std::max(0, result)); | 388 output.StoreArray(data.data(), std::max(0, result)); |
298 else | 389 else |
299 result = PP_ERROR_FAILED; | 390 result = PP_ERROR_FAILED; |
300 | 391 |
301 // End the operation now. The callback may perform another file operation. | 392 // End this operation now, so the user's callback can execute another FileIO |
| 393 // operation, assuming there are no other pending operations. |
302 state_manager_.SetOperationFinished(); | 394 state_manager_.SetOperationFinished(); |
303 callback->Run(result); | 395 callback->Run(result); |
304 } | 396 } |
305 | 397 |
306 void FileIOResource::OnPluginMsgRequestOSFileHandleComplete( | 398 void FileIOResource::OnPluginMsgRequestOSFileHandleComplete( |
307 scoped_refptr<TrackedCallback> callback, | 399 scoped_refptr<TrackedCallback> callback, |
308 PP_FileHandle* output_handle, | 400 PP_FileHandle* output_handle, |
309 const ResourceMessageReplyParams& params) { | 401 const ResourceMessageReplyParams& params) { |
310 DCHECK(state_manager_.get_pending_operation() == | 402 DCHECK(state_manager_.get_pending_operation() == |
311 FileIOStateManager::OPERATION_EXCLUSIVE); | 403 FileIOStateManager::OPERATION_EXCLUSIVE); |
312 | 404 |
313 if (!TrackedCallback::IsPending(callback)) { | 405 if (!TrackedCallback::IsPending(callback)) { |
314 state_manager_.SetOperationFinished(); | 406 state_manager_.SetOperationFinished(); |
315 return; | 407 return; |
316 } | 408 } |
317 | 409 |
318 int32_t result = params.result(); | 410 int32_t result = params.result(); |
319 IPC::PlatformFileForTransit transit_file; | 411 IPC::PlatformFileForTransit transit_file; |
320 if (!params.TakeFileHandleAtIndex(0, &transit_file)) | 412 if (!params.TakeFileHandleAtIndex(0, &transit_file)) |
321 result = PP_ERROR_FAILED; | 413 result = PP_ERROR_FAILED; |
322 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); | 414 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); |
323 | 415 |
324 // End the operation now. The callback may perform another file operation. | 416 // End this operation now, so the user's callback can execute another FileIO |
| 417 // operation, assuming there are no other pending operations. |
325 state_manager_.SetOperationFinished(); | 418 state_manager_.SetOperationFinished(); |
326 callback->Run(result); | 419 callback->Run(result); |
327 } | 420 } |
328 | 421 |
329 } // namespace proxy | 422 } // namespace proxy |
330 } // namespace ppapi | 423 } // namespace ppapi |
OLD | NEW |