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

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

Powered by Google App Engine
This is Rietveld 408576698