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

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

Issue 18063005: Do PPB_FileIO Query and Read in the plugin process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rethink - Just optimize the blocking callback case. Created 7 years, 4 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/proxy/file_io_resource.h ('k') | ppapi/shared_impl/tracked_callback.h » ('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 #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 }
bbudge 2013/08/07 19:05:38 We could eliminate this and the file thread if we
dmichael (off chromium) 2013/08/08 17:44:44 I'm not sure. I'd look around at how ClosePlatform
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 {
102 ProxyAutoUnlock unlock;
103 result = base::GetPlatformFileInfo(file_handle_, &file_info) ?
104 PP_OK : PP_ERROR_FAILED;
105 }
106 if ((result == PP_OK) && TrackedCallback::IsPending(callback)) {
107 ppapi::PlatformFileInfoToPepperFileInfo(file_info, file_system_type_,
108 info);
109 }
110
111 // End the operation now. The callback may perform another file operation.
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
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
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 scoped_ptr<char[]> buffer(new char[bytes_to_read]);
284 {
285 ProxyAutoUnlock unlock;
286 int32_t bytes_read = base::ReadPlatformFile(
287 file_handle_, offset, buffer.get(), bytes_to_read);
288 result = (bytes_read >= 0) ? bytes_read : PP_ERROR_FAILED;
289 }
290 if ((result >= 0) && TrackedCallback::IsPending(callback)) {
291 ArrayWriter output;
292 output.set_pp_array_output(array_output);
293 if (output.is_valid())
294 output.StoreArray(buffer.get(), result);
295 else
296 result = PP_ERROR_FAILED;
297 }
298 }
299
300 // End the operation now. The callback may perform another file operation.
301 state_manager_.SetOperationFinished();
302 return result;
303 }
304
220 Call<PpapiPluginMsg_FileIO_ReadReply>(RENDERER, 305 Call<PpapiPluginMsg_FileIO_ReadReply>(RENDERER,
221 PpapiHostMsg_FileIO_Read(offset, bytes_to_read), 306 PpapiHostMsg_FileIO_Read(offset, bytes_to_read),
222 base::Bind(&FileIOResource::OnPluginMsgReadComplete, this, 307 base::Bind(&FileIOResource::OnPluginMsgReadComplete, this,
223 callback, array_output)); 308 callback, array_output));
224 return PP_OK_COMPLETIONPENDING; 309 return PP_OK_COMPLETIONPENDING;
225 } 310 }
226 311
227 int32_t FileIOResource::RequestOSFileHandle( 312 void FileIOResource::CloseFileHandle() {
228 PP_FileHandle* handle, 313 if (file_handle_ != base::kInvalidPlatformFileValue) {
229 scoped_refptr<TrackedCallback> callback) { 314 base::TaskRunner* file_task_runner =
230 int32_t rv = state_manager_.CheckOperationState( 315 PpapiGlobals::Get()->GetFileTaskRunner(pp_instance());
231 FileIOStateManager::OPERATION_EXCLUSIVE, true); 316 file_task_runner->PostTask(FROM_HERE,
232 if (rv != PP_OK) 317 base::Bind(&DoClose, file_handle_));
233 return rv;
234 318
235 Call<PpapiPluginMsg_FileIO_RequestOSFileHandleReply>(RENDERER, 319 file_handle_ = base::kInvalidPlatformFileValue;
236 PpapiHostMsg_FileIO_RequestOSFileHandle(), 320 }
237 base::Bind(&FileIOResource::OnPluginMsgRequestOSFileHandleComplete, this,
238 callback, handle));
239
240 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
241 return PP_OK_COMPLETIONPENDING;
242 } 321 }
243 322
244 void FileIOResource::OnPluginMsgGeneralComplete( 323 void FileIOResource::OnPluginMsgGeneralComplete(
245 scoped_refptr<TrackedCallback> callback, 324 scoped_refptr<TrackedCallback> callback,
246 const ResourceMessageReplyParams& params) { 325 const ResourceMessageReplyParams& params) {
247 DCHECK(state_manager_.get_pending_operation() == 326 DCHECK(state_manager_.get_pending_operation() ==
248 FileIOStateManager::OPERATION_EXCLUSIVE || 327 FileIOStateManager::OPERATION_EXCLUSIVE ||
249 state_manager_.get_pending_operation() == 328 state_manager_.get_pending_operation() ==
250 FileIOStateManager::OPERATION_WRITE); 329 FileIOStateManager::OPERATION_WRITE);
251 // End the operation now. The callback may perform another file operation. 330 // End this operation now, so the user's callback can execute another FileIO
331 // operation, assuming there are no other pending operations.
252 state_manager_.SetOperationFinished(); 332 state_manager_.SetOperationFinished();
253 callback->Run(params.result()); 333 callback->Run(params.result());
254 } 334 }
255 335
256 void FileIOResource::OnPluginMsgOpenFileComplete( 336 void FileIOResource::OnPluginMsgOpenFileComplete(
257 scoped_refptr<TrackedCallback> callback, 337 scoped_refptr<TrackedCallback> callback,
258 const ResourceMessageReplyParams& params) { 338 const ResourceMessageReplyParams& params) {
259 DCHECK(state_manager_.get_pending_operation() == 339 DCHECK(state_manager_.get_pending_operation() ==
260 FileIOStateManager::OPERATION_EXCLUSIVE); 340 FileIOStateManager::OPERATION_EXCLUSIVE);
261 if (params.result() == PP_OK) 341 if (params.result() == PP_OK)
262 state_manager_.SetOpenSucceed(); 342 state_manager_.SetOpenSucceed();
263 // End the operation now. The callback may perform another file operation. 343
344 int32_t result = params.result();
345 IPC::PlatformFileForTransit transit_file;
346 if ((result == PP_OK) && params.TakeFileHandleAtIndex(0, &transit_file))
347 file_handle_ = IPC::PlatformFileForTransitToPlatformFile(transit_file);
348 // End this operation now, so the user's callback can execute another FileIO
349 // operation, assuming there are no other pending operations.
264 state_manager_.SetOperationFinished(); 350 state_manager_.SetOperationFinished();
265 callback->Run(params.result()); 351 callback->Run(result);
266 } 352 }
267 353
268 void FileIOResource::OnPluginMsgQueryComplete( 354 void FileIOResource::OnPluginMsgQueryComplete(
269 scoped_refptr<TrackedCallback> callback, 355 scoped_refptr<TrackedCallback> callback,
270 PP_FileInfo* output_info, 356 PP_FileInfo* output_info,
271 const ResourceMessageReplyParams& params, 357 const ResourceMessageReplyParams& params,
272 const PP_FileInfo& info) { 358 const PP_FileInfo& info) {
273 DCHECK(state_manager_.get_pending_operation() == 359 DCHECK(state_manager_.get_pending_operation() ==
274 FileIOStateManager::OPERATION_EXCLUSIVE); 360 FileIOStateManager::OPERATION_EXCLUSIVE);
275 *output_info = info; 361 *output_info = info;
276 // End the operation now. The callback may perform another file operation. 362 // End this operation now, so the user's callback can execute another FileIO
363 // operation, assuming there are no other pending operations.
277 state_manager_.SetOperationFinished(); 364 state_manager_.SetOperationFinished();
278 callback->Run(params.result()); 365 callback->Run(params.result());
279 } 366 }
280 367
281 void FileIOResource::OnPluginMsgReadComplete( 368 void FileIOResource::OnPluginMsgReadComplete(
282 scoped_refptr<TrackedCallback> callback, 369 scoped_refptr<TrackedCallback> callback,
283 PP_ArrayOutput array_output, 370 PP_ArrayOutput array_output,
284 const ResourceMessageReplyParams& params, 371 const ResourceMessageReplyParams& params,
285 const std::string& data) { 372 const std::string& data) {
286 DCHECK(state_manager_.get_pending_operation() == 373 DCHECK(state_manager_.get_pending_operation() ==
287 FileIOStateManager::OPERATION_READ); 374 FileIOStateManager::OPERATION_READ);
288 375
289 // The result code should contain the data size if it's positive. 376 // The result code should contain the data size if it's positive.
290 int32_t result = params.result(); 377 int32_t result = params.result();
291 DCHECK((result < 0 && data.size() == 0) || 378 DCHECK((result < 0 && data.size() == 0) ||
292 result == static_cast<int32_t>(data.size())); 379 result == static_cast<int32_t>(data.size()));
293 380
294 ArrayWriter output; 381 ArrayWriter output;
295 output.set_pp_array_output(array_output); 382 output.set_pp_array_output(array_output);
296 if (output.is_valid()) 383 if (output.is_valid())
297 output.StoreArray(data.data(), std::max(0, result)); 384 output.StoreArray(data.data(), std::max(0, result));
298 else 385 else
299 result = PP_ERROR_FAILED; 386 result = PP_ERROR_FAILED;
300 387
301 // End the operation now. The callback may perform another file operation. 388 // End this operation now, so the user's callback can execute another FileIO
389 // operation, assuming there are no other pending operations.
302 state_manager_.SetOperationFinished(); 390 state_manager_.SetOperationFinished();
303 callback->Run(result); 391 callback->Run(result);
304 } 392 }
305 393
306 void FileIOResource::OnPluginMsgRequestOSFileHandleComplete( 394 void FileIOResource::OnPluginMsgRequestOSFileHandleComplete(
307 scoped_refptr<TrackedCallback> callback, 395 scoped_refptr<TrackedCallback> callback,
308 PP_FileHandle* output_handle, 396 PP_FileHandle* output_handle,
309 const ResourceMessageReplyParams& params) { 397 const ResourceMessageReplyParams& params) {
310 DCHECK(state_manager_.get_pending_operation() == 398 DCHECK(state_manager_.get_pending_operation() ==
311 FileIOStateManager::OPERATION_EXCLUSIVE); 399 FileIOStateManager::OPERATION_EXCLUSIVE);
312 400
313 if (!TrackedCallback::IsPending(callback)) { 401 if (!TrackedCallback::IsPending(callback)) {
314 state_manager_.SetOperationFinished(); 402 state_manager_.SetOperationFinished();
315 return; 403 return;
316 } 404 }
317 405
318 int32_t result = params.result(); 406 int32_t result = params.result();
319 IPC::PlatformFileForTransit transit_file; 407 IPC::PlatformFileForTransit transit_file;
320 if (!params.TakeFileHandleAtIndex(0, &transit_file)) 408 if (!params.TakeFileHandleAtIndex(0, &transit_file))
321 result = PP_ERROR_FAILED; 409 result = PP_ERROR_FAILED;
322 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); 410 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file);
323 411
324 // End the operation now. The callback may perform another file operation. 412 // End this operation now, so the user's callback can execute another FileIO
413 // operation, assuming there are no other pending operations.
325 state_manager_.SetOperationFinished(); 414 state_manager_.SetOperationFinished();
326 callback->Run(result); 415 callback->Run(result);
327 } 416 }
328 417
329 } // namespace proxy 418 } // namespace proxy
330 } // namespace ppapi 419 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/file_io_resource.h ('k') | ppapi/shared_impl/tracked_callback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698